Stop rotation of extended pistons, beds, and double chests Fixes #3634

Fix rotation of repeaters and comparators
This commit is contained in:
James Mitchell 2017-02-19 12:48:43 -06:00 committed by LexManos
parent caa85b33bf
commit 5f6bf3b063
7 changed files with 194 additions and 6 deletions

View file

@ -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<EnumFacing> facingProperty = (IProperty<EnumFacing>) prop;
+ EnumFacing facing = state.func_177229_b(facingProperty);
+ java.util.Collection<EnumFacing> 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<EnumFacing> values = ((java.util.Collection<EnumFacing>)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
{

View file

@ -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);
+ }
}

View file

@ -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);
+ }
}

View file

@ -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;
+ }
}

View file

@ -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";
}
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "wrenchrotatedebug:items/test_wrench"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 B