From 983c21184d706aa2b5cdc74cb626fe11d240f62f Mon Sep 17 00:00:00 2001 From: Alexander Behrhof Date: Sun, 4 Jul 2021 19:37:52 -0400 Subject: [PATCH] Move Tinker's Construct register wood objects to Mantle for use in other mods. --- .../mantle/block/StrippableLogBlock.java | 28 ++++ .../mantle/block/WoodenDoorBlock.java | 22 +++ .../mantle/item/BurnableBlockItem.java | 18 +++ .../mantle/item/BurnableTallBlockItem.java | 18 +++ .../deferred/BlockDeferredRegister.java | 74 ++++++++++ .../registration/object/WoodBlockObject.java | 128 ++++++++++++++++++ .../resources/META-INF/accesstransformer.cfg | 3 + 7 files changed, 291 insertions(+) create mode 100644 src/main/java/slimeknights/mantle/block/StrippableLogBlock.java create mode 100644 src/main/java/slimeknights/mantle/block/WoodenDoorBlock.java create mode 100644 src/main/java/slimeknights/mantle/item/BurnableBlockItem.java create mode 100644 src/main/java/slimeknights/mantle/item/BurnableTallBlockItem.java create mode 100644 src/main/java/slimeknights/mantle/registration/object/WoodBlockObject.java diff --git a/src/main/java/slimeknights/mantle/block/StrippableLogBlock.java b/src/main/java/slimeknights/mantle/block/StrippableLogBlock.java new file mode 100644 index 0000000..47c0604 --- /dev/null +++ b/src/main/java/slimeknights/mantle/block/StrippableLogBlock.java @@ -0,0 +1,28 @@ +package slimeknights.mantle.block; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.RotatedPillarBlock; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.common.ToolType; + +import javax.annotation.Nullable; +import java.util.function.Supplier; + +/** Log block that can be stripped */ +public class StrippableLogBlock extends RotatedPillarBlock { + private final Supplier stripped; + public StrippableLogBlock(Supplier stripped, Properties properties) { + super(properties); + this.stripped = stripped; + } + + @Nullable + @Override + public BlockState getToolModifiedState(BlockState state, World world, BlockPos pos, PlayerEntity player, ItemStack stack, ToolType toolType) { + return stripped.get().getDefaultState().with(AXIS, state.get(AXIS)); + } +} diff --git a/src/main/java/slimeknights/mantle/block/WoodenDoorBlock.java b/src/main/java/slimeknights/mantle/block/WoodenDoorBlock.java new file mode 100644 index 0000000..adc8632 --- /dev/null +++ b/src/main/java/slimeknights/mantle/block/WoodenDoorBlock.java @@ -0,0 +1,22 @@ +package slimeknights.mantle.block; + +import net.minecraft.block.BlockState; +import net.minecraft.block.DoorBlock; +import net.minecraft.entity.MobEntity; +import net.minecraft.pathfinding.PathNodeType; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IBlockReader; + +import javax.annotation.Nullable; + +public class WoodenDoorBlock extends DoorBlock { + public WoodenDoorBlock(Properties builder) { + super(builder); + } + + @Nullable + @Override + public PathNodeType getAiPathNodeType(BlockState state, IBlockReader world, BlockPos pos, @Nullable MobEntity entity) { + return state.get(OPEN) ? PathNodeType.DOOR_OPEN : PathNodeType.DOOR_WOOD_CLOSED; + } +} diff --git a/src/main/java/slimeknights/mantle/item/BurnableBlockItem.java b/src/main/java/slimeknights/mantle/item/BurnableBlockItem.java new file mode 100644 index 0000000..656bed3 --- /dev/null +++ b/src/main/java/slimeknights/mantle/item/BurnableBlockItem.java @@ -0,0 +1,18 @@ +package slimeknights.mantle.item; + +import net.minecraft.block.Block; +import net.minecraft.item.BlockItem; +import net.minecraft.item.ItemStack; + +public class BurnableBlockItem extends BlockItem { + private final int burnTime; + public BurnableBlockItem(Block blockIn, Properties builder, int burnTime) { + super(blockIn, builder); + this.burnTime = burnTime; + } + + @Override + public int getBurnTime(ItemStack itemStack) { + return burnTime; + } +} diff --git a/src/main/java/slimeknights/mantle/item/BurnableTallBlockItem.java b/src/main/java/slimeknights/mantle/item/BurnableTallBlockItem.java new file mode 100644 index 0000000..bb991ed --- /dev/null +++ b/src/main/java/slimeknights/mantle/item/BurnableTallBlockItem.java @@ -0,0 +1,18 @@ +package slimeknights.mantle.item; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.item.TallBlockItem; + +public class BurnableTallBlockItem extends TallBlockItem { + private final int burnTime; + public BurnableTallBlockItem(Block blockIn, Properties builder, int burnTime) { + super(blockIn, builder); + this.burnTime = burnTime; + } + + @Override + public int getBurnTime(ItemStack itemStack) { + return burnTime; + } +} diff --git a/src/main/java/slimeknights/mantle/registration/deferred/BlockDeferredRegister.java b/src/main/java/slimeknights/mantle/registration/deferred/BlockDeferredRegister.java index 5607ffd..2331919 100644 --- a/src/main/java/slimeknights/mantle/registration/deferred/BlockDeferredRegister.java +++ b/src/main/java/slimeknights/mantle/registration/deferred/BlockDeferredRegister.java @@ -2,22 +2,41 @@ package slimeknights.mantle.registration.deferred; import net.minecraft.block.AbstractBlock; import net.minecraft.block.Block; +import net.minecraft.block.Blocks; +import net.minecraft.block.DoorBlock; import net.minecraft.block.FenceBlock; +import net.minecraft.block.FenceGateBlock; +import net.minecraft.block.PressurePlateBlock; +import net.minecraft.block.RotatedPillarBlock; import net.minecraft.block.SlabBlock; +import net.minecraft.block.SoundType; import net.minecraft.block.StairsBlock; +import net.minecraft.block.TrapDoorBlock; import net.minecraft.block.WallBlock; +import net.minecraft.block.WoodButtonBlock; +import net.minecraft.block.material.Material; +import net.minecraft.block.material.MaterialColor; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; +import net.minecraft.item.ItemGroup; +import net.minecraft.item.TallBlockItem; +import net.minecraft.util.Direction; import net.minecraft.util.IStringSerializable; +import net.minecraftforge.common.ToolType; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.RegistryObject; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; +import slimeknights.mantle.block.StrippableLogBlock; +import slimeknights.mantle.block.WoodenDoorBlock; +import slimeknights.mantle.item.BurnableBlockItem; +import slimeknights.mantle.item.BurnableTallBlockItem; import slimeknights.mantle.registration.object.BuildingBlockObject; import slimeknights.mantle.registration.object.EnumObject; import slimeknights.mantle.registration.object.FenceBuildingBlockObject; import slimeknights.mantle.registration.object.ItemObject; import slimeknights.mantle.registration.object.WallBuildingBlockObject; +import slimeknights.mantle.registration.object.WoodBlockObject; import java.util.function.Function; import java.util.function.Supplier; @@ -176,6 +195,61 @@ public class BlockDeferredRegister extends DeferredRegisterWrapper { ); } + /** + * Registers everything needed to make a new wood type, including a wood type + * @param name Wood name + * @param planksColor Color of the planks + * @param barkColor Bark color + * @param plankSound Sound for the wood + * @param group Item group for the wood + * @return Wood object + */ + public WoodBlockObject registerWood(String name, Material planksMaterial, MaterialColor planksColor, SoundType plankSound, ToolType planksTool, Material barkMaterial, MaterialColor barkColor, SoundType barkSound, ItemGroup group) { + //WoodType woodType = WoodType.create(resourceName(name)); + Item.Properties itemProps = new Item.Properties().group(group); + + // many of these are already burnable via tags, but simplier to set them all here + Function> burnableItem; + Function> burnableTallItem; + if (barkMaterial.isFlammable()) { + burnableItem = burnTime -> block -> new BurnableBlockItem(block, itemProps, burnTime); + burnableTallItem = burnTime -> block -> new BurnableTallBlockItem(block, itemProps, burnTime); + } else { + Function defaultItemBlock = block -> new BlockItem(block, itemProps); + burnableItem = burnTime -> defaultItemBlock; + burnableTallItem = burnTime -> block -> new TallBlockItem(block, itemProps); + } + + // planks + Function burnable300 = burnableItem.apply(300); + AbstractBlock.Properties planksProps = AbstractBlock.Properties.create(planksMaterial, planksColor).harvestTool(planksTool).hardnessAndResistance(2.0f, 3.0f).sound(plankSound); + BuildingBlockObject planks = registerBuilding(name + "_planks", planksProps, burnable300); + ItemObject fence = register(name + "_fence", () -> new FenceBlock(AbstractBlock.Properties.from(planks.get())), burnable300); + // logs and wood + Supplier stripped = () -> new RotatedPillarBlock(AbstractBlock.Properties.create(planksMaterial, planksColor).harvestTool(planksTool).hardnessAndResistance(2.0f).sound(plankSound)); + ItemObject strippedLog = register("stripped_" + name + "_log", stripped, burnable300); + ItemObject strippedWood = register("stripped_" + name + "_wood", stripped, burnable300); + ItemObject log = register(name + "_log", () -> new StrippableLogBlock(strippedLog, + AbstractBlock.Properties.create(barkMaterial, state -> state.get(RotatedPillarBlock.AXIS) == Direction.Axis.Y ? planksColor : barkColor) + .harvestTool(ToolType.AXE).hardnessAndResistance(2.0f).sound(barkSound)), burnable300); + ItemObject wood = register(name + "_wood", () -> new StrippableLogBlock(strippedWood, AbstractBlock.Properties.create(barkMaterial, barkColor).harvestTool(ToolType.AXE).hardnessAndResistance(2.0f).sound(barkSound)), burnable300); + + // doors + ItemObject door = register(name + "_door", () -> new WoodenDoorBlock(AbstractBlock.Properties.create(planksMaterial, planksColor).harvestTool(planksTool).hardnessAndResistance(3.0F).sound(plankSound).notSolid()), burnableTallItem.apply(200)); + ItemObject trapdoor = register(name + "_trapdoor", () -> new TrapDoorBlock(AbstractBlock.Properties.create(planksMaterial, planksColor).harvestTool(planksTool).hardnessAndResistance(3.0F).sound(SoundType.WOOD).notSolid().setAllowsSpawn(Blocks::neverAllowSpawn)), burnable300); + ItemObject fenceGate = register(name + "_fence_gate", () -> new FenceGateBlock(planksProps), burnable300); + // redstone + AbstractBlock.Properties redstoneProps = AbstractBlock.Properties.create(planksMaterial, planksColor).harvestTool(planksTool).doesNotBlockMovement().hardnessAndResistance(0.5F).sound(plankSound); + ItemObject pressurePlate = register(name + "_pressure_plate", () -> new PressurePlateBlock(PressurePlateBlock.Sensitivity.EVERYTHING, redstoneProps), burnable300); + ItemObject button = register(name + "_button", () -> new WoodButtonBlock(redstoneProps), burnableItem.apply(100)); + // signs + //RegistryObject standingSign = registerNoItem(name + "_sign", () -> new StandingSignBlock(AbstractBlock.Properties.create(material, planksColor).doesNotBlockMovement().hardnessAndResistance(1.0F).sound(sound), woodType)); + //RegistryObject wallSign = registerNoItem(name + "_wall_sign", () -> new WallSignBlock(AbstractBlock.Properties.create(material, planksColor).doesNotBlockMovement().hardnessAndResistance(1.0F).sound(sound).lootFrom(standingSign), woodType)); + //RegistryObject signItem = this.itemRegister.register(name + "_sign", () -> new SignItem(new Item.Properties().maxStackSize(16).group(group), standingSign.get(), wallSign.get())); + // finally, return + return new WoodBlockObject(resource(name), /*woodType,*/ planks, log, strippedLog, wood, strippedWood, fence, fenceGate, door, trapdoor, pressurePlate, button/*, standingSign, wallSign*/); + } + /** * Registers an item with multiple variants, prefixing the name with the value name * @param values Enum values to use for this block diff --git a/src/main/java/slimeknights/mantle/registration/object/WoodBlockObject.java b/src/main/java/slimeknights/mantle/registration/object/WoodBlockObject.java new file mode 100644 index 0000000..00efbd8 --- /dev/null +++ b/src/main/java/slimeknights/mantle/registration/object/WoodBlockObject.java @@ -0,0 +1,128 @@ +package slimeknights.mantle.registration.object; + +import lombok.Getter; +import net.minecraft.block.Block; +import net.minecraft.block.DoorBlock; +import net.minecraft.block.FenceBlock; +import net.minecraft.block.FenceGateBlock; +import net.minecraft.block.PressurePlateBlock; +import net.minecraft.block.TrapDoorBlock; +import net.minecraft.block.WoodButtonBlock; +import net.minecraft.item.Item; +import net.minecraft.tags.BlockTags; +import net.minecraft.tags.ItemTags; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.common.Tags.IOptionalNamedTag; + +import java.util.function.Supplier; + +/** Extension of the fence object with all other wood blocks */ +@SuppressWarnings("unused") +public class WoodBlockObject extends FenceBuildingBlockObject { + //@Getter + //private final WoodType woodType; + // basic + private final Supplier log; + private final Supplier strippedLog; + private final Supplier wood; + private final Supplier strippedWood; + // doors + private final Supplier fenceGate; + private final Supplier door; + private final Supplier trapdoor; + // redstone + private final Supplier pressurePlate; + private final Supplier button; + // signs + //private final Supplier sign; + //private final Supplier wallSign; + // tags + @Getter + private final IOptionalNamedTag logBlockTag; + @Getter + private final IOptionalNamedTag logItemTag; + + public WoodBlockObject(ResourceLocation name, /*WoodType woodType,*/ BuildingBlockObject planks, + Supplier log, Supplier strippedLog, Supplier wood, Supplier strippedWood, + Supplier fence, Supplier fenceGate, Supplier door, Supplier trapdoor, + Supplier pressurePlate, Supplier button/*, + Supplier sign, Supplier wallSign*/) { + super(planks, fence); + //this.woodType = woodType; + this.log = log; + this.strippedLog = strippedLog; + this.wood = wood; + this.strippedWood = strippedWood; + this.fenceGate = fenceGate; + this.door = door; + this.trapdoor = trapdoor; + this.pressurePlate = pressurePlate; + this.button = button; + //this.sign = sign; + //this.wallSign = wallSign; + ResourceLocation tagName = new ResourceLocation(name.getNamespace(), name.getPath() + "_logs"); + this.logBlockTag = BlockTags.createOptional(tagName); + this.logItemTag = ItemTags.createOptional(tagName); + } + + /** Gets the log for this wood type */ + public Block getLog() { + return log.get(); + } + + /** Gets the stripped log for this wood type */ + public Block getStrippedLog() { + return strippedLog.get(); + } + + /** Gets the wood for this wood type */ + public Block getWood() { + return wood.get(); + } + + /** Gets the stripped wood for this wood type */ + public Block getStrippedWood() { + return strippedWood.get(); + } + + /* Doors */ + + /** Gets the fence gate for this wood type */ + public FenceGateBlock getFenceGate() { + return fenceGate.get(); + } + + /** Gets the door for this wood type */ + public DoorBlock getDoor() { + return door.get(); + } + + /** Gets the trapdoor for this wood type */ + public TrapDoorBlock getTrapdoor() { + return trapdoor.get(); + } + + /* Redstone */ + + /** Gets the pressure plate for this wood type */ + public PressurePlateBlock getPressurePlate() { + return pressurePlate.get(); + } + + /** Gets the button for this wood type */ + public WoodButtonBlock getButton() { + return button.get(); + } + + /* Signs */ + + /* Gets the sign for this wood type, can also be used to get the item / + public StandingSignBlock getSign() { + return sign.get(); + }*/ + + /* Gets the wall sign for this wood type / + public WallSignBlock getWallSign() { + return wallSign.get(); + }*/ +} diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index a759916..e548f63 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -53,3 +53,6 @@ protected net.minecraft.util.IntReferenceHolder field_221498_a # lastKnownValue # Fix hand swinging animations resetting cooldown public net.minecraft.entity.LivingEntity func_82166_i()I # getArmSwingAnimationEnd + +# Block properties +public net.minecraft.block.Blocks func_235427_a_(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/IBlockReader;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/EntityType;)Ljava/lang/Boolean; # neverAllowSpawn