From 5f6bf3b063d5c8a44f6b9bfd1b1b7d85de3ab58c Mon Sep 17 00:00:00 2001 From: James Mitchell Date: Sun, 19 Feb 2017 12:48:43 -0600 Subject: [PATCH] Stop rotation of extended pistons, beds, and double chests Fixes #3634 Fix rotation of repeaters and comparators --- .../net/minecraft/block/Block.java.patch | 41 ++++++- .../net/minecraft/block/BlockChest.java.patch | 11 ++ .../block/BlockPistonBase.java.patch | 12 ++ .../block/BlockRedstoneDiode.java.patch | 24 ++++ .../debug/WrenchRotateDebug.java | 106 ++++++++++++++++++ .../models/item/test_wrench.json | 6 + .../textures/items/test_wrench.png | Bin 0 -> 202 bytes 7 files changed, 194 insertions(+), 6 deletions(-) create mode 100644 src/test/java/net/minecraftforge/debug/WrenchRotateDebug.java create mode 100644 src/test/resources/assets/wrenchrotatedebug/models/item/test_wrench.json create mode 100644 src/test/resources/assets/wrenchrotatedebug/textures/items/test_wrench.png diff --git a/patches/minecraft/net/minecraft/block/Block.java.patch b/patches/minecraft/net/minecraft/block/Block.java.patch index 8df9a21274..cbf7f64160 100644 --- a/patches/minecraft/net/minecraft/block/Block.java.patch +++ b/patches/minecraft/net/minecraft/block/Block.java.patch @@ -197,7 +197,7 @@ public SoundType func_185467_w() { return this.field_149762_H; -@@ -908,6 +932,1188 @@ +@@ -908,6 +932,1217 @@ { } @@ -1037,10 +1037,39 @@ + IBlockState state = world.func_180495_p(pos); + for (IProperty prop : state.func_177228_b().keySet()) + { -+ if (prop.func_177701_a().equals("facing") || prop.func_177701_a().equals("rotation")) ++ if ((prop.func_177701_a().equals("facing") || prop.func_177701_a().equals("rotation")) && prop.func_177699_b() == EnumFacing.class) + { -+ world.func_175656_a(pos, state.func_177231_a(prop)); -+ return true; ++ Block block = state.func_177230_c(); ++ if (!(block instanceof BlockBed) && !(block instanceof BlockPistonExtension)) ++ { ++ IBlockState newState; ++ //noinspection unchecked ++ IProperty facingProperty = (IProperty) prop; ++ EnumFacing facing = state.func_177229_b(facingProperty); ++ java.util.Collection validFacings = facingProperty.func_177700_c(); ++ ++ // rotate horizontal facings clockwise ++ if (validFacings.size() == 4 && !validFacings.contains(EnumFacing.UP) && !validFacings.contains(EnumFacing.DOWN)) ++ { ++ newState = state.func_177226_a(facingProperty, facing.func_176746_e()); ++ } ++ else ++ { ++ // rotate other facings about the axis ++ EnumFacing rotatedFacing = facing.func_176732_a(axis.func_176740_k()); ++ if (validFacings.contains(rotatedFacing)) ++ { ++ newState = state.func_177226_a(facingProperty, rotatedFacing); ++ } ++ else // abnormal facing property, just cycle it ++ { ++ newState = state.func_177231_a(facingProperty); ++ } ++ } ++ ++ world.func_175656_a(pos, newState); ++ return true; ++ } + } + } + return false; @@ -1059,7 +1088,7 @@ + IBlockState state = world.func_180495_p(pos); + for (IProperty prop : state.func_177228_b().keySet()) + { -+ if (prop.func_177701_a().equals("facing") && prop.func_177699_b() == EnumFacing.class) ++ if ((prop.func_177701_a().equals("facing") || prop.func_177701_a().equals("rotation")) && prop.func_177699_b() == EnumFacing.class) + { + @SuppressWarnings("unchecked") + java.util.Collection values = ((java.util.Collection)prop.func_177700_c()); @@ -1386,7 +1415,7 @@ public static void func_149671_p() { func_176215_a(0, field_176230_a, (new BlockAir()).func_149663_c("air")); -@@ -1201,14 +2407,7 @@ +@@ -1201,14 +2436,7 @@ } else { diff --git a/patches/minecraft/net/minecraft/block/BlockChest.java.patch b/patches/minecraft/net/minecraft/block/BlockChest.java.patch index 55d6a8433c..338a9c4499 100644 --- a/patches/minecraft/net/minecraft/block/BlockChest.java.patch +++ b/patches/minecraft/net/minecraft/block/BlockChest.java.patch @@ -9,3 +9,14 @@ } private boolean func_176453_o(World p_176453_1_, BlockPos p_176453_2_) +@@ -587,4 +587,10 @@ + BASIC, + TRAP; + } ++ ++ /* ======================================== FORGE START =====================================*/ ++ public boolean rotateBlock(World world, BlockPos pos, EnumFacing axis) ++ { ++ return !func_176454_e(world, pos) && super.rotateBlock(world, pos, axis); ++ } + } diff --git a/patches/minecraft/net/minecraft/block/BlockPistonBase.java.patch b/patches/minecraft/net/minecraft/block/BlockPistonBase.java.patch index de7791e604..7acd5d449c 100644 --- a/patches/minecraft/net/minecraft/block/BlockPistonBase.java.patch +++ b/patches/minecraft/net/minecraft/block/BlockPistonBase.java.patch @@ -29,3 +29,15 @@ p_176319_1_.func_180501_a(blockpos1, Blocks.field_150350_a.func_176223_P(), 4); --k; aiblockstate[k] = iblockstate; +@@ -432,4 +434,11 @@ + { + return new BlockStateContainer(this, new IProperty[] {field_176387_N, field_176320_b}); + } ++ ++ /* ======================================== FORGE START =====================================*/ ++ public boolean rotateBlock(World world, BlockPos pos, EnumFacing axis) ++ { ++ IBlockState state = world.func_180495_p(pos); ++ return !state.func_177229_b(field_176320_b) && super.rotateBlock(world, pos, axis); ++ } + } diff --git a/patches/minecraft/net/minecraft/block/BlockRedstoneDiode.java.patch b/patches/minecraft/net/minecraft/block/BlockRedstoneDiode.java.patch index 43c5d17416..7225c69915 100644 --- a/patches/minecraft/net/minecraft/block/BlockRedstoneDiode.java.patch +++ b/patches/minecraft/net/minecraft/block/BlockRedstoneDiode.java.patch @@ -9,3 +9,27 @@ p_176400_1_.func_190524_a(blockpos, this, p_176400_2_); p_176400_1_.func_175695_a(blockpos, this, enumfacing); } +@@ -275,4 +277,23 @@ + { + return BlockRenderLayer.CUTOUT; + } ++ ++ /* ======================================== FORGE START =====================================*/ ++ @Override ++ public boolean rotateBlock(World world, BlockPos pos, EnumFacing axis) ++ { ++ if (super.rotateBlock(world, pos, axis)) ++ { ++ IBlockState state = world.func_180495_p(pos); ++ state = func_180675_k(state); ++ world.func_175656_a(pos, state); ++ ++ if (func_176404_e(world, pos, state)) ++ { ++ world.func_175684_a(pos, this, 1); ++ } ++ return true; ++ } ++ return false; ++ } + } diff --git a/src/test/java/net/minecraftforge/debug/WrenchRotateDebug.java b/src/test/java/net/minecraftforge/debug/WrenchRotateDebug.java new file mode 100644 index 0000000000..412f1de617 --- /dev/null +++ b/src/test/java/net/minecraftforge/debug/WrenchRotateDebug.java @@ -0,0 +1,106 @@ +package net.minecraftforge.debug; + +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.ItemMeshDefinition; +import net.minecraft.client.renderer.block.model.ModelBakery; +import net.minecraft.client.renderer.block.model.ModelResourceLocation; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.client.model.ModelLoader; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.SidedProxy; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.fml.common.registry.GameRegistry; + +@Mod(modid = WrenchRotateDebug.modID, name = "Wrench Rotate Debug", version = "0.0.0") +public class WrenchRotateDebug +{ + public static final String modID = "wrenchrotatedebug"; + private static final ResourceLocation testWrenchName = new ResourceLocation(modID, "test_wrench"); + + @SidedProxy + public static CommonProxy proxy; + + @Mod.EventHandler + public void preInit(FMLPreInitializationEvent event) + { + TestWrench wrench = new TestWrench(); + wrench.setRegistryName(testWrenchName); + + GameRegistry.register(wrench); + proxy.setupModel(wrench); + } + + public static class CommonProxy + { + void setupModel(TestWrench wrench) + { + } + } + + public static class ServerProxy extends CommonProxy + { + } + + public static class ClientProxy extends CommonProxy + { + @SuppressWarnings("unused") + @Override + void setupModel(TestWrench wrench) + { + final ModelResourceLocation wrenchName = new ModelResourceLocation(testWrenchName, "inventory"); + ModelBakery.registerItemVariants(wrench, wrenchName); + ModelLoader.setCustomMeshDefinition(wrench, new ItemMeshDefinition() + { + @Override + public ModelResourceLocation getModelLocation(ItemStack stack) + { + return wrenchName; + } + }); + } + } + + public static class TestWrench extends Item + { + public TestWrench() + { + setCreativeTab(CreativeTabs.TOOLS); + setMaxStackSize(1); + setHarvestLevel("wrench", 0); + } + + @Override + public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) + { + ItemStack wrench = player.getHeldItem(hand); + if (player.canPlayerEdit(pos, facing, wrench) && worldIn.isBlockModifiable(player, pos)) + { + IBlockState blockState = worldIn.getBlockState(pos); + Block block = blockState.getBlock(); + if (block.rotateBlock(worldIn, pos, facing)) + { + player.swingArm(hand); + worldIn.notifyNeighborsOfStateChange(pos, block, false); + return EnumActionResult.SUCCESS; + } + } + return EnumActionResult.FAIL; + } + + @Override + public String getItemStackDisplayName(ItemStack stack) + { + return "Forge Test Wrench"; + } + } +} diff --git a/src/test/resources/assets/wrenchrotatedebug/models/item/test_wrench.json b/src/test/resources/assets/wrenchrotatedebug/models/item/test_wrench.json new file mode 100644 index 0000000000..c4b504fa82 --- /dev/null +++ b/src/test/resources/assets/wrenchrotatedebug/models/item/test_wrench.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "wrenchrotatedebug:items/test_wrench" + } +} diff --git a/src/test/resources/assets/wrenchrotatedebug/textures/items/test_wrench.png b/src/test/resources/assets/wrenchrotatedebug/textures/items/test_wrench.png new file mode 100644 index 0000000000000000000000000000000000000000..3a6ce07e3eb4e709050d133897307faa4cbcf160 GIT binary patch literal 202 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbL!WQl7;NpOBzNqJ&XDuZK6ep0G} zXKrG8YEWuoN@d~6R2!fo&H$efS0KH>hWr2j|C)k4yMP?#k|4j}|Nj}TpW<}{ay>j< z978H@#hi~8V^Cmmy?FQ!``j-FzFyo^rm=(NISZpPo6E_`^??PqtW$19E2W?7FfR*m t-u%d`_63(-Q}+XBwI_Wqet9=AGF&ZZoN!6*ry0;p22WQ%mvv4FO#rU2L;U~% literal 0 HcmV?d00001