From 8b433056d2510521c267efce72d0a8b654433a74 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 18 May 2016 21:14:11 +0200 Subject: [PATCH] Made impure iron convert in water and in the crusher --- .../mod/blocks/BlockImpureIron.java | 92 +++++++++++++++++++ .../mod/blocks/InitBlocks.java | 2 +- .../mod/crafting/CrusherCrafting.java | 7 ++ 3 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockImpureIron.java diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockImpureIron.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockImpureIron.java new file mode 100644 index 000000000..8639fb69e --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockImpureIron.java @@ -0,0 +1,92 @@ +/* + * This file ("BlockImpureIron.java") is part of the Actually Additions mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://ellpeck.de/actaddlicense + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015-2016 Ellpeck + */ + +package de.ellpeck.actuallyadditions.mod.blocks; + +import de.ellpeck.actuallyadditions.mod.blocks.base.ItemBlockBase; +import de.ellpeck.actuallyadditions.mod.gen.cave.CaveWorldType; +import de.ellpeck.actuallyadditions.mod.items.InitItems; +import de.ellpeck.actuallyadditions.mod.items.metalists.TheDusts; +import de.ellpeck.actuallyadditions.mod.util.Util; +import net.minecraft.block.Block; +import net.minecraft.block.SoundType; +import net.minecraft.block.material.Material; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumParticleTypes; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.WorldServer; + +public class BlockImpureIron extends BlockGeneric{ + + public BlockImpureIron(String name){ + super(name, Material.ROCK, SoundType.STONE, 3.5F, 12.5F, "pickaxe", 1); + } + + @Override + protected ItemBlockBase getItemBlock(){ + return new TheItemBlock(this); + } + + public static class TheItemBlock extends ItemBlockBase{ + + public TheItemBlock(Block block){ + super(block); + this.setHasSubtypes(false); + this.setMaxDamage(0); + } + + @Override + public String getUnlocalizedName(ItemStack stack){ + return this.getUnlocalizedName(); + } + + @Override + public int getMetadata(int damage){ + return damage; + } + + @Override + public boolean onEntityItemUpdate(EntityItem item){ + if(item != null && CaveWorldType.isCave(item.getEntityWorld())){ + if(item.isInWater()){ + if(!item.getEntityWorld().isRemote){ + ItemStack stack = item.getEntityItem(); + if(stack != null){ + if(!stack.hasTagCompound()){ + stack.setTagCompound(new NBTTagCompound()); + } + NBTTagCompound compound = stack.getTagCompound(); + + int conversionTimer = compound.getInteger("ConversionTimer"); + if(conversionTimer >= 2000){ + item.setEntityItemStack(new ItemStack(InitItems.itemDust, 1, TheDusts.IRON.ordinal())); + + if(item.getEntityWorld() instanceof WorldServer){ + ((WorldServer)item.getEntityWorld()).spawnParticle(EnumParticleTypes.SMOKE_NORMAL, item.posX, item.posY, item.posZ, 30, 0D, 0D, 0D, 0.05D); + } + } + else{ + compound.setInteger("ConversionTimer", conversionTimer+1); + } + } + } + else{ + if(item.getEntityWorld().getTotalWorldTime()%20 == 0){ + item.getEntityWorld().spawnParticle(EnumParticleTypes.VILLAGER_HAPPY, MathHelper.floor_double(item.posX)+Util.RANDOM.nextDouble(), MathHelper.floor_double(item.posY)+Util.RANDOM.nextDouble(), MathHelper.floor_double(item.posZ)+Util.RANDOM.nextDouble(), 0D, 0D, 0D); + } + } + } + } + return false; + } + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/InitBlocks.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/InitBlocks.java index a5e0080ee..e14482166 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/InitBlocks.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/InitBlocks.java @@ -123,7 +123,7 @@ public class InitBlocks{ ModUtil.LOGGER.info("Initializing Blocks..."); if(ConfigValues.caveWorld){ - blockImpureIron = new BlockGeneric("blockImpureIron", Material.ROCK, SoundType.STONE, 3.5F, 12.5F, "pickaxe", 1); + blockImpureIron = new BlockImpureIron("blockImpureIron"); } blockItemViewer = new BlockItemViewer("blockItemViewer"); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/CrusherCrafting.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/CrusherCrafting.java index f15aa8e9c..defb2b03e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/CrusherCrafting.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/CrusherCrafting.java @@ -12,8 +12,11 @@ package de.ellpeck.actuallyadditions.mod.crafting; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.recipe.CrusherRecipe; +import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks; +import de.ellpeck.actuallyadditions.mod.config.ConfigValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigCrafting; import de.ellpeck.actuallyadditions.mod.items.InitItems; +import de.ellpeck.actuallyadditions.mod.items.metalists.TheDusts; import de.ellpeck.actuallyadditions.mod.items.metalists.TheFoods; import de.ellpeck.actuallyadditions.mod.recipe.CrusherRecipeRegistry; import de.ellpeck.actuallyadditions.mod.util.ModUtil; @@ -34,6 +37,10 @@ public class CrusherCrafting{ public static void init(){ ModUtil.LOGGER.info("Initializing Crusher Recipes..."); + if(ConfigValues.caveWorld){ + ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(InitBlocks.blockImpureIron), new ItemStack(InitItems.itemDust, 2, TheDusts.IRON.ordinal())); + } + ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Items.BONE), new ItemStack(Items.DYE, 6, 15)); miscRecipes.add(RecipeUtil.lastCrusherRecipe()); ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Items.REEDS), new ItemStack(Items.SUGAR, 3));