Files
thaumicadditions/src/main/java/com/pengu/thaumcraft/additions/tileentity/TileVoidChest.java
T
layue13 e18263c12b fix F-001..F-004: concurrency, maven content, idle TE canUpdate
- F-001: add workflow concurrency group (cancel-in-progress false for publish)
- F-002: TDLM Maven content includeGroup uk.potatolab
- F-003: TileVoidChest canUpdate false (empty updateEntity)
- F-004: TileReturner canUpdate false
2026-10-26 22:26:38 +08:00

206 lines
6.3 KiB
Java

package com.pengu.thaumcraft.additions.tileentity;
import com.pengu.thaumcraft.additions.VoidChestLootRegistry;
import com.pengu.thaumcraft.additions.utils.Chance;
import com.pengu.thaumcraft.additions.utils.Lang;
import java.util.ArrayList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import thaumcraft.api.TileThaumcraft;
public class TileVoidChest extends TileThaumcraft implements IInventory, ISidedInventory {
private static int[] slots_top = new int[]{0};
private static int[] slots_bottom = new int[]{1};
private static int[] slots_sides = new int[]{2, 3, 4};
private String name;
private String localizedName;
public ItemStack[] slots = new ItemStack[72];
public TileVoidChest(World w, boolean generateLoot) {
if(generateLoot) {
ArrayList alreadyGenerated = new ArrayList();
for(int i = 0; i < this.slots.length; ++i) {
for(int j = 0; j < VoidChestLootRegistry.ITEMS.size(); ++j) {
if(!w.isRemote && !this.isItemInArrayForSomeTime(alreadyGenerated, ((ItemStack)VoidChestLootRegistry.ITEMS.get(j)).getItem(), ((ItemStack)VoidChestLootRegistry.ITEMS.get(j)).getItemDamage(), ((Chance)VoidChestLootRegistry.MAXITEMSTACKSINONECHEST.get(j)).chance) && ((Chance)VoidChestLootRegistry.ITEMCHANCE.get(j)).chance > 0 && w.rand.nextInt(100) < ((Chance)VoidChestLootRegistry.ITEMCHANCE.get(j)).chance - 1) {
this.slots[i] = new ItemStack(((ItemStack)VoidChestLootRegistry.ITEMS.get(j)).getItem(), 1 + w.rand.nextInt(((ItemStack)VoidChestLootRegistry.ITEMS.get(j)).stackSize), ((ItemStack)VoidChestLootRegistry.ITEMS.get(j)).getItemDamage());
alreadyGenerated.add(this.slots[i]);
}
}
}
}
}
private boolean isItemInArrayForSomeTime(ArrayList<ItemStack> array, Item item, int metadata, int times) {
int numbers = 0;
for(int i = 0; i < array.size(); ++i) {
if(array.get(i) != null && ((ItemStack)array.get(i)).getItem() == item && ((ItemStack)array.get(i)).getItemDamage() == metadata) {
++numbers;
}
}
return numbers >= times;
}
public void updateEntity() {}
@Override
public boolean canUpdate() {
return false;
}
public int getSizeInv() {
return this.slots.length;
}
public boolean isInvNameLocalised() {
return this.localizedName != null && this.localizedName.length() > 0;
}
public String getInvName() {
return this.isInvNameLocalised()?this.localizedName:Lang.localise(this.worldObj.getBlock(this.xCoord, this.yCoord, this.zCoord).getUnlocalizedName() + ".name");
}
public void setGuiDisplayName(String name) {
this.localizedName = name;
}
public int getSizeInventory() {
return this.getSizeInv();
}
public ItemStack getStackInSlot(int slot) {
return this.slots[slot];
}
public ItemStack decrStackSize(int slot, int j) {
if(this.slots[slot] != null) {
ItemStack is;
if(this.slots[slot].stackSize <= j) {
is = this.slots[slot];
this.slots[slot] = null;
return is;
} else {
is = this.slots[slot].splitStack(j);
if(this.slots[slot].stackSize == 0) {
this.slots[slot] = null;
}
return is;
}
} else {
return null;
}
}
public ItemStack getStackInSlotOnClosing(int slot) {
if(this.slots[slot] != null) {
ItemStack is = this.slots[slot];
this.slots[slot] = null;
return is;
} else {
return null;
}
}
public void setInventorySlotContents(int slot, ItemStack is) {
this.slots[slot] = is;
if(is != null && is.stackSize > this.getInventoryStackLimit()) {
is.stackSize = this.getInventoryStackLimit();
}
}
public String getInventoryName() {
return this.getInvName();
}
public boolean hasCustomInventoryName() {
return this.isInvNameLocalised();
}
public int getInventoryStackLimit() {
return 64;
}
public boolean isUseableByPlayer(EntityPlayer player) {
return this.getWorldObj().getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this?false:player.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D;
}
public void openInventory() {}
public void closeInventory() {}
public boolean isItemValidForSlot(int slot, ItemStack is) {
return true;
}
public int[] getAccessibleSlotsFromSide(int side) {
int[] slotsi = new int[this.slots.length];
for(int i = 0; i < this.slots.length; slotsi[i] = i++) {
;
}
return slotsi;
}
public boolean canInsertItem(int slot, ItemStack is, int side) {
return true;
}
public boolean canExtractItem(int slot, ItemStack is, int side) {
return true;
}
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
NBTTagList nbttaglist = nbt.getTagList("Items", 10);
this.slots = new ItemStack[72];
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);
}
}
if(nbt.hasKey("CustomName", 8)) {
this.name = nbt.getString("CustomName");
}
}
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(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);
if(this.hasCustomInventoryName()) {
nbt.setString("CustomName", this.name);
}
}
}