From 2be8b18d7147b21bedd3baadce583c6d30a0b105 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 14 Nov 2015 23:05:20 +0100 Subject: [PATCH] Fixed Atomic Reconstructor Recipes, added Item Support & textures! --- .../blocks/BlockAtomicReconstructor.java | 33 +++++++- .../actuallyadditions/ore/InitOreDict.java | 20 +++-- .../AtomicReconstructorRecipeHandler.java | 53 +++++++----- .../tile/TileEntityAtomicReconstructor.java | 80 +++++++++++++----- .../blocks/blockAtomicReconstructor.png | Bin 0 -> 378 bytes .../blocks/blockAtomicReconstructorFront.png | Bin 0 -> 376 bytes .../blocks/blockAtomicReconstructorTop.png | Bin 0 -> 318 bytes 7 files changed, 135 insertions(+), 51 deletions(-) create mode 100644 src/main/resources/assets/actuallyadditions/textures/blocks/blockAtomicReconstructor.png create mode 100644 src/main/resources/assets/actuallyadditions/textures/blocks/blockAtomicReconstructorFront.png create mode 100644 src/main/resources/assets/actuallyadditions/textures/blocks/blockAtomicReconstructorTop.png diff --git a/src/main/java/ellpeck/actuallyadditions/blocks/BlockAtomicReconstructor.java b/src/main/java/ellpeck/actuallyadditions/blocks/BlockAtomicReconstructor.java index cd03dd709..14e5753ba 100644 --- a/src/main/java/ellpeck/actuallyadditions/blocks/BlockAtomicReconstructor.java +++ b/src/main/java/ellpeck/actuallyadditions/blocks/BlockAtomicReconstructor.java @@ -14,19 +14,25 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import ellpeck.actuallyadditions.tile.TileEntityAtomicReconstructor; import ellpeck.actuallyadditions.util.IActAddItemOrBlock; +import ellpeck.actuallyadditions.util.ModUtil; import net.minecraft.block.BlockPistonBase; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.EntityLivingBase; -import net.minecraft.init.Blocks; import net.minecraft.item.EnumRarity; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; public class BlockAtomicReconstructor extends BlockContainerBase implements IActAddItemOrBlock{ + @SideOnly(Side.CLIENT) + private IIcon frontIcon; + @SideOnly(Side.CLIENT) + private IIcon topIcon; + public BlockAtomicReconstructor(){ super(Material.rock); this.setHarvestLevel("pickaxe", 0); @@ -37,14 +43,35 @@ public class BlockAtomicReconstructor extends BlockContainerBase implements IAct @Override @SideOnly(Side.CLIENT) - public IIcon getIcon(int side, int metadata){ + public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side){ + int meta = world.getBlockMetadata(x, y, z); + if(side != meta && (side == 0 || side == 1)){ + return this.topIcon; + } + if(side == meta){ + return this.frontIcon; + } + return this.blockIcon; + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(int side, int meta){ + if(side == 0 || side == 1){ + return this.topIcon; + } + if(side == 3){ + return this.frontIcon; + } return this.blockIcon; } @Override @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister iconReg){ - this.blockIcon = Blocks.stone.getIcon(0, 0); + this.blockIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getName()); + this.frontIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getName()+"Front"); + this.topIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getName()+"Top"); } @Override diff --git a/src/main/java/ellpeck/actuallyadditions/ore/InitOreDict.java b/src/main/java/ellpeck/actuallyadditions/ore/InitOreDict.java index d4255ffd1..8ee5cb099 100644 --- a/src/main/java/ellpeck/actuallyadditions/ore/InitOreDict.java +++ b/src/main/java/ellpeck/actuallyadditions/ore/InitOreDict.java @@ -13,10 +13,7 @@ package ellpeck.actuallyadditions.ore; import ellpeck.actuallyadditions.blocks.InitBlocks; import ellpeck.actuallyadditions.blocks.metalists.TheMiscBlocks; import ellpeck.actuallyadditions.items.InitItems; -import ellpeck.actuallyadditions.items.metalists.TheDusts; -import ellpeck.actuallyadditions.items.metalists.TheFoods; -import ellpeck.actuallyadditions.items.metalists.TheMiscItems; -import ellpeck.actuallyadditions.items.metalists.TheSpecialDrops; +import ellpeck.actuallyadditions.items.metalists.*; import ellpeck.actuallyadditions.util.ModUtil; import net.minecraft.block.Block; import net.minecraft.init.Blocks; @@ -59,7 +56,7 @@ public class InitOreDict{ addOre(Blocks.double_plant, 4, "flowerRoseBush"); addOre(Blocks.double_plant, 5, "flowerPeony"); - //My Ores + //Ores addOre(InitItems.itemDust, TheDusts.IRON.ordinal(), "dustIron"); addOre(InitItems.itemDust, TheDusts.GOLD.ordinal(), "dustGold"); addOre(InitItems.itemDust, TheDusts.DIAMOND.ordinal(), "dustDiamond"); @@ -69,6 +66,19 @@ public class InitOreDict{ addOre(InitItems.itemDust, TheDusts.COAL.ordinal(), "dustCoal"); addOre(InitItems.itemDust, TheDusts.QUARTZ_BLACK.ordinal(), "dustQuartzBlack"); + //Crystals + addOre(InitItems.itemCrystal, TheCrystals.REDSTONE.ordinal(), "crystalRed"); + addOre(InitItems.itemCrystal, TheCrystals.LAPIS.ordinal(), "crystalBlue"); + addOre(InitItems.itemCrystal, TheCrystals.DIAMOND.ordinal(), "crystalLightBlue"); + addOre(InitItems.itemCrystal, TheCrystals.EMERALD.ordinal(), "crystalGreen"); + addOre(InitItems.itemCrystal, TheCrystals.COAL.ordinal(), "crystalBlack"); + + addOre(InitBlocks.blockCrystal, TheCrystals.REDSTONE.ordinal(), "blockCrystalRed"); + addOre(InitBlocks.blockCrystal, TheCrystals.LAPIS.ordinal(), "blockCrystalBlue"); + addOre(InitBlocks.blockCrystal, TheCrystals.DIAMOND.ordinal(), "blockCrystalLightBlue"); + addOre(InitBlocks.blockCrystal, TheCrystals.EMERALD.ordinal(), "blockCrystalGreen"); + addOre(InitBlocks.blockCrystal, TheCrystals.COAL.ordinal(), "blockCrystalBlack"); + addOre(InitBlocks.blockMisc, TheMiscBlocks.ORE_QUARTZ.ordinal(), "oreQuartzBlack"); addOre(InitItems.itemCanolaSeed, "seedCanola"); diff --git a/src/main/java/ellpeck/actuallyadditions/recipe/AtomicReconstructorRecipeHandler.java b/src/main/java/ellpeck/actuallyadditions/recipe/AtomicReconstructorRecipeHandler.java index fe9a80d4a..657f5b992 100644 --- a/src/main/java/ellpeck/actuallyadditions/recipe/AtomicReconstructorRecipeHandler.java +++ b/src/main/java/ellpeck/actuallyadditions/recipe/AtomicReconstructorRecipeHandler.java @@ -10,33 +10,41 @@ package ellpeck.actuallyadditions.recipe; -import ellpeck.actuallyadditions.blocks.InitBlocks; -import ellpeck.actuallyadditions.items.metalists.TheCrystals; -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; import java.util.ArrayList; +import java.util.Objects; public class AtomicReconstructorRecipeHandler{ public static ArrayList recipes = new ArrayList(); public static void init(){ - addRecipe(Blocks.redstone_block, 0, InitBlocks.blockCrystal, TheCrystals.REDSTONE.ordinal()); - addRecipe(Blocks.lapis_block, 0, InitBlocks.blockCrystal, TheCrystals.LAPIS.ordinal()); - addRecipe(Blocks.diamond_block, 0, InitBlocks.blockCrystal, TheCrystals.DIAMOND.ordinal()); - addRecipe(Blocks.coal_block, 0, InitBlocks.blockCrystal, TheCrystals.COAL.ordinal()); - addRecipe(Blocks.emerald_block, 0, InitBlocks.blockCrystal, TheCrystals.EMERALD.ordinal()); + addRecipe("blockRedstone", "blockCrystalRed"); + addRecipe("blockLapis", "blockCrystalBlue"); + addRecipe("blockDiamond", "blockCrystalLightBlue"); + addRecipe("blockEmerald", "blockCrystalGreen"); + addRecipe("blockCoal", "blockCrystalBlack"); + + addRecipe("dustRedstone", "crystalRed"); + addRecipe("gemLapis", "crystalBlue"); + addRecipe("gemDiamond", "crystalLightBlue"); + addRecipe("gemEmerald", "crystalGreen"); + addRecipe("coal", "crystalBlack"); } - public static void addRecipe(Block input, int inputMeta, Block output, int outputMeta){ - recipes.add(new Recipe(input, inputMeta, output, outputMeta)); + public static void addRecipe(String input, String output){ + recipes.add(new Recipe(input, output)); } - public static Recipe getRecipe(Block input, int inputMeta){ + public static Recipe getRecipe(ItemStack input){ for(Recipe recipe : recipes){ - if(recipe.input == input && recipe.inputMeta == inputMeta){ - return recipe; + int[] ids = OreDictionary.getOreIDs(input); + for(int id : ids){ + if(Objects.equals(OreDictionary.getOreName(id), recipe.input)){ + return recipe; + } } } return null; @@ -44,18 +52,21 @@ public class AtomicReconstructorRecipeHandler{ public static class Recipe{ - public Block input; - public int inputMeta; - public Block output; - public int outputMeta; + public String input; + public String output; - public Recipe(Block input, int inputMeta, Block output, int outputMeta){ + public Recipe(String input, String output){ this.input = input; - this.inputMeta = inputMeta; this.output = output; - this.outputMeta = outputMeta; } + public ItemStack getFirstOutput(){ + ArrayList stacks = OreDictionary.getOres(this.output); + if(stacks != null && !stacks.isEmpty()){ + return stacks.get(0); + } + return null; + } } } diff --git a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityAtomicReconstructor.java b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityAtomicReconstructor.java index 4f9bb90d1..813a4e10c 100644 --- a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityAtomicReconstructor.java +++ b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityAtomicReconstructor.java @@ -14,9 +14,15 @@ import ellpeck.actuallyadditions.recipe.AtomicReconstructorRecipeHandler; import ellpeck.actuallyadditions.util.WorldPos; import ellpeck.actuallyadditions.util.WorldUtil; import net.minecraft.block.Block; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.AxisAlignedBB; import net.minecraftforge.common.util.ForgeDirection; +import java.util.ArrayList; + public class TileEntityAtomicReconstructor extends TileEntityBase{ private int currentTime; @@ -25,37 +31,67 @@ public class TileEntityAtomicReconstructor extends TileEntityBase{ @SuppressWarnings("unchecked") public void updateEntity(){ if(!this.worldObj.isRemote){ - if(this.currentTime > 0){ - this.currentTime--; - if(this.currentTime <= 0){ - ForgeDirection sideToManipulate = ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord)); + if(!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)){ + if(this.currentTime > 0){ + this.currentTime--; + if(this.currentTime <= 0){ + ForgeDirection sideToManipulate = ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord)); - for(int i = 0; i < 10; i++){ - WorldPos coordsBlock = WorldUtil.getCoordsFromSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord, i); - if(coordsBlock != null){ - if(!coordsBlock.getBlock().isAir(coordsBlock.getWorld(), coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ())){ - //Converting the Blocks - int range = 2; //TODO Config - for(int reachX = -range; reachX < range+1; reachX++){ - for(int reachZ = -range; reachZ < range+1; reachZ++){ - for(int reachY = -range; reachY < range+1; reachY++){ - WorldPos pos = new WorldPos(worldObj, coordsBlock.getX()+reachX, coordsBlock.getY()+reachY, coordsBlock.getZ()+reachZ); - AtomicReconstructorRecipeHandler.Recipe recipe = AtomicReconstructorRecipeHandler.getRecipe(pos.getBlock(), pos.getMetadata()); - if(recipe != null){ - pos.setBlock(recipe.output, recipe.outputMeta, 2); - this.worldObj.playAuxSFX(2001, coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ(), Block.getIdFromBlock(pos.getBlock())+(pos.getMetadata() << 12)); + for(int i = 0; i < 10; i++){ + WorldPos coordsBlock = WorldUtil.getCoordsFromSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord, i); + if(coordsBlock != null){ + if(!coordsBlock.getBlock().isAir(coordsBlock.getWorld(), coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ())){ + int range = 2; //TODO Config + + //Converting the Blocks + for(int reachX = -range; reachX < range+1; reachX++){ + for(int reachZ = -range; reachZ < range+1; reachZ++){ + for(int reachY = -range; reachY < range+1; reachY++){ + WorldPos pos = new WorldPos(worldObj, coordsBlock.getX()+reachX, coordsBlock.getY()+reachY, coordsBlock.getZ()+reachZ); + AtomicReconstructorRecipeHandler.Recipe recipe = AtomicReconstructorRecipeHandler.getRecipe(new ItemStack(pos.getBlock(), pos.getMetadata())); + if(recipe != null){ + ItemStack output = recipe.getFirstOutput(); + if(output != null){ + if(output.getItem() instanceof ItemBlock){ + this.worldObj.playAuxSFX(2001, pos.getX(), pos.getY(), pos.getZ(), Block.getIdFromBlock(pos.getBlock())+(pos.getMetadata() << 12)); + pos.setBlock(Block.getBlockFromItem(output.getItem()), output.getItemDamage(), 2); + } + else{ + EntityItem item = new EntityItem(worldObj, pos.getX()+0.5, pos.getY()+0.5, pos.getZ()+0.5, output.copy()); + worldObj.spawnEntityInWorld(item); + } + } + } } } } + + //Converting the Items + ArrayList items = (ArrayList)worldObj.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(coordsBlock.getX()-range, coordsBlock.getY()-range, coordsBlock.getZ()-range, coordsBlock.getX()+range, coordsBlock.getY()+range, coordsBlock.getZ()+range)); + for(EntityItem item : items){ + ItemStack stack = item.getEntityItem(); + if(stack != null){ + AtomicReconstructorRecipeHandler.Recipe recipe = AtomicReconstructorRecipeHandler.getRecipe(stack); + if(recipe != null){ + ItemStack output = recipe.getFirstOutput(); + if(output != null){ + ItemStack outputCopy = output.copy(); + outputCopy.stackSize = stack.stackSize; + item.setEntityItemStack(outputCopy); + } + } + } + } + + break; } - break; } } } } - } - else{ - this.currentTime = 40; //TODO Config + else{ + this.currentTime = 40; //TODO Config + } } } } diff --git a/src/main/resources/assets/actuallyadditions/textures/blocks/blockAtomicReconstructor.png b/src/main/resources/assets/actuallyadditions/textures/blocks/blockAtomicReconstructor.png new file mode 100644 index 0000000000000000000000000000000000000000..e0c0029cf076cdc5bc4e4096349bc284d561cb86 GIT binary patch literal 378 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmP~H=hWf^!BQ?+kir{nIRD+&iT2ysd*(pE(3#eQEFmI zYKlU6W=V#EyQgnJie4%^Q2d^!i(`nz>7^5`yAB(OxcakwEi!x+D#5n+Sno{MOy)?Z zX%ljJgLf5uk9w@R}FYk;QHD~Sg+nP#G{EDgKX zz5HFbzje;d9L31k!?Sfwd?zop%6|xSOz-24;y!^xTTUE|y?&ST-p}UxrZwenw9I<; Pf`Y)))z4*}Q$iB}@i>-+ literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/actuallyadditions/textures/blocks/blockAtomicReconstructorFront.png b/src/main/resources/assets/actuallyadditions/textures/blocks/blockAtomicReconstructorFront.png new file mode 100644 index 0000000000000000000000000000000000000000..bbdc3aa8afcd25ecc3cee197807f3962541f7c7b GIT binary patch literal 376 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmP~H=hW<@$4%myg(t@%#er@=ltB<)VvZPmw~~#C^fMp zHASI3vm`^o-P1Q9MK6^dD1OJ&#WBR<^wLQi`&&ho@cG+voAbJ+to4yxVQ~>?9{g!@l>76M`P?J^#q}vO>!PsVT2^ z#od=#x0S7e(?fISGR^8Yt5y}9+snG=yT;N0ueGl8cWj-uNaLR5o5Z!gWp+G<+XQx< z{k%t0=X8jf{-u`<~R{v+V-nN3LDwD(*>gs2u@EvU85IfZOeO@r*_T1AJeaE9M zysTT#Djq#9(*36L(}Z2?PQQ}Mf0)!$sdu{Rn$+_bP0l+XkK&Uu#Y literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/actuallyadditions/textures/blocks/blockAtomicReconstructorTop.png b/src/main/resources/assets/actuallyadditions/textures/blocks/blockAtomicReconstructorTop.png new file mode 100644 index 0000000000000000000000000000000000000000..62ca7e3c9632199e5c2911ea7d7c3b85a43b041b GIT binary patch literal 318 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmP~H=hWf+Iyjg%Yj0&nIRD+&iT2ysd*(pE(3#eQEFmI zYKlU6W=V#EyQgnJie4%^P<)Z6i(`nz>9>;<`420IwCvZb$ojy+cl