diff --git a/src/main/java/electroblob/wizardry/block/BlockCrystalFlowerPot.java b/src/main/java/electroblob/wizardry/block/BlockCrystalFlowerPot.java new file mode 100644 index 00000000..361ad0d2 --- /dev/null +++ b/src/main/java/electroblob/wizardry/block/BlockCrystalFlowerPot.java @@ -0,0 +1,148 @@ +package electroblob.wizardry.block; + +import electroblob.wizardry.registry.WizardryBlocks; +import electroblob.wizardry.util.ParticleBuilder; +import electroblob.wizardry.util.ParticleBuilder.Type; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.block.state.BlockFaceShape; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntityFlowerPot; +import net.minecraft.util.BlockRenderLayer; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.RayTraceResult; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; + +import javax.annotation.Nullable; +import java.util.Random; + +public class BlockCrystalFlowerPot extends Block { + + protected static final AxisAlignedBB BOUNDING_BOX = new AxisAlignedBB(0.3125D, 0.0D, 0.3125D, 0.6875D, 0.375D, 0.6875D); + + public BlockCrystalFlowerPot(){ + super(Material.CIRCUITS); + this.setLightLevel(0.4f); + this.setTickRandomly(true); + } + + @Override + public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random random){ + if(world.isRemote && random.nextBoolean()){ + ParticleBuilder.create(Type.SPARKLE) + .pos(pos.getX() + 0.3 + random.nextDouble() * 0.4, pos.getY() + 0.6 + random.nextDouble() * 0.3, pos.getZ() + 0.3 + random.nextDouble() * 0.4) + .vel(0, 0.01, 0) + .time(20 + random.nextInt(10)) + .clr(0.5f + (random.nextFloat() / 2), 0.5f + (random.nextFloat() / 2), 0.5f + (random.nextFloat() / 2)) + .spawn(world); + } + } + + @Nullable + @Override + public TileEntity createTileEntity(World world, IBlockState state){ + return new TileEntityFlowerPot(Item.getItemFromBlock(WizardryBlocks.crystal_flower), 0); + } + + @Override + public boolean hasTileEntity(IBlockState state){ + return true; + } + + @Override + public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ){ + + ItemStack stack = new ItemStack(WizardryBlocks.crystal_flower); + + if(player.getHeldItem(hand).isEmpty()){ + player.setHeldItem(hand, stack); + }else if(!player.addItemStackToInventory(stack)){ + player.dropItem(stack, false); + } + + world.setBlockState(pos, Blocks.FLOWER_POT.getDefaultState()); + + return true; + } + + @Override + public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player){ + return new ItemStack(WizardryBlocks.crystal_flower); + } + + @Override + public void getDrops(net.minecraft.util.NonNullList drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune){ + super.getDrops(drops, world, pos, state, fortune); + drops.add(new ItemStack(WizardryBlocks.crystal_flower)); + } + + @Override + public Item getItemDropped(IBlockState state, Random rand, int fortune){ + return Items.FLOWER_POT; + } + + // The rest are identical behaviour to BlockFlowerPot + + @Override + public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos){ + return BOUNDING_BOX; + } + + @Override + public boolean isOpaqueCube(IBlockState state){ + return false; + } + + @Override + public boolean isFullCube(IBlockState state){ + return false; + } + + @Override + public boolean canPlaceBlockAt(World world, BlockPos pos){ + IBlockState downState = world.getBlockState(pos.down()); + return super.canPlaceBlockAt(world, pos) && (downState.isTopSolid() || downState.getBlockFaceShape(world, pos.down(), EnumFacing.UP) == BlockFaceShape.SOLID); + } + + @Override + public void neighborChanged(IBlockState state, World world, BlockPos pos, Block block, BlockPos neighbour){ + IBlockState downState = world.getBlockState(pos.down()); + if(!downState.isTopSolid() && downState.getBlockFaceShape(world, pos.down(), EnumFacing.UP) != BlockFaceShape.SOLID){ + this.dropBlockAsItem(world, pos, state, 0); + world.setBlockToAir(pos); + } + } + + @Override + public BlockRenderLayer getRenderLayer(){ + return BlockRenderLayer.CUTOUT; + } + + @Override + public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face){ + return BlockFaceShape.UNDEFINED; + } + + @Override + public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest){ + if(willHarvest) return true; // If it will harvest, delay deletion of the block until after getDrops + return super.removedByPlayer(state, world, pos, player, willHarvest); + } + + @Override + public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack tool){ + super.harvestBlock(world, player, pos, state, te, tool); + world.setBlockToAir(pos); + } + +} diff --git a/src/main/java/electroblob/wizardry/item/ItemCrystalFlower.java b/src/main/java/electroblob/wizardry/item/ItemCrystalFlower.java new file mode 100644 index 00000000..040a74cd --- /dev/null +++ b/src/main/java/electroblob/wizardry/item/ItemCrystalFlower.java @@ -0,0 +1,39 @@ +package electroblob.wizardry.item; + +import electroblob.wizardry.registry.WizardryBlocks; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.item.ItemBlock; +import net.minecraft.stats.StatList; +import net.minecraft.tileentity.TileEntityFlowerPot; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class ItemCrystalFlower extends ItemBlock { + + public ItemCrystalFlower(){ + super(WizardryBlocks.crystal_flower); + } + + @Override + public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand){ + + if(world.getTileEntity(pos) instanceof TileEntityFlowerPot){ + + TileEntityFlowerPot tileEntity = (TileEntityFlowerPot)world.getTileEntity(pos); + + if(tileEntity.getFlowerPotItem() == null || tileEntity.getFlowerPotItem() == Items.AIR){ + player.addStat(StatList.FLOWER_POTTED); + if(!player.capabilities.isCreativeMode) player.getHeldItem(hand).shrink(1); + world.setBlockState(pos, WizardryBlocks.crystal_flower_pot.getDefaultState()); + return EnumActionResult.SUCCESS; + } + } + + return super.onItemUseFirst(player, world, pos, side, hitX, hitY, hitZ, hand); + } + +} diff --git a/src/main/java/electroblob/wizardry/registry/WizardryBlocks.java b/src/main/java/electroblob/wizardry/registry/WizardryBlocks.java index 3d63775f..d1fdc412 100644 --- a/src/main/java/electroblob/wizardry/registry/WizardryBlocks.java +++ b/src/main/java/electroblob/wizardry/registry/WizardryBlocks.java @@ -55,6 +55,7 @@ public final class WizardryBlocks { public static final Block thorns = placeholder(); public static final Block obsidian_crust = placeholder(); public static final Block dry_frosted_ice = placeholder(); + public static final Block crystal_flower_pot = placeholder(); public static final Block runestone = placeholder(); public static final Block runestone_pedestal = placeholder(); @@ -116,6 +117,7 @@ public final class WizardryBlocks { registerBlock(registry, "thorns", new BlockThorns()); registerBlock(registry, "obsidian_crust", new BlockObsidianCrust()); registerBlock(registry, "dry_frosted_ice", new BlockDryFrostedIce()); + registerBlock(registry, "crystal_flower_pot", new BlockCrystalFlowerPot()); registerBlock(registry, "runestone", new BlockRunestone(Material.ROCK)); registerBlock(registry, "runestone_pedestal", new BlockPedestal(Material.ROCK)); diff --git a/src/main/java/electroblob/wizardry/registry/WizardryItems.java b/src/main/java/electroblob/wizardry/registry/WizardryItems.java index 9754c6df..dabdca7a 100644 --- a/src/main/java/electroblob/wizardry/registry/WizardryItems.java +++ b/src/main/java/electroblob/wizardry/registry/WizardryItems.java @@ -370,8 +370,15 @@ public final class WizardryItems { * also automatically adds it to the order list for its creative tab if that tab is a {@link CreativeTabListed}, * meaning the order can be defined simply by the order in which the items are registered in this class. */ private static void registerItemBlock(IForgeRegistry registry, Block block){ + registerItemBlock(registry, block, new ItemBlock(block)); + } + + /** Registers the given ItemBlock for the given block, with the same registry name as that block. This + * also automatically adds it to the order list for its creative tab if that tab is a {@link CreativeTabListed}, + * meaning the order can be defined simply by the order in which the items are registered in this class. */ + private static void registerItemBlock(IForgeRegistry registry, Block block, ItemBlock itemblock){ // We don't need to keep a reference to the ItemBlock - Item itemblock = new ItemBlock(block).setRegistryName(block.getRegistryName()); + itemblock.setRegistryName(block.getRegistryName()); registry.register(itemblock); if(block.getCreativeTab() instanceof CreativeTabListed){ @@ -400,7 +407,7 @@ public final class WizardryItems { // Not all blocks need an ItemBlock registerItemBlock(registry, WizardryBlocks.arcane_workbench); registerItemBlock(registry, WizardryBlocks.crystal_ore); - registerItemBlock(registry, WizardryBlocks.crystal_flower); + registerItemBlock(registry, WizardryBlocks.crystal_flower, new ItemCrystalFlower()); registerItemBlock(registry, WizardryBlocks.transportation_stone); String[] elements = Arrays.stream(Element.values()).map(Element::getName).toArray(String[]::new); diff --git a/src/main/resources/assets/ebwizardry/blockstates/crystal_flower_pot.json b/src/main/resources/assets/ebwizardry/blockstates/crystal_flower_pot.json new file mode 100644 index 00000000..446174e2 --- /dev/null +++ b/src/main/resources/assets/ebwizardry/blockstates/crystal_flower_pot.json @@ -0,0 +1,6 @@ +{ + "forge_marker": 1, + "variants": { + "normal": { "model": "ebwizardry:crystal_flower_pot" } + } +} diff --git a/src/main/resources/assets/ebwizardry/lang/en_gb.lang b/src/main/resources/assets/ebwizardry/lang/en_gb.lang index 27b89588..1eb096f6 100644 --- a/src/main/resources/assets/ebwizardry/lang/en_gb.lang +++ b/src/main/resources/assets/ebwizardry/lang/en_gb.lang @@ -16,6 +16,7 @@ tile.ebwizardry\:runestone_pedestal.name=Runestone Pedestal tile.ebwizardry\:thorns.name=Thorns tile.ebwizardry\:obsidian_crust.name=Obsidian Crust tile.ebwizardry\:dry_frosted_ice.name=Dry Frosted Ice +tile.ebwizardry\:crystal_flower_pot.name=Flower Pot tile.ebwizardry\:magic_crystal_block.name=Block of Crystal tile.ebwizardry\:fire_crystal_block.name=Block of Fiery Crystal diff --git a/src/main/resources/assets/ebwizardry/lang/en_us.lang b/src/main/resources/assets/ebwizardry/lang/en_us.lang index c50099d1..13a09d17 100644 --- a/src/main/resources/assets/ebwizardry/lang/en_us.lang +++ b/src/main/resources/assets/ebwizardry/lang/en_us.lang @@ -16,6 +16,7 @@ tile.ebwizardry\:runestone_pedestal.name=Runestone Pedestal tile.ebwizardry\:thorns.name=Thorns tile.ebwizardry\:obsidian_crust.name=Obsidian Crust tile.ebwizardry\:dry_frosted_ice.name=Dry Frosted Ice +tile.ebwizardry\:crystal_flower_pot.name=Flower Pot tile.ebwizardry\:magic_crystal_block.name=Block of Crystal tile.ebwizardry\:fire_crystal_block.name=Block of Fiery Crystal diff --git a/src/main/resources/assets/ebwizardry/models/block/crystal_flower_pot.json b/src/main/resources/assets/ebwizardry/models/block/crystal_flower_pot.json new file mode 100644 index 00000000..cde19ace --- /dev/null +++ b/src/main/resources/assets/ebwizardry/models/block/crystal_flower_pot.json @@ -0,0 +1,6 @@ +{ + "parent": "block/flower_pot_cross", + "textures": { + "plant": "ebwizardry:blocks/crystal_flower" + } +} \ No newline at end of file