Update BlockInteger/String

This commit is contained in:
Nick 2016-03-18 12:01:58 -07:00
parent 5e9454d390
commit d05d3b90df
5 changed files with 27 additions and 19 deletions

View file

@ -6,15 +6,15 @@ import net.minecraft.block.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyInteger; import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockState; import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.property.ExtendedBlockState; import net.minecraftforge.common.property.ExtendedBlockState;
import net.minecraftforge.common.property.IExtendedBlockState; import net.minecraftforge.common.property.IExtendedBlockState;
@ -38,7 +38,7 @@ public class BlockInteger extends Block
private final int maxMeta; private final int maxMeta;
private final PropertyInteger metaProp; private final PropertyInteger metaProp;
private final IUnlistedProperty unlistedMetaProp; private final IUnlistedProperty unlistedMetaProp;
private final BlockState realBlockState; private final BlockStateContainer realBlockState;
public BlockInteger(Material material, int maxMeta, String propName) public BlockInteger(Material material, int maxMeta, String propName)
{ {
@ -60,7 +60,7 @@ public class BlockInteger extends Block
@Override @Override
public IBlockState getStateFromMeta(int meta) public IBlockState getStateFromMeta(int meta)
{ {
return getBlockState().getBaseState().withProperty(metaProp, meta); return getDefaultState().withProperty(metaProp, meta);
} }
@Override @Override
@ -76,19 +76,19 @@ public class BlockInteger extends Block
} }
@Override @Override
public BlockState getBlockState() public BlockStateContainer getBlockState()
{ {
return this.realBlockState; return this.realBlockState;
} }
@Override @Override
public BlockState createBlockState() public BlockStateContainer createBlockState()
{ {
return Blocks.air.getBlockState(); return Blocks.air.getBlockState();
} }
@Override @Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, BlockPos pos, EntityPlayer player) public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player)
{ {
return new ItemStack(this, 1, this.getMetaFromState(world.getBlockState(pos))); return new ItemStack(this, 1, this.getMetaFromState(world.getBlockState(pos)));
} }
@ -116,7 +116,7 @@ public class BlockInteger extends Block
return (IExtendedBlockState) this.getBaseExtendedState().getBaseState(); return (IExtendedBlockState) this.getBaseExtendedState().getBaseState();
} }
private BlockState createRealBlockState() private BlockStateContainer createRealBlockState()
{ {
return new ExtendedBlockState(this, new IProperty[] { metaProp }, new IUnlistedProperty[] { unlistedMetaProp }); return new ExtendedBlockState(this, new IProperty[] { metaProp }, new IUnlistedProperty[] { unlistedMetaProp });
} }

View file

@ -4,7 +4,7 @@ import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
public abstract class BlockIntegerContainer extends BlockInteger implements ITileEntityProvider public abstract class BlockIntegerContainer extends BlockInteger implements ITileEntityProvider

View file

@ -6,15 +6,15 @@ import lombok.Getter;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockState; import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.property.ExtendedBlockState; import net.minecraftforge.common.property.ExtendedBlockState;
import net.minecraftforge.common.property.IExtendedBlockState; import net.minecraftforge.common.property.IExtendedBlockState;
@ -42,7 +42,7 @@ public class BlockString extends Block
private final List<String> values; private final List<String> values;
private final PropertyString stringProp; private final PropertyString stringProp;
private final IUnlistedProperty unlistedStringProp; private final IUnlistedProperty unlistedStringProp;
private final BlockState realBlockState; private final BlockStateContainer realBlockState;
public BlockString(Material material, String[] values, String propName) public BlockString(Material material, String[] values, String propName)
{ {
@ -81,19 +81,19 @@ public class BlockString extends Block
} }
@Override @Override
public BlockState getBlockState() public BlockStateContainer getBlockState()
{ {
return this.realBlockState; return this.realBlockState;
} }
@Override @Override
public BlockState createBlockState() public BlockStateContainer createBlockState()
{ {
return Blocks.air.getBlockState(); return Blocks.air.getBlockState();
} }
@Override @Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, BlockPos pos, EntityPlayer player) public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player)
{ {
return new ItemStack(this, 1, this.getMetaFromState(world.getBlockState(pos))); return new ItemStack(this, 1, this.getMetaFromState(world.getBlockState(pos)));
} }
@ -121,7 +121,7 @@ public class BlockString extends Block
return (IExtendedBlockState) this.getBaseExtendedState().getBaseState(); return (IExtendedBlockState) this.getBaseExtendedState().getBaseState();
} }
private BlockState createRealBlockState() private BlockStateContainer createRealBlockState()
{ {
return new ExtendedBlockState(this, new IProperty[] { stringProp }, new IUnlistedProperty[] { unlistedStringProp }); return new ExtendedBlockState(this, new IProperty[] { stringProp }, new IUnlistedProperty[] { unlistedStringProp });
} }

View file

@ -4,7 +4,7 @@ import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
public abstract class BlockStringContainer extends BlockString implements ITileEntityProvider public abstract class BlockStringContainer extends BlockString implements ITileEntityProvider

View file

@ -1,8 +1,11 @@
package WayofTime.bloodmagic.block.property; package WayofTime.bloodmagic.block.property;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import net.minecraft.block.properties.PropertyHelper; import net.minecraft.block.properties.PropertyHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@ -21,6 +24,11 @@ public class PropertyString extends PropertyHelper<String>
allowedValues = ImmutableSet.copyOf(hashSet); allowedValues = ImmutableSet.copyOf(hashSet);
} }
@SideOnly(Side.CLIENT)
public Optional<String> parseValue(String value) {
return allowedValues.contains(value) ? Optional.of(value) : Optional.<String>absent();
}
public static PropertyString create(String name, String[] values) public static PropertyString create(String name, String[] values)
{ {
return new PropertyString(name, values); return new PropertyString(name, values);