Initial work on pillars - needs some serious bug fixing!

This commit is contained in:
WayofTime 2016-09-04 16:20:10 -04:00
parent bafbd0b076
commit d52240813e
6 changed files with 306 additions and 3 deletions

View file

@ -0,0 +1,58 @@
package WayofTime.bloodmagic.block;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.util.EnumFacing;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.block.base.BlockStringPillar;
import WayofTime.bloodmagic.client.IVariantProvider;
public class BlockDemonPillar extends BlockStringPillar implements IVariantProvider
{
public static final String[] names = new String[] { "raw", "corrosive" };
public BlockDemonPillar(String baseName, Material materialIn)
{
super(materialIn, names);
setUnlocalizedName(Constants.Mod.MODID + "." + baseName + ".");
setCreativeTab(BloodMagic.tabBloodMagic);
setHardness(2.0F);
setResistance(5.0F);
setSoundType(SoundType.STONE);
setHarvestLevel("pickaxe", 2);
}
@Override
public List<Pair<Integer, String>> getVariants()
{
List<Pair<Integer, String>> ret = new ArrayList<Pair<Integer, String>>();
// for (int i = 0; i < 3; i++)
// {
// ret.add(new ImmutablePair<Integer, String>(i, "axis=" + EnumFacing.Axis.values()[i]));
// }
//
// for (int i = 0; i < names.length; i++)
// {
// ret.add(new ImmutablePair<Integer, String>(i + 3, "type=" + names[i]));
// }
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < names.length; j++)
{
ret.add(new ImmutablePair<Integer, String>(j * 3 + i, "axis=" + EnumFacing.Axis.values()[i] + ",type=" + names[j]));
}
}
return ret;
}
}

View file

@ -99,7 +99,7 @@ public class BlockString extends Block
list.add(new ItemStack(this, 1, i));
}
private void setupStates()
protected void setupStates()
{
this.setDefaultState(getExtendedBlockState().withProperty(unlistedStringProp, values.get(0)).withProperty(stringProp, values.get(0)));
}
@ -114,7 +114,7 @@ public class BlockString extends Block
return (IExtendedBlockState) this.getBaseExtendedState().getBaseState();
}
private BlockStateContainer createRealBlockState()
protected BlockStateContainer createRealBlockState()
{
return new ExtendedBlockState(this, new IProperty[] { stringProp }, new IUnlistedProperty[] { unlistedStringProp });
}

View file

@ -0,0 +1,156 @@
package WayofTime.bloodmagic.block.base;
import net.minecraft.block.BlockRotatedPillar;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.property.ExtendedBlockState;
import net.minecraftforge.common.property.IUnlistedProperty;
public class BlockStringPillar extends BlockString
{
public BlockStringPillar(Material material, String[] values, String propName)
{
super(material, values, propName);
}
public BlockStringPillar(Material material, String[] values)
{
this(material, values, "type");
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
{
// System.out.println(state);
return false;
}
/**
* Convert the given metadata into a BlockState for this Block
*/
@Override
public IBlockState getStateFromMeta(int meta)
{
IBlockState iblockstate = this.getDefaultState().withProperty(this.getStringProp(), this.getValues().get((meta & 3) % 4));
switch (meta & 12)
{
case 0:
iblockstate = iblockstate.withProperty(BlockRotatedPillar.AXIS, EnumFacing.Axis.Y);
break;
case 4:
iblockstate = iblockstate.withProperty(BlockRotatedPillar.AXIS, EnumFacing.Axis.X);
break;
case 8:
iblockstate = iblockstate.withProperty(BlockRotatedPillar.AXIS, EnumFacing.Axis.Z);
break;
default:
iblockstate.withProperty(BlockRotatedPillar.AXIS, EnumFacing.Axis.Y);
break;
}
// System.out.println(iblockstate);
return iblockstate;
}
@SuppressWarnings("incomplete-switch")
@Override
public int getMetaFromState(IBlockState state)
{
int i = 0;
i = i | this.getValues().indexOf(String.valueOf(state.getValue(this.getStringProp())));
switch ((EnumFacing.Axis) state.getValue(BlockRotatedPillar.AXIS))
{
case X:
i |= 4;
break;
case Z:
i |= 8;
break;
// case NONE:
// i |= 12;
}
return i;
}
@Override
public boolean rotateBlock(net.minecraft.world.World world, BlockPos pos, EnumFacing axis)
{
net.minecraft.block.state.IBlockState state = world.getBlockState(pos);
for (net.minecraft.block.properties.IProperty<?> prop : state.getProperties().keySet())
{
if (prop == BlockRotatedPillar.AXIS)
{
world.setBlockState(pos, state.cycleProperty(prop));
return true;
}
}
return false;
}
@Override
public IBlockState withRotation(IBlockState state, Rotation rot)
{
switch (rot)
{
case COUNTERCLOCKWISE_90:
case CLOCKWISE_90:
switch (state.getValue(BlockRotatedPillar.AXIS))
{
case X:
return state.withProperty(BlockRotatedPillar.AXIS, EnumFacing.Axis.Z);
case Z:
return state.withProperty(BlockRotatedPillar.AXIS, EnumFacing.Axis.X);
default:
return state;
}
default:
return state;
}
}
@Override
protected void setupStates()
{
this.setDefaultState(getExtendedBlockState().withProperty(this.getUnlistedStringProp(), this.getValues().get(0)).withProperty(this.getStringProp(), this.getValues().get(0)).withProperty(BlockRotatedPillar.AXIS, EnumFacing.Axis.Y));
}
// @Override
// protected BlockStateContainer createBlockState()
// {
// return new BlockStateContainer(this, new IProperty[] { this.getStringProp(), BlockRotatedPillar.AXIS });
// }
@Override
protected BlockStateContainer createRealBlockState()
{
return new ExtendedBlockState(this, new IProperty[] { BlockRotatedPillar.AXIS, this.getStringProp() }, new IUnlistedProperty[] { this.getUnlistedStringProp() });
}
@Override
protected ItemStack createStackedBlock(IBlockState state)
{
return new ItemStack(Item.getItemFromBlock(this), 1, this.getValues().indexOf(String.valueOf(state.getValue(this.getStringProp()))));
}
@Override
public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
return super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer).withProperty(BlockRotatedPillar.AXIS, facing.getAxis());
}
}