mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
pain²
This commit is contained in:
parent
8ce3e9837b
commit
ee34c59908
@ -1,17 +1,33 @@
|
||||
package com.hbm.blocks.network;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.hbm.blocks.ILookOverlay;
|
||||
import com.hbm.blocks.ITooltipProvider;
|
||||
import com.hbm.lib.RefStrings;
|
||||
import com.hbm.tileentity.network.TileEntityDroneCrate;
|
||||
import com.hbm.util.I18nUtil;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.material.Material;
|
||||
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.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent.Pre;
|
||||
|
||||
public class DroneCrate extends BlockContainer {
|
||||
public class DroneCrate extends BlockContainer implements ILookOverlay, ITooltipProvider {
|
||||
|
||||
private static Random rand = new Random();
|
||||
|
||||
@SideOnly(Side.CLIENT) private IIcon iconTop;
|
||||
@SideOnly(Side.CLIENT) private IIcon iconBottom;
|
||||
@ -22,7 +38,7 @@ public class DroneCrate extends BlockContainer {
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int meta) {
|
||||
return null;
|
||||
return new TileEntityDroneCrate();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -38,4 +54,62 @@ public class DroneCrate extends BlockContainer {
|
||||
public IIcon getIcon(int side, int metadata) {
|
||||
return side == 1 ? this.iconTop : (side == 0 ? this.iconBottom : this.blockIcon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
|
||||
TileEntityDroneCrate tileentityfurnace = (TileEntityDroneCrate) world.getTileEntity(x, y, z);
|
||||
|
||||
if(tileentityfurnace != null) {
|
||||
for(int i1 = 0; i1 < tileentityfurnace.getSizeInventory(); ++i1) {
|
||||
ItemStack itemstack = tileentityfurnace.getStackInSlot(i1);
|
||||
|
||||
if(itemstack != null) {
|
||||
float f = this.rand.nextFloat() * 0.8F + 0.1F;
|
||||
float f1 = this.rand.nextFloat() * 0.8F + 0.1F;
|
||||
float f2 = this.rand.nextFloat() * 0.8F + 0.1F;
|
||||
|
||||
while(itemstack.stackSize > 0) {
|
||||
int j1 = this.rand.nextInt(21) + 10;
|
||||
|
||||
if(j1 > itemstack.stackSize) {
|
||||
j1 = itemstack.stackSize;
|
||||
}
|
||||
|
||||
itemstack.stackSize -= j1;
|
||||
EntityItem entityitem = new EntityItem(world, x + f, y + f1, z + f2, new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));
|
||||
|
||||
if(itemstack.hasTagCompound()) {
|
||||
entityitem.getEntityItem().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy());
|
||||
}
|
||||
|
||||
float f3 = 0.05F;
|
||||
entityitem.motionX = (float) this.rand.nextGaussian() * f3;
|
||||
entityitem.motionY = (float) this.rand.nextGaussian() * f3 + 0.2F;
|
||||
entityitem.motionZ = (float) this.rand.nextGaussian() * f3;
|
||||
world.spawnEntityInWorld(entityitem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
world.func_147453_f(x, y, z, block);
|
||||
}
|
||||
|
||||
super.breakBlock(world, x, y, z, block, meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean ext) {
|
||||
addStandardInfo(stack, player, list, ext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printHook(Pre event, World world, int x, int y, int z) {
|
||||
TileEntityDroneCrate tile = (TileEntityDroneCrate) world.getTileEntity(x, y, z);
|
||||
List<String> text = new ArrayList();
|
||||
|
||||
if(tile.nextY != -1) {
|
||||
text.add("Next waypoint: " + tile.nextX + " / " + tile.nextY + " / " + tile.nextZ);
|
||||
ILookOverlay.printGeneric(event, I18nUtil.resolveKey(getUnlocalizedName() + ".name"), 0xffff00, 0x404000, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -393,6 +393,7 @@ public class TileMappings {
|
||||
put(TileEntityRadioTelex.class, "tileentity_rtty_telex");
|
||||
|
||||
put(TileEntityDroneWaypoint.class, "tileentity_drone_waypoint");
|
||||
put(TileEntityDroneCrate.class, "tileentity_drone_crate");
|
||||
}
|
||||
|
||||
private static void put(Class<? extends TileEntity> clazz, String... names) {
|
||||
|
||||
@ -25,7 +25,6 @@ import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
@ -211,16 +210,16 @@ public class TileEntityMachineAssembler extends TileEntityMachineAssemblerBase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkCoordinates[] getInputPositions() {
|
||||
public DirPos[] getInputPositions() {
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
|
||||
return new ChunkCoordinates[] {new ChunkCoordinates(xCoord - dir.offsetX * 3 + rot.offsetX, yCoord, zCoord - dir.offsetZ * 3 + rot.offsetZ)};
|
||||
return new DirPos[] {new DirPos(xCoord - dir.offsetX * 3 + rot.offsetX, yCoord, zCoord - dir.offsetZ * 3 + rot.offsetZ, dir.getOpposite())};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkCoordinates[] getOutputPositions() {
|
||||
public DirPos[] getOutputPositions() {
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
|
||||
return new ChunkCoordinates[] {new ChunkCoordinates(xCoord + dir.offsetX * 2, yCoord, zCoord + dir.offsetZ * 2)};
|
||||
return new DirPos[] {new DirPos(xCoord + dir.offsetX * 2, yCoord, zCoord + dir.offsetZ * 2, dir)};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -11,13 +11,13 @@ import com.hbm.tileentity.IGUIProvider;
|
||||
import com.hbm.tileentity.TileEntityMachineBase;
|
||||
import com.hbm.tileentity.machine.storage.TileEntityCrateTemplate;
|
||||
import com.hbm.util.InventoryUtil;
|
||||
import com.hbm.util.fauxpointtwelve.DirPos;
|
||||
|
||||
import api.hbm.energy.IEnergyUser;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
|
||||
public abstract class TileEntityMachineAssemblerBase extends TileEntityMachineBase implements IEnergyUser, IGUIProvider {
|
||||
|
||||
@ -145,27 +145,29 @@ public abstract class TileEntityMachineAssemblerBase extends TileEntityMachineBa
|
||||
|
||||
int template = getTemplateIndex(index);
|
||||
|
||||
ChunkCoordinates[] positions = getInputPositions();
|
||||
DirPos[] positions = getInputPositions();
|
||||
int[] indices = getSlotIndicesFromIndex(index);
|
||||
|
||||
for(ChunkCoordinates coord : positions) {
|
||||
for(DirPos coord : positions) {
|
||||
|
||||
TileEntity te = worldObj.getTileEntity(coord.posX, coord.posY, coord.posZ);
|
||||
TileEntity te = worldObj.getTileEntity(coord.getX(), coord.getY(), coord.getZ());
|
||||
|
||||
if(te instanceof IInventory) {
|
||||
|
||||
IInventory inv = (IInventory) te;
|
||||
ISidedInventory sided = inv instanceof ISidedInventory ? (ISidedInventory) inv : null;
|
||||
int[] access = sided != null ? sided.getAccessibleSlotsFromSide(coord.getDir().ordinal()) : null;
|
||||
boolean templateCrate = te instanceof TileEntityCrateTemplate;
|
||||
|
||||
if(templateCrate && slots[template] == null) {
|
||||
|
||||
for(int i = 0; i < inv.getSizeInventory(); i++) {
|
||||
ItemStack stack = inv.getStackInSlot(i);
|
||||
for(int i = 0; i < (access != null ? access.length : inv.getSizeInventory()); i++) {
|
||||
int slot = access != null ? access[i] : i;
|
||||
ItemStack stack = inv.getStackInSlot(slot);
|
||||
|
||||
if(stack != null && stack.getItem() == ModItems.assembly_template && (sided == null || sided.canExtractItem(i, stack, 0))) {
|
||||
if(stack != null && stack.getItem() == ModItems.assembly_template && (sided == null || sided.canExtractItem(slot, stack, 0))) {
|
||||
slots[template] = stack.copy();
|
||||
sided.setInventorySlotContents(i, null);
|
||||
sided.setInventorySlotContents(slot, null);
|
||||
this.needsTemplateSwitch[index] = false;
|
||||
break;
|
||||
}
|
||||
@ -186,16 +188,17 @@ public abstract class TileEntityMachineAssemblerBase extends TileEntityMachineBa
|
||||
|
||||
boolean found = false;
|
||||
|
||||
for(int i = 0; i < inv.getSizeInventory(); i++) {
|
||||
|
||||
ItemStack stack = inv.getStackInSlot(i);
|
||||
if(ingredient.matchesRecipe(stack, true) && (sided == null || sided.canExtractItem(i, stack, 0))) {
|
||||
for(int i = 0; i < (access != null ? access.length : inv.getSizeInventory()); i++) {
|
||||
|
||||
int slot = access != null ? access[i] : i;
|
||||
ItemStack stack = inv.getStackInSlot(slot);
|
||||
if(ingredient.matchesRecipe(stack, true) && (sided == null || sided.canExtractItem(slot, stack, 0))) {
|
||||
found = true;
|
||||
|
||||
for(int j = indices[0]; j <= indices[1]; j++) {
|
||||
|
||||
if(slots[j] != null && slots[j].stackSize < slots[j].getMaxStackSize() & InventoryUtil.doesStackDataMatch(slots[j], stack)) {
|
||||
inv.decrStackSize(i, 1);
|
||||
inv.decrStackSize(slot, 1);
|
||||
slots[j].stackSize++;
|
||||
continue outer;
|
||||
}
|
||||
@ -206,7 +209,7 @@ public abstract class TileEntityMachineAssemblerBase extends TileEntityMachineBa
|
||||
if(slots[j] == null) {
|
||||
slots[j] = stack.copy();
|
||||
slots[j].stackSize = 1;
|
||||
inv.decrStackSize(i, 1);
|
||||
inv.decrStackSize(slot, 1);
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
@ -224,16 +227,18 @@ public abstract class TileEntityMachineAssemblerBase extends TileEntityMachineBa
|
||||
|
||||
private void unloadItems(int index) {
|
||||
|
||||
ChunkCoordinates[] positions = getOutputPositions();
|
||||
DirPos[] positions = getOutputPositions();
|
||||
int[] indices = getSlotIndicesFromIndex(index);
|
||||
|
||||
for(ChunkCoordinates coord : positions) {
|
||||
for(DirPos coord : positions) {
|
||||
|
||||
TileEntity te = worldObj.getTileEntity(coord.posX, coord.posY, coord.posZ);
|
||||
TileEntity te = worldObj.getTileEntity(coord.getX(), coord.getY(), coord.getZ());
|
||||
|
||||
if(te instanceof IInventory) {
|
||||
|
||||
IInventory inv = (IInventory) te;
|
||||
ISidedInventory sided = inv instanceof ISidedInventory ? (ISidedInventory) inv : null;
|
||||
int[] access = sided != null ? sided.getAccessibleSlotsFromSide(coord.getDir().ordinal()) : null;
|
||||
|
||||
int i = indices[2];
|
||||
ItemStack out = slots[i];
|
||||
@ -246,12 +251,14 @@ public abstract class TileEntityMachineAssemblerBase extends TileEntityMachineBa
|
||||
|
||||
if(out != null) {
|
||||
|
||||
for(int j = 0; j < inv.getSizeInventory(); j++) {
|
||||
for(int j = 0; j < (access != null ? access.length : inv.getSizeInventory()); j++) {
|
||||
|
||||
int slot = access != null ? access[j] : j;
|
||||
|
||||
if(!inv.isItemValidForSlot(j, out))
|
||||
if(!(sided != null ? sided.canInsertItem(slot, out, coord.getDir().ordinal()) : inv.isItemValidForSlot(slot, out)))
|
||||
continue;
|
||||
|
||||
ItemStack target = inv.getStackInSlot(j);
|
||||
ItemStack target = inv.getStackInSlot(slot);
|
||||
|
||||
if(InventoryUtil.doesStackDataMatch(out, target) && target.stackSize < target.getMaxStackSize() && target.stackSize < inv.getInventoryStackLimit()) {
|
||||
this.decrStackSize(i, 1);
|
||||
@ -260,15 +267,17 @@ public abstract class TileEntityMachineAssemblerBase extends TileEntityMachineBa
|
||||
}
|
||||
}
|
||||
|
||||
for(int j = 0; j < inv.getSizeInventory(); j++) {
|
||||
for(int j = 0; j < (access != null ? access.length : inv.getSizeInventory()); j++) {
|
||||
|
||||
int slot = access != null ? access[j] : j;
|
||||
|
||||
if(!inv.isItemValidForSlot(j, out))
|
||||
if(!inv.isItemValidForSlot(slot, out))
|
||||
continue;
|
||||
|
||||
if(inv.getStackInSlot(j) == null && inv.isItemValidForSlot(j, out)) {
|
||||
if(inv.getStackInSlot(slot) == null && (sided != null ? sided.canInsertItem(slot, out, coord.getDir().ordinal()) : inv.isItemValidForSlot(slot, out))) {
|
||||
ItemStack copy = out.copy();
|
||||
copy.stackSize = 1;
|
||||
inv.setInventorySlotContents(j, copy);
|
||||
inv.setInventorySlotContents(slot, copy);
|
||||
this.decrStackSize(i, 1);
|
||||
return;
|
||||
}
|
||||
@ -296,7 +305,7 @@ public abstract class TileEntityMachineAssemblerBase extends TileEntityMachineBa
|
||||
* @return A size 3 int array containing min input, max input and output indices in that order.
|
||||
*/
|
||||
public abstract int[] getSlotIndicesFromIndex(int index);
|
||||
public abstract ChunkCoordinates[] getInputPositions();
|
||||
public abstract ChunkCoordinates[] getOutputPositions();
|
||||
public abstract DirPos[] getInputPositions();
|
||||
public abstract DirPos[] getOutputPositions();
|
||||
public abstract int getPowerSlot();
|
||||
}
|
||||
|
||||
@ -21,7 +21,6 @@ import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
@ -351,11 +350,11 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
|
||||
return new int[] { 5 + index * 14, 16 + index * 14, 18 + index * 14};
|
||||
}
|
||||
|
||||
ChunkCoordinates[] inpos;
|
||||
ChunkCoordinates[] outpos;
|
||||
DirPos[] inpos;
|
||||
DirPos[] outpos;
|
||||
|
||||
@Override
|
||||
public ChunkCoordinates[] getInputPositions() {
|
||||
public DirPos[] getInputPositions() {
|
||||
|
||||
if(inpos != null)
|
||||
return inpos;
|
||||
@ -363,18 +362,18 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
|
||||
|
||||
inpos = new ChunkCoordinates[] {
|
||||
new ChunkCoordinates(xCoord + dir.offsetX * 4 - rot.offsetX * 1, yCoord, zCoord + dir.offsetZ * 4 - rot.offsetZ * 1),
|
||||
new ChunkCoordinates(xCoord - dir.offsetX * 5 + rot.offsetX * 2, yCoord, zCoord - dir.offsetZ * 5 + rot.offsetZ * 2),
|
||||
new ChunkCoordinates(xCoord - dir.offsetX * 2 - rot.offsetX * 4, yCoord, zCoord - dir.offsetZ * 2 - rot.offsetZ * 4),
|
||||
new ChunkCoordinates(xCoord + dir.offsetX * 1 + rot.offsetX * 5, yCoord, zCoord + dir.offsetZ * 1 + rot.offsetZ * 5)
|
||||
inpos = new DirPos[] {
|
||||
new DirPos(xCoord + dir.offsetX * 4 - rot.offsetX * 1, yCoord, zCoord + dir.offsetZ * 4 - rot.offsetZ * 1, dir),
|
||||
new DirPos(xCoord - dir.offsetX * 5 + rot.offsetX * 2, yCoord, zCoord - dir.offsetZ * 5 + rot.offsetZ * 2, dir.getOpposite()),
|
||||
new DirPos(xCoord - dir.offsetX * 2 - rot.offsetX * 4, yCoord, zCoord - dir.offsetZ * 2 - rot.offsetZ * 4, rot.getOpposite()),
|
||||
new DirPos(xCoord + dir.offsetX * 1 + rot.offsetX * 5, yCoord, zCoord + dir.offsetZ * 1 + rot.offsetZ * 5, rot)
|
||||
};
|
||||
|
||||
return inpos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkCoordinates[] getOutputPositions() {
|
||||
public DirPos[] getOutputPositions() {
|
||||
|
||||
if(outpos != null)
|
||||
return outpos;
|
||||
@ -382,11 +381,11 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
|
||||
|
||||
outpos = new ChunkCoordinates[] {
|
||||
new ChunkCoordinates(xCoord + dir.offsetX * 4 + rot.offsetX * 2, yCoord, zCoord + dir.offsetZ * 4 + rot.offsetZ * 2),
|
||||
new ChunkCoordinates(xCoord - dir.offsetX * 5 - rot.offsetX * 1, yCoord, zCoord - dir.offsetZ * 5 - rot.offsetZ * 1),
|
||||
new ChunkCoordinates(xCoord + dir.offsetX * 1 - rot.offsetX * 4, yCoord, zCoord + dir.offsetZ * 1 - rot.offsetZ * 4),
|
||||
new ChunkCoordinates(xCoord - dir.offsetX * 2 + rot.offsetX * 5, yCoord, zCoord - dir.offsetZ * 2 + rot.offsetZ * 5)
|
||||
outpos = new DirPos[] {
|
||||
new DirPos(xCoord + dir.offsetX * 4 + rot.offsetX * 2, yCoord, zCoord + dir.offsetZ * 4 + rot.offsetZ * 2, dir),
|
||||
new DirPos(xCoord - dir.offsetX * 5 - rot.offsetX * 1, yCoord, zCoord - dir.offsetZ * 5 - rot.offsetZ * 1, dir.getOpposite()),
|
||||
new DirPos(xCoord + dir.offsetX * 1 - rot.offsetX * 4, yCoord, zCoord + dir.offsetZ * 1 - rot.offsetZ * 4, rot.getOpposite()),
|
||||
new DirPos(xCoord - dir.offsetX * 2 + rot.offsetX * 5, yCoord, zCoord - dir.offsetZ * 2 + rot.offsetZ * 5, rot)
|
||||
};
|
||||
|
||||
return outpos;
|
||||
|
||||
@ -23,7 +23,6 @@ import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
@ -234,11 +233,11 @@ public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase {
|
||||
return new int[] {5 + index * 9, 8 + index * 9, 9 + index * 9, 12 + index * 9};
|
||||
}
|
||||
|
||||
ChunkCoordinates[] inpos;
|
||||
ChunkCoordinates[] outpos;
|
||||
DirPos[] inpos;
|
||||
DirPos[] outpos;
|
||||
|
||||
@Override
|
||||
public ChunkCoordinates[] getInputPositions() {
|
||||
public DirPos[] getInputPositions() {
|
||||
|
||||
if(inpos != null)
|
||||
return inpos;
|
||||
@ -246,18 +245,18 @@ public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase {
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
|
||||
|
||||
inpos = new ChunkCoordinates[] {
|
||||
new ChunkCoordinates(xCoord + dir.offsetX * 4 - rot.offsetX * 1, yCoord, zCoord + dir.offsetZ * 4 - rot.offsetZ * 1),
|
||||
new ChunkCoordinates(xCoord - dir.offsetX * 5 + rot.offsetX * 2, yCoord, zCoord - dir.offsetZ * 5 + rot.offsetZ * 2),
|
||||
new ChunkCoordinates(xCoord - dir.offsetX * 2 - rot.offsetX * 4, yCoord, zCoord - dir.offsetZ * 2 - rot.offsetZ * 4),
|
||||
new ChunkCoordinates(xCoord + dir.offsetX * 1 + rot.offsetX * 5, yCoord, zCoord + dir.offsetZ * 1 + rot.offsetZ * 5)
|
||||
inpos = new DirPos[] {
|
||||
new DirPos(xCoord + dir.offsetX * 4 - rot.offsetX * 1, yCoord, zCoord + dir.offsetZ * 4 - rot.offsetZ * 1, dir),
|
||||
new DirPos(xCoord - dir.offsetX * 5 + rot.offsetX * 2, yCoord, zCoord - dir.offsetZ * 5 + rot.offsetZ * 2, dir.getOpposite()),
|
||||
new DirPos(xCoord - dir.offsetX * 2 - rot.offsetX * 4, yCoord, zCoord - dir.offsetZ * 2 - rot.offsetZ * 4, rot.getOpposite()),
|
||||
new DirPos(xCoord + dir.offsetX * 1 + rot.offsetX * 5, yCoord, zCoord + dir.offsetZ * 1 + rot.offsetZ * 5, rot)
|
||||
};
|
||||
|
||||
return inpos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkCoordinates[] getOutputPositions() {
|
||||
public DirPos[] getOutputPositions() {
|
||||
|
||||
if(outpos != null)
|
||||
return outpos;
|
||||
@ -265,11 +264,11 @@ public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase {
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
|
||||
|
||||
outpos = new ChunkCoordinates[] {
|
||||
new ChunkCoordinates(xCoord + dir.offsetX * 4 + rot.offsetX * 2, yCoord, zCoord + dir.offsetZ * 4 + rot.offsetZ * 2),
|
||||
new ChunkCoordinates(xCoord - dir.offsetX * 5 - rot.offsetX * 1, yCoord, zCoord - dir.offsetZ * 5 - rot.offsetZ * 1),
|
||||
new ChunkCoordinates(xCoord + dir.offsetX * 1 - rot.offsetX * 4, yCoord, zCoord + dir.offsetZ * 1 - rot.offsetZ * 4),
|
||||
new ChunkCoordinates(xCoord - dir.offsetX * 2 + rot.offsetX * 5, yCoord, zCoord - dir.offsetZ * 2 + rot.offsetZ * 5)
|
||||
outpos = new DirPos[] {
|
||||
new DirPos(xCoord + dir.offsetX * 4 + rot.offsetX * 2, yCoord, zCoord + dir.offsetZ * 4 + rot.offsetZ * 2, dir),
|
||||
new DirPos(xCoord - dir.offsetX * 5 - rot.offsetX * 1, yCoord, zCoord - dir.offsetZ * 5 - rot.offsetZ * 1, dir.getOpposite()),
|
||||
new DirPos(xCoord + dir.offsetX * 1 - rot.offsetX * 4, yCoord, zCoord + dir.offsetZ * 1 - rot.offsetZ * 4, rot.getOpposite()),
|
||||
new DirPos(xCoord - dir.offsetX * 2 + rot.offsetX * 5, yCoord, zCoord - dir.offsetZ * 2 + rot.offsetZ * 5, rot)
|
||||
};
|
||||
|
||||
return outpos;
|
||||
|
||||
@ -363,6 +363,7 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
|
||||
|
||||
IInventory inv = (IInventory) te;
|
||||
ISidedInventory sided = inv instanceof ISidedInventory ? (ISidedInventory) inv : null;
|
||||
int[] access = sided != null ? sided.getAccessibleSlotsFromSide(dir.ordinal()) : null;
|
||||
|
||||
for(AStack ingredient : recipe.inputs) {
|
||||
|
||||
@ -371,15 +372,17 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
|
||||
|
||||
boolean found = false;
|
||||
|
||||
for(int i = 0; i < inv.getSizeInventory(); i++) {
|
||||
for(int i = 0; i < (access != null ? access.length : inv.getSizeInventory()); i++) {
|
||||
|
||||
int slot = access != null ? access[i] : i;
|
||||
ItemStack stack = inv.getStackInSlot(slot);
|
||||
|
||||
ItemStack stack = inv.getStackInSlot(i);
|
||||
if(ingredient.matchesRecipe(stack, true) && (sided == null || sided.canExtractItem(i, stack, 0))) {
|
||||
if(ingredient.matchesRecipe(stack, true) && (sided == null || sided.canExtractItem(slot, stack, 0))) {
|
||||
|
||||
for(int j = 13; j <= 16; j++) {
|
||||
|
||||
if(slots[j] != null && slots[j].stackSize < slots[j].getMaxStackSize() & InventoryUtil.doesStackDataMatch(slots[j], stack)) {
|
||||
inv.decrStackSize(i, 1);
|
||||
inv.decrStackSize(slot, 1);
|
||||
slots[j].stackSize++;
|
||||
continue outer;
|
||||
}
|
||||
@ -390,7 +393,7 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
|
||||
if(slots[j] == null) {
|
||||
slots[j] = stack.copy();
|
||||
slots[j].stackSize = 1;
|
||||
inv.decrStackSize(i, 1);
|
||||
inv.decrStackSize(slot, 1);
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
@ -417,6 +420,8 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
|
||||
if(te instanceof IInventory) {
|
||||
|
||||
IInventory inv = (IInventory) te;
|
||||
ISidedInventory sided = inv instanceof ISidedInventory ? (ISidedInventory) inv : null;
|
||||
int[] access = sided != null ? sided.getAccessibleSlotsFromSide(dir.ordinal()) : null;
|
||||
|
||||
for(int i = 5; i <= 8; i++) {
|
||||
|
||||
@ -424,12 +429,14 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
|
||||
|
||||
if(out != null) {
|
||||
|
||||
for(int j = 0; j < inv.getSizeInventory(); j++) {
|
||||
for(int j = 0; j < (access != null ? access.length : inv.getSizeInventory()); j++) {
|
||||
|
||||
int slot = access != null ? access[j] : j;
|
||||
|
||||
if(!inv.isItemValidForSlot(j, out))
|
||||
if(!inv.isItemValidForSlot(slot, out))
|
||||
continue;
|
||||
|
||||
ItemStack target = inv.getStackInSlot(j);
|
||||
ItemStack target = inv.getStackInSlot(slot);
|
||||
|
||||
if(InventoryUtil.doesStackDataMatch(out, target) && target.stackSize < target.getMaxStackSize()) {
|
||||
this.decrStackSize(i, 1);
|
||||
@ -438,15 +445,17 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
|
||||
}
|
||||
}
|
||||
|
||||
for(int j = 0; j < inv.getSizeInventory(); j++) {
|
||||
for(int j = 0; j < (access != null ? access.length : inv.getSizeInventory()); j++) {
|
||||
|
||||
int slot = access != null ? access[j] : j;
|
||||
|
||||
if(!inv.isItemValidForSlot(j, out))
|
||||
if(!inv.isItemValidForSlot(slot, out))
|
||||
continue;
|
||||
|
||||
if(inv.getStackInSlot(j) == null && inv.isItemValidForSlot(j, out)) {
|
||||
if(inv.getStackInSlot(slot) == null && (sided != null ? sided.canInsertItem(slot, out, dir.ordinal()) : inv.isItemValidForSlot(slot, out))) {
|
||||
ItemStack copy = out.copy();
|
||||
copy.stackSize = 1;
|
||||
inv.setInventorySlotContents(j, copy);
|
||||
inv.setInventorySlotContents(slot, copy);
|
||||
this.decrStackSize(i, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -14,6 +14,7 @@ import com.hbm.lib.Library;
|
||||
import com.hbm.tileentity.IGUIProvider;
|
||||
import com.hbm.tileentity.TileEntityMachineBase;
|
||||
import com.hbm.util.InventoryUtil;
|
||||
import com.hbm.util.fauxpointtwelve.DirPos;
|
||||
|
||||
import api.hbm.energy.IEnergyUser;
|
||||
import api.hbm.fluid.IFluidUser;
|
||||
@ -22,7 +23,6 @@ import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
|
||||
/**
|
||||
* Base class for single and multi chemplants.
|
||||
@ -202,17 +202,18 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa
|
||||
|
||||
if(recipe != null) {
|
||||
|
||||
ChunkCoordinates[] positions = getInputPositions();
|
||||
DirPos[] positions = getInputPositions();
|
||||
int[] indices = getSlotIndicesFromIndex(index);
|
||||
|
||||
for(ChunkCoordinates coord : positions) {
|
||||
|
||||
TileEntity te = worldObj.getTileEntity(coord.posX, coord.posY, coord.posZ);
|
||||
for(DirPos coord : positions) {
|
||||
|
||||
TileEntity te = worldObj.getTileEntity(coord.getX(), coord.getY(), coord.getZ());
|
||||
|
||||
if(te instanceof IInventory) {
|
||||
|
||||
IInventory inv = (IInventory) te;
|
||||
ISidedInventory sided = inv instanceof ISidedInventory ? (ISidedInventory) inv : null;
|
||||
int[] access = sided != null ? sided.getAccessibleSlotsFromSide(coord.getDir().ordinal()) : null;
|
||||
|
||||
for(AStack ingredient : recipe.inputs) {
|
||||
|
||||
@ -221,15 +222,16 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa
|
||||
|
||||
boolean found = false;
|
||||
|
||||
for(int i = 0; i < inv.getSizeInventory(); i++) {
|
||||
|
||||
ItemStack stack = inv.getStackInSlot(i);
|
||||
if(ingredient.matchesRecipe(stack, true) && (sided == null || sided.canExtractItem(i, stack, 0))) {
|
||||
for(int i = 0; i < (access != null ? access.length : inv.getSizeInventory()); i++) {
|
||||
|
||||
int slot = access != null ? access[i] : i;
|
||||
ItemStack stack = inv.getStackInSlot(slot);
|
||||
if(ingredient.matchesRecipe(stack, true) && (sided == null || sided.canExtractItem(slot, stack, 0))) {
|
||||
|
||||
for(int j = indices[0]; j <= indices[1]; j++) {
|
||||
|
||||
if(slots[j] != null && slots[j].stackSize < slots[j].getMaxStackSize() & InventoryUtil.doesStackDataMatch(slots[j], stack)) {
|
||||
inv.decrStackSize(i, 1);
|
||||
inv.decrStackSize(slot, 1);
|
||||
slots[j].stackSize++;
|
||||
continue outer;
|
||||
}
|
||||
@ -240,7 +242,7 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa
|
||||
if(slots[j] == null) {
|
||||
slots[j] = stack.copy();
|
||||
slots[j].stackSize = 1;
|
||||
inv.decrStackSize(i, 1);
|
||||
inv.decrStackSize(slot, 1);
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
@ -257,17 +259,18 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa
|
||||
|
||||
private void unloadItems(int index) {
|
||||
|
||||
ChunkCoordinates[] positions = getOutputPositions();
|
||||
DirPos[] positions = getOutputPositions();
|
||||
int[] indices = getSlotIndicesFromIndex(index);
|
||||
|
||||
for(ChunkCoordinates coord : positions) {
|
||||
|
||||
TileEntity te = worldObj.getTileEntity(coord.posX, coord.posY, coord.posZ);
|
||||
for(DirPos coord : positions) {
|
||||
|
||||
TileEntity te = worldObj.getTileEntity(coord.getX(), coord.getY(), coord.getZ());
|
||||
|
||||
if(te instanceof IInventory) {
|
||||
|
||||
IInventory inv = (IInventory) te;
|
||||
//ISidedInventory sided = inv instanceof ISidedInventory ? (ISidedInventory) inv : null;
|
||||
ISidedInventory sided = inv instanceof ISidedInventory ? (ISidedInventory) inv : null;
|
||||
int[] access = sided != null ? sided.getAccessibleSlotsFromSide(coord.getDir().ordinal()) : null;
|
||||
|
||||
for(int i = indices[2]; i <= indices[3]; i++) {
|
||||
|
||||
@ -275,12 +278,14 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa
|
||||
|
||||
if(out != null) {
|
||||
|
||||
for(int j = 0; j < inv.getSizeInventory(); j++) {
|
||||
for(int j = 0; j < (access != null ? access.length : inv.getSizeInventory()); j++) {
|
||||
|
||||
int slot = access != null ? access[j] : j;
|
||||
|
||||
if(!inv.isItemValidForSlot(j, out))
|
||||
if(!inv.isItemValidForSlot(slot, out))
|
||||
continue;
|
||||
|
||||
ItemStack target = inv.getStackInSlot(j);
|
||||
ItemStack target = inv.getStackInSlot(slot);
|
||||
|
||||
if(InventoryUtil.doesStackDataMatch(out, target) && target.stackSize < target.getMaxStackSize() && target.stackSize < inv.getInventoryStackLimit()) {
|
||||
this.decrStackSize(i, 1);
|
||||
@ -289,15 +294,17 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa
|
||||
}
|
||||
}
|
||||
|
||||
for(int j = 0; j < inv.getSizeInventory(); j++) {
|
||||
for(int j = 0; j < (access != null ? access.length : inv.getSizeInventory()); j++) {
|
||||
|
||||
int slot = access != null ? access[j] : j;
|
||||
|
||||
if(!inv.isItemValidForSlot(j, out))
|
||||
if(!inv.isItemValidForSlot(slot, out))
|
||||
continue;
|
||||
|
||||
if(inv.getStackInSlot(j) == null && inv.isItemValidForSlot(j, out)) {
|
||||
if(inv.getStackInSlot(slot) == null && (sided != null ? sided.canInsertItem(slot, out, coord.getDir().ordinal()) : inv.isItemValidForSlot(slot, out))) {
|
||||
ItemStack copy = out.copy();
|
||||
copy.stackSize = 1;
|
||||
inv.setInventorySlotContents(j, copy);
|
||||
inv.setInventorySlotContents(slot, copy);
|
||||
this.decrStackSize(i, 1);
|
||||
return;
|
||||
}
|
||||
@ -585,6 +592,6 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa
|
||||
* @return A size 4 int array containing min input, max input, min output and max output indices in that order.
|
||||
*/
|
||||
public abstract int[] getSlotIndicesFromIndex(int index);
|
||||
public abstract ChunkCoordinates[] getInputPositions();
|
||||
public abstract ChunkCoordinates[] getOutputPositions();
|
||||
public abstract DirPos[] getInputPositions();
|
||||
public abstract DirPos[] getOutputPositions();
|
||||
}
|
||||
|
||||
@ -0,0 +1,88 @@
|
||||
package com.hbm.tileentity.network;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.entity.item.EntityDeliveryDrone;
|
||||
import com.hbm.tileentity.IGUIProvider;
|
||||
import com.hbm.tileentity.INBTPacketReceiver;
|
||||
import com.hbm.tileentity.TileEntityMachineBase;
|
||||
import com.hbm.util.fauxpointtwelve.BlockPos;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class TileEntityDroneCrate extends TileEntityMachineBase implements IGUIProvider, INBTPacketReceiver, IDroneLinkable {
|
||||
|
||||
public int nextX = -1;
|
||||
public int nextY = -1;
|
||||
public int nextZ = -1;
|
||||
|
||||
public TileEntityDroneCrate() {
|
||||
super(19);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "container.droneCrate";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
if(nextY != -1) {
|
||||
|
||||
List<EntityDeliveryDrone> drones = worldObj.getEntitiesWithinAABB(EntityDeliveryDrone.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord + 1, zCoord, xCoord + 1, yCoord + 2, zCoord + 1));
|
||||
for(EntityDeliveryDrone drone : drones) {
|
||||
if(Vec3.createVectorHelper(drone.motionX, drone.motionY, drone.motionZ).lengthVector() < 0.05) {
|
||||
drone.setTarget(nextX + 0.5, nextY, nextZ + 0.5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setIntArray("pos", new int[] {nextX, nextY, nextZ});
|
||||
INBTPacketReceiver.networkPack(this, data, 25);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos getPoint() {
|
||||
return new BlockPos(xCoord, yCoord + 1, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNextTarget(int x, int y, int z) {
|
||||
this.nextX = x;
|
||||
this.nextY = y;
|
||||
this.nextZ = z;
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void networkUnpack(NBTTagCompound nbt) {
|
||||
int[] pos = nbt.getIntArray("pos");
|
||||
this.nextX = pos[0];
|
||||
this.nextY = pos[1];
|
||||
this.nextZ = pos[2];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public GuiScreen provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -30,7 +30,7 @@ public class TileEntityDroneWaypoint extends TileEntity implements INBTPacketRec
|
||||
List<EntityDeliveryDrone> drones = worldObj.getEntitiesWithinAABB(EntityDeliveryDrone.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1).offset(dir.offsetX * height, dir.offsetY * height, dir.offsetZ * height));
|
||||
for(EntityDeliveryDrone drone : drones) {
|
||||
if(Vec3.createVectorHelper(drone.motionX, drone.motionY, drone.motionZ).lengthVector() < 0.05) {
|
||||
drone.setTarget(nextX + 0.5, nextY + 0.5, nextZ + 0.5);
|
||||
drone.setTarget(nextX + 0.5, nextY, nextZ + 0.5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.7 KiB |
Loading…
x
Reference in New Issue
Block a user