mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-17 19:05:29 +00:00
begin work
This commit is contained in:
commit
db2ad29b52
124 files changed
+11799
No files matched your search
@@ -0,0 +1,507 @@
|
||||
package com.glodblock.github.common.parts;
|
||||
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.SortDir;
|
||||
import appeng.api.config.SortOrder;
|
||||
import appeng.api.config.ViewItems;
|
||||
import appeng.api.implementations.IPowerChannelState;
|
||||
import appeng.api.implementations.tiles.IViewCellStorage;
|
||||
import appeng.api.networking.GridFlags;
|
||||
import appeng.api.networking.events.MENetworkBootingStatusChange;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.ITerminalHost;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.parts.AEBasePart;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.inventory.IAEAppEngInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.ConfigManager;
|
||||
import appeng.util.IConfigManagerHost;
|
||||
import appeng.util.Platform;
|
||||
import com.glodblock.github.client.textures.FCPartsTexture;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
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.IIcon;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class FCBasePart extends AEBasePart implements IPowerChannelState, ITerminalHost, IConfigManagerHost, IViewCellStorage, IAEAppEngInventory {
|
||||
|
||||
protected static final int POWERED_FLAG = 4;
|
||||
protected static final int CHANNEL_FLAG = 16;
|
||||
private static final int BOOTING_FLAG = 8;
|
||||
|
||||
private byte spin = 0; // 0-3
|
||||
private int clientFlags = 0; // sent as byte.
|
||||
private float opacity = -1;
|
||||
|
||||
private final IConfigManager cm = new ConfigManager( this );
|
||||
private final AppEngInternalInventory viewCell = new AppEngInternalInventory( this, 5 );
|
||||
|
||||
public FCBasePart( final ItemStack is )
|
||||
{
|
||||
this( is, false );
|
||||
}
|
||||
|
||||
protected FCBasePart( final ItemStack is, final boolean requireChannel )
|
||||
{
|
||||
super( is );
|
||||
|
||||
if( requireChannel )
|
||||
{
|
||||
this.getProxy().setFlags( GridFlags.REQUIRE_CHANNEL );
|
||||
this.getProxy().setIdlePowerUsage( 1.0 / 2.0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.getProxy().setIdlePowerUsage( 1.0 / 16.0 ); // lights drain a little bit.
|
||||
}
|
||||
this.cm.registerSetting( Settings.SORT_BY, SortOrder.NAME );
|
||||
this.cm.registerSetting( Settings.VIEW_MODE, ViewItems.ALL );
|
||||
this.cm.registerSetting( Settings.SORT_DIRECTION, SortDir.ASCENDING );
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public final void bootingRender( final MENetworkBootingStatusChange c )
|
||||
{
|
||||
if( !this.isLightSource() )
|
||||
{
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public final void powerRender( final MENetworkPowerStatusChange c )
|
||||
{
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void getBoxes( final IPartCollisionHelper bch )
|
||||
{
|
||||
bch.addBox( 2, 2, 14, 14, 14, 16 );
|
||||
bch.addBox( 4, 4, 13, 12, 12, 14 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged()
|
||||
{
|
||||
this.opacity = -1;
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops(final List<ItemStack> drops, final boolean wrenched )
|
||||
{
|
||||
super.getDrops( drops, wrenched );
|
||||
|
||||
for( final ItemStack is : this.viewCell )
|
||||
{
|
||||
if( is != null )
|
||||
{
|
||||
drops.add( is );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IConfigManager getConfigManager()
|
||||
{
|
||||
return this.cm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final NBTTagCompound data )
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
if( data.hasKey( "opacity" ) )
|
||||
{
|
||||
this.opacity = data.getFloat( "opacity" );
|
||||
}
|
||||
this.spin = data.getByte( "spin" );
|
||||
this.cm.readFromNBT( data );
|
||||
this.viewCell.readFromNBT( data, "viewCell" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final NBTTagCompound data )
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
data.setFloat( "opacity", this.opacity );
|
||||
data.setByte( "spin", this.getSpin() );
|
||||
this.cm.writeToNBT( data );
|
||||
this.viewCell.writeToNBT( data, "viewCell" );
|
||||
}
|
||||
|
||||
public GuiBridge getGui(final EntityPlayer player )
|
||||
{
|
||||
return GuiBridge.GUI_ME;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToStream( final ByteBuf data ) throws IOException
|
||||
{
|
||||
super.writeToStream( data );
|
||||
this.clientFlags = this.getSpin() & 3;
|
||||
|
||||
try
|
||||
{
|
||||
if( this.getProxy().getEnergy().isNetworkPowered() )
|
||||
{
|
||||
this.clientFlags = this.getClientFlags() | FCBasePart.POWERED_FLAG;
|
||||
}
|
||||
|
||||
if( this.getProxy().getPath().isNetworkBooting() )
|
||||
{
|
||||
this.clientFlags = this.getClientFlags() | FCBasePart.BOOTING_FLAG;
|
||||
}
|
||||
|
||||
if( this.getProxy().getNode().meetsChannelRequirements() )
|
||||
{
|
||||
this.clientFlags = this.getClientFlags() | FCBasePart.CHANNEL_FLAG;
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// um.. nothing.
|
||||
}
|
||||
|
||||
data.writeByte( (byte) this.getClientFlags() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readFromStream( final ByteBuf data ) throws IOException
|
||||
{
|
||||
super.readFromStream( data );
|
||||
final int oldFlags = this.getClientFlags();
|
||||
this.clientFlags = data.readByte();
|
||||
this.spin = (byte) ( this.getClientFlags() & 3 );
|
||||
return this.getClientFlags() != oldFlags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int getLightLevel()
|
||||
{
|
||||
return this.blockLight( this.isPowered() ? ( this.isLightSource() ? 15 : 9 ) : 0 );
|
||||
}
|
||||
|
||||
public boolean onPartActivate0(final EntityPlayer player, final Vec3 pos )
|
||||
{
|
||||
final TileEntity te = this.getTile();
|
||||
|
||||
if( !player.isSneaking() && Platform.isWrench( player, player.inventory.getCurrentItem(), te.xCoord, te.yCoord, te.zCoord ) )
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
if( this.getSpin() > 3 )
|
||||
{
|
||||
this.spin = 0;
|
||||
}
|
||||
|
||||
switch( this.getSpin() )
|
||||
{
|
||||
case 0:
|
||||
this.spin = 1;
|
||||
break;
|
||||
case 1:
|
||||
this.spin = 3;
|
||||
break;
|
||||
case 2:
|
||||
this.spin = 0;
|
||||
break;
|
||||
case 3:
|
||||
this.spin = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
this.getHost().markForUpdate();
|
||||
this.saveChanges();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return super.onPartActivate( player, pos );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate( final EntityPlayer player, final Vec3 pos )
|
||||
{
|
||||
if( !onPartActivate0( player, pos ) )
|
||||
{
|
||||
if( !player.isSneaking() )
|
||||
{
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Platform.openGUI( player, this.getHost().getTile(), this.getSide(), this.getGui( player ) );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onPlacement( final EntityPlayer player, final ItemStack held, final ForgeDirection side )
|
||||
{
|
||||
super.onPlacement( player, held, side );
|
||||
|
||||
final byte rotation = (byte) ( MathHelper.floor_double( ( player.rotationYaw * 4F ) / 360F + 2.5D ) & 3 );
|
||||
if( side == ForgeDirection.UP )
|
||||
{
|
||||
this.spin = rotation;
|
||||
}
|
||||
else if( side == ForgeDirection.DOWN )
|
||||
{
|
||||
this.spin = rotation;
|
||||
}
|
||||
}
|
||||
|
||||
private int blockLight(final int emit )
|
||||
{
|
||||
if( this.opacity < 0 )
|
||||
{
|
||||
final TileEntity te = this.getTile();
|
||||
this.opacity = 255 - te.getWorldObj().getBlockLightOpacity( te.xCoord + this.getSide().offsetX, te.yCoord + this.getSide().offsetY, te.zCoord + this.getSide().offsetZ );
|
||||
}
|
||||
|
||||
return (int) ( emit * ( this.opacity / 255.0f ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isPowered()
|
||||
{
|
||||
try
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
return this.getProxy().getEnergy().isNetworkPowered();
|
||||
}
|
||||
else
|
||||
{
|
||||
return ( ( this.getClientFlags() & FCBasePart.POWERED_FLAG ) == FCBasePart.POWERED_FLAG );
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMEMonitor<IAEItemStack> getItemInventory()
|
||||
{
|
||||
try
|
||||
{
|
||||
return this.getProxy().getStorage().getItemInventory();
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// err nope?
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMEMonitor<IAEFluidStack> getFluidInventory()
|
||||
{
|
||||
try
|
||||
{
|
||||
return this.getProxy().getStorage().getFluidInventory();
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// err nope?
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getViewCellStorage()
|
||||
{
|
||||
return this.viewCell;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(final IInventory inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
|
||||
{
|
||||
this.getHost().markForSave();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isActive()
|
||||
{
|
||||
if( !this.isLightSource() )
|
||||
{
|
||||
return ( ( this.getClientFlags() & ( FCBasePart.CHANNEL_FLAG | FCBasePart.POWERED_FLAG ) ) == ( FCBasePart.CHANNEL_FLAG | FCBasePart.POWERED_FLAG ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.isPowered();
|
||||
}
|
||||
}
|
||||
|
||||
public final int getClientFlags()
|
||||
{
|
||||
return this.clientFlags;
|
||||
}
|
||||
|
||||
public final byte getSpin()
|
||||
{
|
||||
return this.spin;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly( Side.CLIENT )
|
||||
public void renderInventory(final IPartRenderHelper rh, final RenderBlocks renderer )
|
||||
{
|
||||
rh.setBounds( 2, 2, 14, 14, 14, 16 );
|
||||
|
||||
final IIcon sideTexture = CableBusTextures.PartMonitorSides.getIcon();
|
||||
final IIcon backTexture = CableBusTextures.PartMonitorBack.getIcon();
|
||||
|
||||
rh.setTexture( sideTexture, sideTexture, backTexture, FCPartsTexture.PartTerminalBroad.getIcon(), sideTexture, sideTexture );
|
||||
rh.renderInventoryBox( renderer );
|
||||
|
||||
rh.setInvColor( this.getColor().whiteVariant );
|
||||
rh.renderInventoryFace( this.getFrontBright().getIcon(), ForgeDirection.SOUTH, renderer );
|
||||
|
||||
rh.setInvColor( this.getColor().mediumVariant );
|
||||
rh.renderInventoryFace( this.getFrontDark().getIcon(), ForgeDirection.SOUTH, renderer );
|
||||
|
||||
rh.setInvColor( this.getColor().blackVariant );
|
||||
rh.renderInventoryFace( this.getFrontColored().getIcon(), ForgeDirection.SOUTH, renderer );
|
||||
|
||||
rh.setBounds( 4, 4, 13, 12, 12, 14 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly( Side.CLIENT )
|
||||
public void renderStatic( final int x, final int y, final int z, final IPartRenderHelper rh, final RenderBlocks renderer )
|
||||
{
|
||||
this.setRenderCache( rh.useSimplifiedRendering( x, y, z, this, this.getRenderCache() ) );
|
||||
|
||||
final IIcon sideTexture = CableBusTextures.PartMonitorSides.getIcon();
|
||||
final IIcon backTexture = CableBusTextures.PartMonitorBack.getIcon();
|
||||
|
||||
rh.setTexture( sideTexture, sideTexture, backTexture, FCPartsTexture.PartTerminalBroad.getIcon(), sideTexture, sideTexture );
|
||||
|
||||
rh.setBounds( 2, 2, 14, 14, 14, 16 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
if( this.getLightLevel() > 0 )
|
||||
{
|
||||
final int l = 13;
|
||||
Tessellator.instance.setBrightness( l << 20 | l << 4 );
|
||||
}
|
||||
|
||||
renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = this.getSpin();
|
||||
|
||||
Tessellator.instance.setColorOpaque_I( this.getColor().whiteVariant );
|
||||
rh.renderFace( x, y, z, this.getFrontBright().getIcon(), ForgeDirection.SOUTH, renderer );
|
||||
|
||||
Tessellator.instance.setColorOpaque_I( this.getColor().mediumVariant );
|
||||
rh.renderFace( x, y, z, this.getFrontDark().getIcon(), ForgeDirection.SOUTH, renderer );
|
||||
|
||||
Tessellator.instance.setColorOpaque_I( this.getColor().blackVariant );
|
||||
rh.renderFace( x, y, z, this.getFrontColored().getIcon(), ForgeDirection.SOUTH, renderer );
|
||||
|
||||
renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0;
|
||||
|
||||
final IIcon sideStatusTexture = CableBusTextures.PartMonitorSidesStatus.getIcon();
|
||||
|
||||
rh.setTexture( sideStatusTexture, sideStatusTexture, backTexture, this.getItemStack().getIconIndex(), sideStatusTexture, sideStatusTexture );
|
||||
|
||||
rh.setBounds( 4, 4, 13, 12, 12, 14 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
final boolean hasChan = ( this.getClientFlags() & ( FCBasePart.POWERED_FLAG | FCBasePart.CHANNEL_FLAG ) ) == ( FCBasePart.POWERED_FLAG | FCBasePart.CHANNEL_FLAG );
|
||||
final boolean hasPower = ( this.getClientFlags() & FCBasePart.POWERED_FLAG ) == FCBasePart.POWERED_FLAG;
|
||||
|
||||
if( hasChan )
|
||||
{
|
||||
final int l = 14;
|
||||
Tessellator.instance.setBrightness( l << 20 | l << 4 );
|
||||
Tessellator.instance.setColorOpaque_I( this.getColor().blackVariant );
|
||||
}
|
||||
else if( hasPower )
|
||||
{
|
||||
final int l = 9;
|
||||
Tessellator.instance.setBrightness( l << 20 | l << 4 );
|
||||
Tessellator.instance.setColorOpaque_I( this.getColor().whiteVariant );
|
||||
}
|
||||
else
|
||||
{
|
||||
Tessellator.instance.setBrightness( 0 );
|
||||
Tessellator.instance.setColorOpaque_I( 0x000000 );
|
||||
}
|
||||
|
||||
final IIcon sideStatusLightTexture = CableBusTextures.PartMonitorSidesStatusLights.getIcon();
|
||||
|
||||
rh.renderFace( x, y, z, sideStatusLightTexture, ForgeDirection.EAST, renderer );
|
||||
rh.renderFace( x, y, z, sideStatusLightTexture, ForgeDirection.WEST, renderer );
|
||||
rh.renderFace( x, y, z, sideStatusLightTexture, ForgeDirection.UP, renderer );
|
||||
rh.renderFace( x, y, z, sideStatusLightTexture, ForgeDirection.DOWN, renderer );
|
||||
}
|
||||
|
||||
/**
|
||||
* The texture used for the bright front layer.
|
||||
* <p>
|
||||
* The final texture can overlap any of the the texture in no particular order.
|
||||
*/
|
||||
public abstract FCPartsTexture getFrontBright();
|
||||
|
||||
/**
|
||||
* The texture used for the colored (medium) front layer.
|
||||
* <p>
|
||||
* The final texture can overlap any of the the texture in no particular order.
|
||||
*/
|
||||
public abstract FCPartsTexture getFrontColored();
|
||||
|
||||
/**
|
||||
* The texture used for the dark front layer.
|
||||
* <p>
|
||||
* The final texture can overlap any of the the texture in no particular order.
|
||||
*/
|
||||
public abstract FCPartsTexture getFrontDark();
|
||||
|
||||
/**
|
||||
* Should the part emit light. This actually only affects the light level, light source use a level of 15 and non
|
||||
* light source 9.
|
||||
*/
|
||||
public abstract boolean isLightSource();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,288 @@
|
||||
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.FluidPatternDetails;
|
||||
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 PartFluidPatternTerminal 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, 9 );
|
||||
private final AppEngInternalInventory output = new AppEngInternalInventory( this, 3 );
|
||||
private final AppEngInternalInventory pattern = new AppEngInternalInventory( this, 2 );
|
||||
|
||||
private boolean craftingMode = true;
|
||||
private boolean substitute = false;
|
||||
|
||||
public PartFluidPatternTerminal(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);
|
||||
}
|
||||
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.setCraftingRecipe( data.getBoolean( "craftingMode" ) );
|
||||
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( "craftingMode", this.craftingMode );
|
||||
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.setCraftingRecipe( details.isCraftable() );
|
||||
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() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( inv == this.crafting )
|
||||
{
|
||||
this.fixCraftingRecipes();
|
||||
}
|
||||
|
||||
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.setCraftingRecipe( details.isCraftable() );
|
||||
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);
|
||||
}
|
||||
|
||||
private void fixCraftingRecipes()
|
||||
{
|
||||
if( this.craftingMode )
|
||||
{
|
||||
for( int x = 0; x < this.crafting.getSizeInventory(); x++ )
|
||||
{
|
||||
final ItemStack is = this.crafting.getStackInSlot( x );
|
||||
if( is != null )
|
||||
{
|
||||
is.stackSize = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCraftingRecipe()
|
||||
{
|
||||
return this.craftingMode;
|
||||
}
|
||||
|
||||
public void setCraftingRecipe( final boolean craftingMode )
|
||||
{
|
||||
this.craftingMode = craftingMode;
|
||||
this.fixCraftingRecipes();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user