From fbd869dc7b4a8130b39b5be86c3d7897bc21ca6f Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 14 Nov 2015 21:27:36 +0100 Subject: [PATCH] Added Atomic Reconstructor, made it function (Still needs particles etc. though) --- .../actuallyadditions/ActuallyAdditions.java | 2 + .../blocks/BlockAtomicReconstructor.java | 70 ++++++++++++++++ .../actuallyadditions/blocks/InitBlocks.java | 3 + .../actuallyadditions/items/ItemCrystal.java | 18 ++--- .../items/metalists/TheCrystals.java | 9 ++- .../AtomicReconstructorRecipeHandler.java | 61 ++++++++++++++ .../tile/TileEntityAtomicReconstructor.java | 75 ++++++++++++++++++ .../tile/TileEntityBase.java | 2 + .../actuallyadditions/util/WorldPos.java | 6 ++ .../textures/blocks/blockCrystal.png | Bin 384 -> 264 bytes .../textures/items/itemCrystal.png | Bin 429 -> 0 bytes 11 files changed, 233 insertions(+), 13 deletions(-) create mode 100644 src/main/java/ellpeck/actuallyadditions/blocks/BlockAtomicReconstructor.java create mode 100644 src/main/java/ellpeck/actuallyadditions/recipe/AtomicReconstructorRecipeHandler.java create mode 100644 src/main/java/ellpeck/actuallyadditions/tile/TileEntityAtomicReconstructor.java delete mode 100644 src/main/resources/assets/actuallyadditions/textures/items/itemCrystal.png diff --git a/src/main/java/ellpeck/actuallyadditions/ActuallyAdditions.java b/src/main/java/ellpeck/actuallyadditions/ActuallyAdditions.java index 0f4db919e..1bb5e5b01 100644 --- a/src/main/java/ellpeck/actuallyadditions/ActuallyAdditions.java +++ b/src/main/java/ellpeck/actuallyadditions/ActuallyAdditions.java @@ -35,6 +35,7 @@ import ellpeck.actuallyadditions.misc.*; import ellpeck.actuallyadditions.network.PacketHandler; import ellpeck.actuallyadditions.ore.InitOreDict; import ellpeck.actuallyadditions.proxy.IProxy; +import ellpeck.actuallyadditions.recipe.AtomicReconstructorRecipeHandler; import ellpeck.actuallyadditions.recipe.FuelHandler; import ellpeck.actuallyadditions.recipe.HairyBallHandler; import ellpeck.actuallyadditions.recipe.TreasureChestHandler; @@ -100,6 +101,7 @@ public class ActuallyAdditions{ ItemCrafting.initMashedFoodRecipes(); HairyBallHandler.init(); TreasureChestHandler.init(); + AtomicReconstructorRecipeHandler.init(); InitForeignPaxels.init(); proxy.postInit(event); diff --git a/src/main/java/ellpeck/actuallyadditions/blocks/BlockAtomicReconstructor.java b/src/main/java/ellpeck/actuallyadditions/blocks/BlockAtomicReconstructor.java new file mode 100644 index 000000000..cd03dd709 --- /dev/null +++ b/src/main/java/ellpeck/actuallyadditions/blocks/BlockAtomicReconstructor.java @@ -0,0 +1,70 @@ +/* + * This file ("BlockAtomicReconstructor.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://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015 Ellpeck + */ + +package ellpeck.actuallyadditions.blocks; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import ellpeck.actuallyadditions.tile.TileEntityAtomicReconstructor; +import ellpeck.actuallyadditions.util.IActAddItemOrBlock; +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.World; + +public class BlockAtomicReconstructor extends BlockContainerBase implements IActAddItemOrBlock{ + + public BlockAtomicReconstructor(){ + super(Material.rock); + this.setHarvestLevel("pickaxe", 0); + this.setHardness(6F); + this.setResistance(20F); + this.setStepSound(soundTypeStone); + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(int side, int metadata){ + return this.blockIcon; + } + + @Override + @SideOnly(Side.CLIENT) + public void registerBlockIcons(IIconRegister iconReg){ + this.blockIcon = Blocks.stone.getIcon(0, 0); + } + + @Override + public String getName(){ + return "blockAtomicReconstructor"; + } + + @Override + public EnumRarity getRarity(ItemStack stack){ + return EnumRarity.epic; + } + + @Override + public TileEntity createNewTileEntity(World world, int i){ + return new TileEntityAtomicReconstructor(); + } + + @Override + public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack){ + int rotation = BlockPistonBase.determineOrientation(world, x, y, z, player); + world.setBlockMetadataWithNotify(x, y, z, rotation, 2); + } +} \ No newline at end of file diff --git a/src/main/java/ellpeck/actuallyadditions/blocks/InitBlocks.java b/src/main/java/ellpeck/actuallyadditions/blocks/InitBlocks.java index ff038f104..25a60ad5a 100644 --- a/src/main/java/ellpeck/actuallyadditions/blocks/InitBlocks.java +++ b/src/main/java/ellpeck/actuallyadditions/blocks/InitBlocks.java @@ -107,6 +107,9 @@ public class InitBlocks{ public static void init(){ ModUtil.LOGGER.info("Initializing Blocks..."); + blockAtomicReconstructor = new BlockAtomicReconstructor(); + BlockUtil.register(blockAtomicReconstructor); + blockCrystal = new BlockCrystal(); BlockUtil.register(blockCrystal, BlockCrystal.TheItemBlock.class); diff --git a/src/main/java/ellpeck/actuallyadditions/items/ItemCrystal.java b/src/main/java/ellpeck/actuallyadditions/items/ItemCrystal.java index 3e766dd3c..8902955be 100644 --- a/src/main/java/ellpeck/actuallyadditions/items/ItemCrystal.java +++ b/src/main/java/ellpeck/actuallyadditions/items/ItemCrystal.java @@ -26,6 +26,9 @@ import java.util.List; public class ItemCrystal extends Item implements IActAddItemOrBlock{ + @SideOnly(Side.CLIENT) + public IIcon[] textures; + public ItemCrystal(){ this.setHasSubtypes(true); this.setMaxDamage(0); @@ -43,8 +46,8 @@ public class ItemCrystal extends Item implements IActAddItemOrBlock{ @Override @SideOnly(Side.CLIENT) - public int getColorFromItemStack(ItemStack stack, int pass){ - return stack.getItemDamage() >= BlockCrystal.allCrystals.length ? super.getColorFromItemStack(stack, pass) : BlockCrystal.allCrystals[stack.getItemDamage()].color; + public IIcon getIconFromDamage(int par1){ + return par1 >= this.textures.length ? null : this.textures[par1]; } @Override @@ -52,12 +55,6 @@ public class ItemCrystal extends Item implements IActAddItemOrBlock{ return stack.getItemDamage() >= BlockCrystal.allCrystals.length ? EnumRarity.common : BlockCrystal.allCrystals[stack.getItemDamage()].rarity; } - @Override - @SideOnly(Side.CLIENT) - public IIcon getIcon(ItemStack stack, int pass){ - return this.itemIcon; - } - @SuppressWarnings("all") @SideOnly(Side.CLIENT) public void getSubItems(Item item, CreativeTabs tab, List list){ @@ -69,7 +66,10 @@ public class ItemCrystal extends Item implements IActAddItemOrBlock{ @Override @SideOnly(Side.CLIENT) public void registerIcons(IIconRegister iconReg){ - this.itemIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getName()); + this.textures = new IIcon[BlockCrystal.allCrystals.length]; + for(int i = 0; i < this.textures.length; i++){ + this.textures[i] = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getName()+BlockCrystal.allCrystals[i].name); + } } @Override diff --git a/src/main/java/ellpeck/actuallyadditions/items/metalists/TheCrystals.java b/src/main/java/ellpeck/actuallyadditions/items/metalists/TheCrystals.java index 443b55bf0..e3d41c195 100644 --- a/src/main/java/ellpeck/actuallyadditions/items/metalists/TheCrystals.java +++ b/src/main/java/ellpeck/actuallyadditions/items/metalists/TheCrystals.java @@ -14,10 +14,11 @@ import net.minecraft.item.EnumRarity; public enum TheCrystals{ - REDSTONE("Red", EnumRarity.rare, 12595250), - LAPIS("Blue", EnumRarity.uncommon, 24983), - DIAMOND("LightBlue", EnumRarity.epic, 40140), - COAL("Black", EnumRarity.uncommon, 2500135); + REDSTONE("Red", EnumRarity.rare, 16318464), + LAPIS("Blue", EnumRarity.uncommon, 131437), + DIAMOND("LightBlue", EnumRarity.epic, 9211636), + COAL("Black", EnumRarity.uncommon, 986895), + EMERALD("Green", EnumRarity.epic, 382466); public final String name; public final EnumRarity rarity; diff --git a/src/main/java/ellpeck/actuallyadditions/recipe/AtomicReconstructorRecipeHandler.java b/src/main/java/ellpeck/actuallyadditions/recipe/AtomicReconstructorRecipeHandler.java new file mode 100644 index 000000000..fe9a80d4a --- /dev/null +++ b/src/main/java/ellpeck/actuallyadditions/recipe/AtomicReconstructorRecipeHandler.java @@ -0,0 +1,61 @@ +/* + * This file ("AtomicReconstructorRecipeHandler.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://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015 Ellpeck + */ + +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 java.util.ArrayList; + +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()); + } + + public static void addRecipe(Block input, int inputMeta, Block output, int outputMeta){ + recipes.add(new Recipe(input, inputMeta, output, outputMeta)); + } + + public static Recipe getRecipe(Block input, int inputMeta){ + for(Recipe recipe : recipes){ + if(recipe.input == input && recipe.inputMeta == inputMeta){ + return recipe; + } + } + return null; + } + + public static class Recipe{ + + public Block input; + public int inputMeta; + public Block output; + public int outputMeta; + + public Recipe(Block input, int inputMeta, Block output, int outputMeta){ + this.input = input; + this.inputMeta = inputMeta; + this.output = output; + this.outputMeta = outputMeta; + } + + } + +} diff --git a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityAtomicReconstructor.java b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityAtomicReconstructor.java new file mode 100644 index 000000000..4f9bb90d1 --- /dev/null +++ b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityAtomicReconstructor.java @@ -0,0 +1,75 @@ +/* + * This file ("TileEntityAtomicReconstructor.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://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015 Ellpeck + */ + +package ellpeck.actuallyadditions.tile; + +import ellpeck.actuallyadditions.recipe.AtomicReconstructorRecipeHandler; +import ellpeck.actuallyadditions.util.WorldPos; +import ellpeck.actuallyadditions.util.WorldUtil; +import net.minecraft.block.Block; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; + +public class TileEntityAtomicReconstructor extends TileEntityBase{ + + private int currentTime; + + @Override + @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)); + + 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)); + } + } + } + } + break; + } + } + } + } + } + else{ + this.currentTime = 40; //TODO Config + } + } + } + + @Override + public void writeSyncableNBT(NBTTagCompound compound, boolean sync){ + super.writeSyncableNBT(compound, sync); + compound.setInteger("CurrentTime", this.currentTime); + } + + @Override + public void readSyncableNBT(NBTTagCompound compound, boolean sync){ + super.readSyncableNBT(compound, sync); + this.currentTime = compound.getInteger("CurrentTime"); + } + +} diff --git a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityBase.java b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityBase.java index 44e6ca79c..bb5986212 100644 --- a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityBase.java +++ b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityBase.java @@ -24,6 +24,7 @@ public abstract class TileEntityBase extends TileEntity{ public static void init(){ ModUtil.LOGGER.info("Registering TileEntities..."); + GameRegistry.registerTileEntity(TileEntityCompost.class, ModUtil.MOD_ID_LOWER+":tileEntityCompost"); GameRegistry.registerTileEntity(TileEntityFeeder.class, ModUtil.MOD_ID_LOWER+":tileEntityFeeder"); GameRegistry.registerTileEntity(TileEntityGiantChest.class, ModUtil.MOD_ID_LOWER+":tileEntityGiantChest"); @@ -62,6 +63,7 @@ public abstract class TileEntityBase extends TileEntity{ GameRegistry.registerTileEntity(TileEntityDirectionalBreaker.class, ModUtil.MOD_ID_LOWER+":tileEntityDirectionalBreaker"); GameRegistry.registerTileEntity(TileEntityRangedCollector.class, ModUtil.MOD_ID_LOWER+":tileEntityRangedCollector"); GameRegistry.registerTileEntity(TileEntityLaserRelay.class, ModUtil.MOD_ID_LOWER+":tileEntityLaserRelay"); + GameRegistry.registerTileEntity(TileEntityAtomicReconstructor.class, ModUtil.MOD_ID_LOWER+":tileEntityAtomicReconstructor"); } @Override diff --git a/src/main/java/ellpeck/actuallyadditions/util/WorldPos.java b/src/main/java/ellpeck/actuallyadditions/util/WorldPos.java index 0fa89625a..8f4a69ea5 100644 --- a/src/main/java/ellpeck/actuallyadditions/util/WorldPos.java +++ b/src/main/java/ellpeck/actuallyadditions/util/WorldPos.java @@ -68,6 +68,12 @@ public class WorldPos{ return pos != null && this.x == pos.getX() && this.y == pos.getY() && this.z == pos.getZ() && this.getWorld() == pos.getWorld(); } + public void setBlock(Block block, int meta, int flag){ + if(this.getWorld() != null){ + this.getWorld().setBlock(this.x, this.y, this.z, block, meta, flag); + } + } + public int getX(){ return this.x; } diff --git a/src/main/resources/assets/actuallyadditions/textures/blocks/blockCrystal.png b/src/main/resources/assets/actuallyadditions/textures/blocks/blockCrystal.png index 3c7a30a1e8019640d933bb35bf802ec4d5f31d28..91c61cbf61bb4e8c6cd2533edd10f9b8944020cb 100644 GIT binary patch delta 236 zcmZo*?qHgrQqPv;?e4-L4uTsk58P*9VBjq9h%9Dc;1&j9Muu5)B!GhKC7!;n?Dx6( zgjrecoXqD13dv@MM3gw^=jNv7l>oU649-QVi6yBi3gww484B*6z5ywEsq8@U98VX= z5R21qCmQk{P~dQ_mo9&F>aS&cy1_(ki`1glU0ZLN`F5wZdFKnUZ}-fbR!aYATF-Ik>il-rG&bYvmKl`(AE6pEvvIFl%WaaB2QO8mvv4FO#nSLPM`n) delta 357 zcmV-r0h<1Z0)PXMB!2;OQb$4nuFf3k00004XF*Lt006O%3;baP00009a7bBm000XT z000XT0n*)m`~Uy|2XskIMF-yt0~0zaGorzn0000ObVXQnQ*UN;cVTj60B~VxZgehg zWpp4kE-)@O{ETDY0002qNklAtpe#!o$B~()iI!z?7>3~%93G&u@8uJ? z0Ah7rM{V0)==~Kzyrs+EcE&v6Is?jQ1K{T*B z3i8uv1@LPgc$nTOZ~=_3jHU)^0G?7 z;xEA;#HfvxHaF4a1`*Fw17M72?+bXuLM<9iQ_opdEQaLhV`})urMG9bzQ6OggFg?mJnnT zB-|I6;I;E>*brz5WAm+96wv)s7z_bW!01}Q!fvq;5P_