Added some last finishing touches on Dimensional walls.

Added some last finishing touches on Dimensional walls.
This commit is contained in:
Waterpicker 2017-01-13 00:36:28 -06:00
parent e1facdbf3b
commit 8ef079b122
2 changed files with 39 additions and 14 deletions

View file

@ -8,6 +8,7 @@ import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
@ -19,6 +20,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.Explosion;
@ -33,7 +35,7 @@ import javax.annotation.Nullable;
public class BlockDimWall extends Block {
public static final String ID = "blockDimWall";
public static final PropertyInteger TYPE = PropertyInteger.create("type", 0, 2);
public static final PropertyEnum<BlockDimWall.EnumType> TYPE = PropertyEnum.<BlockDimWall.EnumType>create("type", BlockDimWall.EnumType.class);
private static final float SUPER_HIGH_HARDNESS = 10000000000000F;
private static final float SUPER_EXPLOSION_RESISTANCE = 18000000F;
@ -45,14 +47,14 @@ public class BlockDimWall extends Block {
setHardness(0.1F);
setUnlocalizedName(ID);
setRegistryName(ID);
setDefaultState(blockState.getBaseState().withProperty(TYPE, 0));
setDefaultState(blockState.getBaseState().withProperty(TYPE, EnumType.FABRIC));
setSoundType(SoundType.STONE);
}
@Override
public IBlockState getStateFromMeta(int meta) {
if (meta >= 0 && meta <= 2) {
return getDefaultState().withProperty(TYPE, meta);
return getDefaultState().withProperty(TYPE, EnumType.values()[meta]);
} else {
return getDefaultState();
}
@ -60,7 +62,7 @@ public class BlockDimWall extends Block {
@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(TYPE);
return state.getValue(TYPE).ordinal();
}
@Override
@ -70,7 +72,7 @@ public class BlockDimWall extends Block {
@Override
public float getBlockHardness(IBlockState state, World world, BlockPos pos) {
if (state.getValue(TYPE) != 1) {
if (!state.getValue(TYPE).equals(EnumType.ANCIENT)) {
return this.blockHardness;
} else {
return SUPER_HIGH_HARDNESS;
@ -79,7 +81,7 @@ public class BlockDimWall extends Block {
@Override
public float getExplosionResistance(World world, BlockPos pos, Entity exploder, Explosion explosion) {
if (world.getBlockState(pos).getValue(TYPE) != 1) {
if (!world.getBlockState(pos).getValue(TYPE).equals(EnumType.ANCIENT)) {
return super.getExplosionResistance(world, pos, exploder, explosion);
} else {
return SUPER_EXPLOSION_RESISTANCE;
@ -88,7 +90,7 @@ public class BlockDimWall extends Block {
@Override
public int damageDropped(IBlockState state) {
int metadata = state.getValue(TYPE);
int metadata = state.getValue(TYPE).ordinal();
//Return 0 to avoid dropping Ancient Fabric even if the player somehow manages to break it
return metadata == 1 ? 0 : metadata;
}
@ -123,7 +125,7 @@ public class BlockDimWall extends Block {
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
//Check if the metadata value is 0 -- we don't want the user to replace Ancient Fabric
if (heldItem != null && state.getValue(TYPE) != 1) {
if (heldItem != null && !state.getValue(TYPE).equals(EnumType.ANCIENT)) {
Block block = Block.getBlockFromItem(heldItem.getItem());
if (!state.isNormalCube() || block.hasTileEntity(block.getDefaultState())
|| block == this //this also keeps it from being replaced by Ancient Fabric
@ -134,11 +136,34 @@ public class BlockDimWall extends Block {
if (!player.capabilities.isCreativeMode) {
heldItem.stackSize--;
}
world.setBlockState(pos, block.getStateForPlacement(
world, pos, side, hitX, hitY, hitZ, 0, player, heldItem)); //choosing getStateForPlacement over getDefaultState, because it will cause directional blocks, like logs to rotate correctly
world.setBlockState(pos, block.getStateForPlacement(world, pos, side, hitX, hitY, hitZ, 0, player, heldItem)); //choosing getStateForPlacement over getDefaultState, because it will cause directional blocks, like logs to rotate correctly
heldItem.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ);
}
return true;
}
return false;
}
public static enum EnumType implements IStringSerializable {
FABRIC("fabric"),
ANCIENT("ancient"),
ALTERED("altered");
private final String name;
private EnumType(String name)
{
this.name = name;
}
public String toString()
{
return this.name;
}
public String getName()
{
return this.name;
}
}
}

View file

@ -1,7 +1,7 @@
{
"variants": {
"type=0": { "model": "dimdoors:blockDimWall" },
"type=1": { "model": "dimdoors:blockDimWallAncient" },
"type=2": { "model": "dimdoors:blockDimWallAltered" }
"type=fabric": { "model": "dimdoors:blockDimWall" },
"type=ancient": { "model": "dimdoors:blockDimWallAncient" },
"type=altered": { "model": "dimdoors:blockDimWallAltered" }
}
}