From 0a787826939b247450a89fb97bd92e7d6d9c0513 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 22 Nov 2015 18:52:11 +0100 Subject: [PATCH] Reconstructor Colors, Part 1 --- .../blocks/BlockAtomicReconstructor.java | 24 ++++++- .../items/IReconstructorLens.java | 18 ++++++ .../actuallyadditions/items/InitItems.java | 5 ++ .../actuallyadditions/items/ItemLens.java | 61 ++++++++++++++++++ .../network/PacketAtomicReconstructor.java | 10 ++- .../recipe/ReconstructorRecipeHandler.java | 38 ++++++++++- .../tile/TileEntityAtomicReconstructor.java | 41 ++++++++++-- .../ellpeck/actuallyadditions/util/Util.java | 2 + .../textures/items/itemColorLens.png | Bin 0 -> 658 bytes 9 files changed, 188 insertions(+), 11 deletions(-) create mode 100644 src/main/java/ellpeck/actuallyadditions/items/IReconstructorLens.java create mode 100644 src/main/java/ellpeck/actuallyadditions/items/ItemLens.java create mode 100644 src/main/resources/assets/actuallyadditions/textures/items/itemColorLens.png diff --git a/src/main/java/ellpeck/actuallyadditions/blocks/BlockAtomicReconstructor.java b/src/main/java/ellpeck/actuallyadditions/blocks/BlockAtomicReconstructor.java index 0a9ff4ea5..9facabc0b 100644 --- a/src/main/java/ellpeck/actuallyadditions/blocks/BlockAtomicReconstructor.java +++ b/src/main/java/ellpeck/actuallyadditions/blocks/BlockAtomicReconstructor.java @@ -12,6 +12,7 @@ package ellpeck.actuallyadditions.blocks; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import ellpeck.actuallyadditions.items.IReconstructorLens; import ellpeck.actuallyadditions.tile.TileEntityAtomicReconstructor; import ellpeck.actuallyadditions.util.IActAddItemOrBlock; import ellpeck.actuallyadditions.util.ModUtil; @@ -102,9 +103,28 @@ public class BlockAtomicReconstructor extends BlockContainerBase implements IAct if(!world.isRemote){ TileEntityAtomicReconstructor reconstructor = (TileEntityAtomicReconstructor)world.getTileEntity(x, y, z); if(reconstructor != null){ - player.addChatComponentMessage(new ChatComponentText(reconstructor.storage.getEnergyStored()+"/"+reconstructor.storage.getMaxEnergyStored()+" RF")); + if(!player.isSneaking()){ + ItemStack heldItem = player.getCurrentEquippedItem(); + if(heldItem != null){ + if(heldItem.getItem() instanceof IReconstructorLens && reconstructor.getStackInSlot(0) == null){ + ItemStack toPut = heldItem.copy(); + toPut.stackSize = 1; + reconstructor.setInventorySlotContents(0, toPut); + + player.inventory.decrStackSize(player.inventory.currentItem, 1); + } + } + else{ + if(reconstructor.getStackInSlot(0) != null){ + player.inventory.setInventorySlotContents(player.inventory.currentItem, reconstructor.getStackInSlot(0).copy()); + reconstructor.setInventorySlotContents(0, null); + } + } + } + else{ + player.addChatComponentMessage(new ChatComponentText(reconstructor.storage.getEnergyStored()+"/"+reconstructor.storage.getMaxEnergyStored()+" RF")); + } } - return true; } return true; } diff --git a/src/main/java/ellpeck/actuallyadditions/items/IReconstructorLens.java b/src/main/java/ellpeck/actuallyadditions/items/IReconstructorLens.java new file mode 100644 index 000000000..3102bbfa7 --- /dev/null +++ b/src/main/java/ellpeck/actuallyadditions/items/IReconstructorLens.java @@ -0,0 +1,18 @@ +/* + * This file ("ILens.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.items; + +import ellpeck.actuallyadditions.recipe.ReconstructorRecipeHandler; + +public interface IReconstructorLens{ + + ReconstructorRecipeHandler.LensType getLensType(); +} diff --git a/src/main/java/ellpeck/actuallyadditions/items/InitItems.java b/src/main/java/ellpeck/actuallyadditions/items/InitItems.java index 2b06cbecb..2490f6af3 100644 --- a/src/main/java/ellpeck/actuallyadditions/items/InitItems.java +++ b/src/main/java/ellpeck/actuallyadditions/items/InitItems.java @@ -16,6 +16,7 @@ import ellpeck.actuallyadditions.items.metalists.TheMiscItems; import ellpeck.actuallyadditions.items.tools.*; import ellpeck.actuallyadditions.material.InitArmorMaterials; import ellpeck.actuallyadditions.material.InitToolMaterials; +import ellpeck.actuallyadditions.recipe.ReconstructorRecipeHandler; import ellpeck.actuallyadditions.util.CompatUtil; import ellpeck.actuallyadditions.util.ItemUtil; import ellpeck.actuallyadditions.util.ModUtil; @@ -129,10 +130,14 @@ public class InitItems{ public static Item itemLaserWrench; public static Item itemCrystal; + public static Item itemColorLens; public static void init(){ ModUtil.LOGGER.info("Initializing Items..."); + itemColorLens = new ItemLens("itemColorLens", ReconstructorRecipeHandler.LensType.COLOR); + ItemUtil.register(itemColorLens); + itemCrystal = new ItemCrystal(); ItemUtil.register(itemCrystal); diff --git a/src/main/java/ellpeck/actuallyadditions/items/ItemLens.java b/src/main/java/ellpeck/actuallyadditions/items/ItemLens.java new file mode 100644 index 000000000..0128b9743 --- /dev/null +++ b/src/main/java/ellpeck/actuallyadditions/items/ItemLens.java @@ -0,0 +1,61 @@ +/* + * This file ("ItemLens.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.items; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import ellpeck.actuallyadditions.recipe.ReconstructorRecipeHandler; +import ellpeck.actuallyadditions.util.IActAddItemOrBlock; +import ellpeck.actuallyadditions.util.ModUtil; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; + +public class ItemLens extends Item implements IActAddItemOrBlock, IReconstructorLens{ + + private String name; + private ReconstructorRecipeHandler.LensType type; + + public ItemLens(String name, ReconstructorRecipeHandler.LensType type){ + this.name = name; + this.type = type; + this.setMaxStackSize(1); + } + + @Override + public EnumRarity getRarity(ItemStack stack){ + return EnumRarity.uncommon; + } + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister iconReg){ + this.itemIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getName()); + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(ItemStack stack, int pass){ + return this.itemIcon; + } + + @Override + public String getName(){ + return this.name; + } + + @Override + public ReconstructorRecipeHandler.LensType getLensType(){ + return this.type; + } +} diff --git a/src/main/java/ellpeck/actuallyadditions/network/PacketAtomicReconstructor.java b/src/main/java/ellpeck/actuallyadditions/network/PacketAtomicReconstructor.java index 197bdeb0a..5d0895f07 100644 --- a/src/main/java/ellpeck/actuallyadditions/network/PacketAtomicReconstructor.java +++ b/src/main/java/ellpeck/actuallyadditions/network/PacketAtomicReconstructor.java @@ -15,6 +15,7 @@ import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import ellpeck.actuallyadditions.recipe.ReconstructorRecipeHandler; import io.netty.buffer.ByteBuf; import net.minecraft.client.Minecraft; import net.minecraft.client.particle.EntityReddustFX; @@ -29,19 +30,21 @@ public class PacketAtomicReconstructor implements IMessage{ private int endX; private int endY; private int endZ; + private int lensTypeOrdinal; @SuppressWarnings("unused") public PacketAtomicReconstructor(){ } - public PacketAtomicReconstructor(int startX, int startY, int startZ, int endX, int endY, int endZ){ + public PacketAtomicReconstructor(int startX, int startY, int startZ, int endX, int endY, int endZ, ReconstructorRecipeHandler.LensType type){ this.startX = startX; this.startY = startY; this.startZ = startZ; this.endX = endX; this.endY = endY; this.endZ = endZ; + this.lensTypeOrdinal = type.ordinal(); } @Override @@ -52,6 +55,7 @@ public class PacketAtomicReconstructor implements IMessage{ this.endX = buf.readInt(); this.endY = buf.readInt(); this.endZ = buf.readInt(); + this.lensTypeOrdinal = buf.readInt(); } @Override @@ -62,6 +66,7 @@ public class PacketAtomicReconstructor implements IMessage{ buf.writeInt(this.endX); buf.writeInt(this.endY); buf.writeInt(this.endZ); + buf.writeInt(this.lensTypeOrdinal); } public static class Handler implements IMessageHandler{ @@ -79,7 +84,8 @@ public class PacketAtomicReconstructor implements IMessage{ for(int times = 0; times < 5; times++){ for(double i = 0; i <= 1; i += 1/(distance*8)){ - Minecraft.getMinecraft().effectRenderer.addEffect(new EntityReddustFX(world, (difX*i)+message.endX+0.5, (difY*i)+message.endY+0.5, (difZ*i)+message.endZ+0.5, 2F, 0, 0, 0)); + ReconstructorRecipeHandler.LensType type = ReconstructorRecipeHandler.LensType.values()[message.lensTypeOrdinal]; + Minecraft.getMinecraft().effectRenderer.addEffect(new EntityReddustFX(world, (difX*i)+message.endX+0.5, (difY*i)+message.endY+0.5, (difZ*i)+message.endZ+0.5, 2F, type.getR(), type.getG(), type.getB())); } } } diff --git a/src/main/java/ellpeck/actuallyadditions/recipe/ReconstructorRecipeHandler.java b/src/main/java/ellpeck/actuallyadditions/recipe/ReconstructorRecipeHandler.java index 860e5778e..45cad468c 100644 --- a/src/main/java/ellpeck/actuallyadditions/recipe/ReconstructorRecipeHandler.java +++ b/src/main/java/ellpeck/actuallyadditions/recipe/ReconstructorRecipeHandler.java @@ -11,6 +11,7 @@ package ellpeck.actuallyadditions.recipe; import ellpeck.actuallyadditions.config.values.ConfigCrafting; +import ellpeck.actuallyadditions.util.Util; import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.OreDictionary; @@ -45,7 +46,11 @@ public class ReconstructorRecipeHandler{ } public static void addRecipe(String input, String output, int energyUse){ - recipes.add(new Recipe(input, output, energyUse)); + addRecipe(input, output, energyUse, LensType.NONE); + } + + public static void addRecipe(String input, String output, int energyUse, LensType type){ + recipes.add(new Recipe(input, output, energyUse, type)); } public static Recipe getRecipe(ItemStack input){ @@ -65,11 +70,13 @@ public class ReconstructorRecipeHandler{ public String input; public String output; public int energyUse; + public LensType type; - public Recipe(String input, String output, int energyUse){ + public Recipe(String input, String output, int energyUse, LensType type){ this.input = input; this.output = output; this.energyUse = energyUse; + this.type = type; } public ItemStack getFirstOutput(){ @@ -81,4 +88,31 @@ public class ReconstructorRecipeHandler{ } } + public enum LensType{ + + NONE, + COLOR; + + public float getR(){ + if(this == COLOR){ + return Util.RANDOM.nextFloat(); + } + return 27F/255F; + } + + public float getG(){ + if(this == COLOR){ + return Util.RANDOM.nextFloat(); + } + return 109F/255F; + } + + public float getB(){ + if(this == COLOR){ + return Util.RANDOM.nextFloat(); + } + return 1F; + } + } + } diff --git a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityAtomicReconstructor.java b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityAtomicReconstructor.java index df4cb48ad..e25b89aac 100644 --- a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityAtomicReconstructor.java +++ b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityAtomicReconstructor.java @@ -14,6 +14,7 @@ import cofh.api.energy.EnergyStorage; import cofh.api.energy.IEnergyReceiver; import cpw.mods.fml.common.network.NetworkRegistry; import ellpeck.actuallyadditions.config.values.ConfigIntValues; +import ellpeck.actuallyadditions.items.IReconstructorLens; import ellpeck.actuallyadditions.misc.DamageSources; import ellpeck.actuallyadditions.network.PacketAtomicReconstructor; import ellpeck.actuallyadditions.network.PacketHandler; @@ -31,12 +32,16 @@ import net.minecraftforge.common.util.ForgeDirection; import java.util.ArrayList; -public class TileEntityAtomicReconstructor extends TileEntityBase implements IEnergyReceiver{ +public class TileEntityAtomicReconstructor extends TileEntityInventoryBase implements IEnergyReceiver{ public EnergyStorage storage = new EnergyStorage(3000000); private int currentTime; + public TileEntityAtomicReconstructor(){ + super(1, "reconstructor"); + } + @Override @SuppressWarnings("unchecked") public void updateEntity(){ @@ -51,6 +56,8 @@ public class TileEntityAtomicReconstructor extends TileEntityBase implements IEn //Extract energy for shooting the laser itself too! this.storage.extractEnergy(baseUse, false); + //The Lens the Reconstructor currently has installed + ReconstructorRecipeHandler.LensType currentLens = this.getCurrentLens(); int distance = ConfigIntValues.RECONSTRUCTOR_DISTANCE.getValue(); for(int i = 0; i < distance; i++){ WorldPos coordsBlock = WorldUtil.getCoordsFromSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord, i); @@ -58,7 +65,7 @@ public class TileEntityAtomicReconstructor extends TileEntityBase implements IEn if(coordsBlock != null){ if(!coordsBlock.getBlock().isAir(coordsBlock.getWorld(), coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ())){ - PacketHandler.theNetwork.sendToAllAround(new PacketAtomicReconstructor(xCoord, yCoord, zCoord, coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ()), new NetworkRegistry.TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 64)); + PacketHandler.theNetwork.sendToAllAround(new PacketAtomicReconstructor(xCoord, yCoord, zCoord, coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ(), currentLens), new NetworkRegistry.TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 64)); int range = ConfigIntValues.RECONSTRCUTOR_RANGE.getValue(); @@ -69,7 +76,7 @@ public class TileEntityAtomicReconstructor extends TileEntityBase implements IEn if(this.storage.getEnergyStored() >= baseUse){ WorldPos pos = new WorldPos(worldObj, coordsBlock.getX()+reachX, coordsBlock.getY()+reachY, coordsBlock.getZ()+reachZ); ReconstructorRecipeHandler.Recipe recipe = ReconstructorRecipeHandler.getRecipe(new ItemStack(pos.getBlock(), 1, pos.getMetadata())); - if(recipe != null && this.storage.getEnergyStored() >= baseUse+recipe.energyUse){ + if(recipe != null && this.storage.getEnergyStored() >= baseUse+recipe.energyUse && recipe.type == currentLens){ ItemStack output = recipe.getFirstOutput(); if(output != null){ if(output.getItem() instanceof ItemBlock){ @@ -95,7 +102,7 @@ public class TileEntityAtomicReconstructor extends TileEntityBase implements IEn ItemStack stack = item.getEntityItem(); if(stack != null){ ReconstructorRecipeHandler.Recipe recipe = ReconstructorRecipeHandler.getRecipe(stack); - if(recipe != null && this.storage.getEnergyStored() >= baseUse+recipe.energyUse){ + if(recipe != null && this.storage.getEnergyStored() >= baseUse+recipe.energyUse && recipe.type == currentLens){ ItemStack output = recipe.getFirstOutput(); if(output != null){ ItemStack outputCopy = output.copy(); @@ -111,7 +118,7 @@ public class TileEntityAtomicReconstructor extends TileEntityBase implements IEn break; } if(i >= distance-1){ - PacketHandler.theNetwork.sendToAllAround(new PacketAtomicReconstructor(xCoord, yCoord, zCoord, coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ()), new NetworkRegistry.TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 64)); + PacketHandler.theNetwork.sendToAllAround(new PacketAtomicReconstructor(xCoord, yCoord, zCoord, coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ(), currentLens), new NetworkRegistry.TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 64)); } } } @@ -124,6 +131,15 @@ public class TileEntityAtomicReconstructor extends TileEntityBase implements IEn } } + public ReconstructorRecipeHandler.LensType getCurrentLens(){ + if(this.slots[0] != null){ + if(this.slots[0].getItem() instanceof IReconstructorLens){ + return ((IReconstructorLens)this.slots[0].getItem()).getLensType(); + } + } + return ReconstructorRecipeHandler.LensType.NONE; + } + @SuppressWarnings("unchecked") public void damagePlayer(int x, int y, int z){ ArrayList entities = (ArrayList)worldObj.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.getBoundingBox(x, y, z, x+1, y+1, z+1)); @@ -165,4 +181,19 @@ public class TileEntityAtomicReconstructor extends TileEntityBase implements IEn public boolean canConnectEnergy(ForgeDirection from){ return true; } + + @Override + public boolean canInsertItem(int slot, ItemStack stack, int side){ + return stack != null && stack.getItem() instanceof IReconstructorLens; + } + + @Override + public boolean canExtractItem(int slot, ItemStack stack, int side){ + return true; + } + + @Override + public int getInventoryStackLimit(){ + return 1; + } } diff --git a/src/main/java/ellpeck/actuallyadditions/util/Util.java b/src/main/java/ellpeck/actuallyadditions/util/Util.java index cbf11eb1f..9f0d951e2 100644 --- a/src/main/java/ellpeck/actuallyadditions/util/Util.java +++ b/src/main/java/ellpeck/actuallyadditions/util/Util.java @@ -22,10 +22,12 @@ import net.minecraftforge.oredict.OreDictionary; import java.util.ArrayList; import java.util.List; +import java.util.Random; @SuppressWarnings("unused") public class Util{ + public static final Random RANDOM = new Random(); public static final int WILDCARD = OreDictionary.WILDCARD_VALUE; public static void registerEvent(Object o){ diff --git a/src/main/resources/assets/actuallyadditions/textures/items/itemColorLens.png b/src/main/resources/assets/actuallyadditions/textures/items/itemColorLens.png new file mode 100644 index 0000000000000000000000000000000000000000..bdf3018a63b01b39f896e62bd957936371e9aa9a GIT binary patch literal 658 zcmV;D0&V??P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGf5&!@T5&_cPe*6Fc00(qQO+^Ra3l;zl zFBnWM-v9sr7<5HgbW?9;ba!ELWdLwtX>N2bZe?^JG%heMHvEiZ-v9ss@JU2LR5(wK zQ|(gXKoHCesds{+fI_|#3<)Fzkb^)H0v`H`_wSzPUZJmN-_lUNiKBIsOsnZXTf5yudp3P^K&%DKzJ?aEjB4VlGAlmg96_0ytU~AMzy1m{^;Xn|K@${KbOSF`z4{@AwlBY;cXFO&F=m$flO%o>?1O7p~Y?sxy(B@SeAYE z2|EH;u|79x|#{;zP4>`VK^S(%t2dZv z6;x)@fG|&4&YA&viru3Dz(?G sL-Y|E4bHj_>;4ik?*g=`+!F@cU%C*?4%mBt-v9sr07*qoM6N<$f-1Zr^8f$< literal 0 HcmV?d00001