mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
the unboxing apparatus, conveyor chute fix
This commit is contained in:
parent
77de64c7b6
commit
1e1dac2f11
@ -1,9 +1,11 @@
|
||||
package com.hbm.blocks.network;
|
||||
|
||||
import api.hbm.conveyor.IConveyorBelt;
|
||||
import api.hbm.conveyor.IEnterableBlock;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
@ -15,7 +17,8 @@ public class BlockConveyorChute extends BlockConveyor {
|
||||
@Override
|
||||
public Vec3 getTravelLocation(World world, int x, int y, int z, Vec3 itemPos, double speed) {
|
||||
|
||||
if(world.getBlock(x, y - 1, z) instanceof IConveyorBelt) {
|
||||
Block below = world.getBlock(x, y - 1, z);
|
||||
if(below instanceof IConveyorBelt || below instanceof IEnterableBlock) {
|
||||
speed *= 5;
|
||||
} else if(itemPos.yCoord > y + 0.25) {
|
||||
speed *= 3;
|
||||
@ -26,8 +29,9 @@ public class BlockConveyorChute extends BlockConveyor {
|
||||
|
||||
@Override
|
||||
public ForgeDirection getTravelDirection(World world, int x, int y, int z, Vec3 itemPos, double speed) {
|
||||
|
||||
if(world.getBlock(x, y - 1, z) instanceof IConveyorBelt || itemPos.yCoord > y + 0.25) {
|
||||
|
||||
Block below = world.getBlock(x, y - 1, z);
|
||||
if(below instanceof IConveyorBelt || below instanceof IEnterableBlock || itemPos.yCoord > y + 0.25) {
|
||||
return ForgeDirection.UP;
|
||||
}
|
||||
|
||||
@ -37,7 +41,8 @@ public class BlockConveyorChute extends BlockConveyor {
|
||||
@Override
|
||||
public Vec3 getClosestSnappingPosition(World world, int x, int y, int z, Vec3 itemPos) {
|
||||
|
||||
if(world.getBlock(x, y - 1, z) instanceof IConveyorBelt || itemPos.yCoord > y + 0.25) {
|
||||
Block below = world.getBlock(x, y - 1, z);
|
||||
if(below instanceof IConveyorBelt || below instanceof IEnterableBlock || itemPos.yCoord > y + 0.25) {
|
||||
return Vec3.createVectorHelper(x + 0.5, itemPos.yCoord, z + 0.5);
|
||||
} else {
|
||||
return super.getClosestSnappingPosition(world, x, y, z, itemPos);
|
||||
|
||||
@ -10,14 +10,14 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ContainerCraneBoxer extends Container {
|
||||
|
||||
protected TileEntityCraneBoxer extractor;
|
||||
protected TileEntityCraneBoxer boxer;
|
||||
|
||||
public ContainerCraneBoxer(InventoryPlayer invPlayer, TileEntityCraneBoxer inserter) {
|
||||
this.extractor = inserter;
|
||||
public ContainerCraneBoxer(InventoryPlayer invPlayer, TileEntityCraneBoxer boxer) {
|
||||
this.boxer = boxer;
|
||||
|
||||
for(int i = 0; i < 3; i++) {
|
||||
for(int j = 0; j < 7; j++) {
|
||||
this.addSlotToContainer(new Slot(inserter, j + i * 7, 8 + j * 18, 17 + i * 18));
|
||||
this.addSlotToContainer(new Slot(boxer, j + i * 7, 8 + j * 18, 17 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,12 +41,12 @@ public class ContainerCraneBoxer extends Container {
|
||||
ItemStack var5 = var4.getStack();
|
||||
var3 = var5.copy();
|
||||
|
||||
if(slot <= extractor.getSizeInventory() - 1) {
|
||||
if(!this.mergeItemStack(var5, extractor.getSizeInventory(), this.inventorySlots.size(), true)) {
|
||||
if(slot <= boxer.getSizeInventory() - 1) {
|
||||
if(!this.mergeItemStack(var5, boxer.getSizeInventory(), this.inventorySlots.size(), true)) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
if(!this.mergeItemStack(var5, 0, extractor.getSizeInventory(), false)) {
|
||||
if(!this.mergeItemStack(var5, 0, boxer.getSizeInventory(), false)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -67,6 +67,6 @@ public class ContainerCraneBoxer extends Container {
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player) {
|
||||
return extractor.isUseableByPlayer(player);
|
||||
return boxer.isUseableByPlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,43 @@
|
||||
package com.hbm.inventory.container;
|
||||
|
||||
import com.hbm.inventory.SlotUpgrade;
|
||||
import com.hbm.tileentity.network.TileEntityCraneUnboxer;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
|
||||
public class ContainerCraneUnboxer extends Container {
|
||||
|
||||
protected TileEntityCraneUnboxer unboxer;
|
||||
|
||||
public ContainerCraneUnboxer(InventoryPlayer invPlayer, TileEntityCraneUnboxer unboxer) {
|
||||
this.unboxer = unboxer;
|
||||
|
||||
for(int i = 0; i < 3; i++) {
|
||||
for(int j = 0; j < 7; j++) {
|
||||
this.addSlotToContainer(new Slot(unboxer, j + i * 7, 8 + j * 18, 17 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
//upgrades
|
||||
this.addSlotToContainer(new SlotUpgrade(unboxer, 21, 152, 23));
|
||||
this.addSlotToContainer(new SlotUpgrade(unboxer, 22, 152, 47));
|
||||
|
||||
for(int i = 0; i < 3; i++) {
|
||||
for(int j = 0; j < 9; j++) {
|
||||
this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 103 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < 9; i++) {
|
||||
this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 161));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player) {
|
||||
return unboxer.isUseableByPlayer(player);
|
||||
}
|
||||
}
|
||||
50
src/main/java/com/hbm/inventory/gui/GUICraneUnboxer.java
Normal file
50
src/main/java/com/hbm/inventory/gui/GUICraneUnboxer.java
Normal file
@ -0,0 +1,50 @@
|
||||
package com.hbm.inventory.gui;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.hbm.inventory.container.ContainerCraneUnboxer;
|
||||
import com.hbm.lib.RefStrings;
|
||||
import com.hbm.tileentity.network.TileEntityCraneUnboxer;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class GUICraneUnboxer extends GuiInfoContainer {
|
||||
|
||||
private static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/storage/gui_crane_unboxer.png");
|
||||
private TileEntityCraneUnboxer boxer;
|
||||
|
||||
public GUICraneUnboxer(InventoryPlayer invPlayer, TileEntityCraneUnboxer tedf) {
|
||||
super(new ContainerCraneUnboxer(invPlayer, tedf));
|
||||
boxer = tedf;
|
||||
|
||||
this.xSize = 176;
|
||||
this.ySize = 185;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int x, int y, float interp) {
|
||||
super.drawScreen(x, y, interp);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int x, int y, int i) {
|
||||
super.mouseClicked(x, y, i);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int i, int j) {
|
||||
String name = this.boxer.hasCustomInventoryName() ? this.boxer.getInventoryName() : I18n.format(this.boxer.getInventoryName());
|
||||
this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6, 4210752);
|
||||
this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float interp, int i, int j) {
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
|
||||
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
|
||||
}
|
||||
}
|
||||
@ -28,6 +28,8 @@ public class TileEntityCraneBoxer extends TileEntityMachineBase implements IGUIP
|
||||
public static final byte MODE_16 = 2;
|
||||
public static final byte MODE_REDSTONE = 3;
|
||||
|
||||
private boolean lastRedstone = false;
|
||||
|
||||
|
||||
public TileEntityCraneBoxer() {
|
||||
super(7 * 3);
|
||||
@ -43,6 +45,50 @@ public class TileEntityCraneBoxer extends TileEntityMachineBase implements IGUIP
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
boolean redstone = worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
|
||||
|
||||
if(mode == MODE_REDSTONE && redstone && !lastRedstone) {
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata()).getOpposite();
|
||||
Block b = worldObj.getBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ);
|
||||
IConveyorBelt belt = null;
|
||||
|
||||
if(b instanceof IConveyorBelt) {
|
||||
belt = (IConveyorBelt) b;
|
||||
}
|
||||
|
||||
int pack = 0;
|
||||
|
||||
for(int i = 0; i < slots.length; i++) {
|
||||
if(slots[i] != null) {
|
||||
pack++;
|
||||
}
|
||||
}
|
||||
|
||||
if(belt != null && pack > 0) {
|
||||
|
||||
ItemStack[] box = new ItemStack[pack];
|
||||
|
||||
for(int i = 0; i < slots.length && pack > 0; i++) {
|
||||
|
||||
if(slots[i] != null) {
|
||||
pack--;
|
||||
box[pack] = slots[i].copy();
|
||||
slots[i] = null;
|
||||
}
|
||||
}
|
||||
|
||||
EntityMovingPackage moving = new EntityMovingPackage(worldObj);
|
||||
Vec3 pos = Vec3.createVectorHelper(xCoord + 0.5 + dir.offsetX * 0.55, yCoord + 0.5 + dir.offsetY * 0.55, zCoord + 0.5 + dir.offsetZ * 0.55);
|
||||
Vec3 snap = belt.getClosestSnappingPosition(worldObj, xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, pos);
|
||||
moving.setPosition(snap.xCoord, snap.yCoord, snap.zCoord);
|
||||
moving.setItemStacks(box);
|
||||
worldObj.spawnEntityInWorld(moving);
|
||||
}
|
||||
}
|
||||
|
||||
this.lastRedstone = redstone;
|
||||
|
||||
if(mode != MODE_REDSTONE && worldObj.getTotalWorldTime() % 20 == 0) {
|
||||
int pack = 1;
|
||||
|
||||
@ -119,6 +165,20 @@ public class TileEntityCraneBoxer extends TileEntityMachineBase implements IGUIP
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemStack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
this.mode = nbt.getByte("mode");
|
||||
this.lastRedstone = nbt.getBoolean("lastRedstone");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
nbt.setByte("mode", mode);
|
||||
nbt.setBoolean("lastRedstone", lastRedstone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
|
||||
@ -1,13 +1,28 @@
|
||||
package com.hbm.tileentity.network;
|
||||
|
||||
import com.hbm.entity.item.EntityMovingItem;
|
||||
import com.hbm.inventory.container.ContainerCraneUnboxer;
|
||||
import com.hbm.inventory.gui.GUICraneUnboxer;
|
||||
import com.hbm.items.ModItems;
|
||||
import com.hbm.tileentity.IGUIProvider;
|
||||
import com.hbm.tileentity.TileEntityMachineBase;
|
||||
|
||||
import api.hbm.conveyor.IConveyorBelt;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class TileEntityCraneUnboxer extends TileEntityMachineBase {
|
||||
public class TileEntityCraneUnboxer extends TileEntityMachineBase implements IGUIProvider {
|
||||
|
||||
public TileEntityCraneUnboxer() {
|
||||
super(7 * 3);
|
||||
super(23);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -18,10 +33,72 @@ public class TileEntityCraneUnboxer extends TileEntityMachineBase {
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
int delay = 20;
|
||||
|
||||
if(slots[19] != null && slots[19].getItem() == ModItems.upgrade_ejector) {
|
||||
switch(slots[19].getItemDamage()) {
|
||||
case 0: delay = 10; break;
|
||||
case 1: delay = 5; break;
|
||||
case 2: delay = 2; break;
|
||||
}
|
||||
}
|
||||
|
||||
/*boolean powered = false;
|
||||
|
||||
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
if(this.worldObj.isBlockIndirectlyGettingPowered(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ)) {
|
||||
powered = true;
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
|
||||
if(worldObj.getTotalWorldTime() % delay == 0 && !worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)) {
|
||||
int amount = 1;
|
||||
|
||||
if(slots[18] != null && slots[18].getItem() == ModItems.upgrade_stack) {
|
||||
switch(slots[18].getItemDamage()) {
|
||||
case 0: amount = 4; break;
|
||||
case 1: amount = 16; break;
|
||||
case 2: amount = 64; break;
|
||||
}
|
||||
}
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata());
|
||||
Block b = worldObj.getBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ);
|
||||
|
||||
boolean hasSent = false;
|
||||
|
||||
if(b instanceof IConveyorBelt) {
|
||||
|
||||
IConveyorBelt belt = (IConveyorBelt) b;
|
||||
|
||||
for(int i = 9; i < 18; i++) {
|
||||
ItemStack stack = slots[i];
|
||||
|
||||
if(stack != null){
|
||||
stack = stack.copy();
|
||||
int toSend = Math.min(amount, stack.stackSize);
|
||||
decrStackSize(i, toSend);
|
||||
stack.stackSize = toSend;
|
||||
|
||||
EntityMovingItem moving = new EntityMovingItem(worldObj);
|
||||
Vec3 pos = Vec3.createVectorHelper(xCoord + 0.5 + dir.offsetX * 0.55, yCoord + 0.5 + dir.offsetY * 0.55, zCoord + 0.5 + dir.offsetZ * 0.55);
|
||||
Vec3 snap = belt.getClosestSnappingPosition(worldObj, xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, pos);
|
||||
moving.setPosition(snap.xCoord, snap.yCoord, snap.zCoord);
|
||||
moving.setItemStack(stack);
|
||||
worldObj.spawnEntityInWorld(moving);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int p_94128_1_) {
|
||||
public int[] getAccessibleSlotsFromSide(int side) {
|
||||
return new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
|
||||
}
|
||||
|
||||
@ -29,4 +106,15 @@ public class TileEntityCraneUnboxer extends TileEntityMachineBase {
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemStack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
return new ContainerCraneUnboxer(player.inventory, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public GuiScreen provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
return new GUICraneUnboxer(player.inventory, this);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user