initial 1.8 port

This commit is contained in:
Raoul Van den Berge
2015-12-25 18:51:58 +01:00
parent 8acd72fffc
commit 6c3c113521
74 changed files with 6796 additions and 7094 deletions

View File

@@ -1,110 +1,110 @@
package storagecraft.tile;
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.nbt.NBTTagCompound;
import storagecraft.StorageCraft;
import storagecraft.container.ContainerGridCrafting;
import storagecraft.inventory.InventorySimple;
import storagecraft.network.MessageGridCraftingUpdate;
import storagecraft.storage.StorageItem;
import storagecraft.util.InventoryUtils;
public class TileGrid extends TileMachine
{
private ContainerGridCrafting craftingMatrixContainer = new ContainerGridCrafting(this);
private InventoryCrafting craftingMatrix = new InventoryCrafting(craftingMatrixContainer, 3, 3);
private InventorySimple craftingResult = new InventorySimple("craftingResult", 1);
@Override
public int getEnergyUsage()
{
return 5;
}
@Override
public void updateMachine()
{
}
public int getType()
{
return worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
}
public boolean isCrafting()
{
return getType() == 1;
}
public InventoryCrafting getCraftingMatrix()
{
return craftingMatrix;
}
public void onCraftingMatrixChanged()
{
craftingResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(craftingMatrix, worldObj));
}
public void onCrafted(ItemStack[] matrixSlots)
{
if (isConnected() && !worldObj.isRemote)
{
for (int i = 0; i < craftingMatrix.getSizeInventory(); ++i)
{
ItemStack slot = craftingMatrix.getStackInSlot(i);
if (slot == null && matrixSlots[i] != null)
{
for (StorageItem item : getController().getItems())
{
if (item.compareNoQuantity(matrixSlots[i].copy()))
{
craftingMatrix.setInventorySlotContents(i, getController().take(matrixSlots[i].copy()));
break;
}
}
}
}
onCraftingMatrixChanged();
// @TODO: HACK!
TargetPoint target = new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, UPDATE_RANGE);
StorageCraft.NETWORK.sendToAllAround(new MessageGridCraftingUpdate(this), target);
}
}
public InventorySimple getCraftingResult()
{
return craftingResult;
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
InventoryUtils.restoreInventory(craftingMatrix, nbt);
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
InventoryUtils.saveInventory(craftingMatrix, nbt);
}
@Override
public IInventory getDroppedInventory()
{
return craftingMatrix;
}
}
package storagecraft.tile;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint;
import storagecraft.StorageCraft;
import storagecraft.container.ContainerGridCrafting;
import storagecraft.inventory.InventorySimple;
import storagecraft.network.MessageGridCraftingUpdate;
import storagecraft.storage.StorageItem;
import storagecraft.util.InventoryUtils;
public class TileGrid extends TileMachine
{
private ContainerGridCrafting craftingMatrixContainer = new ContainerGridCrafting(this);
private InventoryCrafting craftingMatrix = new InventoryCrafting(craftingMatrixContainer, 3, 3);
private InventorySimple craftingResult = new InventorySimple("craftingResult", 1);
@Override
public int getEnergyUsage()
{
return 5;
}
@Override
public void updateMachine()
{
}
public int getType()
{
return 0; // @TODO: Make other grid work too
}
public boolean isCrafting()
{
return getType() == 1;
}
public InventoryCrafting getCraftingMatrix()
{
return craftingMatrix;
}
public void onCraftingMatrixChanged()
{
craftingResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(craftingMatrix, worldObj));
}
public void onCrafted(ItemStack[] matrixSlots)
{
if (isConnected() && !worldObj.isRemote)
{
for (int i = 0; i < craftingMatrix.getSizeInventory(); ++i)
{
ItemStack slot = craftingMatrix.getStackInSlot(i);
if (slot == null && matrixSlots[i] != null)
{
for (StorageItem item : getController().getItems())
{
if (item.compareNoQuantity(matrixSlots[i].copy()))
{
craftingMatrix.setInventorySlotContents(i, getController().take(matrixSlots[i].copy()));
break;
}
}
}
}
onCraftingMatrixChanged();
// @TODO: HACK!
TargetPoint target = new TargetPoint(worldObj.provider.getDimensionId(), pos.getX(), pos.getY(), pos.getZ(), UPDATE_RANGE);
StorageCraft.NETWORK.sendToAllAround(new MessageGridCraftingUpdate(this), target);
}
}
public InventorySimple getCraftingResult()
{
return craftingResult;
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
InventoryUtils.restoreInventory(craftingMatrix, nbt);
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
InventoryUtils.saveInventory(craftingMatrix, nbt);
}
@Override
public IInventory getDroppedInventory()
{
return craftingMatrix;
}
}