fluid pattern terminal ex

This commit is contained in:
GlodBlock committed 2022-05-12 15:24:42 +08:00
1 parent bb4a1e9e58
commit 3e76b36c49
19 files changed
+1247 -30

No files matched your search

@@ -0,0 +1,61 @@
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.PartFluidPatternTerminalEx;
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.world.World;
import javax.annotation.Nullable;
public class ItemPartFluidPatternTerminalEx extends Item implements IPartItem {
public ItemPartFluidPatternTerminalEx() {
this.setMaxStackSize(64);
this.setUnlocalizedName(NameConst.ITEM_PART_FLUID_PATTERN_TERMINAL_EX);
AEApi.instance().partHelper().setItemBusRenderer(this);
}
@Nullable
@Override
public PartFluidPatternTerminalEx createPartFromItemStack(ItemStack is) {
return new PartFluidPatternTerminalEx(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);
}
public ItemPartFluidPatternTerminalEx register() {
GameRegistry.registerItem(this, NameConst.ITEM_PART_FLUID_PATTERN_TERMINAL_EX, FluidCraft.MODID);
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,253 @@
package com.glodblock.github.common.parts;
import appeng.api.config.SecurityPermissions;
import appeng.api.implementations.ICraftingPatternItem;
import appeng.api.networking.IGridHost;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.storage.data.IAEItemStack;
import appeng.core.sync.GuiBridge;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.Platform;
import com.glodblock.github.client.textures.FCPartsTexture;
import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.common.item.ItemFluidEncodedPattern;
import com.glodblock.github.common.item.ItemFluidPacket;
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.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.Vec3;
import java.util.List;
import java.util.Objects;
public class PartFluidPatternTerminalEx extends FCBasePart {
private static final FCPartsTexture FRONT_BRIGHT_ICON = FCPartsTexture.PartFluidPatternTerminal_Bright;
private static final FCPartsTexture FRONT_DARK_ICON = FCPartsTexture.PartFluidPatternTerminal_Colored;
private static final FCPartsTexture FRONT_COLORED_ICON = FCPartsTexture.PartFluidPatternTerminal_Dark;
private final AppEngInternalInventory crafting = new AppEngInternalInventory( this, 16 );
private final AppEngInternalInventory output = new AppEngInternalInventory( this, 4 );
private final AppEngInternalInventory pattern = new AppEngInternalInventory( this, 2 );
private boolean substitute = false;
public PartFluidPatternTerminalEx(ItemStack is) {
super(is, true);
}
@Override
public void getDrops(final List<ItemStack> drops, final boolean wrenched )
{
for( final ItemStack is : this.pattern )
{
if( is != null )
{
drops.add( is );
}
}
}
@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_PATTERN_TERMINAL_EX);
}
else {
player.addChatComponentMessage(new ChatComponentText("You don't have permission to view."));
}
}
return true;
}
@Override
public void readFromNBT( final NBTTagCompound data )
{
super.readFromNBT( data );
this.setSubstitution( data.getBoolean( "substitute" ) );
this.pattern.readFromNBT( data, "pattern" );
this.output.readFromNBT( data, "outputList" );
this.crafting.readFromNBT( data, "craftingGrid" );
}
@Override
public void writeToNBT( final NBTTagCompound data )
{
super.writeToNBT( data );
data.setBoolean( "substitute", this.substitute );
this.pattern.writeToNBT( data, "pattern" );
this.output.writeToNBT( data, "outputList" );
this.crafting.writeToNBT( data, "craftingGrid" );
}
@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_PATTERN_TERMINAL.hasPermissions( this.getHost().getTile(), x, y, z, this.getSide(), p ) )
{
return GuiBridge.GUI_PATTERN_TERMINAL;
}
return GuiBridge.GUI_ME;
}
public void onChangeInventory0(final IInventory inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
if( inv == this.pattern && slot == 1 )
{
final ItemStack is = this.pattern.getStackInSlot( 1 );
if( is != null && is.getItem() instanceof ICraftingPatternItem)
{
final ICraftingPatternItem pattern = (ICraftingPatternItem) is.getItem();
final ICraftingPatternDetails details = pattern.getPatternForItem( is, this.getHost().getTile().getWorldObj() );
if( details != null )
{
this.setSubstitution( details.canSubstitute() );
for( int x = 0; x < this.crafting.getSizeInventory() && x < details.getInputs().length; x++ )
{
final IAEItemStack item = details.getInputs()[x];
this.crafting.setInventorySlotContents( x, item == null ? null : item.getItemStack() );
}
for( int x = 0; x < this.output.getSizeInventory() && x < details.getOutputs().length; x++ )
{
final IAEItemStack item = details.getOutputs()[x];
this.output.setInventorySlotContents( x, item == null ? null : item.getItemStack() );
}
}
}
}
this.getHost().markForSave();
}
@Override
public void onChangeInventory(final IInventory inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
if (inv == this.pattern && slot == 1) {
final ItemStack is = inv.getStackInSlot(1);
if (is != null && is.getItem() instanceof ItemFluidEncodedPattern) {
final ItemFluidEncodedPattern pattern = (ItemFluidEncodedPattern) is.getItem();
final ICraftingPatternDetails details = pattern.getPatternForItem( is, this.getHost().getTile().getWorldObj() );
if( details != null )
{
this.setSubstitution( details.canSubstitute() );
for( int x = 0; x < this.crafting.getSizeInventory() && x < details.getInputs().length; x++ )
{
final IAEItemStack item = details.getInputs()[x];
if (item != null && item.getItem() instanceof ItemFluidDrop) {
ItemStack packet = ItemFluidPacket.newStack(ItemFluidDrop.getFluidStack(item.getItemStack()));
this.crafting.setInventorySlotContents(x, packet);
}
else this.crafting.setInventorySlotContents( x, item == null ? null : item.getItemStack() );
}
for( int x = 0; x < this.output.getSizeInventory() && x < details.getOutputs().length; x++ )
{
final IAEItemStack item = details.getOutputs()[x];
if (item != null && item.getItem() instanceof ItemFluidDrop) {
ItemStack packet = ItemFluidPacket.newStack(ItemFluidDrop.getFluidStack(item.getItemStack()));
this.output.setInventorySlotContents(x, packet);
}
else this.output.setInventorySlotContents( x, item == null ? null : item.getItemStack() );
}
}
this.getHost().markForSave();
return;
}
}
onChangeInventory0(inv, slot, mc, removedStack, newStack);
}
public boolean isSubstitution()
{
return this.substitute;
}
public void setSubstitution( boolean canSubstitute )
{
this.substitute = canSubstitute;
}
public void onChangeCrafting(IAEItemStack[] newCrafting, IAEItemStack[] newOutput) {
IInventory crafting = this.getInventoryByName("crafting");
IInventory output = this.getInventoryByName("output");
if (crafting instanceof AppEngInternalInventory && output instanceof AppEngInternalInventory) {
for (int x = 0; x < crafting.getSizeInventory() && x < newCrafting.length; x++) {
final IAEItemStack item = newCrafting[x];
crafting.setInventorySlotContents(x, item == null ? null: item.getItemStack());
}
for (int x = 0; x < output.getSizeInventory() && x < newOutput.length; x++) {
final IAEItemStack item = newOutput[x];
output.setInventorySlotContents(x, item == null ? null : item.getItemStack());
}
}
}
@Override
public IInventory getInventoryByName( final String name )
{
if( name.equals( "crafting" ) )
{
return this.crafting;
}
if( name.equals( "output" ) )
{
return this.output;
}
if( name.equals( "pattern" ) )
{
return this.pattern;
}
return super.getInventoryByName( name );
}
@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;
}
}