Reconstructor Colors, Part 1

This commit is contained in:
Ellpeck 2015-11-22 18:52:11 +01:00
parent 93fb24e736
commit 0a78782693
9 changed files with 188 additions and 11 deletions

View file

@ -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;
}

View file

@ -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();
}

View file

@ -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);

View file

@ -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;
}
}

View file

@ -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<PacketAtomicReconstructor, IMessage>{
@ -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()));
}
}
}

View file

@ -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;
}
}
}

View file

@ -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<EntityLivingBase> entities = (ArrayList<EntityLivingBase>)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;
}
}

View file

@ -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){

Binary file not shown.

After

Width:  |  Height:  |  Size: 658 B