Formation Plane Added.

This commit is contained in:
AlgorithmX2 2014-02-17 23:51:31 -06:00
parent 2f056ba3b0
commit da8677b70a
7 changed files with 506 additions and 5 deletions

2
api

@ -1 +1 @@
Subproject commit 65a8c85d4c185ede701c195dbe527f92e5eeb24a
Subproject commit 5eac4a9b50819f7f0dfa3a2393d359d94a9ddd8b

View file

@ -0,0 +1,93 @@
package appeng.client.gui.implementations;
import java.io.IOException;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import org.lwjgl.input.Mouse;
import appeng.api.config.FuzzyMode;
import appeng.api.config.Settings;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.container.implementations.ContainerFormationPlane;
import appeng.core.AELog;
import appeng.core.localization.GuiText;
import appeng.core.sync.GuiBridge;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketConfigButton;
import appeng.core.sync.packets.PacketSwitchGuis;
import appeng.parts.automation.PartFormationPlane;
public class GuiFormationPlane extends GuiUpgradeable
{
GuiTabButton priority;
public GuiFormationPlane(InventoryPlayer inventoryPlayer, PartFormationPlane te) {
super( new ContainerFormationPlane( inventoryPlayer, te ) );
this.ySize = 251;
}
@Override
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY)
{
super.drawBG( offsetX, offsetY, mouseX, mouseY );
}
@Override
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY)
{
fontRendererObj.drawString( GuiText.FormationPlane.getLocal(), 8, 6, 4210752 );
fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 );
if ( fuzzyMode != null )
fuzzyMode.set( cvb.fzMode );
}
@Override
protected void addButtons()
{
fuzzyMode = new GuiImgButton( this.guiLeft - 18, guiTop + 28, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
buttonList.add( priority = new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), itemRender ) );
buttonList.add( fuzzyMode );
}
@Override
protected void actionPerformed(GuiButton btn)
{
super.actionPerformed( btn );
boolean backwards = Mouse.isButtonDown( 1 );
if ( btn == priority )
{
try
{
NetworkHandler.instance.sendToServer( new PacketSwitchGuis( GuiBridge.GUI_PRIORITY ) );
}
catch (IOException e)
{
AELog.error( e );
}
}
try
{
if ( btn == fuzzyMode )
NetworkHandler.instance.sendToServer( new PacketConfigButton( fuzzyMode.getSetting(), backwards ) );
}
catch (IOException e)
{
AELog.error( e );
}
}
protected String getBackground()
{
return "guis/storagebus.png";
}
}

View file

@ -0,0 +1,112 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInventory;
import appeng.api.config.FuzzyMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
import appeng.container.slot.OptionalSlotFakeTypeOnly;
import appeng.container.slot.SlotFakeTypeOnly;
import appeng.container.slot.SlotRestrictedInput;
import appeng.container.slot.SlotRestrictedInput.PlaceableItemType;
import appeng.parts.automation.PartFormationPlane;
import appeng.util.Platform;
public class ContainerFormationPlane extends ContainerUpgradeable
{
PartFormationPlane storageBus;
public ContainerFormationPlane(InventoryPlayer ip, PartFormationPlane te) {
super( ip, te );
storageBus = te;
}
@Override
protected int getHeight()
{
return 251;
}
@Override
public int availableUpgrades()
{
return 5;
}
@Override
protected boolean supportCapacity()
{
return true;
}
@Override
public boolean isSlotEnabled(int idx)
{
int upgrades = myte.getInstalledUpgrades( Upgrades.CAPACITY );
return upgrades > idx;
}
@Override
protected void setupConfig()
{
int xo = 8;
int yo = 23 + 6;
IInventory config = myte.getInventoryByName( "config" );
for (int y = 0; y < 7; y++)
{
for (int x = 0; x < 9; x++)
{
if ( y < 2 )
addSlotToContainer( new SlotFakeTypeOnly( config, y * 9 + x, xo + x * 18, yo + y * 18 ) );
else
addSlotToContainer( new OptionalSlotFakeTypeOnly( config, this, y * 9 + x, xo, yo, x, y, y - 2 ) );
}
}
IInventory upgrades = myte.getInventoryByName( "upgrades" );
addSlotToContainer( (new SlotRestrictedInput( PlaceableItemType.UPGRADES, upgrades, 0, 187, 8 + 18 * 0 )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( PlaceableItemType.UPGRADES, upgrades, 1, 187, 8 + 18 * 1 )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( PlaceableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2 )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( PlaceableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3 )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( PlaceableItemType.UPGRADES, upgrades, 4, 187, 8 + 18 * 4 )).setNotDraggable() );
}
@Override
public void detectAndSendChanges()
{
verifyPermissions( SecurityPermissions.BUILD, false );
if ( Platform.isServer() )
{
for (int i = 0; i < this.crafters.size(); ++i)
{
ICrafting icrafting = (ICrafting) this.crafters.get( i );
if ( this.fzMode != this.myte.getConfigManager().getSetting( Settings.FUZZY_MODE ) )
{
icrafting.sendProgressBarUpdate( this, 4, (int) this.myte.getConfigManager().getSetting( Settings.FUZZY_MODE ).ordinal() );
}
}
this.fzMode = (FuzzyMode) this.myte.getConfigManager().getSetting( Settings.FUZZY_MODE );
}
standardDetectAndSendChanges();
}
@Override
public void updateProgressBar(int idx, int value)
{
super.updateProgressBar( idx, value );
if ( idx == 4 )
this.fzMode = FuzzyMode.values()[value];
}
}

View file

@ -22,7 +22,7 @@ public enum GuiText
SecurityCardEditor, NoPermissions, WirelessTerminal, Wireless,
CraftingTerminal,
CraftingTerminal, FormationPlane,
METunnel, ItemTunnel, RedstoneTunnel, MJTunnel, EUTunnel, FluidTunnel;

View file

@ -33,6 +33,7 @@ import appeng.container.implementations.ContainerChest;
import appeng.container.implementations.ContainerCondenser;
import appeng.container.implementations.ContainerCraftingTerm;
import appeng.container.implementations.ContainerDrive;
import appeng.container.implementations.ContainerFormationPlane;
import appeng.container.implementations.ContainerGrinder;
import appeng.container.implementations.ContainerIOPort;
import appeng.container.implementations.ContainerInterface;
@ -52,6 +53,7 @@ import appeng.container.implementations.ContainerWirelessTerm;
import appeng.helpers.IInterfaceHost;
import appeng.helpers.IPriorityHost;
import appeng.helpers.WirelessTerminalGuiObject;
import appeng.parts.automation.PartFormationPlane;
import appeng.parts.automation.PartLevelEmitter;
import appeng.parts.misc.PartStorageBus;
import appeng.parts.reporting.PartCraftingTerminal;
@ -106,6 +108,8 @@ public enum GuiBridge implements IGuiHandler
GUI_STORAGEBUS(ContainerStorageBus.class, PartStorageBus.class, false, SecurityPermissions.BUILD),
GUI_FPLANE(ContainerFormationPlane.class, PartFormationPlane.class, false, SecurityPermissions.BUILD),
GUI_PRIORITY(ContainerPriority.class, IPriorityHost.class, false, SecurityPermissions.BUILD),
GUI_SECURITY(ContainerSecurity.class, TileSecurity.class, false, SecurityPermissions.SECURITY),

View file

@ -8,6 +8,7 @@ import appeng.core.features.AEFeature;
import appeng.core.localization.GuiText;
import appeng.parts.automation.PartAnnihilationPlane;
import appeng.parts.automation.PartExportBus;
import appeng.parts.automation.PartFormationPlane;
import appeng.parts.automation.PartImportBus;
import appeng.parts.automation.PartLevelEmitter;
import appeng.parts.misc.PartCableAnchor;
@ -65,7 +66,7 @@ public enum PartType
AnnihilationPlane(AEFeature.AnnihilationPlane, PartAnnihilationPlane.class),
// FormationPlane(AEFeature.FormationPlane, PartFormationPlane.class),
FormationPlane(AEFeature.FormationPlane, PartFormationPlane.class),
P2PTunnelME(AEFeature.P2PTunnelME, PartP2PTunnelME.class, GuiText.METunnel),

View file

@ -1,23 +1,117 @@
package appeng.parts.automation;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode;
import appeng.api.config.IncludeExclude;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
import appeng.api.networking.events.MENetworkCellArrayUpdate;
import appeng.api.networking.events.MENetworkChannelsChanged;
import appeng.api.networking.events.MENetworkEventSubscribe;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartCollsionHelper;
import appeng.api.parts.IPartHost;
import appeng.api.parts.IPartRenderHelper;
import appeng.api.storage.ICellContainer;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.api.util.IConfigManager;
import appeng.client.texture.CableBusTextures;
import appeng.parts.PartBasicState;
import appeng.core.sync.GuiBridge;
import appeng.helpers.IPriorityHost;
import appeng.me.GridAccessException;
import appeng.me.storage.MEInventoryHandler;
import appeng.tile.inventory.AppEngInternalAEInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.Platform;
import appeng.util.item.ItemList;
import appeng.util.prioitylist.FuzzyPriorityList;
import appeng.util.prioitylist.PrecisePriorityList;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PartFormationPlane extends PartBasicState
public class PartFormationPlane extends PartUpgradeable implements ICellContainer, IPriorityHost, IMEInventory<IAEItemStack>
{
int priority = 0;
boolean wasActive = false;
boolean blocked = false;
MEInventoryHandler myHandler = new MEInventoryHandler( this );
AppEngInternalAEInventory Config = new AppEngInternalAEInventory( this, 63 );
public PartFormationPlane(ItemStack is) {
super( PartFormationPlane.class, is );
settings.registerSetting( Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
updateHandler();
}
@Override
public boolean onActivate(EntityPlayer player, Vec3 pos)
{
if ( !player.isSneaking() )
{
if ( Platform.isClient() )
return true;
Platform.openGUI( player, getHost().getTile(), side, GuiBridge.GUI_FPLANE );
return true;
}
return false;
}
protected int getUpgradeSlots()
{
return 5;
}
@Override
public IInventory getInventoryByName(String name)
{
if ( name.equals( "config" ) )
return Config;
return super.getInventoryByName( name );
}
@MENetworkEventSubscribe
public void updateChannels(MENetworkChannelsChanged chann)
{
boolean currentActive = proxy.isActive();
if ( wasActive != currentActive )
{
wasActive = currentActive;
try
{
proxy.getGrid().postEvent( new MENetworkCellArrayUpdate() );
}
catch (GridAccessException e)
{
// :P
}
}
}
@Override
@ -129,4 +223,201 @@ public class PartFormationPlane extends PartBasicState
return 1;
}
@Override
public List<IMEInventoryHandler> getCellArray(StorageChannel channel)
{
if ( proxy.isActive() )
{
List<IMEInventoryHandler> Handler = new ArrayList( 1 );
Handler.add( myHandler );
return Handler;
}
return new ArrayList();
}
@Override
public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue)
{
updateHandler();
host.markForSave();
}
@Override
public void setPriority(int newValue)
{
priority = newValue;
host.markForSave();
updateHandler();
}
@Override
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack)
{
super.onChangeInventory( inv, slot, mc, removedStack, newStack );
if ( inv == Config )
updateHandler();
}
private void updateHandler()
{
myHandler.myAccess = AccessRestriction.WRITE;
myHandler.myWhitelist = getInstalledUpgrades( Upgrades.INVERTER ) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST;
myHandler.myPriority = priority;
IItemList priorityList = new ItemList();
int slotsToUse = 18 + getInstalledUpgrades( Upgrades.CAPACITY ) * 9;
for (int x = 0; x < Config.getSizeInventory() && x < slotsToUse; x++)
{
IAEItemStack is = Config.getAEStackInSlot( x );
if ( is != null )
priorityList.add( is );
}
if ( getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
myHandler.myPartitionList = new FuzzyPriorityList( priorityList, (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE ) );
else
myHandler.myPartitionList = new PrecisePriorityList( priorityList );
try
{
proxy.getGrid().postEvent( new MENetworkCellArrayUpdate() );
}
catch (GridAccessException e)
{
// :P
}
}
@Override
public void writeToNBT(NBTTagCompound data)
{
super.writeToNBT( data );
Config.writeToNBT( data, "config" );
data.setInteger( "priority", priority );
}
public void readFromNBT(NBTTagCompound data)
{
super.readFromNBT( data );
Config.readFromNBT( data, "config" );
priority = data.getInteger( "priority" );
updateHandler();
}
@Override
public IAEItemStack extractItems(IAEItemStack request, Actionable mode, BaseActionSource src)
{
return null;
}
@Override
public IItemList<IAEItemStack> getAvailableItems(IItemList<IAEItemStack> out)
{
return out;
}
@Override
public StorageChannel getChannel()
{
return StorageChannel.ITEMS;
}
@Override
public int getPriority()
{
return priority;
}
@Override
public void blinkCell(int slot)
{
// :P
}
@Override
public void onNeighborChanged()
{
TileEntity te = host.getTile();
World w = te.getWorldObj();
ForgeDirection side = this.side;
int x = te.xCoord + side.offsetX;
int y = te.yCoord + side.offsetY;
int z = te.zCoord + side.offsetZ;
blocked = !w.getBlock( x, y, z ).isAir( w, x, y, z );
}
@Override
public IAEItemStack injectItems(IAEItemStack input, Actionable type, BaseActionSource src)
{
if ( blocked || input == null || input.getStackSize() <= 0 )
return input;
ItemStack is = input.getItemStack();
Item i = is.getItem();
long maxStorage = Math.min( input.getStackSize(), is.getMaxStackSize() );
boolean worked = false;
TileEntity te = host.getTile();
World w = te.getWorldObj();
ForgeDirection side = this.side;
int x = te.xCoord + side.offsetX;
int y = te.yCoord + side.offsetY;
int z = te.zCoord + side.offsetZ;
if ( w.getBlock( x, y, z ).isAir( w, x, y, z ) )
{
if ( i instanceof ItemBlock || i instanceof IPlantable )
{
EntityPlayer player = Platform.getPlayer( (WorldServer) w );
player.prevCameraPitch = player.cameraPitch = 0;
player.prevCameraYaw = player.cameraYaw = 0;
maxStorage = is.stackSize;
worked = true;
if ( type == Actionable.MODULATE )
{
i.onItemUse( is, player, w, x, y, z, side.ordinal(), side.offsetX, side.offsetY, side.offsetZ );
maxStorage = maxStorage - is.stackSize;
}
else
maxStorage = 1;
}
else
{
worked = true;
Chunk c = w.getChunkFromBlockCoords( x, z );
int sum = 0;
for (List Z : c.entityLists)
sum += Z.size();
if ( sum < 32 )
{
if ( type == Actionable.MODULATE )
{
is.stackSize = (int) maxStorage;
List<ItemStack> out = new ArrayList( 1 );
out.add( is );
if ( type == Actionable.MODULATE )
Platform.spawnDrops( w, x, y, z, out );
}
}
}
}
blocked = !w.getBlock( x, y, z ).isAir( w, x, y, z );
if ( worked )
{
IAEItemStack out = input.copy();
out.decStackSize( maxStorage );
return out;
}
return input;
}
}