add fluid terminal

This commit is contained in:
asdflj committed 2022-10-20 12:28:01 +08:00
1 parent 87d7f699e8
commit 238fd317e4
31 files changed
+2275 -60

No files matched your search

@@ -79,8 +79,19 @@ public class ItemFluidDrop extends Item {
return stack;
}
public static ItemStack newStack1(FluidStack fluid) {
if (fluid == null) {
return null;
}
ItemStack stack = new ItemStack(ItemAndBlockHolder.DROP, fluid.amount);
NBTTagCompound tag = new NBTTagCompound();
tag.setString("Fluid", fluid.getFluid().getName());
stack.setTagCompound(tag);
return stack;
}
public static FluidStack getFluidStack(ItemStack stack) {
if (stack == null|| stack.getItem() != ItemAndBlockHolder.DROP || !stack.hasTagCompound()) {
if (stack == null || stack.getItem() != ItemAndBlockHolder.DROP || !stack.hasTagCompound()) {
return null;
}
NBTTagCompound tag = Objects.requireNonNull(stack.getTagCompound());
@@ -0,0 +1,74 @@
package com.glodblock.github.common.item;
import appeng.api.AEApi;
import appeng.api.parts.IPartItem;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.common.parts.PartFluidTerminal;
import com.glodblock.github.common.tabs.FluidCraftingTabs;
import com.glodblock.github.util.NameConst;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import javax.annotation.Nullable;
import java.util.List;
import static net.minecraft.client.gui.GuiScreen.isShiftKeyDown;
public class ItemPartFluidTerminal extends Item implements IPartItem {
public ItemPartFluidTerminal() {
this.setMaxStackSize(64);
this.setUnlocalizedName(NameConst.ITEM_PART_FLUID_TERMINAL);
AEApi.instance().partHelper().setItemBusRenderer(this);
}
@Nullable
@Override
public PartFluidTerminal createPartFromItemStack(ItemStack is) {
return new PartFluidTerminal(is);
}
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float xOffset, float yOffset, float zOffset) {
return AEApi.instance().partHelper().placeBus(player.getHeldItem(), x, y, z, side, player, world);
}
@Override
@SuppressWarnings("unchecked")
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List tooltip, boolean flag) {
if (isShiftKeyDown()) tooltip.add(StatCollector.translateToLocalFormatted(NameConst.TT_FLUID_TERMINAL));
}
public ItemPartFluidTerminal register() {
GameRegistry.registerItem(this, NameConst.ITEM_PART_FLUID_TERMINAL, FluidCraft.MODID);
setCreativeTab(FluidCraftingTabs.INSTANCE);
return this;
}
@Override
public void registerIcons(IIconRegister _iconRegister) {
}
@Override
@SideOnly(Side.CLIENT)
public int getSpriteNumber() {
return 0;
}
public ItemStack stack(int size) {
return new ItemStack(this, size);
}
public ItemStack stack() {
return new ItemStack(this, 1);
}
}
@@ -0,0 +1,88 @@
package com.glodblock.github.common.parts;
import appeng.api.config.SecurityPermissions;
import appeng.api.networking.IGridHost;
import appeng.core.sync.GuiBridge;
import appeng.util.Platform;
import com.glodblock.github.client.textures.FCPartsTexture;
import com.glodblock.github.inventory.InventoryHandler;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.util.BlockPos;
import com.glodblock.github.util.Util;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.Vec3;
import java.util.Objects;
public class PartFluidTerminal extends FCBasePart {
private static final FCPartsTexture FRONT_BRIGHT_ICON = FCPartsTexture.PartFluidTerminal_Bright;
private static final FCPartsTexture FRONT_DARK_ICON = FCPartsTexture.PartFluidTerminal_Dark;
private static final FCPartsTexture FRONT_COLORED_ICON = FCPartsTexture.PartFluidTerminal_Colored;
public PartFluidTerminal(ItemStack is) {
super(is, true);
}
@Override
public FCPartsTexture getFrontBright() {
return FRONT_BRIGHT_ICON;
}
@Override
public FCPartsTexture getFrontColored() {
return FRONT_COLORED_ICON;
}
@Override
public FCPartsTexture getFrontDark() {
return FRONT_DARK_ICON;
}
@Override
public boolean isLightSource() {
return false;
}
@Override
public boolean isBooting() {
return super.isBooting();
}
@Override
public boolean onPartActivate(final EntityPlayer player, final Vec3 pos) {
TileEntity te = this.getTile();
BlockPos tePos = new BlockPos(te);
if (Platform.isWrench(player, player.inventory.getCurrentItem(), tePos.getX(), tePos.getY(), tePos.getZ())) {
return super.onPartActivate(player, pos);
}
if (Platform.isServer()) {
if (Util.hasPermission(player, SecurityPermissions.INJECT, (IGridHost) this) || Util.hasPermission(player, SecurityPermissions.EXTRACT, (IGridHost) this)) {
InventoryHandler.openGui(player, te.getWorldObj(), tePos, Objects.requireNonNull(Util.from(getSide())), GuiType.FLUID_TERMINAL);
} else {
player.addChatComponentMessage(new ChatComponentText("You don't have permission to view."));
}
}
return true;
}
@Override
public GuiBridge getGui(final EntityPlayer p) {
int x = (int) p.posX;
int y = (int) p.posY;
int z = (int) p.posZ;
if (this.getHost().getTile() != null) {
x = this.getTile().xCoord;
y = this.getTile().yCoord;
z = this.getTile().zCoord;
}
if (GuiBridge.GUI_WIRELESS_TERM.hasPermissions(this.getHost().getTile(), x, y, z, this.getSide(), p)) {
return GuiBridge.GUI_WIRELESS_TERM;
}
return GuiBridge.GUI_ME;
}
}
@@ -133,9 +133,7 @@ public class FluidCellInventory implements IFluidCellInventory {
@Override
public boolean canHoldNewFluid() {
final long bytesFree = this.getFreeBytes();
return ( bytesFree > this.getBytesPerType() || ( bytesFree == this.getBytesPerType() && this.getUnusedFluidCount() > 0 ) ) && this.getRemainingFluidTypes() > 0;
return this.getRemainingFluidCount() > 0 && getRemainingFluidTypes() > 0;
}
@Override
@@ -150,8 +148,10 @@ public class FluidCellInventory implements IFluidCellInventory {
@Override
public long getUsedBytes() {
final long bytesForItemCount = ( this.getStoredFluidCount() + this.getUnusedFluidCount() ) / 8 / 256;
return this.getStoredFluidTypes() * this.getBytesPerType() + bytesForItemCount;
long bytesForItemCount = (this.getStoredFluidCount() + this.getUnusedFluidCount()) / (8 * 256);
long tmp = this.getStoredFluidTypes() * this.getBytesPerType() + bytesForItemCount;
if (this.getUnusedFluidCount() > 0 && tmp < this.getTotalBytes()) tmp++;
return tmp;
}
@Override
@@ -178,7 +178,7 @@ public class FluidCellInventory implements IFluidCellInventory {
@Override
public long getRemainingFluidCount() {
final long remaining = this.getFreeBytes() * 8 * 256 + this.getUnusedFluidCount();
final long remaining = (this.getTotalBytes() - (this.getTotalFluidTypes() * 8)) * 8 * 256 - this.getStoredFluidCount();
return remaining > 0 ? remaining : 0;
}
@@ -370,7 +370,6 @@ public class FluidCellInventory implements IFluidCellInventory {
this.updateFluidCount( remainingItemSlots );
this.saveChanges();
}
return r;
}
else