Add missing itemblock for demon crystals ()

Still need to figure out the rendering issue. Might just need to rewrite
them to store the age as meta instead of the type.
This commit is contained in:
Nicholas Ignoffo 2018-04-07 13:05:32 -07:00
parent 234ccd4935
commit c8b394bf86
2 changed files with 82 additions and 95 deletions
src/main/java/WayofTime/bloodmagic

View file

@ -1,9 +1,12 @@
package WayofTime.bloodmagic.block; package WayofTime.bloodmagic.block;
import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.client.IVariantProvider;
import WayofTime.bloodmagic.item.block.ItemBlockDemonCrystal;
import WayofTime.bloodmagic.soul.EnumDemonWillType; import WayofTime.bloodmagic.soul.EnumDemonWillType;
import WayofTime.bloodmagic.soul.PlayerDemonWillHandler; import WayofTime.bloodmagic.soul.PlayerDemonWillHandler;
import WayofTime.bloodmagic.tile.TileDemonCrystal; import WayofTime.bloodmagic.tile.TileDemonCrystal;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
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.PropertyEnum; import net.minecraft.block.properties.PropertyEnum;
@ -12,6 +15,7 @@ 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.item.ItemBlock;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumBlockRenderType; import net.minecraft.util.EnumBlockRenderType;
@ -22,10 +26,11 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Random; import java.util.Random;
public class BlockDemonCrystal extends Block { public class BlockDemonCrystal extends Block implements IBMBlock, IVariantProvider {
public static final PropertyInteger AGE = PropertyInteger.create("age", 0, 6); public static final PropertyInteger AGE = PropertyInteger.create("age", 0, 6);
public static final PropertyEnum<EnumDemonWillType> TYPE = PropertyEnum.create("type", EnumDemonWillType.class); public static final PropertyEnum<EnumDemonWillType> TYPE = PropertyEnum.create("type", EnumDemonWillType.class);
public static final PropertyEnum<EnumFacing> ATTACHED = PropertyEnum.create("attached", EnumFacing.class); public static final PropertyEnum<EnumFacing> ATTACHED = PropertyEnum.create("attached", EnumFacing.class);
@ -42,40 +47,80 @@ public class BlockDemonCrystal extends Block {
} }
@Override @Override
public boolean canPlaceBlockOnSide(World world, BlockPos pos, EnumFacing side) { public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
BlockPos offsetPos = pos.offset(side.getOpposite()); if (world.isRemote)
IBlockState offsetState = world.getBlockState(offsetPos); return true;
Block offsetBlock = offsetState.getBlock();
return offsetBlock.isSideSolid(offsetState, world, offsetPos, side) && this.canPlaceBlockAt(world, pos); TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileDemonCrystal) {
TileDemonCrystal crystal = (TileDemonCrystal) tile;
if (PlayerDemonWillHandler.getTotalDemonWill(EnumDemonWillType.DEFAULT, player) > 1024)
crystal.dropSingleCrystal();
}
return true;
} }
@Override @Override
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos) { public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
TileDemonCrystal tile = (TileDemonCrystal) world.getTileEntity(pos); TileEntity tile = world.getTileEntity(pos);
EnumFacing placement = tile.getPlacement(); if (tile instanceof TileDemonCrystal) {
BlockPos offsetPos = pos.offset(placement.getOpposite()); EnumDemonWillType type = state.getValue(TYPE);
IBlockState offsetState = world.getBlockState(offsetPos); int number = ((TileDemonCrystal) tile).getCrystalCount();
Block offsetBlock = offsetState.getBlock();
if (!offsetBlock.isSideSolid(offsetState, world, offsetPos, placement)) { drops.add(getItemStackDropped(type, number));
world.setBlockToAir(pos);
} }
} }
@Override @Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) { public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
if (world.getTileEntity(pos) == null) { TileEntity tile = world.getTileEntity(pos);
return state; if (tile instanceof TileDemonCrystal) {
TileDemonCrystal crystal = (TileDemonCrystal) tile;
state = state.withProperty(AGE, crystal.getCrystalCountForRender());
state = state.withProperty(ATTACHED, crystal.getPlacement());
} }
TileDemonCrystal tile = (TileDemonCrystal) world.getTileEntity(pos); return state;
return state.withProperty(AGE, tile.getCrystalCountForRender()).withProperty(ATTACHED, tile.getPlacement()); }
@Override
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileDemonCrystal) {
TileDemonCrystal crystal = (TileDemonCrystal) tile;
EnumFacing placement = crystal.getPlacement();
BlockPos offsetPos = pos.offset(placement.getOpposite());
IBlockState offsetState = world.getBlockState(offsetPos);
if (!offsetState.isSideSolid(world, offsetPos, placement))
world.destroyBlock(pos, true);
}
}
@Override
public boolean canPlaceBlockOnSide(World world, BlockPos pos, EnumFacing side) {
BlockPos offsetPos = pos.offset(side.getOpposite());
IBlockState offsetState = world.getBlockState(offsetPos);
return offsetState.isSideSolid(world, offsetPos, side) && this.canPlaceBlockAt(world, pos);
} }
@Override @Override
public void getSubBlocks(CreativeTabs creativeTabs, NonNullList<ItemStack> list) { public void getSubBlocks(CreativeTabs creativeTabs, NonNullList<ItemStack> list) {
for (int i = 0; i < EnumDemonWillType.values().length; i++) for (EnumDemonWillType willType : EnumDemonWillType.values())
list.add(new ItemStack(this, 1, i)); list.add(new ItemStack(this, 1, willType.ordinal()));
}
@Override
public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity tile, ItemStack stack) {
super.harvestBlock(world, player, pos, state, tile, stack);
world.setBlockToAir(pos);
}
@Override
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
return willHarvest || super.removedByPlayer(state, world, pos, player, false);
} }
@Override @Override
@ -103,22 +148,11 @@ public class BlockDemonCrystal extends Block {
return EnumBlockRenderType.MODEL; return EnumBlockRenderType.MODEL;
} }
// public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state)
// {
// return (worldIn.getLight(pos) >= 8 || worldIn.canSeeSky(pos)) && worldIn.getBlockState(pos.down()).getBlock().canSustainPlant(worldIn, pos.down(), net.minecraft.util.EnumFacing.UP, this);
// }
/**
* Convert the given metadata into a BlockState for this Block
*/
@Override @Override
public IBlockState getStateFromMeta(int meta) { public IBlockState getStateFromMeta(int meta) {
return this.getDefaultState().withProperty(TYPE, EnumDemonWillType.values()[meta]); return this.getDefaultState().withProperty(TYPE, EnumDemonWillType.values()[meta]);
} }
/**
* Convert the BlockState into the correct metadata value
*/
@Override @Override
public int getMetaFromState(IBlockState state) { public int getMetaFromState(IBlockState state) {
return state.getValue(TYPE).ordinal(); return state.getValue(TYPE).ordinal();
@ -129,42 +163,6 @@ public class BlockDemonCrystal extends Block {
return new BlockStateContainer(this, TYPE, AGE, ATTACHED); return new BlockStateContainer(this, TYPE, AGE, ATTACHED);
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileDemonCrystal) {
EnumDemonWillType type = state.getValue(TYPE);
int number = ((TileDemonCrystal) tile).getCrystalCount();
spawnAsEntity(world, pos, getItemStackDropped(type, number));
world.removeTileEntity(pos);
}
super.breakBlock(world, pos, state);
}
@Override
public int quantityDropped(Random random) {
return 0;
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (world.isRemote) {
return true;
}
TileDemonCrystal crystal = (TileDemonCrystal) world.getTileEntity(pos);
if (PlayerDemonWillHandler.getTotalDemonWill(EnumDemonWillType.DEFAULT, player) > 1024) {
crystal.dropSingleCrystal();
world.notifyBlockUpdate(pos, state, state, 3);
}
return true;
}
@Override @Override
public boolean hasTileEntity(IBlockState state) { public boolean hasTileEntity(IBlockState state) {
return true; return true;
@ -177,7 +175,7 @@ public class BlockDemonCrystal extends Block {
} }
public static ItemStack getItemStackDropped(EnumDemonWillType type, int crystalNumber) { public static ItemStack getItemStackDropped(EnumDemonWillType type, int crystalNumber) {
ItemStack stack = null; ItemStack stack = ItemStack.EMPTY;
switch (type) { switch (type) {
case CORROSIVE: case CORROSIVE:
stack = EnumDemonWillType.CORROSIVE.getStack(); stack = EnumDemonWillType.CORROSIVE.getStack();
@ -200,25 +198,14 @@ public class BlockDemonCrystal extends Block {
return stack; return stack;
} }
// @Override @Override
// public java.util.List<ItemStack> getDrops(net.minecraft.world.IBlockAccess world, BlockPos pos, IBlockState state, int fortune) public ItemBlock getItem() {
// { return new ItemBlockDemonCrystal(this);
// java.util.List<ItemStack> ret = super.getDrops(world, pos, state, fortune); }
// int age = ((Integer) state.getValue(AGE)).intValue();
// Random rand = world instanceof World ? ((World) world).rand : new Random(); @Override
// public void gatherVariants(@Nonnull Int2ObjectMap<String> variants) {
// if (age >= 7) for (EnumDemonWillType willType : EnumDemonWillType.values())
// { variants.put(willType.ordinal(), "age=3,attached=up,type=" + willType.getName());
// int k = 3 + fortune; }
//
// for (int i = 0; i < 3 + fortune; ++i)
// {
// if (rand.nextInt(15) <= age)
// {
// ret.add(new ItemStack(this.getSeed(), 1, 0));
// }
// }
// }
// return ret;
// }
} }

View file

@ -6,7 +6,7 @@ import WayofTime.bloodmagic.block.BlockDemonCrystal;
import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler; import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler;
import WayofTime.bloodmagic.tile.base.TileTicking; import WayofTime.bloodmagic.tile.base.TileTicking;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem; import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
@ -103,12 +103,11 @@ public class TileDemonCrystal extends TileTicking {
} }
public void checkAndGrowCrystal() { public void checkAndGrowCrystal() {
if (progressToNextCrystal >= 1) { if (progressToNextCrystal >= 1 || internalCounter % 100 == 0) {
progressToNextCrystal--; progressToNextCrystal--;
crystalCount++; crystalCount++;
IBlockState thisState = getWorld().getBlockState(pos);
getWorld().notifyBlockUpdate(pos, thisState, thisState, 3);
markDirty(); markDirty();
notifyUpdate();
} }
} }
@ -121,9 +120,10 @@ public class TileDemonCrystal extends TileTicking {
IBlockState state = getWorld().getBlockState(pos); IBlockState state = getWorld().getBlockState(pos);
EnumDemonWillType type = state.getValue(BlockDemonCrystal.TYPE); EnumDemonWillType type = state.getValue(BlockDemonCrystal.TYPE);
ItemStack stack = BlockDemonCrystal.getItemStackDropped(type, 1); ItemStack stack = BlockDemonCrystal.getItemStackDropped(type, 1);
if (stack != null) { if (!stack.isEmpty()) {
crystalCount--; crystalCount--;
getWorld().spawnEntity(new EntityItem(getWorld(), pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, stack)); InventoryHelper.spawnItemStack(getWorld(), pos.getX(), pos.getY(), pos.getZ(), stack);
notifyUpdate();
return true; return true;
} }
} }