Working on a WoodChipper!
This commit is contained in:
parent
1b56819928
commit
33ea8185d8
27 changed files with 904 additions and 21 deletions
|
|
@ -2,8 +2,9 @@ package com.oitsjustjose.criss_cross.Blocks;
|
|||
|
||||
import com.oitsjustjose.criss_cross.CrissCross;
|
||||
import com.oitsjustjose.criss_cross.GUI.GUIHandler;
|
||||
import com.oitsjustjose.criss_cross.Util.CropomatorRecipes;
|
||||
import com.oitsjustjose.criss_cross.Util.ElectroextractorRecipes;
|
||||
import com.oitsjustjose.criss_cross.Recipes.CropomatorRecipes;
|
||||
import com.oitsjustjose.criss_cross.Recipes.ElectroextractorRecipes;
|
||||
import com.oitsjustjose.criss_cross.Recipes.WoodchipperRecipes;
|
||||
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import net.minecraft.block.Block;
|
||||
|
|
@ -12,6 +13,7 @@ public class BlockManager
|
|||
{
|
||||
public static Block cropomator;
|
||||
public static Block electroextractor;
|
||||
public static Block woodchipper;
|
||||
|
||||
public static void init()
|
||||
{
|
||||
|
|
@ -23,6 +25,10 @@ public class BlockManager
|
|||
ElectroextractorRecipes.initRecipes();
|
||||
ElectroextractorRecipes.initFuels();
|
||||
|
||||
woodchipper = new BlockWoodchipper();
|
||||
WoodchipperRecipes.initRecipes();
|
||||
WoodchipperRecipes.initFuels();
|
||||
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler(CrissCross.instance, new GUIHandler());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
package com.oitsjustjose.criss_cross.Blocks;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import com.oitsjustjose.criss_cross.CrissCross;
|
||||
import com.oitsjustjose.criss_cross.GUI.GUIHandler;
|
||||
import com.oitsjustjose.criss_cross.TileEntity.TileEntityWoodchipper;
|
||||
import com.oitsjustjose.criss_cross.Util.Reference;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BlockWoodchipper extends BlockMachineBase
|
||||
{
|
||||
private static String unlocName = "WoodChipper";
|
||||
public BlockWoodchipper()
|
||||
{
|
||||
super(unlocName);
|
||||
|
||||
GameRegistry.registerBlock(this, unlocName);
|
||||
GameRegistry.registerTileEntity(TileEntityWoodchipper.class, unlocName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerBlockIcons(IIconRegister register)
|
||||
{
|
||||
blockTextures[0] = register.registerIcon(Reference.modid + ":" + this.unlocName + "/" + unlocName + "_Bottom");
|
||||
blockTextures[1] = register.registerIcon(Reference.modid + ":" + this.unlocName + "/" + unlocName + "_Top");
|
||||
blockTextures[2] = register.registerIcon(Reference.modid + ":" + this.unlocName + "/" + unlocName + "_Front");
|
||||
blockTextures[3] = register.registerIcon(Reference.modid + ":" + this.unlocName + "/" + unlocName + "_Sides");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int meta)
|
||||
{
|
||||
return new TileEntityWoodchipper();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World world, int x, int y, int z, Block block, int meta)
|
||||
{
|
||||
Random random = new Random();
|
||||
TileEntityWoodchipper tile = (TileEntityWoodchipper)world.getTileEntity(x, y, z);
|
||||
|
||||
if (tile != null)
|
||||
{
|
||||
for (int i = 0; i < tile.getSizeInventory(); ++i)
|
||||
{
|
||||
ItemStack itemstack = tile.getStackInSlot(i);
|
||||
|
||||
if (itemstack != null)
|
||||
{
|
||||
float f = random.nextFloat() * 0.8F + 0.1F;
|
||||
float f1 = random.nextFloat() * 0.8F + 0.1F;
|
||||
float f2 = random.nextFloat() * 0.8F + 0.1F;
|
||||
|
||||
while (itemstack.stackSize > 0)
|
||||
{
|
||||
int j = random.nextInt(21) + 10;
|
||||
|
||||
if (j > itemstack.stackSize)
|
||||
{
|
||||
j = itemstack.stackSize;
|
||||
}
|
||||
|
||||
itemstack.stackSize -= j;
|
||||
EntityItem entityitem = new EntityItem(world, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(itemstack.getItem(), j, itemstack.getItemDamage()));
|
||||
|
||||
if (itemstack.hasTagCompound())
|
||||
{
|
||||
entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
|
||||
}
|
||||
|
||||
float f3 = 0.05F;
|
||||
entityitem.motionX = (double)((float)random.nextGaussian() * f3);
|
||||
entityitem.motionY = (double)((float)random.nextGaussian() * f3 + 0.2F);
|
||||
entityitem.motionZ = (double)((float)random.nextGaussian() * f3);
|
||||
world.spawnEntityInWorld(entityitem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
world.func_147453_f(x, y, z, block);
|
||||
|
||||
}
|
||||
|
||||
super.breakBlock(world, x, y, z, block, meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if(world.isRemote)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
TileEntityWoodchipper tileext = (TileEntityWoodchipper)world.getTileEntity(x, y, z);
|
||||
if(tileext != null)
|
||||
player.openGui(CrissCross.instance, GUIHandler.Woodchipper, world, x, y, z);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ public class ContainerElectroextractor extends Container
|
|||
|
||||
private int lastUseTime;
|
||||
private int lastCrushTime;
|
||||
private int lastCatalystInUseTime;
|
||||
private int lastFuelTime;
|
||||
|
||||
public ContainerElectroextractor(EntityPlayer player, TileEntityElectroextractor electroextractor)
|
||||
{
|
||||
|
|
@ -27,7 +27,7 @@ public class ContainerElectroextractor extends Container
|
|||
|
||||
lastUseTime = 0;
|
||||
lastCrushTime = 0;
|
||||
lastCatalystInUseTime = 0;
|
||||
lastFuelTime = 0;
|
||||
|
||||
this.addSlotToContainer(new Slot(electroextractor, 0, 56, 17)); //input
|
||||
this.addSlotToContainer(new Slot(electroextractor, 1, 56, 53)); //fuelitem
|
||||
|
|
@ -75,12 +75,12 @@ public class ContainerElectroextractor extends Container
|
|||
crafting.sendProgressBarUpdate(this, 0, this.electroextractor.crushTime);
|
||||
if(this.lastCrushTime != this.electroextractor.fuelTime)
|
||||
crafting.sendProgressBarUpdate(this, 1, this.electroextractor.fuelTime);
|
||||
if(this.lastCatalystInUseTime != this.electroextractor.fuelInUseTime)
|
||||
if(this.lastFuelTime != this.electroextractor.fuelInUseTime)
|
||||
crafting.sendProgressBarUpdate(this, 2, this.electroextractor.fuelInUseTime);
|
||||
}
|
||||
this.lastUseTime = this.electroextractor.crushTime;
|
||||
this.lastCrushTime = this.electroextractor.fuelTime;
|
||||
this.lastCatalystInUseTime = this.electroextractor.fuelInUseTime;
|
||||
this.lastFuelTime = this.electroextractor.fuelInUseTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -0,0 +1,176 @@
|
|||
package com.oitsjustjose.criss_cross.Container;
|
||||
|
||||
import com.oitsjustjose.criss_cross.TileEntity.TileEntityWoodchipper;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ContainerWoodchipper extends Container
|
||||
{
|
||||
TileEntityWoodchipper woodchipper;
|
||||
EntityPlayer player;
|
||||
|
||||
private int lastUseTime;
|
||||
private int lastChopTime;
|
||||
private int lastFuelTime;
|
||||
|
||||
public ContainerWoodchipper(EntityPlayer player, TileEntityWoodchipper woodchipper)
|
||||
{
|
||||
this.player = player;
|
||||
this.woodchipper = woodchipper;
|
||||
|
||||
lastUseTime = 0;
|
||||
lastChopTime = 0;
|
||||
lastFuelTime = 0;
|
||||
|
||||
this.addSlotToContainer(new Slot(woodchipper, 0, 56, 17)); //input
|
||||
this.addSlotToContainer(new Slot(woodchipper, 1, 56, 53)); //catalyst
|
||||
this.addSlotToContainer(new MachineOutputSlot(player, woodchipper, 2, 116, 35));
|
||||
this.addInventorySlots();
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void updateProgressBar(int timeType1, int timeType2)
|
||||
{
|
||||
switch(timeType1)
|
||||
{
|
||||
case 0:this.woodchipper.processTime = timeType2;
|
||||
break;
|
||||
case 1:this.woodchipper.fuelTime = timeType2;
|
||||
break;
|
||||
case 2:this.woodchipper.fuelUsetime = timeType2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCraftingToCrafters(ICrafting crafting)
|
||||
{
|
||||
super.addCraftingToCrafters(crafting);
|
||||
crafting.sendProgressBarUpdate(this, 0, this.woodchipper.processTime);
|
||||
crafting.sendProgressBarUpdate(this, 1, this.woodchipper.fuelTime);
|
||||
crafting.sendProgressBarUpdate(this, 2, this.woodchipper.fuelUsetime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges()
|
||||
{
|
||||
super.detectAndSendChanges();
|
||||
for(int i = 0; i < this.crafters.size(); ++i)
|
||||
{
|
||||
ICrafting crafting = (ICrafting)this.crafters.get(i);
|
||||
|
||||
if(this.lastUseTime != this.woodchipper.processTime)
|
||||
crafting.sendProgressBarUpdate(this, 0, this.woodchipper.processTime);
|
||||
if(this.lastChopTime != this.woodchipper.fuelTime)
|
||||
crafting.sendProgressBarUpdate(this, 1, this.woodchipper.fuelTime);
|
||||
if(this.lastFuelTime != this.woodchipper.fuelUsetime)
|
||||
crafting.sendProgressBarUpdate(this, 2, this.woodchipper.fuelUsetime);
|
||||
}
|
||||
this.lastUseTime = this.woodchipper.processTime;
|
||||
this.lastChopTime = this.woodchipper.fuelTime;
|
||||
this.lastFuelTime = this.woodchipper.fuelUsetime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer player, int slotID)
|
||||
{
|
||||
ItemStack itemstack = null;
|
||||
Slot slot = (Slot)this.inventorySlots.get(slotID);
|
||||
|
||||
if (slot != null && slot.getHasStack())
|
||||
{
|
||||
ItemStack itemstack1 = slot.getStack();
|
||||
itemstack = itemstack1.copy();
|
||||
|
||||
if (slotID == 2)
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 3, 39, true))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
slot.onSlotChange(itemstack1, itemstack);
|
||||
}
|
||||
else if (slotID != 1 && slotID != 0)
|
||||
{
|
||||
if (TileEntityWoodchipper.isValidForWoodchipper(itemstack1))
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 0, 1, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (TileEntityWoodchipper.isItemFuel(itemstack1))
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 1, 2, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (slotID >= 3 && slotID < 30)
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 30, 39, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (slotID >= 30 && slotID < 39 && !this.mergeItemStack(itemstack1, 3, 30, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (!this.mergeItemStack(itemstack1, 3, 39, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == 0)
|
||||
{
|
||||
slot.putStack((ItemStack)null);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == itemstack.stackSize)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
slot.onPickupFromSlot(player, itemstack1);
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player)
|
||||
{
|
||||
return this.woodchipper.isUseableByPlayer(this.player);
|
||||
}
|
||||
|
||||
public final void addInventorySlots()
|
||||
{
|
||||
this.addInventorySlots(8, 84, 142);
|
||||
}
|
||||
|
||||
public final void addInventorySlots(int xOffset, int yOffset, int yHotbar)
|
||||
{
|
||||
InventoryPlayer inventory = this.player.inventory;
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
for (int j = 0; j < 9; ++j)
|
||||
this.addSlotToContainer(new Slot(inventory, 9 + j + i * 9, xOffset + j * 18, yOffset + i * 18));
|
||||
|
||||
for (int i = 0; i < 9; ++i)
|
||||
this.addSlotToContainer(new Slot(inventory, i, xOffset + i * 18, yHotbar));
|
||||
}
|
||||
}
|
||||
|
|
@ -2,9 +2,9 @@ package com.oitsjustjose.criss_cross;
|
|||
|
||||
import com.oitsjustjose.criss_cross.Blocks.BlockManager;
|
||||
import com.oitsjustjose.criss_cross.Items.ItemManager;
|
||||
import com.oitsjustjose.criss_cross.Recipes.RecipeHandler;
|
||||
import com.oitsjustjose.criss_cross.Util.CommonProxy;
|
||||
import com.oitsjustjose.criss_cross.Util.ConfigHandler;
|
||||
import com.oitsjustjose.criss_cross.Util.RecipeHandler;
|
||||
import com.oitsjustjose.criss_cross.Util.Reference;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
|
|
|
|||
|
|
@ -2,8 +2,10 @@ package com.oitsjustjose.criss_cross.GUI;
|
|||
|
||||
import com.oitsjustjose.criss_cross.Container.ContainerCropomator;
|
||||
import com.oitsjustjose.criss_cross.Container.ContainerElectroextractor;
|
||||
import com.oitsjustjose.criss_cross.Container.ContainerWoodchipper;
|
||||
import com.oitsjustjose.criss_cross.TileEntity.TileEntityCropomator;
|
||||
import com.oitsjustjose.criss_cross.TileEntity.TileEntityElectroextractor;
|
||||
import com.oitsjustjose.criss_cross.TileEntity.TileEntityWoodchipper;
|
||||
|
||||
import cpw.mods.fml.common.network.IGuiHandler;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
|
@ -14,6 +16,7 @@ public class GUIHandler implements IGuiHandler
|
|||
{
|
||||
public static final int Cropomator = 1;
|
||||
public static final int Electroextractor = 2;
|
||||
public static final int Woodchipper = 3;
|
||||
|
||||
@Override
|
||||
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
|
||||
|
|
@ -22,15 +25,21 @@ public class GUIHandler implements IGuiHandler
|
|||
|
||||
if(tile instanceof TileEntityCropomator)
|
||||
{
|
||||
TileEntityCropomator tileCropomator = (TileEntityCropomator)tile;
|
||||
TileEntityCropomator TE = (TileEntityCropomator)tile;
|
||||
|
||||
return new ContainerCropomator(player, tileCropomator);
|
||||
return new ContainerCropomator(player, TE);
|
||||
}
|
||||
if(tile instanceof TileEntityElectroextractor)
|
||||
{
|
||||
TileEntityElectroextractor tileExt = (TileEntityElectroextractor)tile;
|
||||
TileEntityElectroextractor TE = (TileEntityElectroextractor)tile;
|
||||
|
||||
return new ContainerElectroextractor(player, tileExt);
|
||||
return new ContainerElectroextractor(player, TE);
|
||||
}
|
||||
if(tile instanceof TileEntityWoodchipper)
|
||||
{
|
||||
TileEntityWoodchipper TE = (TileEntityWoodchipper)tile;
|
||||
|
||||
return new ContainerWoodchipper(player, TE);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
@ -42,16 +51,22 @@ public class GUIHandler implements IGuiHandler
|
|||
|
||||
if(tile instanceof TileEntityCropomator)
|
||||
{
|
||||
TileEntityCropomator tileCropomator = (TileEntityCropomator)tile;
|
||||
TileEntityCropomator TE = (TileEntityCropomator)tile;
|
||||
|
||||
return new GUICropomator(player, tileCropomator);
|
||||
return new GUICropomator(player, TE);
|
||||
}
|
||||
|
||||
if(tile instanceof TileEntityElectroextractor)
|
||||
{
|
||||
TileEntityElectroextractor tileExt = (TileEntityElectroextractor)tile;
|
||||
TileEntityElectroextractor TE = (TileEntityElectroextractor)tile;
|
||||
|
||||
return new GUIElectroextractor(player, tileExt);
|
||||
return new GUIElectroextractor(player, TE);
|
||||
}
|
||||
if(tile instanceof TileEntityWoodchipper)
|
||||
{
|
||||
TileEntityWoodchipper TE = (TileEntityWoodchipper)tile;
|
||||
|
||||
return new GUIWoodchipper(player, TE);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
package com.oitsjustjose.criss_cross.GUI;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.oitsjustjose.criss_cross.Container.ContainerWoodchipper;
|
||||
import com.oitsjustjose.criss_cross.TileEntity.TileEntityWoodchipper;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
public class GUIWoodchipper extends GuiContainer
|
||||
{
|
||||
public static final ResourceLocation texture = new ResourceLocation("crisscross", "textures/gui/woodchipper.png");
|
||||
|
||||
private TileEntityWoodchipper woodchipper;
|
||||
|
||||
public GUIWoodchipper(EntityPlayer player, TileEntityWoodchipper woodchipper)
|
||||
{
|
||||
super(new ContainerWoodchipper(player, woodchipper));
|
||||
this.woodchipper = woodchipper;
|
||||
}
|
||||
|
||||
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
|
||||
{
|
||||
this.fontRendererObj.drawString(StatCollector.translateToLocal("container.woodchipper"), 55, 7, 4210752);
|
||||
this.fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 7, this.ySize - 92, 4210752);
|
||||
}
|
||||
|
||||
protected void drawGuiContainerBackgroundLayer(float partialTickTime, int mouseX, int mouseY)
|
||||
{
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.mc.renderEngine.bindTexture(texture);
|
||||
int k = (this.width - this.xSize) / 2;
|
||||
int l = (this.height - this.ySize) / 2;
|
||||
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
|
||||
|
||||
if (this.woodchipper.isUsingFuel())
|
||||
{
|
||||
int i1 = this.woodchipper.getBurnTimeRemainingScaled(13);
|
||||
this.drawTexturedModalRect(k + 56, l + 36 + 12 - i1, 176, 12 - i1, 14, i1 + 1);
|
||||
i1 = this.woodchipper.getProgressScaled(24);
|
||||
this.drawTexturedModalRect(k + 79, l + 34, 176, 14, i1 + 1, 16);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package com.oitsjustjose.criss_cross.Util;
|
||||
package com.oitsjustjose.criss_cross.Recipes;
|
||||
|
||||
import com.oitsjustjose.criss_cross.TileEntity.TileEntityCropomator;
|
||||
import com.oitsjustjose.criss_cross.Util.ConfigHandler;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
package com.oitsjustjose.criss_cross.Util;
|
||||
package com.oitsjustjose.criss_cross.Recipes;
|
||||
|
||||
import com.oitsjustjose.criss_cross.Items.ItemManager;
|
||||
import com.oitsjustjose.criss_cross.TileEntity.TileEntityCropomator;
|
||||
import com.oitsjustjose.criss_cross.TileEntity.TileEntityElectroextractor;
|
||||
import com.oitsjustjose.criss_cross.Util.ConfigHandler;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import net.minecraft.init.Blocks;
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
package com.oitsjustjose.criss_cross.Util;
|
||||
package com.oitsjustjose.criss_cross.Recipes;
|
||||
|
||||
import com.oitsjustjose.criss_cross.Blocks.BlockManager;
|
||||
import com.oitsjustjose.criss_cross.Items.ItemManager;
|
||||
import com.oitsjustjose.criss_cross.Util.ConfigHandler;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import net.minecraft.init.Blocks;
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
package com.oitsjustjose.criss_cross.Recipes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.oitsjustjose.criss_cross.TileEntity.TileEntityWoodchipper;
|
||||
import com.oitsjustjose.criss_cross.Util.ConfigHandler;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
public class WoodchipperRecipes
|
||||
{
|
||||
public static void initRecipes()
|
||||
{
|
||||
ArrayList<ItemStack> logs = OreDictionary.getOres("logWood");
|
||||
ArrayList<ItemStack> planks = OreDictionary.getOres("plankWood");
|
||||
|
||||
for(int i = 0; i < logs.size(); i++)
|
||||
{
|
||||
for(int j = 0; j < planks.size(); j++)
|
||||
{
|
||||
ItemStack tempLog = logs.get(i);
|
||||
ItemStack tempPlank = planks.get(j);
|
||||
|
||||
String logName = tempLog.getDisplayName().toLowerCase();
|
||||
String plankName = tempPlank.getDisplayName().toLowerCase();
|
||||
|
||||
logName.replaceFirst("wood", "");
|
||||
logName.trim();
|
||||
|
||||
if(plankName.contains(logName))
|
||||
TileEntityWoodchipper.addRecipe(tempLog, tempPlank);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void initFuels()
|
||||
{
|
||||
for(int i = 0; i < ConfigHandler.woodchipperFuels.length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
String[] unlocStack = ConfigHandler.woodchipperFuels[i].split(":");
|
||||
if(unlocStack.length == 2)
|
||||
{
|
||||
if(GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1) != null)
|
||||
TileEntityWoodchipper.addItemStackToFuels(GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 0));
|
||||
else
|
||||
System.out.println("[CrissCross] Item " + ConfigHandler.woodchipperFuels[i] + " could not be added to the Woodchipper's fuel list. Please confirm you have the name and formatting correct.");
|
||||
}
|
||||
|
||||
if(unlocStack.length == 3)
|
||||
{
|
||||
if(GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1) != null)
|
||||
{
|
||||
ItemStack newStack = new ItemStack(GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1).getItem(), 1, Integer.parseInt(unlocStack[2]));
|
||||
TileEntityWoodchipper.addItemStackToFuels(newStack);
|
||||
}
|
||||
else
|
||||
System.out.println("[CrissCross] Item " + ConfigHandler.woodchipperFuels[i] + " could not be added to the Woodchipper's fuel list. Please confirm you have the name and formatting correct.");
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("[CrissCross]: Error reading itemstack for Woodchipper's energy sources at item: " + (i + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,432 @@
|
|||
package com.oitsjustjose.criss_cross.TileEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.oitsjustjose.criss_cross.Blocks.BlockCropomator;
|
||||
import com.oitsjustjose.criss_cross.Recipes.WoodchipperRecipes;
|
||||
import com.oitsjustjose.criss_cross.Util.ConfigHandler;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class TileEntityWoodchipper extends TileEntity implements ISidedInventory
|
||||
{
|
||||
private static int proTicks = ConfigHandler.woodchipperProcessTime;
|
||||
private static int qty = ConfigHandler.woodchipperOutput;
|
||||
private static final int[] slotsTop = new int[] {0};
|
||||
private static final int[] slotsBottom = new int[] {2, 1};
|
||||
private static final int[] slotsSides = new int[] {1};
|
||||
private static ArrayList<ItemStack> inputItems = new ArrayList<ItemStack>();
|
||||
private static ArrayList<ItemStack> outputItems = new ArrayList<ItemStack>();
|
||||
private static ArrayList<ItemStack> fuelItems = new ArrayList<ItemStack>();
|
||||
|
||||
private ItemStack[] ItemStacks = new ItemStack[3];
|
||||
|
||||
public int fuelTime;
|
||||
public int processTime;
|
||||
public int fuelUsetime;
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return this.ItemStacks.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot)
|
||||
{
|
||||
return this.ItemStacks[slot];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int qtyToDecr)
|
||||
{
|
||||
if (this.ItemStacks[slot] != null)
|
||||
{
|
||||
ItemStack itemstack;
|
||||
|
||||
if (this.ItemStacks[slot].stackSize <= qtyToDecr)
|
||||
{
|
||||
itemstack = this.ItemStacks[slot];
|
||||
this.ItemStacks[slot] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else
|
||||
{
|
||||
itemstack = this.ItemStacks[slot].splitStack(qtyToDecr);
|
||||
|
||||
if (this.ItemStacks[slot].stackSize == 0)
|
||||
{
|
||||
this.ItemStacks[slot] = null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slot)
|
||||
{
|
||||
if (this.ItemStacks[slot] != null)
|
||||
{
|
||||
ItemStack itemstack = this.ItemStacks[slot];
|
||||
this.ItemStacks[slot] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack itemstack)
|
||||
{
|
||||
this.ItemStacks[slot] = itemstack;
|
||||
|
||||
if (itemstack != null && itemstack.stackSize > this.getInventoryStackLimit())
|
||||
{
|
||||
itemstack.stackSize = this.getInventoryStackLimit();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName()
|
||||
{
|
||||
return "container.woodchipper";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.readFromNBT(tag);
|
||||
NBTTagList nbttaglist = tag.getTagList("Items", 10);
|
||||
this.ItemStacks = new ItemStack[this.getSizeInventory()];
|
||||
|
||||
for (int i = 0; i < nbttaglist.tagCount(); ++i)
|
||||
{
|
||||
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
|
||||
byte b0 = nbttagcompound1.getByte("Slot");
|
||||
|
||||
if (b0 >= 0 && b0 < this.ItemStacks.length)
|
||||
{
|
||||
this.ItemStacks[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
|
||||
}
|
||||
}
|
||||
|
||||
this.fuelTime = tag.getShort("FuelTime");
|
||||
this.processTime = tag.getShort("WorkTime");
|
||||
this.fuelUsetime = getItemBurnTime(this.ItemStacks[1]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.writeToNBT(tag);
|
||||
tag.setShort("FuelTime", (short)this.fuelTime);
|
||||
tag.setShort("WorkTime", (short)this.processTime);
|
||||
NBTTagList nbttaglist = new NBTTagList();
|
||||
|
||||
for (int i = 0; i < this.ItemStacks.length; ++i)
|
||||
{
|
||||
if (this.ItemStacks[i] != null)
|
||||
{
|
||||
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
||||
nbttagcompound1.setByte("Slot", (byte)i);
|
||||
this.ItemStacks[i].writeToNBT(nbttagcompound1);
|
||||
nbttaglist.appendTag(nbttagcompound1);
|
||||
}
|
||||
}
|
||||
|
||||
tag.setTag("Items", nbttaglist);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getProgressScaled(int par1)
|
||||
{
|
||||
return this.processTime * par1 / proTicks;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getBurnTimeRemainingScaled(int par1)
|
||||
{
|
||||
if (this.fuelUsetime == 0)
|
||||
{
|
||||
this.fuelUsetime = proTicks;
|
||||
}
|
||||
|
||||
return this.fuelTime * par1 / this.fuelUsetime;
|
||||
}
|
||||
|
||||
public boolean isUsingFuel()
|
||||
{
|
||||
return this.fuelTime > 0;
|
||||
}
|
||||
|
||||
public void updateEntity()
|
||||
{
|
||||
boolean flag = this.fuelTime > 0;
|
||||
boolean flag1 = false;
|
||||
|
||||
if (this.fuelTime > 0)
|
||||
{
|
||||
--this.fuelTime;
|
||||
}
|
||||
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
if (this.fuelTime != 0 || this.ItemStacks[1] != null && this.ItemStacks[0] != null)
|
||||
{
|
||||
if (this.fuelTime == 0 && this.canProcess())
|
||||
{
|
||||
this.fuelUsetime = this.fuelTime = getItemBurnTime(this.ItemStacks[1]);
|
||||
|
||||
if (this.fuelTime > 0)
|
||||
{
|
||||
flag1 = true;
|
||||
|
||||
if (this.ItemStacks[1] != null)
|
||||
{
|
||||
--this.ItemStacks[1].stackSize;
|
||||
|
||||
if (this.ItemStacks[1].stackSize == 0)
|
||||
{
|
||||
this.ItemStacks[1] = ItemStacks[1].getItem().getContainerItem(ItemStacks[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.isUsingFuel() && this.canProcess())
|
||||
{
|
||||
++this.processTime;
|
||||
|
||||
if (this.processTime == proTicks)
|
||||
{
|
||||
this.processTime = 0;
|
||||
this.processItem();
|
||||
flag1 = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.processTime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (flag != this.fuelTime > 0)
|
||||
{
|
||||
flag1 = true;
|
||||
BlockCropomator.updateBlockState(this.fuelTime > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
|
||||
}
|
||||
}
|
||||
|
||||
if (flag1)
|
||||
{
|
||||
this.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canProcess()
|
||||
{
|
||||
if (this.ItemStacks[0] == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
int posInArList = 0;
|
||||
for(int i = 0; i < inputItems.size(); i++)
|
||||
{
|
||||
if(inputItems.get(i).getItem() == ItemStacks[0].getItem() && inputItems.get(i).getItemDamage() == ItemStacks[0].getItemDamage())
|
||||
{
|
||||
posInArList = i;
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack itemstack = new ItemStack(outputItems.get(posInArList).getItem(), qty, outputItems.get(posInArList).getItemDamage());
|
||||
|
||||
if(this.ItemStacks[2] == null)
|
||||
return true;
|
||||
if(!this.ItemStacks[2].isItemEqual(itemstack))
|
||||
return false;
|
||||
int result = ItemStacks[2].stackSize + itemstack.stackSize;
|
||||
|
||||
return result <= getInventoryStackLimit() && result <= this.ItemStacks[2].getMaxStackSize();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean removeRecipe(ItemStack itemstack)
|
||||
{
|
||||
for(int i = 0; i < inputItems.size(); i++)
|
||||
{
|
||||
if(inputItems.get(i) == itemstack)
|
||||
{
|
||||
inputItems.remove(i);
|
||||
outputItems.remove(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void addRecipe(ItemStack input, ItemStack output)
|
||||
{
|
||||
inputItems.add(input);
|
||||
outputItems.add(output);
|
||||
}
|
||||
|
||||
public static void addItemRecipe(Item item, ItemStack output)
|
||||
{
|
||||
inputItems.add(new ItemStack(item));
|
||||
outputItems.add(output);
|
||||
}
|
||||
|
||||
public static void addBlockRecipe(Block block, ItemStack output)
|
||||
{
|
||||
inputItems.add(new ItemStack(block));
|
||||
outputItems.add(output);
|
||||
}
|
||||
|
||||
public static void addItemStackToFuels(ItemStack itemstack)
|
||||
{
|
||||
fuelItems.add(itemstack);
|
||||
}
|
||||
|
||||
public static boolean removeItemStackFromFuels(ItemStack itemstack)
|
||||
{
|
||||
for(int i = 0; i < fuelItems.size(); i++)
|
||||
{
|
||||
if(fuelItems.get(i) == itemstack)
|
||||
{
|
||||
fuelItems.remove(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isValidForWoodchipper(ItemStack itemstack)
|
||||
{
|
||||
for(int i = 0; i < inputItems.size(); i++)
|
||||
{
|
||||
ItemStack temp = inputItems.get(i);
|
||||
if(temp.getItem() == itemstack.getItem() && temp.getItemDamage() == itemstack.getItemDamage())
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void processItem()
|
||||
{
|
||||
if (this.canProcess())
|
||||
{
|
||||
int posInArList = 0;
|
||||
for(int i = 0; i < inputItems.size(); i++)
|
||||
{
|
||||
if(inputItems.get(i).getItem() == ItemStacks[0].getItem() && inputItems.get(i).getItemDamage() == ItemStacks[0].getItemDamage())
|
||||
{
|
||||
posInArList = i;
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack output = new ItemStack(outputItems.get(posInArList).getItem(), qty, outputItems.get(posInArList).getItemDamage());
|
||||
|
||||
if (this.ItemStacks[2] == null)
|
||||
{
|
||||
this.ItemStacks[2] = output.copy();
|
||||
}
|
||||
else if (this.ItemStacks[2].getItem() == output.getItem())
|
||||
{
|
||||
this.ItemStacks[2].stackSize += output.stackSize;
|
||||
}
|
||||
|
||||
--this.ItemStacks[0].stackSize;
|
||||
|
||||
if (this.ItemStacks[0].stackSize <= 0)
|
||||
{
|
||||
this.ItemStacks[0] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int getItemBurnTime(ItemStack itemstack)
|
||||
{
|
||||
return isItemFuel(itemstack) ? proTicks : 0;
|
||||
}
|
||||
|
||||
public static boolean isItemFuel(ItemStack itemstack)
|
||||
{
|
||||
for(int i = 0; i < fuelItems.size(); i++)
|
||||
{
|
||||
ItemStack temp = fuelItems.get(i);
|
||||
if(temp.getItem() == itemstack.getItem() && temp.getItemDamage() == itemstack.getItemDamage())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isUseableByPlayer(EntityPlayer player)
|
||||
{
|
||||
|
||||
return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D;
|
||||
}
|
||||
|
||||
public void openInventory(){}
|
||||
|
||||
public void closeInventory(){}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack itemstack)
|
||||
{
|
||||
return slot == 2 ? false : (slot == 1 ? isItemFuel(itemstack) : true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int slot)
|
||||
{
|
||||
return slot == 0 ? slotsBottom : (slot == 1 ? slotsTop : slotsSides);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem(int slot, ItemStack itemstack, int side)
|
||||
{
|
||||
return this.isItemValidForSlot(slot, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int slot, ItemStack itemstack, int side)
|
||||
{
|
||||
return side != 0 || slot != 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty(){}
|
||||
}
|
||||
|
|
@ -33,7 +33,6 @@ public class ConfigHandler
|
|||
public static int electroextractorProcessTime;
|
||||
public static int electroextractorOutput;
|
||||
public static String electroextractorRecipeItem;
|
||||
public static String[] electroextractorInputs;
|
||||
public static String[] electroextractorEnergySources;
|
||||
|
||||
public static String[] defaultElectroextractorEnergySources = new String[]
|
||||
|
|
@ -41,7 +40,15 @@ public class ConfigHandler
|
|||
"minecraft:redstone_block"
|
||||
};
|
||||
|
||||
|
||||
public static int woodchipperProcessTime;
|
||||
public static int woodchipperOutput;
|
||||
public static String woodchipperRecipeItem;
|
||||
public static String[] woodchipperFuels;
|
||||
|
||||
public static String[] defaultWoodchipperFuels = new String[]
|
||||
{
|
||||
"minecraft:water_bucket"
|
||||
};
|
||||
|
||||
public static void init(File configFile)
|
||||
{
|
||||
|
|
@ -79,11 +86,23 @@ public class ConfigHandler
|
|||
"Control how many ticks it takes the Electroextractor to process an item. Default is 250; furnaces are 200.");
|
||||
|
||||
electroextractorOutput = config.getInt("Electroextractor Output Quantity", config.CATEGORY_GENERAL, 2, 0, 64,
|
||||
"Control how many of the input item you get as the output item. Default is 2.");
|
||||
"Control how many dusts you get as the output. Default is 2.");
|
||||
|
||||
electroextractorRecipeItem = config.getString("Key crafting item of the Electroextractor.", config.CATEGORY_GENERAL, "minecraft:diamond_block",
|
||||
"This is the item located in the center of the crafting recipe for the Electroextractor. Formatted as: <modid>:<item>:<meta> or <modid>:<item>.");
|
||||
|
||||
//Woodchipper's Configs
|
||||
woodchipperFuels = config.get(config.CATEGORY_GENERAL, "Items to be added as the Woodchipper's 'fuels'", defaultWoodchipperFuels,
|
||||
"A list of items to be added as the Woodchipper's 'fuels'. Formatted as: <modid>:<item>:<meta> or <modid>:<item>.").getStringList();
|
||||
|
||||
woodchipperProcessTime = config.getInt("Woodchipper Process Time", config.CATEGORY_GENERAL, 400, 0, Short.MAX_VALUE,
|
||||
"Control how many ticks it takes the Woodchipper to process an item. Default is 400; furnaces are 200.");
|
||||
|
||||
woodchipperOutput = config.getInt("Woodchipper Output Quantity", config.CATEGORY_GENERAL, 6, 0, 64,
|
||||
"Control how many planks are yielded from processing a log. Default is 6.");
|
||||
|
||||
woodchipperRecipeItem = config.getString("Key crafting item of the Woodchipper", config.CATEGORY_GENERAL, "minecraft:diamond_block",
|
||||
"This is the item located in the center of the crafting recipe for the Woodchipper. Formatted as: <modid>:<item>:<meta> or <modid>:<item>.");
|
||||
|
||||
if (config.hasChanged())
|
||||
config.save();
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 403 B |
Binary file not shown.
|
After Width: | Height: | Size: 3.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 531 B |
Binary file not shown.
|
After Width: | Height: | Size: 738 B |
Loading…
Reference in a new issue