Limited some blocks to only have a direction on the x-axis

This commit is contained in:
Raoul Van den Berge
2016-07-08 02:34:49 +02:00
parent 0c3462d7bb
commit 48023abb0f
25 changed files with 189 additions and 144 deletions

View File

@@ -1,9 +1,7 @@
package refinedstorage.block;
import net.minecraft.block.Block;
import net.minecraft.block.BlockPistonBase;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
@@ -43,11 +41,19 @@ public abstract class BlockBase extends Block {
return "block." + RefinedStorage.ID + ":" + name;
}
protected BlockStateContainer.Builder createBlockStateBuilder() {
BlockStateContainer.Builder builder = new BlockStateContainer.Builder(this);
if (getDirectionType() != null) {
builder.add(DIRECTION);
}
return builder;
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, new IProperty[]{
DIRECTION,
});
return createBlockStateBuilder().build();
}
@Override
@@ -62,10 +68,12 @@ public abstract class BlockBase extends Block {
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
TileEntity tile = world.getTileEntity(pos);
if (getDirectionType() != null) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileBase) {
return state.withProperty(DIRECTION, ((TileBase) tile).getDirection());
if (tile instanceof TileBase) {
return state.withProperty(DIRECTION, ((TileBase) tile).getDirection());
}
}
return state;
@@ -78,41 +86,37 @@ public abstract class BlockBase extends Block {
@Override
public boolean rotateBlock(World world, BlockPos pos, EnumFacing axis) {
TileEntity tile = world.getTileEntity(pos);
if (!world.isRemote && getDirectionType() != null) {
TileEntity tile = world.getTileEntity(pos);
if (!world.isRemote && tile instanceof TileBase) {
EnumFacing dir = ((TileBase) tile).getDirection();
if (tile instanceof TileBase) {
((TileBase) tile).setDirection(getDirectionType().getNext(((TileBase) tile).getDirection()));
int newDir = dir.ordinal() + 1;
RefinedStorageUtils.updateBlock(world, pos);
if (newDir > EnumFacing.VALUES.length - 1) {
newDir = 0;
return true;
}
((TileBase) tile).setDirection(EnumFacing.getFront(newDir));
RefinedStorageUtils.updateBlock(world, pos);
return true;
}
return false;
}
@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack itemStack) {
super.onBlockPlacedBy(world, pos, state, player, itemStack);
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack stack) {
super.onBlockPlacedBy(world, pos, state, player, stack);
TileEntity tile = world.getTileEntity(pos);
if (getDirectionType() != null) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileBase) {
EnumFacing facing = BlockPistonBase.getFacingFromEntity(pos, player);
if (tile instanceof TileBase) {
EnumFacing facing = getDirectionType().getFrom(pos, player);
if (player.isSneaking() && hasOppositeFacingOnSneakPlace()) {
facing = facing.getOpposite();
if (player.isSneaking() && canBePlacedOpposite()) {
facing = facing.getOpposite();
}
((TileBase) tile).setDirection(facing);
}
((TileBase) tile).setDirection(facing);
}
}
@@ -135,11 +139,7 @@ public abstract class BlockBase extends Block {
@Override
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
if (willHarvest) {
return true;
}
return super.removedByPlayer(state, world, pos, player, willHarvest);
return willHarvest ? true : super.removedByPlayer(state, world, pos, player, willHarvest);
}
@Override
@@ -153,7 +153,11 @@ public abstract class BlockBase extends Block {
return new ItemBlockBase(this, false);
}
public boolean hasOppositeFacingOnSneakPlace() {
public boolean canBePlacedOpposite() {
return false;
}
public EnumDirectionType getDirectionType() {
return EnumDirectionType.HORIZONTAL;
}
}

View File

@@ -1,6 +1,5 @@
package refinedstorage.block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
@@ -36,14 +35,14 @@ public class BlockCable extends BlockNode {
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, new IProperty[]{
NORTH,
EAST,
SOUTH,
WEST,
UP,
DOWN,
});
return new BlockStateContainer.Builder(this)
.add(NORTH)
.add(EAST)
.add(SOUTH)
.add(WEST)
.add(UP)
.add(DOWN)
.build();
}
@Override
@@ -74,4 +73,9 @@ public class BlockCable extends BlockNode {
public boolean isFullCube(IBlockState state) {
return false;
}
@Override
public EnumDirectionType getDirectionType() {
return null;
}
}

View File

@@ -32,7 +32,12 @@ public class BlockConstructor extends BlockNode {
}
@Override
public boolean hasOppositeFacingOnSneakPlace() {
public boolean canBePlacedOpposite() {
return true;
}
@Override
public EnumDirectionType getDirectionType() {
return EnumDirectionType.ANY;
}
}

View File

@@ -1,7 +1,6 @@
package refinedstorage.block;
import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockStateContainer;
@@ -44,11 +43,10 @@ public class BlockController extends BlockBase {
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, new IProperty[]{
DIRECTION,
TYPE,
ENERGY
});
return createBlockStateBuilder()
.add(TYPE)
.add(ENERGY)
.build();
}
@Override

View File

@@ -32,7 +32,12 @@ public class BlockCrafter extends BlockNode {
}
@Override
public boolean hasOppositeFacingOnSneakPlace() {
public boolean canBePlacedOpposite() {
return true;
}
@Override
public EnumDirectionType getDirectionType() {
return EnumDirectionType.ANY;
}
}

View File

@@ -32,7 +32,12 @@ public class BlockDestructor extends BlockNode {
}
@Override
public boolean hasOppositeFacingOnSneakPlace() {
public boolean canBePlacedOpposite() {
return true;
}
@Override
public EnumDirectionType getDirectionType() {
return EnumDirectionType.ANY;
}
}

View File

@@ -1,6 +1,5 @@
package refinedstorage.block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
@@ -25,11 +24,9 @@ public class BlockDetector extends BlockNode {
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, new IProperty[]{
DIRECTION,
CONNECTED,
POWERED
});
return createBlockStateBuilder()
.add(POWERED)
.build();
}
@Override
@@ -72,4 +69,9 @@ public class BlockDetector extends BlockNode {
return true;
}
@Override
public EnumDirectionType getDirectionType() {
return EnumDirectionType.ANY;
}
}

View File

@@ -32,7 +32,12 @@ public class BlockExporter extends BlockNode {
}
@Override
public boolean hasOppositeFacingOnSneakPlace() {
public boolean canBePlacedOpposite() {
return true;
}
@Override
public EnumDirectionType getDirectionType() {
return EnumDirectionType.ANY;
}
}

View File

@@ -46,7 +46,12 @@ public class BlockExternalStorage extends BlockNode {
}
@Override
public boolean hasOppositeFacingOnSneakPlace() {
public boolean canBePlacedOpposite() {
return true;
}
@Override
public EnumDirectionType getDirectionType() {
return EnumDirectionType.ANY;
}
}

View File

@@ -1,6 +1,5 @@
package refinedstorage.block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
@@ -41,11 +40,9 @@ public class BlockGrid extends BlockNode {
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, new IProperty[]{
DIRECTION,
CONNECTED,
TYPE
});
return createBlockStateBuilder()
.add(TYPE)
.build();
}
@Override

View File

@@ -32,7 +32,12 @@ public class BlockImporter extends BlockNode {
}
@Override
public boolean hasOppositeFacingOnSneakPlace() {
public boolean canBePlacedOpposite() {
return true;
}
@Override
public EnumDirectionType getDirectionType() {
return EnumDirectionType.ANY;
}
}

View File

@@ -30,4 +30,9 @@ public class BlockInterface extends BlockNode {
return true;
}
@Override
public EnumDirectionType getDirectionType() {
return null;
}
}

View File

@@ -4,4 +4,9 @@ public class BlockMachineCasing extends BlockBase {
public BlockMachineCasing() {
super("machine_casing");
}
@Override
public EnumDirectionType getDirectionType() {
return null;
}
}

View File

@@ -1,6 +1,5 @@
package refinedstorage.block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
@@ -26,12 +25,14 @@ public abstract class BlockNode extends BlockBase {
return true;
}
@Override
protected BlockStateContainer.Builder createBlockStateBuilder() {
return super.createBlockStateBuilder().add(CONNECTED);
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, new IProperty[]{
DIRECTION,
CONNECTED
});
return createBlockStateBuilder().build();
}
@Override

View File

@@ -4,4 +4,9 @@ public class BlockQuartzEnrichedIron extends BlockBase {
public BlockQuartzEnrichedIron() {
super("quartz_enriched_iron_block");
}
@Override
public EnumDirectionType getDirectionType() {
return null;
}
}

View File

@@ -30,4 +30,9 @@ public class BlockRelay extends BlockNode {
return true;
}
@Override
public EnumDirectionType getDirectionType() {
return null;
}
}

View File

@@ -1,6 +1,5 @@
package refinedstorage.block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
@@ -39,11 +38,9 @@ public class BlockSolderer extends BlockNode {
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, new IProperty[]{
DIRECTION,
CONNECTED,
WORKING
});
return createBlockStateBuilder()
.add(WORKING)
.build();
}
@Override

View File

@@ -1,6 +1,5 @@
package refinedstorage.block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
@@ -41,11 +40,9 @@ public class BlockStorage extends BlockNode {
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, new IProperty[]{
DIRECTION,
CONNECTED,
TYPE
});
return createBlockStateBuilder()
.add(TYPE)
.build();
}
@Override
@@ -107,4 +104,9 @@ public class BlockStorage extends BlockNode {
public Item createItemForBlock() {
return new ItemBlockStorage();
}
@Override
public EnumDirectionType getDirectionType() {
return null;
}
}

View File

@@ -0,0 +1,46 @@
package refinedstorage.block;
import net.minecraft.block.BlockPistonBase;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
public enum EnumDirectionType {
ANY(
EnumFacing.VALUES
),
HORIZONTAL(
EnumFacing.NORTH,
EnumFacing.EAST,
EnumFacing.SOUTH,
EnumFacing.WEST
);
public final EnumFacing[] allowed;
EnumDirectionType(EnumFacing... allowed) {
this.allowed = allowed;
}
EnumFacing getFrom(BlockPos pos, EntityLivingBase entity) {
switch (this) {
case ANY:
return BlockPistonBase.getFacingFromEntity(pos, entity);
case HORIZONTAL:
return entity.getHorizontalFacing().getOpposite();
default:
return null;
}
}
EnumFacing getNext(EnumFacing previous) {
switch (this) {
case ANY:
return previous.ordinal() + 1 >= EnumFacing.VALUES.length ? EnumFacing.VALUES[0] : EnumFacing.VALUES[previous.ordinal() + 1];
case HORIZONTAL:
return previous.rotateYCCW();
default:
return previous;
}
}
}

View File

@@ -103,7 +103,6 @@ public class ClientProxy extends CommonProxy {
// Blocks
ModelLoader.setCustomStateMapper(RefinedStorageBlocks.STORAGE, (new StateMap.Builder())
.ignore(RefinedStorageBlocks.STORAGE.DIRECTION)
.ignore(RefinedStorageBlocks.STORAGE.CONNECTED)
.build()
);

View File

@@ -12,20 +12,6 @@
"transform": "forge:default-block"
}
],
"direction": {
"north": {
},
"east": {
},
"south": {
},
"west": {
},
"up": {
},
"down": {
}
},
"connected": {
"true": {
},

View File

@@ -11,20 +11,6 @@
{
"transform": "forge:default-block"
}
],
"direction": {
"north": {
},
"east": {
},
"south": {
},
"west": {
},
"up": {
},
"down": {
}
}
]
}
}

View File

@@ -11,20 +11,6 @@
{
"transform": "forge:default-block"
}
],
"direction": {
"north": {
},
"east": {
},
"south": {
},
"west": {
},
"up": {
},
"down": {
}
}
]
}
}

View File

@@ -12,20 +12,6 @@
"transform": "forge:default-block"
}
],
"direction": {
"north": {
},
"east": {
},
"south": {
},
"west": {
},
"up": {
},
"down": {
}
},
"connected": {
"true": {
"textures": {