Skip to content

Commit

Permalink
paintable anchor
Browse files Browse the repository at this point in the history
  • Loading branch information
ferriarnus committed Mar 7, 2024
1 parent 88fc68b commit 61b7677
Show file tree
Hide file tree
Showing 15 changed files with 235 additions and 4 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
Expand Up @@ -35,7 +35,6 @@
"enderio:silent_heavy_weighted_pressure_plate",
"enderio:silent_light_weighted_pressure_plate",
"enderio:painted_redstone_block",
"enderio:conduit",
"enderio:fluid_tank",
"enderio:pressurized_fluid_tank",
"enderio:enchanter",
Expand All @@ -52,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 All @@ -61,6 +61,7 @@
"enderio:crafter",
"enderio:soul_engine",
"enderio:drain",
"enderio:xp_obelisk"
"enderio:xp_obelisk",
"enderio:conduit"
]
}
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
@@ -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(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
@@ -0,0 +1,99 @@
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;

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

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

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

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

@Override
public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket 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 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 Down

0 comments on commit 61b7677

Please sign in to comment.