more boxes per box

This commit is contained in:
Bob 2022-08-09 22:18:48 +02:00
parent 521b040f63
commit 77de64c7b6
4 changed files with 90 additions and 60 deletions

View File

@ -17,7 +17,7 @@ public class ContainerCraneBoxer extends Container {
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 7; j++) {
this.addSlotToContainer(new Slot(inserter, j + i * 3, 8 + j * 18, 17 + i * 18));
this.addSlotToContainer(new Slot(inserter, j + i * 7, 8 + j * 18, 17 + i * 18));
}
}

View File

@ -3,24 +3,26 @@ package com.hbm.inventory.gui;
import org.lwjgl.opengl.GL11;
import com.hbm.inventory.container.ContainerCraneBoxer;
import com.hbm.inventory.container.ContainerCraneExtractor;
import com.hbm.lib.RefStrings;
import com.hbm.packet.NBTControlPacket;
import com.hbm.packet.PacketDispatcher;
import com.hbm.tileentity.network.TileEntityCraneBoxer;
import com.hbm.tileentity.network.TileEntityCraneExtractor;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
public class GUICraneBoxer extends GuiInfoContainer {
private static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/storage/gui_crane_boxer.png");
private TileEntityCraneBoxer inserter;
private TileEntityCraneBoxer boxer;
public GUICraneBoxer(InventoryPlayer invPlayer, TileEntityCraneBoxer tedf) {
super(new ContainerCraneBoxer(invPlayer, tedf));
inserter = tedf;
boxer = tedf;
this.xSize = 176;
this.ySize = 185;
@ -34,11 +36,19 @@ public class GUICraneBoxer extends GuiInfoContainer {
@Override
protected void mouseClicked(int x, int y, int i) {
super.mouseClicked(x, y, i);
if(guiLeft + 151 <= x && guiLeft + 151 + 18 > x && guiTop + 34 < y && guiTop + 34 + 18 >= y) {
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
NBTTagCompound data = new NBTTagCompound();
data.setBoolean("toggle", true);
PacketDispatcher.wrapper.sendToServer(new NBTControlPacket(data, boxer.xCoord, boxer.yCoord, boxer.zCoord));
}
}
@Override
protected void drawGuiContainerForegroundLayer(int i, int j) {
String name = this.inserter.hasCustomInventoryName() ? this.inserter.getInventoryName() : I18n.format(this.inserter.getInventoryName());
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);
}
@ -48,5 +58,7 @@ public class GUICraneBoxer extends GuiInfoContainer {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
drawTexturedModalRect(guiLeft + 151, guiTop + 34, 176, boxer.mode * 18, 18, 18);
}
}

View File

@ -1,7 +1,5 @@
package com.hbm.render.entity.item;
import java.util.Random;
import org.lwjgl.opengl.GL11;
import com.hbm.blocks.ModBlocks;
@ -22,10 +20,7 @@ public class RenderMovingPackage extends Render {
public void doRender(Entity entity, double x, double y, double z, float f1, float f2) {
GL11.glPushMatrix();
GL11.glTranslated(x, y, z);
Random rand = new Random(entity.getEntityId());
GL11.glTranslated(0, rand.nextDouble() * 0.0625, 0);
GL11.glTranslated(x, y - 0.0125, z);
if(this.dummy == null) {
this.dummy = new ItemStack(ModBlocks.crate);
@ -35,7 +30,7 @@ public class RenderMovingPackage extends Render {
dummy.hoverStart = 0.0F;
RenderItem.renderInFrame = true;
double scale = 8D / 6D;
double scale = 2;
GL11.glScaled(scale, scale, scale);
RenderManager.instance.renderEntityWithPosYaw(dummy, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F);
RenderItem.renderInFrame = false;

View File

@ -1,14 +1,13 @@
package com.hbm.tileentity.network;
import com.hbm.entity.item.EntityMovingItem;
import com.hbm.entity.item.EntityMovingPackage;
import com.hbm.interfaces.IControlReceiver;
import com.hbm.inventory.container.ContainerCraneBoxer;
import com.hbm.inventory.gui.GUICraneBoxer;
import com.hbm.tileentity.IGUIProvider;
import com.hbm.tileentity.TileEntityMachineBase;
import api.hbm.conveyor.IConveyorBelt;
import api.hbm.ntl.StorageManifest;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
@ -16,11 +15,12 @@ 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.nbt.NBTTagCompound;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityCraneBoxer extends TileEntityMachineBase implements IGUIProvider {
public class TileEntityCraneBoxer extends TileEntityMachineBase implements IGUIProvider, IControlReceiver {
public byte mode = 0;
public static final byte MODE_4 = 0;
@ -41,63 +41,74 @@ public class TileEntityCraneBoxer extends TileEntityMachineBase implements IGUIP
@Override
public void updateEntity() {
if(!worldObj.isRemote && mode != MODE_REDSTONE && worldObj.getTotalWorldTime() % 20 == 0) {
int pack = 1;
if(!worldObj.isRemote) {
switch(mode) {
case MODE_4: pack = 4; break;
case MODE_8: pack = 8; break;
case MODE_16: pack = 16; break;
}
int fullStacks = 0;
// NO!
/*StorageManifest manifest = new StorageManifest(); //i wrote some of this for a feature that i scrapped so why not make proper use of it?
for(int i = 0; i < slots.length; i++) {
if(slots[i] != null) {
manifest.writeStack(slots[i]);
if(mode != MODE_REDSTONE && worldObj.getTotalWorldTime() % 20 == 0) {
int pack = 1;
switch(mode) {
case MODE_4: pack = 4; break;
case MODE_8: pack = 8; break;
case MODE_16: pack = 16; break;
}
}*/
for(int i = 0; i < slots.length; i++) {
if(slots[i] != null && slots[i].stackSize == slots[i].getMaxStackSize()) {
fullStacks++;
}
}
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata());
Block b = worldObj.getBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ);
IConveyorBelt belt = null;
if(b instanceof IConveyorBelt) {
belt = (IConveyorBelt) b;
}
if(belt != null && fullStacks >= pack) {
int fullStacks = 0;
ItemStack[] box = new ItemStack[pack];
// NO!
/*StorageManifest manifest = new StorageManifest(); //i wrote some of this for a feature that i scrapped so why not make proper use of it?
for(int i = 0; i < slots.length && pack > 0; i++) {
for(int i = 0; i < slots.length; i++) {
if(slots[i] != null) {
manifest.writeStack(slots[i]);
}
}*/
for(int i = 0; i < slots.length; i++) {
if(slots[i] != null && slots[i].stackSize == slots[i].getMaxStackSize()) {
pack--;
box[pack] = slots[i].copy();
slots[i] = null;
fullStacks++;
}
}
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);
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;
}
if(belt != null && fullStacks >= pack) {
ItemStack[] box = new ItemStack[pack];
for(int i = 0; i < slots.length && pack > 0; i++) {
if(slots[i] != null && slots[i].stackSize == slots[i].getMaxStackSize()) {
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);
}
}
NBTTagCompound data = new NBTTagCompound();
data.setByte("mode", mode);
this.networkPack(data, 15);
}
}
public void networkUnpack(NBTTagCompound nbt) {
this.mode = nbt.getByte("mode");
}
@Override
public int[] getAccessibleSlotsFromSide(int p_94128_1_) {
@ -119,4 +130,16 @@ public class TileEntityCraneBoxer extends TileEntityMachineBase implements IGUIP
public GuiScreen provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) {
return new GUICraneBoxer(player.inventory, this);
}
@Override
public boolean hasPermission(EntityPlayer player) {
return Vec3.createVectorHelper(xCoord - player.posX, yCoord - player.posY, zCoord - player.posZ).lengthVector() < 20;
}
@Override
public void receiveControl(NBTTagCompound data) {
if(data.hasKey("toggle")) {
this.mode = (byte) ((this.mode + 1) % 4);
}
}
}