mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
inventories for trains
This commit is contained in:
parent
40d2a3de27
commit
015ee2245a
@ -1,21 +1,12 @@
|
|||||||
package com.hbm.blocks.rail;
|
package com.hbm.blocks.rail;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.hbm.blocks.BlockDummyable;
|
import com.hbm.blocks.BlockDummyable;
|
||||||
import com.hbm.lib.Library;
|
import com.hbm.lib.Library;
|
||||||
import com.hbm.packet.PacketDispatcher;
|
|
||||||
import com.hbm.packet.PlayerInformPacket;
|
|
||||||
import com.hbm.util.ParticleUtil;
|
|
||||||
import com.hbm.util.fauxpointtwelve.BlockPos;
|
import com.hbm.util.fauxpointtwelve.BlockPos;
|
||||||
|
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.AxisAlignedBB;
|
import net.minecraft.util.AxisAlignedBB;
|
||||||
import net.minecraft.util.ChatComponentText;
|
|
||||||
import net.minecraft.util.MathHelper;
|
import net.minecraft.util.MathHelper;
|
||||||
import net.minecraft.util.Vec3;
|
import net.minecraft.util.Vec3;
|
||||||
import net.minecraft.world.IBlockAccess;
|
import net.minecraft.world.IBlockAccess;
|
||||||
|
|||||||
141
src/main/java/com/hbm/entity/train/EntityRailCarCargo.java
Normal file
141
src/main/java/com/hbm/entity/train/EntityRailCarCargo.java
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
package com.hbm.entity.train;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.inventory.IInventory;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
public abstract class EntityRailCarCargo extends EntityRailCarBase implements IInventory {
|
||||||
|
|
||||||
|
protected String entityName;
|
||||||
|
protected ItemStack[] slots = new ItemStack[this.getSizeInventory()];
|
||||||
|
|
||||||
|
public EntityRailCarCargo(World world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getStackInSlot(int slot) {
|
||||||
|
return slots[slot];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack decrStackSize(int slot, int amount) {
|
||||||
|
if(this.slots[slot] != null) {
|
||||||
|
ItemStack itemstack;
|
||||||
|
|
||||||
|
if(this.slots[slot].stackSize <= amount) {
|
||||||
|
itemstack = this.slots[slot];
|
||||||
|
this.slots[slot] = null;
|
||||||
|
return itemstack;
|
||||||
|
} else {
|
||||||
|
itemstack = this.slots[slot].splitStack(amount);
|
||||||
|
|
||||||
|
if(this.slots[slot].stackSize == 0) {
|
||||||
|
this.slots[slot] = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return itemstack;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getStackInSlotOnClosing(int slot) {
|
||||||
|
if(this.slots[slot] != null) {
|
||||||
|
ItemStack itemstack = this.slots[slot];
|
||||||
|
this.slots[slot] = null;
|
||||||
|
return itemstack;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setInventorySlotContents(int slot, ItemStack stack) {
|
||||||
|
this.slots[slot] = stack;
|
||||||
|
|
||||||
|
if(stack != null && stack.stackSize > this.getInventoryStackLimit()) {
|
||||||
|
stack.stackSize = this.getInventoryStackLimit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getInventoryStackLimit() {
|
||||||
|
return 64;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void markDirty() { }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||||
|
return this.isDead ? false : player.getDistanceSqToEntity(this) <= 64.0D;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void openInventory() { }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void closeInventory() { }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void writeEntityToNBT(NBTTagCompound nbt) {
|
||||||
|
super.writeEntityToNBT(nbt);
|
||||||
|
NBTTagList nbttaglist = new NBTTagList();
|
||||||
|
|
||||||
|
for(int i = 0; i < this.slots.length; ++i) {
|
||||||
|
if(this.slots[i] != null) {
|
||||||
|
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
||||||
|
nbttagcompound1.setByte("Slot", (byte) i);
|
||||||
|
this.slots[i].writeToNBT(nbttagcompound1);
|
||||||
|
nbttaglist.appendTag(nbttagcompound1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nbt.setTag("Items", nbttaglist);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void readEntityFromNBT(NBTTagCompound nbt) {
|
||||||
|
super.readEntityFromNBT(nbt);
|
||||||
|
NBTTagList nbttaglist = nbt.getTagList("Items", 10);
|
||||||
|
this.slots = new ItemStack[this.getSizeInventory()];
|
||||||
|
|
||||||
|
for(int i = 0; i < nbttaglist.tagCount(); ++i) {
|
||||||
|
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
|
||||||
|
int j = nbttagcompound1.getByte("Slot") & 255;
|
||||||
|
|
||||||
|
if(j >= 0 && j < this.slots.length) {
|
||||||
|
this.slots[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasCustomInventoryName() {
|
||||||
|
return this.entityName != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEntityName() {
|
||||||
|
return this.entityName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEntityName(String name) {
|
||||||
|
this.entityName = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommandSenderName() {
|
||||||
|
return this.entityName != null ? this.entityName : super.getCommandSenderName();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -6,7 +6,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||||||
import net.minecraft.util.Vec3;
|
import net.minecraft.util.Vec3;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public abstract class EntityRailCarRidable extends EntityRailCarBase {
|
public abstract class EntityRailCarRidable extends EntityRailCarCargo {
|
||||||
|
|
||||||
public SeatDummyEntity[] passengerSeats;
|
public SeatDummyEntity[] passengerSeats;
|
||||||
|
|
||||||
|
|||||||
@ -1,14 +1,21 @@
|
|||||||
package com.hbm.entity.train;
|
package com.hbm.entity.train;
|
||||||
|
|
||||||
import com.hbm.blocks.rail.IRailNTM.TrackGauge;
|
import com.hbm.blocks.rail.IRailNTM.TrackGauge;
|
||||||
|
import com.hbm.inventory.container.ContainerCrateSteel;
|
||||||
|
import com.hbm.inventory.gui.GUICrateSteel;
|
||||||
|
import com.hbm.tileentity.IGUIProvider;
|
||||||
|
|
||||||
|
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.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.inventory.Container;
|
||||||
import net.minecraft.util.DamageSource;
|
import net.minecraft.util.DamageSource;
|
||||||
import net.minecraft.util.MathHelper;
|
import net.minecraft.util.MathHelper;
|
||||||
import net.minecraft.util.Vec3;
|
import net.minecraft.util.Vec3;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class TrainCargoTram extends EntityRailCarRidable {
|
public class TrainCargoTram extends EntityRailCarRidable implements IGUIProvider {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
@ -93,4 +100,27 @@ public class TrainCargoTram extends EntityRailCarRidable {
|
|||||||
Vec3.createVectorHelper(-0.5, 1.75, -1.5)
|
Vec3.createVectorHelper(-0.5, 1.75, -1.5)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSizeInventory() {
|
||||||
|
return 27;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getInventoryName() {
|
||||||
|
return this.hasCustomInventoryName() ? this.getEntityName() : "container.trainTram";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||||
|
//return new ContainerTrainCargoTram(player.inventory, (TrainCargoTram)player.worldObj.getEntityByID(x));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public GuiScreen provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||||
|
//return new GUITrainCargoTram(player.inventory, (TrainCargoTram) player.worldObj.getEntityByID(x));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user