From 02855f7d74880946056961d99f838b6170c927cf Mon Sep 17 00:00:00 2001 From: Wasinthorn Suksri Date: Sun, 17 Dec 2017 09:38:53 +0700 Subject: [PATCH] Added Custom Slime Block hook for Piston. (#4520) --- .../net/minecraft/block/Block.java.patch | 13 +- .../BlockPistonStructureHelper.java.patch | 27 +++- .../tileentity/TileEntityPiston.java.patch | 11 ++ .../debug/CustomSlimeBlockTest.java | 123 ++++++++++++++++++ .../blockstates/custom_slime_block.json | 6 + .../lang/en_US.lang | 2 + .../models/block/blue_slime_block.json | 7 + .../models/block/obsidian_slime_block.json | 7 + .../models/item/blue_slime_block.json | 3 + .../models/item/obsidian_slime_block.json | 3 + .../textures/blocks/blue_slime_block.png | Bin 0 -> 753 bytes .../textures/blocks/obsidian_slime_block.png | Bin 0 -> 719 bytes 12 files changed, 199 insertions(+), 3 deletions(-) create mode 100644 patches/minecraft/net/minecraft/tileentity/TileEntityPiston.java.patch create mode 100644 src/test/java/net/minecraftforge/debug/CustomSlimeBlockTest.java create mode 100644 src/test/resources/assets/forgedebugcustomslimeblock/blockstates/custom_slime_block.json create mode 100644 src/test/resources/assets/forgedebugcustomslimeblock/lang/en_US.lang create mode 100644 src/test/resources/assets/forgedebugcustomslimeblock/models/block/blue_slime_block.json create mode 100644 src/test/resources/assets/forgedebugcustomslimeblock/models/block/obsidian_slime_block.json create mode 100644 src/test/resources/assets/forgedebugcustomslimeblock/models/item/blue_slime_block.json create mode 100644 src/test/resources/assets/forgedebugcustomslimeblock/models/item/obsidian_slime_block.json create mode 100644 src/test/resources/assets/forgedebugcustomslimeblock/textures/blocks/blue_slime_block.png create mode 100644 src/test/resources/assets/forgedebugcustomslimeblock/textures/blocks/obsidian_slime_block.png diff --git a/patches/minecraft/net/minecraft/block/Block.java.patch b/patches/minecraft/net/minecraft/block/Block.java.patch index 2dca4b157..bfeadbdd9 100644 --- a/patches/minecraft/net/minecraft/block/Block.java.patch +++ b/patches/minecraft/net/minecraft/block/Block.java.patch @@ -221,7 +221,7 @@ public SoundType func_185467_w() { return this.field_149762_H; -@@ -934,6 +952,1305 @@ +@@ -934,6 +952,1314 @@ { } @@ -1522,12 +1522,21 @@ + return isSideSolid(blockState, world, pos, side); + } + ++ /** ++ * @param state The state ++ * @return true if the block is sticky block which used for pull or push adjacent blocks (use by piston) ++ */ ++ public boolean isStickyBlock(IBlockState state) ++ { ++ return state.func_177230_c() == Blocks.field_180399_cE; ++ } ++ + /* ========================================= FORGE END ======================================*/ + public static void func_149671_p() { func_176215_a(0, field_176230_a, (new BlockAir()).func_149663_c("air")); -@@ -1230,31 +2547,6 @@ +@@ -1230,31 +2556,6 @@ block15.field_149783_u = flag; } } diff --git a/patches/minecraft/net/minecraft/block/state/BlockPistonStructureHelper.java.patch b/patches/minecraft/net/minecraft/block/state/BlockPistonStructureHelper.java.patch index a9e9834a9..0637b21ec 100644 --- a/patches/minecraft/net/minecraft/block/state/BlockPistonStructureHelper.java.patch +++ b/patches/minecraft/net/minecraft/block/state/BlockPistonStructureHelper.java.patch @@ -1,5 +1,14 @@ --- ../src-base/minecraft/net/minecraft/block/state/BlockPistonStructureHelper.java +++ ../src-work/minecraft/net/minecraft/block/state/BlockPistonStructureHelper.java +@@ -65,7 +65,7 @@ + { + BlockPos blockpos = this.field_177258_e.get(i); + +- if (this.field_177261_a.func_180495_p(blockpos).func_177230_c() == Blocks.field_180399_cE && !this.func_177250_b(blockpos)) ++ if (this.field_177261_a.func_180495_p(blockpos).func_177230_c().isStickyBlock(this.field_177261_a.func_180495_p(blockpos)) && !this.func_177250_b(blockpos)) + { + return false; + } @@ -80,7 +80,7 @@ IBlockState iblockstate = this.field_177261_a.func_180495_p(p_177251_1_); Block block = iblockstate.func_177230_c(); @@ -9,7 +18,14 @@ { return true; } -@@ -112,7 +112,7 @@ +@@ -106,13 +106,13 @@ + } + else + { +- while (block == Blocks.field_180399_cE) ++ while (block.isStickyBlock(iblockstate)) + { + BlockPos blockpos = p_177251_1_.func_177967_a(this.field_177257_d.func_176734_d(), i); iblockstate = this.field_177261_a.func_180495_p(blockpos); block = iblockstate.func_177230_c(); @@ -18,6 +34,15 @@ { break; } +@@ -148,7 +148,7 @@ + { + BlockPos blockpos2 = this.field_177258_e.get(l); + +- if (this.field_177261_a.func_180495_p(blockpos2).func_177230_c() == Blocks.field_180399_cE && !this.func_177250_b(blockpos2)) ++ if (this.field_177261_a.func_180495_p(blockpos2).func_177230_c().isStickyBlock(this.field_177261_a.func_180495_p(blockpos2)) && !this.func_177250_b(blockpos2)) + { + return false; + } @@ -159,7 +159,7 @@ iblockstate = this.field_177261_a.func_180495_p(blockpos1); diff --git a/patches/minecraft/net/minecraft/tileentity/TileEntityPiston.java.patch b/patches/minecraft/net/minecraft/tileentity/TileEntityPiston.java.patch new file mode 100644 index 000000000..6b9608798 --- /dev/null +++ b/patches/minecraft/net/minecraft/tileentity/TileEntityPiston.java.patch @@ -0,0 +1,11 @@ +--- ../src-base/minecraft/net/minecraft/tileentity/TileEntityPiston.java ++++ ../src-work/minecraft/net/minecraft/tileentity/TileEntityPiston.java +@@ -145,7 +145,7 @@ + + if (!list1.isEmpty()) + { +- boolean flag = this.field_174932_a.func_177230_c() == Blocks.field_180399_cE; ++ boolean flag = this.field_174932_a.func_177230_c().isStickyBlock(this.field_174932_a); + + for (int i = 0; i < list1.size(); ++i) + { diff --git a/src/test/java/net/minecraftforge/debug/CustomSlimeBlockTest.java b/src/test/java/net/minecraftforge/debug/CustomSlimeBlockTest.java new file mode 100644 index 000000000..52981ca9f --- /dev/null +++ b/src/test/java/net/minecraftforge/debug/CustomSlimeBlockTest.java @@ -0,0 +1,123 @@ +package net.minecraftforge.debug; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockSlime; +import net.minecraft.block.SoundType; +import net.minecraft.block.properties.PropertyEnum; +import net.minecraft.block.state.BlockStateContainer; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.block.model.ModelResourceLocation; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.Item; +import net.minecraft.item.ItemMultiTexture; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IStringSerializable; +import net.minecraft.util.NonNullList; +import net.minecraftforge.client.event.ModelRegistryEvent; +import net.minecraftforge.client.model.ModelLoader; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber; +import net.minecraftforge.fml.common.Mod.EventHandler; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.registry.ForgeRegistries; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@Mod(modid = CustomSlimeBlockTest.MODID, name = "ForgeDebugCustomSlimeBlock", version = CustomSlimeBlockTest.VERSION, acceptableRemoteVersions = "*") +public class CustomSlimeBlockTest +{ + public static final String MODID = "forgedebugcustomslimeblock"; + public static final String ASSETS = "forgedebugcustomslimeblock:"; + public static final String VERSION = "1.0"; + public static Block CUSTOM_SLIME_BLOCK; + + @EventHandler + public void preInit(FMLPreInitializationEvent event) + { + CUSTOM_SLIME_BLOCK = new CustomSlime(); + ForgeRegistries.BLOCKS.register(CUSTOM_SLIME_BLOCK); + ForgeRegistries.ITEMS.register(new ItemMultiTexture(CUSTOM_SLIME_BLOCK, CUSTOM_SLIME_BLOCK, stack -> CustomSlime.BlockType.values[stack.getMetadata()].toString()).setRegistryName(CUSTOM_SLIME_BLOCK.getRegistryName())); + } + + @EventBusSubscriber(value = Side.CLIENT, modid = MODID) + public static class BakeEventHandler + { + @SubscribeEvent + public static void registerModels(ModelRegistryEvent event) + { + Item item = Item.getItemFromBlock(CUSTOM_SLIME_BLOCK); + ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(ASSETS + "blue_slime_block", "inventory")); + ModelLoader.setCustomModelResourceLocation(item, 1, new ModelResourceLocation(ASSETS + "obsidian_slime_block", "inventory")); + } + } + + public static class CustomSlime extends BlockSlime + { + private static final PropertyEnum VARIANT = PropertyEnum.create("variant", BlockType.class); + + private CustomSlime() + { + super(); + this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, BlockType.BLUE_SLIME_BLOCK)); + this.setCreativeTab(CreativeTabs.DECORATIONS); + this.setUnlocalizedName("custom_slime_block"); + this.setRegistryName("forgedebugcustomslimeblock:custom_slime_block"); + this.setSoundType(SoundType.SLIME); + } + + @Override + @SideOnly(Side.CLIENT) + public void getSubBlocks(CreativeTabs creativeTabs, NonNullList list) + { + for (int i = 0; i < BlockType.values.length; ++i) + { + list.add(new ItemStack(this, 1, i)); + } + } + + @Override + protected BlockStateContainer createBlockState() + { + return new BlockStateContainer(this, VARIANT); + } + + @Override + public IBlockState getStateFromMeta(int meta) + { + return this.getDefaultState().withProperty(VARIANT, BlockType.values[meta]); + } + + @Override + public int getMetaFromState(IBlockState state) + { + return state.getValue(VARIANT).ordinal(); + } + + @Override + public boolean isStickyBlock(IBlockState state) + { + return state.getValue(VARIANT) != BlockType.OBSIDIAN_SLIME_BLOCK; + } + + public static enum BlockType implements IStringSerializable + { + BLUE_SLIME_BLOCK, + OBSIDIAN_SLIME_BLOCK; + + protected static final BlockType[] values = BlockType.values(); + + @Override + public String toString() + { + return this.name().toLowerCase(); + } + + @Override + public String getName() + { + return this.name().toLowerCase(); + } + } + } +} \ No newline at end of file diff --git a/src/test/resources/assets/forgedebugcustomslimeblock/blockstates/custom_slime_block.json b/src/test/resources/assets/forgedebugcustomslimeblock/blockstates/custom_slime_block.json new file mode 100644 index 000000000..2540a3a27 --- /dev/null +++ b/src/test/resources/assets/forgedebugcustomslimeblock/blockstates/custom_slime_block.json @@ -0,0 +1,6 @@ +{ + "variants": { + "variant=blue_slime_block": { "model": "forgedebugcustomslimeblock:blue_slime_block" }, + "variant=obsidian_slime_block": { "model": "forgedebugcustomslimeblock:obsidian_slime_block" } + } +} \ No newline at end of file diff --git a/src/test/resources/assets/forgedebugcustomslimeblock/lang/en_US.lang b/src/test/resources/assets/forgedebugcustomslimeblock/lang/en_US.lang new file mode 100644 index 000000000..4fa89808b --- /dev/null +++ b/src/test/resources/assets/forgedebugcustomslimeblock/lang/en_US.lang @@ -0,0 +1,2 @@ +tile.custom_slime_block.blue_slime_block.name=Blue Slime Block +tile.custom_slime_block.obsidian_slime_block.name=Obsidian Slime Block \ No newline at end of file diff --git a/src/test/resources/assets/forgedebugcustomslimeblock/models/block/blue_slime_block.json b/src/test/resources/assets/forgedebugcustomslimeblock/models/block/blue_slime_block.json new file mode 100644 index 000000000..4cae1df8c --- /dev/null +++ b/src/test/resources/assets/forgedebugcustomslimeblock/models/block/blue_slime_block.json @@ -0,0 +1,7 @@ +{ + "parent": "block/slime", + "textures": { + "particle": "forgedebugcustomslimeblock:blocks/blue_slime_block", + "texture": "forgedebugcustomslimeblock:blocks/blue_slime_block" + } +} \ No newline at end of file diff --git a/src/test/resources/assets/forgedebugcustomslimeblock/models/block/obsidian_slime_block.json b/src/test/resources/assets/forgedebugcustomslimeblock/models/block/obsidian_slime_block.json new file mode 100644 index 000000000..1c19c3910 --- /dev/null +++ b/src/test/resources/assets/forgedebugcustomslimeblock/models/block/obsidian_slime_block.json @@ -0,0 +1,7 @@ +{ + "parent": "block/slime", + "textures": { + "particle": "forgedebugcustomslimeblock:blocks/obsidian_slime_block", + "texture": "forgedebugcustomslimeblock:blocks/obsidian_slime_block" + } +} \ No newline at end of file diff --git a/src/test/resources/assets/forgedebugcustomslimeblock/models/item/blue_slime_block.json b/src/test/resources/assets/forgedebugcustomslimeblock/models/item/blue_slime_block.json new file mode 100644 index 000000000..bd06bf912 --- /dev/null +++ b/src/test/resources/assets/forgedebugcustomslimeblock/models/item/blue_slime_block.json @@ -0,0 +1,3 @@ +{ + "parent": "forgedebugcustomslimeblock:block/blue_slime_block" +} \ No newline at end of file diff --git a/src/test/resources/assets/forgedebugcustomslimeblock/models/item/obsidian_slime_block.json b/src/test/resources/assets/forgedebugcustomslimeblock/models/item/obsidian_slime_block.json new file mode 100644 index 000000000..71737b0c1 --- /dev/null +++ b/src/test/resources/assets/forgedebugcustomslimeblock/models/item/obsidian_slime_block.json @@ -0,0 +1,3 @@ +{ + "parent": "forgedebugcustomslimeblock:block/obsidian_slime_block" +} \ No newline at end of file diff --git a/src/test/resources/assets/forgedebugcustomslimeblock/textures/blocks/blue_slime_block.png b/src/test/resources/assets/forgedebugcustomslimeblock/textures/blocks/blue_slime_block.png new file mode 100644 index 0000000000000000000000000000000000000000..2a59e6dfb7efb40025ae4b5ea9459f7d02cb4093 GIT binary patch literal 753 zcmVH*r*Ujy`KOGWHn%VO;|i%DDWA- zJz#*ELm1p%fGQ5^?L8!!f`BR>ayAI#=r@QeP(=!N>ja)n`mE$HoxJOZM8KLMWq2~r zQOs|6V~Jqz2*YUx$F_JsP%#LO1>^;=$kaW9&e@;PaZJ=41L<0!?h!68&Y5l%6>l4! zWe9scEL)c=g>-rgd79h%pvUj~p-?W0HCi+-1v5_$Hrf+L$%fUB3x6$4`M!Zydp?E?^Z+qdIP02Din}GQQz%Ot86o%4`Y-HL+q4 zSJE0>Gf)9~_Av?tS!9T5VxVP`29XWZS&BNBN>Uh3Qgm7_a;7opF}orI1us8`LZ;d} zK+`u6#U&Qcm8aP49%9CS5@YxSgV~gfF&XtW z71IxNI~{iZf5ioycFrzC>AgspEjg|!*Vc5vv*=t`ycrx|)c?h2E*h; zq{cM_K}TyA5Q8s^NQ$O~j#E-wMqfe32I!D`V6*Gu{2B^{f#S_uUt5h j>GMsLx-X(1%*Mt){|s&XNUxXQ00000NkvXXu0mjfo260> literal 0 HcmV?d00001 diff --git a/src/test/resources/assets/forgedebugcustomslimeblock/textures/blocks/obsidian_slime_block.png b/src/test/resources/assets/forgedebugcustomslimeblock/textures/blocks/obsidian_slime_block.png new file mode 100644 index 0000000000000000000000000000000000000000..1f8d63bdbb4c241415cdc79b0873f98148ededbf GIT binary patch literal 719 zcmV;=0xB7UAXSc;S)9G6{hugr|WFZXJ8?wL8o zYBu}mE2WTSIjX9J>w0LK28LmvZ5wEsjv!b=*G;Nfuq+2aDZQp?K~1M~pPM(EH8m@A zIxduIsL7$TMqO9f>l|Vc{t{r^DtI z4;pG_(U^BD6j&RjbXh$~VmMAmgySC%(RGbC_~f&yNm9vLFAv`lKn;VYS2Sf2{2<^0 z``!tj*53)lmg#M)2+U*=?`VSx+wDqLbsPsBs|S;&2VsDc6sIfpx?_aN663)sY}*zQ zGXfS0MUmrR_zH2pLX-yJT=Y5vL~)Eb3*mV#(a^*`*B;PzI#%IAbW%4rw?sh+XQd3W ziK%eSwR_lXm*NO#BuO%i_QptxEz&fVT&VN&a{@3VKrBjG?h;m2wM=N+k|iSmgB}=k zR`jhBUD#H2altl5=ytnOphaYZ-Mv8^M--ehO5$&NtclGh2XCgwvoKc1XP z^D2Cz4}Yk!LC+hZs4@}vc=8@a6N>-*-*6mL1_{yW^oy_SH7v~m*S1MS{5F`3j>v&j zlGk(h(GuS*%LphFikwEn(Ab4LpM5n96FMvs?fKsn8~+35T7Br`Wmyz->PYekQ55Yq z;2<$)e#A*6hr|&UbO*3=1mN)O+~8!!aYA#83bL002ovPDHLkV1nA# BM9BaE literal 0 HcmV?d00001