Skip to content

Commit

Permalink
Merge pull request #633 from ferriarnus/paintedanchor
Browse files Browse the repository at this point in the history
Paintable Travel Anchor
  • Loading branch information
ferriarnus authored Mar 13, 2024
2 parents 1124735 + e81aba5 commit 9db69e7
Show file tree
Hide file tree
Showing 18 changed files with 261 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "enderio:block/painted_travel_anchor"
}
}
}
1 change: 1 addition & 0 deletions src/generated/resources/assets/enderio/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
"block.enderio.painted_slab": "Painted Slab",
"block.enderio.painted_stairs": "Painted Stairs",
"block.enderio.painted_trapdoor": "Painted Trapdoor",
"block.enderio.painted_travel_anchor": "Painted Travel Anchor",
"block.enderio.painted_wooden_pressure_plate": "Painted Wooden Pressure Plate",
"block.enderio.painting_machine": "Painting Machine",
"block.enderio.powered_light": "Powered Light",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"loader": "enderio:painted_block",
"reference": "minecraft:dirt"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "enderio:block/painted_travel_anchor"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"entries": [
{
"type": "minecraft:item",
"functions": [
{
"function": "minecraft:copy_nbt",
"ops": [
{
"op": "replace",
"source": "Paint",
"target": "BlockEntityTag.Paint"
}
],
"source": "block_entity"
}
],
"name": "enderio:painted_travel_anchor"
}
],
"rolls": 1.0
}
],
"random_sequence": "enderio:blocks/painted_travel_anchor"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "enderio:painting",
"input": {
"item": "enderio:travel_anchor"
},
"output": "enderio:painted_travel_anchor"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "enderio:painting",
"input": {
"item": "enderio:painted_travel_anchor"
},
"output": "enderio:painted_travel_anchor"
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"enderio:vacuum_chest",
"enderio:xp_vacuum",
"enderio:travel_anchor",
"enderio:painted_travel_anchor",
"enderio:energetic_photovoltaic_module",
"enderio:pulsating_photovoltaic_module",
"enderio:vibrant_photovoltaic_module",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"enderio:vacuum_chest",
"enderio:xp_vacuum",
"enderio:travel_anchor",
"enderio:painted_travel_anchor",
"enderio:crafter",
"enderio:soul_engine",
"enderio:drain",
Expand Down
1 change: 0 additions & 1 deletion src/machines/java/com/enderio/machines/EIOMachines.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import net.minecraft.data.DataGenerator;
import net.minecraft.data.PackOutput;
import net.minecraft.data.registries.VanillaRegistries;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.InterModComms;
import net.neoforged.fml.ModLoadingContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.enderio.machines.client.rendering.travel;

import com.enderio.api.travel.TravelRenderer;
import com.enderio.machines.common.blockentity.PaintedTravelAnchorBlockEntity;
import com.enderio.machines.common.init.MachineBlocks;
import com.enderio.machines.common.travel.AnchorTravelTarget;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
Expand Down Expand Up @@ -46,6 +48,9 @@ public void render(AnchorTravelTarget travelData, LevelRenderer levelRenderer, P

// Render Model
BlockState blockState = minecraft.level.getBlockState(travelData.getPos());
if (minecraft.level.getBlockEntity(travelData.getPos()) instanceof PaintedTravelAnchorBlockEntity paintedTravelAnchorBlock) {
blockState = paintedTravelAnchorBlock.getPaint().defaultBlockState();
}
BakedModel blockModel = minecraft.getBlockRenderer().getBlockModel(blockState);
VertexConsumer solid = buffer.getBuffer(RenderType.solid());
minecraft
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.enderio.machines.common.block;

import com.enderio.base.common.block.painted.IPaintedBlock;
import com.enderio.machines.common.blockentity.PaintedTravelAnchorBlockEntity;
import com.enderio.machines.common.init.MachineBlockEntities;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.HitResult;
import org.jetbrains.annotations.Nullable;

public class PaintedTravelAnchorBlock extends TravelAnchorBlock implements IPaintedBlock {

public PaintedTravelAnchorBlock(Properties props) {
super(MachineBlockEntities.PAINTED_TRAVEL_ANCHOR, props);
}

@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) {
return MachineBlockEntities.PAINTED_TRAVEL_ANCHOR.create(pPos, pState);
}

@Override
public ItemStack getCloneItemStack(BlockState state, HitResult target, LevelReader level, BlockPos pos, Player player) {
return getPaintedStack(level, pos, this);
}

@Override
public BlockState getAppearance(BlockState state, BlockAndTintGetter level, BlockPos pos, Direction side, @Nullable BlockState queryState,
@Nullable BlockPos queryPos) {
if (level.getBlockEntity(pos) instanceof PaintedTravelAnchorBlockEntity painted && painted.getPaint() != null) {
return painted.getPaint().defaultBlockState();
}
return super.getAppearance(state, level, pos, side, queryState, queryPos);
}

@Override
public Block getPaint(BlockGetter level, BlockPos pos) {
if (level.getBlockEntity(pos) instanceof PaintedTravelAnchorBlockEntity paintedBlockEntity) {
Block paint = paintedBlockEntity.getPaint();
if (paint != null && !(paint instanceof IPaintedBlock)) {
return paint;
}
}
//sane default (definitely not air)
return Blocks.OAK_PLANKS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@

import com.enderio.base.common.travel.TravelSavedData;
import com.enderio.machines.common.blockentity.TravelAnchorBlockEntity;
import com.enderio.machines.common.blockentity.base.MachineBlockEntity;
import com.enderio.machines.common.init.MachineBlockEntities;
import com.enderio.regilite.holder.RegiliteBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;

public class TravelAnchorBlock extends MachineBlock {
public TravelAnchorBlock(RegiliteBlockEntity<? extends MachineBlockEntity> blockEntityType, Properties props) {
super(blockEntityType, props);
}

public TravelAnchorBlock(Properties props) {
super(MachineBlockEntities.TRAVEL_ANCHOR, props);
this(MachineBlockEntities.TRAVEL_ANCHOR, props);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.enderio.machines.common.blockentity;

import com.enderio.base.EIONBTKeys;
import com.enderio.base.common.blockentity.IPaintableBlockEntity;
import com.enderio.base.common.blockentity.SinglePaintedBlockEntity;
import com.enderio.base.common.util.PaintUtils;
import com.enderio.machines.common.init.MachineBlockEntities;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.Connection;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.client.model.data.ModelData;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

public class PaintedTravelAnchorBlockEntity extends TravelAnchorBlockEntity implements IPaintableBlockEntity {

@Nullable
private Block paint;

@Nullable
public Block getPaint() {
return paint;
}

public PaintedTravelAnchorBlockEntity(BlockPos pWorldPosition, BlockState pBlockState) {
super(MachineBlockEntities.PAINTED_TRAVEL_ANCHOR.get(), pWorldPosition, pBlockState);
}

@Override
public ModelData getModelData() {
return ModelData.builder().with(SinglePaintedBlockEntity.PAINT, paint).build();
}

@Nullable
@Override
public ClientboundBlockEntityDataPacket getUpdatePacket() {
return ClientboundBlockEntityDataPacket.create(this);
}

@Override
public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) {
super.onDataPacket(net, pkt);
Block oldPaint = paint;
CompoundTag tag = pkt.getTag();
if (tag == null) {
return;
}

handleUpdateTag(tag);
if (oldPaint != paint) {
requestModelDataUpdate();
if (level != null) {
level.setBlock(getBlockPos(), level.getBlockState(getBlockPos()), 9);
}
}
}

@Override
public void load(CompoundTag tag) {
super.load(tag);
readPaint(tag);
}

@Override
public void handleUpdateTag(CompoundTag syncData) {
super.handleUpdateTag(syncData);
readPaint(syncData);
}

@Override
public CompoundTag getUpdateTag() {
CompoundTag nbt = super.getUpdateTag();
writePaint(nbt);
return nbt;
}

// TODO: HOUSEKEEPING?: This should probably be converted to a capability.
protected void readPaint(CompoundTag tag) {
if (tag.contains(EIONBTKeys.PAINT)) {
paint = PaintUtils.getBlockFromRL(tag.getString(EIONBTKeys.PAINT));
if (level != null) {
if (level.isClientSide) {
requestModelDataUpdate();
level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(),
Block.UPDATE_NEIGHBORS + Block.UPDATE_CLIENTS);
}
}
}
}

@Override
public void saveAdditional(CompoundTag tag) {
super.saveAdditional(tag);
writePaint(tag);
}

protected void writePaint(CompoundTag tag) {
if (paint != null) {
tag.putString(EIONBTKeys.PAINT, Objects.requireNonNull(BuiltInRegistries.BLOCK.getKey(paint)).toString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ public class TravelAnchorBlockEntity extends MachineBlockEntity {
private final BooleanNetworkDataSlot visibilityDataSlot;
private final ResourceLocationNetworkDataSlot iconDataSlot;
public TravelAnchorBlockEntity(BlockPos pWorldPosition, BlockState pBlockState) {
super(MachineBlockEntities.TRAVEL_ANCHOR.get(), pWorldPosition, pBlockState);
this(MachineBlockEntities.TRAVEL_ANCHOR.get(), pWorldPosition, pBlockState);
}

public TravelAnchorBlockEntity(BlockEntityType<?> type, BlockPos pWorldPosition, BlockState pBlockState) {
super(type, pWorldPosition, pBlockState);
nameDataSlot = new StringNetworkDataSlot(this::getName, name -> getOrCreateTravelTarget().setName(name));
visibilityDataSlot = new BooleanNetworkDataSlot(this::getVisibility, vis -> getOrCreateTravelTarget().setVisibility(vis));
iconDataSlot = new ResourceLocationNetworkDataSlot(() -> BuiltInRegistries.ITEM.getKey(getIcon()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public class MachineBlockEntities {
register("travel_anchor", TravelAnchorBlockEntity::new, MachineBlocks.TRAVEL_ANCHOR)
.apply(MachineBlockEntities::machineBlockEntityCapabilities);

public static final RegiliteBlockEntity<PaintedTravelAnchorBlockEntity> PAINTED_TRAVEL_ANCHOR =
register("painted_travel_anchor", PaintedTravelAnchorBlockEntity::new, MachineBlocks.PAINTED_TRAVEL_ANCHOR)
.apply(MachineBlockEntities::machineBlockEntityCapabilities);

public static final RegiliteBlockEntity<CrafterBlockEntity> CRAFTER =
register("crafter", CrafterBlockEntity::new, MachineBlocks.CRAFTER)
.apply(MachineBlockEntities::poweredMachineBlockEntityCapabilities);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.enderio.machines.common.init;

import com.enderio.EnderIO;
import com.enderio.base.client.renderer.PaintedBlockColor;
import com.enderio.base.common.init.EIOCreativeTabs;
import com.enderio.base.common.tag.EIOTags;
import com.enderio.base.data.loot.DecorLootTable;
import com.enderio.base.data.model.block.EIOBlockState;
import com.enderio.core.data.model.EIOModel;
import com.enderio.machines.common.MachineNBTKeys;
import com.enderio.machines.common.block.CapacitorBankBlock;
import com.enderio.machines.common.block.EnchanterBlock;
import com.enderio.machines.common.block.MachineBlock;
import com.enderio.machines.common.block.PaintedTravelAnchorBlock;
import com.enderio.machines.common.block.ProgressMachineBlock;
import com.enderio.machines.common.block.SolarPanelBlock;
import com.enderio.machines.common.block.TravelAnchorBlock;
Expand All @@ -30,6 +34,7 @@
import net.minecraft.tags.BlockTags;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.capabilities.Capabilities;
Expand Down Expand Up @@ -165,6 +170,14 @@ public class MachineBlocks {
.setBlockStateProvider((prov, ctx) -> prov.simpleBlock(ctx.get(), prov.models().getExistingFile(EnderIO.loc("block/" + ctx.getName()))))
.createBlockItem(ITEM_REGISTRY, item -> item.setTab(EIOCreativeTabs.MACHINES));

public static final RegiliteBlock<PaintedTravelAnchorBlock> PAINTED_TRAVEL_ANCHOR = BLOCK_REGISTRY
.registerBlock("painted_travel_anchor", PaintedTravelAnchorBlock::new, BlockBehaviour.Properties.of().strength(2.5f, 8).noOcclusion())
.addBlockTags(BlockTags.NEEDS_IRON_TOOL, BlockTags.MINEABLE_WITH_PICKAXE)
.setColorSupplier(() -> PaintedBlockColor::new)
.setLootTable(DecorLootTable::withPaint)
.setBlockStateProvider((prov, ctx) -> EIOBlockState.paintedBlock("painted_travel_anchor", prov, ctx.get(), Blocks.DIRT, null)) //Any cube will do
.createBlockItem(ITEM_REGISTRY, item -> item.setColorSupplier(() -> PaintedBlockColor::new));

public static final Map<SolarPanelTier, RegiliteBlock<SolarPanelBlock>> SOLAR_PANELS = Util.make(() -> {
Map<SolarPanelTier, RegiliteBlock<SolarPanelBlock>> panels = new HashMap<>();
for (SolarPanelTier tier: SolarPanelTier.values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.enderio.EnderIO;
import com.enderio.base.common.init.EIOBlocks;
import com.enderio.core.data.recipes.EnderRecipeProvider;
import com.enderio.machines.common.init.MachineBlocks;
import com.enderio.machines.common.recipe.PaintingRecipe;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.data.PackOutput;
Expand Down Expand Up @@ -30,6 +31,7 @@ protected void buildRecipes(RecipeOutput recipeOutput) {
build(EIOBlocks.PAINTED_WOODEN_PRESSURE_PLATE, Ingredient.of(ItemTags.WOODEN_PRESSURE_PLATES), recipeOutput);
build(EIOBlocks.PAINTED_SLAB, Ingredient.of(ItemTags.WOODEN_SLABS), recipeOutput);
build(EIOBlocks.PAINTED_GLOWSTONE, Ingredient.of(Items.GLOWSTONE), recipeOutput);
build(MachineBlocks.PAINTED_TRAVEL_ANCHOR, Ingredient.of(MachineBlocks.TRAVEL_ANCHOR), recipeOutput);
//Painted block to painted block
build(EIOBlocks.PAINTED_FENCE, Ingredient.of(EIOBlocks.PAINTED_FENCE), "_frompainted", recipeOutput);
build(EIOBlocks.PAINTED_FENCE_GATE, Ingredient.of(EIOBlocks.PAINTED_FENCE_GATE), "_frompainted", recipeOutput);
Expand All @@ -41,6 +43,7 @@ protected void buildRecipes(RecipeOutput recipeOutput) {
build(EIOBlocks.PAINTED_WOODEN_PRESSURE_PLATE, Ingredient.of(EIOBlocks.PAINTED_WOODEN_PRESSURE_PLATE), "_frompainted", recipeOutput);
build(EIOBlocks.PAINTED_SLAB, Ingredient.of(EIOBlocks.PAINTED_SLAB), "_frompainted", recipeOutput);
build(EIOBlocks.PAINTED_GLOWSTONE, Ingredient.of(EIOBlocks.PAINTED_GLOWSTONE), "_frompainted", recipeOutput);
build(MachineBlocks.PAINTED_TRAVEL_ANCHOR, Ingredient.of(MachineBlocks.PAINTED_TRAVEL_ANCHOR), "_frompainted", recipeOutput);
}


Expand Down

0 comments on commit 9db69e7

Please sign in to comment.