Relocate Source to proper directory.
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package appeng.items.tools.powered;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.sync.packets.PacketLightning;
|
||||
import appeng.items.tools.powered.powersink.AEBasePoweredItem;
|
||||
import appeng.server.ServerHelper;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class ToolChargedStaff extends AEBasePoweredItem
|
||||
{
|
||||
|
||||
public ToolChargedStaff() {
|
||||
super( ToolChargedStaff.class, null );
|
||||
setFeature( EnumSet.of( AEFeature.ChargedStaff, AEFeature.PoweredTools ) );
|
||||
maxStoredPower = AEConfig.instance.staff_battery;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hitEntity(ItemStack item, EntityLivingBase target, EntityLivingBase hitter)
|
||||
{
|
||||
if ( this.getAECurrentPower( item ) > 300 )
|
||||
{
|
||||
extractAEPower( item, 300 );
|
||||
if ( Platform.isServer() )
|
||||
{
|
||||
try
|
||||
{
|
||||
for (int x = 0; x < 2; x++)
|
||||
{
|
||||
float dx = (float) (Platform.getRandomFloat() * target.width + target.boundingBox.minX);
|
||||
float dy = (float) (Platform.getRandomFloat() * target.height + target.boundingBox.minY);
|
||||
float dz = (float) (Platform.getRandomFloat() * target.width + target.boundingBox.minZ);
|
||||
ServerHelper.proxy.sendToAllNearExcept( null, dx, dy, dz, 32.0, target.worldObj, new PacketLightning( dx, dy, dz ) );
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
target.attackEntityFrom( DamageSource.magic, 6 );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,493 @@
|
||||
package appeng.items.tools.powered;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemSnowball;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.implementations.items.IItemGroup;
|
||||
import appeng.api.implementations.items.IStorageCell;
|
||||
import appeng.api.implementations.tiles.IColorableTile;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.storage.ICellInventory;
|
||||
import appeng.api.storage.ICellInventoryHandler;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.block.misc.BlockPaint;
|
||||
import appeng.block.networking.BlockCableBus;
|
||||
import appeng.client.render.items.ToolColorApplicatorRender;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.helpers.IMouseWheelItem;
|
||||
import appeng.hooks.DispenserBlockTool;
|
||||
import appeng.hooks.IBlockTool;
|
||||
import appeng.items.contents.CellConfig;
|
||||
import appeng.items.contents.CellUpgrades;
|
||||
import appeng.items.misc.ItemPaintBall;
|
||||
import appeng.items.tools.powered.powersink.AEBasePoweredItem;
|
||||
import appeng.me.storage.CellInventoryHandler;
|
||||
import appeng.tile.misc.TilePaint;
|
||||
import appeng.util.ItemSorters;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCell, IItemGroup, IBlockTool, IMouseWheelItem
|
||||
{
|
||||
|
||||
final static HashMap<Integer, AEColor> oreToColor = new HashMap();
|
||||
|
||||
static
|
||||
{
|
||||
|
||||
for (AEColor col : AEColor.values())
|
||||
{
|
||||
if ( col == AEColor.Transparent )
|
||||
continue;
|
||||
|
||||
oreToColor.put( OreDictionary.getOreID( "dye" + col.name() ), col );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public ToolColorApplicator() {
|
||||
super( ToolColorApplicator.class, null );
|
||||
setFeature( EnumSet.of( AEFeature.ColorApplicator, AEFeature.PoweredTools ) );
|
||||
maxStoredPower = AEConfig.instance.colorapplicator_battery;
|
||||
if ( Platform.isClient() )
|
||||
MinecraftForgeClient.registerItemRenderer( this, new ToolColorApplicatorRender() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInit()
|
||||
{
|
||||
super.postInit();
|
||||
BlockDispenser.dispenseBehaviorRegistry.putObject( this, new DispenserBlockTool() );
|
||||
}
|
||||
|
||||
public ItemStack getColor(ItemStack is)
|
||||
{
|
||||
NBTTagCompound c = is.getTagCompound();
|
||||
if ( c != null && c.hasKey( "color" ) )
|
||||
{
|
||||
NBTTagCompound color = c.getCompoundTag( "color" );
|
||||
ItemStack oldColor = ItemStack.loadItemStackFromNBT( color );
|
||||
if ( oldColor != null )
|
||||
return oldColor;
|
||||
}
|
||||
|
||||
return findNextColor( is, null, 0 );
|
||||
}
|
||||
|
||||
public AEColor getColorFromItem(ItemStack paintBall)
|
||||
{
|
||||
if ( paintBall == null )
|
||||
return null;
|
||||
|
||||
if ( paintBall.getItem() instanceof ItemSnowball )
|
||||
return AEColor.Transparent;
|
||||
|
||||
if ( paintBall.getItem() instanceof ItemPaintBall )
|
||||
{
|
||||
ItemPaintBall ipb = (ItemPaintBall) paintBall.getItem();
|
||||
return ipb.getColor( paintBall );
|
||||
}
|
||||
else
|
||||
{
|
||||
int[] id = OreDictionary.getOreIDs( paintBall );
|
||||
|
||||
for (int oreID : id)
|
||||
{
|
||||
if ( oreToColor.containsKey( oreID ) )
|
||||
return oreToColor.get( oreID );
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public AEColor getActiveColor(ItemStack tol)
|
||||
{
|
||||
return getColorFromItem( getColor( tol ) );
|
||||
}
|
||||
|
||||
private ItemStack findNextColor(ItemStack is, ItemStack anchor, int scrollOffset)
|
||||
{
|
||||
ItemStack newColor = null;
|
||||
|
||||
IMEInventory<IAEItemStack> inv = AEApi.instance().registries().cell().getCellInventory( is, null, StorageChannel.ITEMS );
|
||||
if ( inv != null )
|
||||
{
|
||||
IItemList<IAEItemStack> itemList = inv.getAvailableItems( AEApi.instance().storage().createItemList() );
|
||||
if ( anchor == null )
|
||||
{
|
||||
IAEItemStack firstItem = itemList.getFirstItem();
|
||||
if ( firstItem != null )
|
||||
newColor = firstItem.getItemStack();
|
||||
}
|
||||
else
|
||||
{
|
||||
LinkedList<IAEItemStack> list = new LinkedList<IAEItemStack>();
|
||||
|
||||
for (IAEItemStack i : itemList)
|
||||
list.add( i );
|
||||
|
||||
Collections.sort( list, new Comparator<IAEItemStack>() {
|
||||
|
||||
public int compare(IAEItemStack a, IAEItemStack b)
|
||||
{
|
||||
return ItemSorters.compareInt( a.getItemDamage(), b.getItemDamage() );
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
if ( list.size() <= 0 )
|
||||
return null;
|
||||
|
||||
IAEItemStack where = list.getFirst();
|
||||
int cycles = 1 + list.size();
|
||||
|
||||
while (cycles > 0 && !where.equals( anchor ))
|
||||
{
|
||||
list.addLast( list.removeFirst() );
|
||||
cycles--;
|
||||
where = list.getFirst();
|
||||
}
|
||||
|
||||
if ( scrollOffset > 0 )
|
||||
list.addLast( list.removeFirst() );
|
||||
|
||||
if ( scrollOffset < 0 )
|
||||
list.addFirst( list.removeLast() );
|
||||
|
||||
return list.get( 0 ).getItemStack();
|
||||
}
|
||||
}
|
||||
|
||||
if ( newColor != null )
|
||||
setColor( is, newColor );
|
||||
|
||||
return newColor;
|
||||
}
|
||||
|
||||
public void setColor(ItemStack is, ItemStack newColor)
|
||||
{
|
||||
NBTTagCompound data = Platform.openNbtData( is );
|
||||
if ( newColor == null )
|
||||
data.removeTag( "color" );
|
||||
else
|
||||
{
|
||||
NBTTagCompound color = new NBTTagCompound();
|
||||
newColor.writeToNBT( color );
|
||||
data.setTag( "color", color );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUse(ItemStack is, EntityPlayer p, World w, int x, int y, int z, int side, float hitx, float hity, float hitz)
|
||||
{
|
||||
Block blk = w.getBlock( x, y, z );
|
||||
double powerPerUse = 100;
|
||||
|
||||
ItemStack paintBall = getColor( is );
|
||||
|
||||
IMEInventory<IAEItemStack> inv = AEApi.instance().registries().cell().getCellInventory( is, null, StorageChannel.ITEMS );
|
||||
if ( inv != null )
|
||||
{
|
||||
IAEItemStack option = inv.extractItems( AEItemStack.create( paintBall ), Actionable.SIMULATE, new BaseActionSource() );
|
||||
|
||||
if ( option != null )
|
||||
{
|
||||
paintBall = option.getItemStack();
|
||||
paintBall.stackSize = 1;
|
||||
}
|
||||
else
|
||||
paintBall = null;
|
||||
|
||||
if ( !Platform.hasPermissions( new DimensionalCoord( w, x, y, z ), p ) )
|
||||
return false;
|
||||
|
||||
if ( paintBall != null && paintBall.getItem() instanceof ItemSnowball )
|
||||
{
|
||||
ForgeDirection oside = ForgeDirection.getOrientation( side );
|
||||
TileEntity te = w.getTileEntity( x, y, z );
|
||||
// clean cables.
|
||||
if ( te instanceof IColorableTile )
|
||||
{
|
||||
if ( getAECurrentPower( is ) > powerPerUse && ((IColorableTile) te).getColor() != AEColor.Transparent )
|
||||
{
|
||||
if ( ((IColorableTile) te).recolourBlock( oside, AEColor.Transparent, p ) )
|
||||
{
|
||||
inv.extractItems( AEItemStack.create( paintBall ), Actionable.MODULATE, new BaseActionSource() );
|
||||
extractAEPower( is, powerPerUse );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// clean paint balls..
|
||||
Block testBlk = w.getBlock( x + oside.offsetX, y + oside.offsetY, z + oside.offsetZ );
|
||||
TileEntity painted = w.getTileEntity( x + oside.offsetX, y + oside.offsetY, z + oside.offsetZ );
|
||||
if ( getAECurrentPower( is ) > powerPerUse && testBlk instanceof BlockPaint && painted instanceof TilePaint )
|
||||
{
|
||||
inv.extractItems( AEItemStack.create( paintBall ), Actionable.MODULATE, new BaseActionSource() );
|
||||
extractAEPower( is, powerPerUse );
|
||||
((TilePaint) painted).cleanSide( oside.getOpposite() );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if ( paintBall != null )
|
||||
{
|
||||
AEColor color = getColorFromItem( paintBall );
|
||||
|
||||
if ( color != null && getAECurrentPower( is ) > powerPerUse )
|
||||
{
|
||||
if ( color != AEColor.Transparent
|
||||
&& recolourBlock( blk, ForgeDirection.getOrientation( side ), w, x, y, z, ForgeDirection.getOrientation( side ), color, p ) )
|
||||
{
|
||||
inv.extractItems( AEItemStack.create( paintBall ), Actionable.MODULATE, new BaseActionSource() );
|
||||
extractAEPower( is, powerPerUse );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ( p.isSneaking() )
|
||||
{
|
||||
cycleColors( is, paintBall, 1 );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean recolourBlock(Block blk, ForgeDirection side, World w, int x, int y, int z, ForgeDirection orientation, AEColor newColor, EntityPlayer p)
|
||||
{
|
||||
if ( blk == Blocks.carpet )
|
||||
{
|
||||
int meta = w.getBlockMetadata( x, y, z );
|
||||
if ( newColor.ordinal() == meta )
|
||||
return false;
|
||||
return w.setBlock( x, y, z, Blocks.carpet, newColor.ordinal(), 3 );
|
||||
}
|
||||
|
||||
if ( blk == Blocks.glass )
|
||||
{
|
||||
return w.setBlock( x, y, z, Blocks.stained_glass, newColor.ordinal(), 3 );
|
||||
}
|
||||
|
||||
if ( blk == Blocks.stained_glass )
|
||||
{
|
||||
int meta = w.getBlockMetadata( x, y, z );
|
||||
if ( newColor.ordinal() == meta )
|
||||
return false;
|
||||
return w.setBlock( x, y, z, Blocks.stained_glass, newColor.ordinal(), 3 );
|
||||
}
|
||||
|
||||
if ( blk == Blocks.glass_pane )
|
||||
{
|
||||
return w.setBlock( x, y, z, Blocks.stained_glass_pane, newColor.ordinal(), 3 );
|
||||
}
|
||||
|
||||
if ( blk == Blocks.stained_glass_pane )
|
||||
{
|
||||
int meta = w.getBlockMetadata( x, y, z );
|
||||
if ( newColor.ordinal() == meta )
|
||||
return false;
|
||||
return w.setBlock( x, y, z, Blocks.stained_glass_pane, newColor.ordinal(), 3 );
|
||||
}
|
||||
|
||||
if ( blk == Blocks.hardened_clay )
|
||||
{
|
||||
return w.setBlock( x, y, z, Blocks.stained_hardened_clay, newColor.ordinal(), 3 );
|
||||
}
|
||||
|
||||
if ( blk == Blocks.stained_hardened_clay )
|
||||
{
|
||||
int meta = w.getBlockMetadata( x, y, z );
|
||||
if ( newColor.ordinal() == meta )
|
||||
return false;
|
||||
return w.setBlock( x, y, z, Blocks.stained_hardened_clay, newColor.ordinal(), 3 );
|
||||
}
|
||||
|
||||
if ( blk instanceof BlockCableBus )
|
||||
return ((BlockCableBus) blk).recolourBlock( w, x, y, z, side, newColor.ordinal(), p );
|
||||
|
||||
return blk.recolourBlock( w, x, y, z, side, newColor.ordinal() );
|
||||
}
|
||||
|
||||
public void cycleColors(ItemStack is, ItemStack paintBall, int i)
|
||||
{
|
||||
if ( paintBall == null )
|
||||
{
|
||||
setColor( is, getColor( is ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
setColor( is, findNextColor( is, paintBall, i ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemStackDisplayName(ItemStack par1ItemStack)
|
||||
{
|
||||
String extra = GuiText.Empty.getLocal();
|
||||
|
||||
AEColor selected = getActiveColor( par1ItemStack );
|
||||
|
||||
if ( selected != null )
|
||||
extra = Platform.gui_localize( selected.unlocalizedName );
|
||||
|
||||
return super.getItemStackDisplayName( par1ItemStack ) + " - " + extra;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack is, EntityPlayer player, List lines, boolean advancedItemTooltips)
|
||||
{
|
||||
super.addInformation( is, player, lines, advancedItemTooltips );
|
||||
|
||||
IMEInventory<IAEItemStack> cdi = AEApi.instance().registries().cell().getCellInventory( is, null, StorageChannel.ITEMS );
|
||||
|
||||
if ( cdi instanceof CellInventoryHandler )
|
||||
{
|
||||
ICellInventory cd = ((ICellInventoryHandler) cdi).getCellInv();
|
||||
if ( cd != null )
|
||||
{
|
||||
lines.add( cd.getUsedBytes() + " " + GuiText.Of.getLocal() + " " + cd.getTotalBytes() + " " + GuiText.BytesUsed.getLocal() );
|
||||
lines.add( cd.getStoredItemTypes() + " " + GuiText.Of.getLocal() + " " + cd.getTotalItemTypes() + " " + GuiText.Types.getLocal() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBytes(ItemStack cellItem)
|
||||
{
|
||||
return 512;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int BytePerType(ItemStack iscellItem)
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalTypes(ItemStack cellItem)
|
||||
{
|
||||
return 27;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlackListed(ItemStack cellItem, IAEItemStack requestedAddition)
|
||||
{
|
||||
if ( requestedAddition != null )
|
||||
{
|
||||
int[] id = OreDictionary.getOreIDs( requestedAddition.getItemStack() );
|
||||
|
||||
for (int x : id)
|
||||
{
|
||||
if ( oreToColor.containsKey( x ) )
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( requestedAddition.getItem() instanceof ItemSnowball )
|
||||
return false;
|
||||
|
||||
return !(requestedAddition.getItem() instanceof ItemPaintBall && requestedAddition.getItemDamage() < 20);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean storableInStorageCell()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStorageCell(ItemStack i)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getUpgradesInventory(ItemStack is)
|
||||
{
|
||||
return new CellUpgrades( is, 2 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getConfigInventory(ItemStack is)
|
||||
{
|
||||
return new CellConfig( is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public FuzzyMode getFuzzyMode(ItemStack is)
|
||||
{
|
||||
String fz = Platform.openNbtData( is ).getString( "FuzzyMode" );
|
||||
try
|
||||
{
|
||||
return FuzzyMode.valueOf( fz );
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
return FuzzyMode.IGNORE_ALL;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedGroupName(Set<ItemStack> others, ItemStack is)
|
||||
{
|
||||
return GuiText.StorageCells.getUnlocalized();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFuzzyMode(ItemStack is, FuzzyMode fzMode)
|
||||
{
|
||||
Platform.openNbtData( is ).setString( "FuzzyMode", fzMode.name() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEditable(ItemStack is)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getIdleDrain()
|
||||
{
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWheel(ItemStack is, boolean up)
|
||||
{
|
||||
cycleColors( is, getColor( is ), up ? 1 : -1 );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,325 @@
|
||||
package appeng.items.tools.powered;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.block.BlockTNT;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.FurnaceRecipes;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.block.misc.BlockTinyTNT;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.hooks.DispenserBlockTool;
|
||||
import appeng.hooks.IBlockTool;
|
||||
import appeng.items.tools.powered.powersink.AEBasePoweredItem;
|
||||
import appeng.util.InWorldToolOperationResult;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockTool
|
||||
{
|
||||
|
||||
static class Combo
|
||||
{
|
||||
|
||||
final public Block blk;
|
||||
final public int meta;
|
||||
|
||||
public Combo(Block b, int m) {
|
||||
blk = b;
|
||||
meta = m;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return blk.hashCode() ^ meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
return blk == ((Combo) obj).blk && meta == ((Combo) obj).meta;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
static private Hashtable<Combo, InWorldToolOperationResult> heatUp;
|
||||
static private Hashtable<Combo, InWorldToolOperationResult> coolDown;
|
||||
|
||||
static public void heat(Block BlockID, int Metadata, World w, int x, int y, int z)
|
||||
{
|
||||
InWorldToolOperationResult r = heatUp.get( new Combo( BlockID, Metadata ) );
|
||||
|
||||
if ( r == null )
|
||||
{
|
||||
r = heatUp.get( new Combo( BlockID, OreDictionary.WILDCARD_VALUE ) );
|
||||
}
|
||||
|
||||
if ( r.BlockItem != null )
|
||||
{
|
||||
w.setBlock( x, y, z, Block.getBlockFromItem( r.BlockItem.getItem() ), r.BlockItem.getItemDamage(), 3 );
|
||||
}
|
||||
else
|
||||
{
|
||||
w.setBlock( x, y, z, Platform.air, 0, 3 );
|
||||
}
|
||||
|
||||
if ( r.Drops != null )
|
||||
{
|
||||
Platform.spawnDrops( w, x, y, z, r.Drops );
|
||||
}
|
||||
}
|
||||
|
||||
static public boolean canHeat(Block BlockID, int Metadata)
|
||||
{
|
||||
InWorldToolOperationResult r = heatUp.get( new Combo( BlockID, Metadata ) );
|
||||
|
||||
if ( r == null )
|
||||
{
|
||||
r = heatUp.get( new Combo( BlockID, OreDictionary.WILDCARD_VALUE ) );
|
||||
}
|
||||
|
||||
return r != null;
|
||||
}
|
||||
|
||||
static public void cool(Block BlockID, int Metadata, World w, int x, int y, int z)
|
||||
{
|
||||
InWorldToolOperationResult r = coolDown.get( new Combo( BlockID, Metadata ) );
|
||||
|
||||
if ( r == null )
|
||||
{
|
||||
r = coolDown.get( new Combo( BlockID, OreDictionary.WILDCARD_VALUE ) );
|
||||
}
|
||||
|
||||
if ( r.BlockItem != null )
|
||||
{
|
||||
w.setBlock( x, y, z, Block.getBlockFromItem( r.BlockItem.getItem() ), r.BlockItem.getItemDamage(), 3 );
|
||||
}
|
||||
else
|
||||
{
|
||||
w.setBlock( x, y, z, Platform.air, 0, 3 );
|
||||
}
|
||||
|
||||
if ( r.Drops != null )
|
||||
{
|
||||
Platform.spawnDrops( w, x, y, z, r.Drops );
|
||||
}
|
||||
}
|
||||
|
||||
static public boolean canCool(Block BlockID, int Metadata)
|
||||
{
|
||||
InWorldToolOperationResult r = coolDown.get( new Combo( BlockID, Metadata ) );
|
||||
|
||||
if ( r == null )
|
||||
{
|
||||
r = coolDown.get( new Combo( BlockID, OreDictionary.WILDCARD_VALUE ) );
|
||||
}
|
||||
|
||||
return r != null;
|
||||
}
|
||||
|
||||
public ToolEntropyManipulator() {
|
||||
super( ToolEntropyManipulator.class, null );
|
||||
setFeature( EnumSet.of( AEFeature.EntropyManipulator, AEFeature.PoweredTools ) );
|
||||
maxStoredPower = AEConfig.instance.manipulator_battery;
|
||||
|
||||
coolDown = new Hashtable<Combo, InWorldToolOperationResult>();
|
||||
coolDown.put( new Combo( Blocks.stone, 0 ), new InWorldToolOperationResult( new ItemStack( Blocks.cobblestone ) ) );
|
||||
coolDown.put( new Combo( Blocks.stonebrick, 0 ), new InWorldToolOperationResult( new ItemStack( Blocks.stonebrick, 1, 2 ) ) );
|
||||
coolDown.put( new Combo( Blocks.lava, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult( new ItemStack( Blocks.obsidian ) ) );
|
||||
coolDown.put( new Combo( Blocks.flowing_lava, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult( new ItemStack( Blocks.obsidian ) ) );
|
||||
coolDown.put( new Combo( Blocks.grass, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult( new ItemStack( Blocks.dirt ) ) );
|
||||
|
||||
List<ItemStack> snowBalls = new ArrayList();
|
||||
snowBalls.add( new ItemStack( Items.snowball ) );
|
||||
coolDown.put( new Combo( Blocks.flowing_water, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult( null, snowBalls ) );
|
||||
coolDown.put( new Combo( Blocks.water, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult( new ItemStack( Blocks.ice ) ) );
|
||||
|
||||
heatUp = new Hashtable<Combo, InWorldToolOperationResult>();
|
||||
heatUp.put( new Combo( Blocks.ice, 0 ), new InWorldToolOperationResult( new ItemStack( Blocks.water ) ) );
|
||||
heatUp.put( new Combo( Blocks.flowing_water, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult() );
|
||||
heatUp.put( new Combo( Blocks.water, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult() );
|
||||
heatUp.put( new Combo( Blocks.snow, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult( new ItemStack( Blocks.flowing_water ) ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInit()
|
||||
{
|
||||
super.postInit();
|
||||
BlockDispenser.dispenseBehaviorRegistry.putObject( this, new DispenserBlockTool() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hitEntity(ItemStack item, EntityLivingBase target, EntityLivingBase hitter)
|
||||
{
|
||||
if ( this.getAECurrentPower( item ) > 1600 )
|
||||
{
|
||||
extractAEPower( item, 1600 );
|
||||
target.setFire( 8 );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack item, World w, EntityPlayer p)
|
||||
{
|
||||
MovingObjectPosition target = this.getMovingObjectPositionFromPlayer( w, p, true );
|
||||
|
||||
if ( target == null )
|
||||
return item;
|
||||
else
|
||||
{
|
||||
if ( target.typeOfHit == MovingObjectType.BLOCK )
|
||||
{
|
||||
int x = target.blockX;
|
||||
int y = target.blockY;
|
||||
int z = target.blockZ;
|
||||
|
||||
if ( w.getBlock( x, y, z ).getMaterial() == Material.lava || w.getBlock( x, y, z ).getMaterial() == Material.water )
|
||||
{
|
||||
if ( Platform.hasPermissions( new DimensionalCoord( w, x, y, z ), p ) )
|
||||
{
|
||||
onItemUse( item, p, w, x, y, z, 0, 0.0F, 0.0F, 0.0F );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUse(ItemStack item, EntityPlayer p, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if ( this.getAECurrentPower( item ) > 1600 )
|
||||
{
|
||||
if ( !p.canPlayerEdit( x, y, z, side, item ) )
|
||||
return false;
|
||||
|
||||
Block Blk = w.getBlock( x, y, z );
|
||||
int Metadata = w.getBlockMetadata( x, y, z );
|
||||
|
||||
if ( p.isSneaking() )
|
||||
{
|
||||
if ( canCool( Blk, Metadata ) )
|
||||
{
|
||||
extractAEPower( item, 1600 );
|
||||
cool( Blk, Metadata, w, x, y, z );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( Blk instanceof BlockTNT )
|
||||
{
|
||||
w.setBlock( x, y, z, Platform.air, 0, 3 );
|
||||
((BlockTNT) Blk).func_150114_a( w, x, y, z, 1, p );
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( Blk instanceof BlockTinyTNT )
|
||||
{
|
||||
w.setBlock( x, y, z, Platform.air, 0, 3 );
|
||||
((BlockTinyTNT) Blk).startFuse( w, x, y, z, p );
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( canHeat( Blk, Metadata ) )
|
||||
{
|
||||
extractAEPower( item, 1600 );
|
||||
heat( Blk, Metadata, w, x, y, z );
|
||||
return true;
|
||||
}
|
||||
|
||||
ItemStack[] stack = Platform.getBlockDrops( w, x, y, z );
|
||||
List<ItemStack> out = new ArrayList<ItemStack>();
|
||||
boolean hasFurnaceable = false;
|
||||
boolean canFurnaceable = true;
|
||||
|
||||
for (ItemStack i : stack)
|
||||
{
|
||||
ItemStack result = FurnaceRecipes.smelting().getSmeltingResult( i );
|
||||
|
||||
if ( result != null )
|
||||
{
|
||||
if ( result.getItem() instanceof ItemBlock )
|
||||
{
|
||||
if ( Block.getBlockFromItem( (ItemBlock) result.getItem() ) == Blk && result.getItem().getDamage( result ) == Metadata )
|
||||
{
|
||||
canFurnaceable = false;
|
||||
}
|
||||
}
|
||||
hasFurnaceable = true;
|
||||
out.add( result );
|
||||
}
|
||||
else
|
||||
{
|
||||
canFurnaceable = false;
|
||||
out.add( i );
|
||||
}
|
||||
}
|
||||
|
||||
if ( hasFurnaceable && canFurnaceable )
|
||||
{
|
||||
extractAEPower( item, 1600 );
|
||||
InWorldToolOperationResult or = InWorldToolOperationResult.getBlockOperationResult( out.toArray( new ItemStack[out.size()] ) );
|
||||
w.playSoundEffect( (double) x + 0.5D, (double) y + 0.5D, (double) z + 0.5D, "fire.ignite", 1.0F, itemRand.nextFloat() * 0.4F + 0.8F );
|
||||
|
||||
if ( or.BlockItem == null )
|
||||
{
|
||||
w.setBlock( x, y, z, Platform.air, 0, 3 );
|
||||
}
|
||||
else
|
||||
{
|
||||
w.setBlock( x, y, z, Block.getBlockFromItem( or.BlockItem.getItem() ), or.BlockItem.getItemDamage(), 3 );
|
||||
}
|
||||
|
||||
if ( or.Drops != null )
|
||||
{
|
||||
Platform.spawnDrops( w, x, y, z, or.Drops );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ForgeDirection dir = ForgeDirection.getOrientation( side );
|
||||
x += dir.offsetX;
|
||||
y += dir.offsetY;
|
||||
z += dir.offsetZ;
|
||||
|
||||
if ( !p.canPlayerEdit( x, y, z, side, item ) )
|
||||
return false;
|
||||
|
||||
if ( w.isAirBlock( x, y, z ) )
|
||||
{
|
||||
extractAEPower( item, 1600 );
|
||||
w.playSoundEffect( (double) x + 0.5D, (double) y + 0.5D, (double) z + 0.5D, "fire.ignite", 1.0F, itemRand.nextFloat() * 0.4F + 0.8F );
|
||||
w.setBlock( x, y, z, Blocks.fire );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,506 @@
|
||||
package appeng.items.tools.powered;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.passive.EntitySheep;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.implementations.items.IStorageCell;
|
||||
import appeng.api.networking.security.PlayerSource;
|
||||
import appeng.api.storage.ICellInventory;
|
||||
import appeng.api.storage.ICellInventoryHandler;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.CommonHelper;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.localization.PlayerMessages;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketMatterCannon;
|
||||
import appeng.hooks.DispenserMatterCannon;
|
||||
import appeng.hooks.TickHandler;
|
||||
import appeng.hooks.TickHandler.PlayerColor;
|
||||
import appeng.items.contents.CellConfig;
|
||||
import appeng.items.contents.CellUpgrades;
|
||||
import appeng.items.misc.ItemPaintBall;
|
||||
import appeng.items.tools.powered.powersink.AEBasePoweredItem;
|
||||
import appeng.me.storage.CellInventoryHandler;
|
||||
import appeng.tile.misc.TilePaint;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell
|
||||
{
|
||||
|
||||
public ToolMassCannon() {
|
||||
super( ToolMassCannon.class, null );
|
||||
setFeature( EnumSet.of( AEFeature.MatterCannon, AEFeature.PoweredTools ) );
|
||||
maxStoredPower = AEConfig.instance.mattercannon_battery;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInit()
|
||||
{
|
||||
super.postInit();
|
||||
BlockDispenser.dispenseBehaviorRegistry.putObject( this, new DispenserMatterCannon() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack is, EntityPlayer player, List lines, boolean advancedItemTooltips)
|
||||
{
|
||||
super.addInformation( is, player, lines, advancedItemTooltips );
|
||||
|
||||
IMEInventory<IAEItemStack> cdi = AEApi.instance().registries().cell().getCellInventory( is, null, StorageChannel.ITEMS );
|
||||
|
||||
if ( cdi instanceof CellInventoryHandler )
|
||||
{
|
||||
ICellInventory cd = ((ICellInventoryHandler) cdi).getCellInv();
|
||||
if ( cd != null )
|
||||
{
|
||||
lines.add( cd.getUsedBytes() + " " + GuiText.Of.getLocal() + " " + cd.getTotalBytes() + " " + GuiText.BytesUsed.getLocal() );
|
||||
lines.add( cd.getStoredItemTypes() + " " + GuiText.Of.getLocal() + " " + cd.getTotalItemTypes() + " " + GuiText.Types.getLocal() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack item, World w, EntityPlayer p)
|
||||
{
|
||||
if ( this.getAECurrentPower( item ) > 1600 )
|
||||
{
|
||||
int shots = 1;
|
||||
|
||||
CellUpgrades cu = (CellUpgrades) getUpgradesInventory( item );
|
||||
if ( cu != null )
|
||||
shots += cu.getInstalledUpgrades( Upgrades.SPEED );
|
||||
|
||||
IMEInventory inv = AEApi.instance().registries().cell().getCellInventory( item, null, StorageChannel.ITEMS );
|
||||
if ( inv != null )
|
||||
{
|
||||
IItemList itemList = inv.getAvailableItems( AEApi.instance().storage().createItemList() );
|
||||
IAEStack aeammo = itemList.getFirstItem();
|
||||
if ( aeammo instanceof IAEItemStack )
|
||||
{
|
||||
shots = Math.min( shots, (int) aeammo.getStackSize() );
|
||||
for (int sh = 0; sh < shots; sh++)
|
||||
{
|
||||
extractAEPower( item, 1600 );
|
||||
|
||||
if ( Platform.isClient() )
|
||||
return item;
|
||||
|
||||
aeammo.setStackSize( 1 );
|
||||
ItemStack ammo = ((IAEItemStack) aeammo).getItemStack();
|
||||
if ( ammo == null )
|
||||
return item;
|
||||
|
||||
ammo.stackSize = 1;
|
||||
aeammo = inv.extractItems( aeammo, Actionable.MODULATE, new PlayerSource( p, null ) );
|
||||
if ( aeammo == null )
|
||||
return item;
|
||||
|
||||
float f = 1.0F;
|
||||
float f1 = p.prevRotationPitch + (p.rotationPitch - p.prevRotationPitch) * f;
|
||||
float f2 = p.prevRotationYaw + (p.rotationYaw - p.prevRotationYaw) * f;
|
||||
double d0 = p.prevPosX + (p.posX - p.prevPosX) * (double) f;
|
||||
double d1 = p.prevPosY + (p.posY - p.prevPosY) * (double) f + 1.62D - (double) p.yOffset;
|
||||
double d2 = p.prevPosZ + (p.posZ - p.prevPosZ) * (double) f;
|
||||
Vec3 vec3 = Vec3.createVectorHelper( d0, d1, d2 );
|
||||
float f3 = MathHelper.cos( -f2 * 0.017453292F - (float) Math.PI );
|
||||
float f4 = MathHelper.sin( -f2 * 0.017453292F - (float) Math.PI );
|
||||
float f5 = -MathHelper.cos( -f1 * 0.017453292F );
|
||||
float f6 = MathHelper.sin( -f1 * 0.017453292F );
|
||||
float f7 = f4 * f5;
|
||||
float f8 = f3 * f5;
|
||||
double d3 = 32.0D;
|
||||
|
||||
Vec3 vec31 = vec3.addVector( (double) f7 * d3, (double) f6 * d3, (double) f8 * d3 );
|
||||
Vec3 direction = Vec3.createVectorHelper( (double) f7 * d3, (double) f6 * d3, (double) f8 * d3 );
|
||||
direction.normalize();
|
||||
|
||||
float penetration = AEApi.instance().registries().matterCannon().getPenetration( ammo ); // 196.96655f;
|
||||
if ( penetration <= 0 )
|
||||
{
|
||||
ItemStack type = ((IAEItemStack) aeammo).getItemStack();
|
||||
if ( type.getItem() instanceof ItemPaintBall )
|
||||
{
|
||||
shootPaintBalls( type, w, p, vec3, vec31, direction, d0, d1, d2 );
|
||||
}
|
||||
return item;
|
||||
}
|
||||
else
|
||||
{
|
||||
standardAmmo( penetration, w, p, vec3, vec31, direction, d0, d1, d2 );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( Platform.isServer() )
|
||||
p.addChatMessage( PlayerMessages.AmmoDepleted.get() );
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
private void shootPaintBalls(ItemStack type, World w, EntityPlayer p, Vec3 vec3, Vec3 vec31, Vec3 direction, double d0, double d1, double d2)
|
||||
{
|
||||
AxisAlignedBB bb = AxisAlignedBB.getBoundingBox( Math.min( vec3.xCoord, vec31.xCoord ), Math.min( vec3.yCoord, vec31.yCoord ),
|
||||
Math.min( vec3.zCoord, vec31.zCoord ), Math.max( vec3.xCoord, vec31.xCoord ), Math.max( vec3.yCoord, vec31.yCoord ),
|
||||
Math.max( vec3.zCoord, vec31.zCoord ) ).expand( 16, 16, 16 );
|
||||
|
||||
Entity entity = null;
|
||||
List list = w.getEntitiesWithinAABBExcludingEntity( p, bb );
|
||||
double closest = 9999999.0D;
|
||||
int l;
|
||||
|
||||
for (l = 0; l < list.size(); ++l)
|
||||
{
|
||||
Entity entity1 = (Entity) list.get( l );
|
||||
|
||||
if ( entity1.isDead == false && entity1 != p && !(entity1 instanceof EntityItem) )
|
||||
{
|
||||
if ( entity1.isEntityAlive() )
|
||||
{
|
||||
// prevent killing / flying of mounts.
|
||||
if ( entity1.riddenByEntity == p )
|
||||
continue;
|
||||
|
||||
float f1 = 0.3F;
|
||||
AxisAlignedBB axisalignedbb1 = entity1.boundingBox.expand( (double) f1, (double) f1, (double) f1 );
|
||||
MovingObjectPosition movingobjectposition1 = axisalignedbb1.calculateIntercept( vec3, vec31 );
|
||||
|
||||
if ( movingobjectposition1 != null )
|
||||
{
|
||||
double nd = vec3.squareDistanceTo( movingobjectposition1.hitVec );
|
||||
|
||||
if ( nd < closest )
|
||||
{
|
||||
entity = entity1;
|
||||
closest = nd;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MovingObjectPosition pos = w.rayTraceBlocks( vec3, vec31, false );
|
||||
|
||||
Vec3 Srec = Vec3.createVectorHelper( d0, d1, d2 );
|
||||
if ( entity != null && pos != null && pos.hitVec.squareDistanceTo( Srec ) > closest )
|
||||
{
|
||||
pos = new MovingObjectPosition( entity );
|
||||
}
|
||||
else if ( entity != null && pos == null )
|
||||
{
|
||||
pos = new MovingObjectPosition( entity );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
CommonHelper.proxy.sendToAllNearExcept( null, d0, d1, d2, 128, w, new PacketMatterCannon( d0, d1, d2, (float) direction.xCoord,
|
||||
(float) direction.yCoord, (float) direction.zCoord, (byte) (pos == null ? 32 : pos.hitVec.squareDistanceTo( Srec ) + 1) ) );
|
||||
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
AELog.error( err );
|
||||
}
|
||||
|
||||
if ( pos != null && type != null && type.getItem() instanceof ItemPaintBall )
|
||||
{
|
||||
ItemPaintBall ipb = (ItemPaintBall) type.getItem();
|
||||
|
||||
AEColor col = ipb.getColor( type );
|
||||
// boolean lit = ipb.isLumen( type );
|
||||
|
||||
if ( pos.typeOfHit == MovingObjectType.ENTITY )
|
||||
{
|
||||
int id = pos.entityHit.getEntityId();
|
||||
PlayerColor marker = new PlayerColor( id, col, 20 * 30 );
|
||||
TickHandler.instance.getPlayerColors().put( id, marker );
|
||||
|
||||
if ( pos.entityHit instanceof EntitySheep )
|
||||
{
|
||||
EntitySheep sh = (EntitySheep) pos.entityHit;
|
||||
sh.setFleeceColor( col.ordinal() );
|
||||
}
|
||||
|
||||
pos.entityHit.attackEntityFrom( DamageSource.causePlayerDamage( p ), (float) 0 );
|
||||
NetworkHandler.instance.sendToAll( marker.getPacket() );
|
||||
}
|
||||
else if ( pos.typeOfHit == MovingObjectType.BLOCK )
|
||||
{
|
||||
ForgeDirection side = ForgeDirection.getOrientation( pos.sideHit );
|
||||
|
||||
int x = pos.blockX + side.offsetX;
|
||||
int y = pos.blockY + side.offsetY;
|
||||
int z = pos.blockZ + side.offsetZ;
|
||||
|
||||
if ( !Platform.hasPermissions( new DimensionalCoord( w, x, y, z ), p ) )
|
||||
return;
|
||||
|
||||
Block whatsThere = w.getBlock( x, y, z );
|
||||
if ( whatsThere == AEApi.instance().blocks().blockPaint.block() )
|
||||
{
|
||||
|
||||
}
|
||||
else if ( whatsThere.isReplaceable( w, x, y, z ) && w.isAirBlock( x, y, z ) )
|
||||
{
|
||||
w.setBlock( x, y, z, AEApi.instance().blocks().blockPaint.block(), 0, 3 );
|
||||
}
|
||||
|
||||
TileEntity te = w.getTileEntity( x, y, z );
|
||||
if ( te instanceof TilePaint )
|
||||
{
|
||||
pos.hitVec.xCoord -= x;
|
||||
pos.hitVec.yCoord -= y;
|
||||
pos.hitVec.zCoord -= z;
|
||||
((TilePaint) te).addBlot( type, side.getOpposite(), pos.hitVec );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void standardAmmo(float penetration, World w, EntityPlayer p, Vec3 vec3, Vec3 vec31, Vec3 direction, double d0, double d1, double d2)
|
||||
{
|
||||
boolean hasDestroyedSomething = true;
|
||||
while (penetration > 0 && hasDestroyedSomething)
|
||||
{
|
||||
hasDestroyedSomething = false;
|
||||
|
||||
AxisAlignedBB bb = AxisAlignedBB.getBoundingBox( Math.min( vec3.xCoord, vec31.xCoord ), Math.min( vec3.yCoord, vec31.yCoord ),
|
||||
Math.min( vec3.zCoord, vec31.zCoord ), Math.max( vec3.xCoord, vec31.xCoord ), Math.max( vec3.yCoord, vec31.yCoord ),
|
||||
Math.max( vec3.zCoord, vec31.zCoord ) ).expand( 16, 16, 16 );
|
||||
|
||||
Entity entity = null;
|
||||
List list = w.getEntitiesWithinAABBExcludingEntity( p, bb );
|
||||
double closest = 9999999.0D;
|
||||
int l;
|
||||
|
||||
for (l = 0; l < list.size(); ++l)
|
||||
{
|
||||
Entity entity1 = (Entity) list.get( l );
|
||||
|
||||
if ( entity1.isDead == false && entity1 != p && !(entity1 instanceof EntityItem) )
|
||||
{
|
||||
if ( entity1.isEntityAlive() )
|
||||
{
|
||||
// prevent killing / flying of mounts.
|
||||
if ( entity1.riddenByEntity == p )
|
||||
continue;
|
||||
|
||||
float f1 = 0.3F;
|
||||
AxisAlignedBB axisalignedbb1 = entity1.boundingBox.expand( (double) f1, (double) f1, (double) f1 );
|
||||
MovingObjectPosition movingobjectposition1 = axisalignedbb1.calculateIntercept( vec3, vec31 );
|
||||
|
||||
if ( movingobjectposition1 != null )
|
||||
{
|
||||
double nd = vec3.squareDistanceTo( movingobjectposition1.hitVec );
|
||||
|
||||
if ( nd < closest )
|
||||
{
|
||||
entity = entity1;
|
||||
closest = nd;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vec3 Srec = Vec3.createVectorHelper( d0, d1, d2 );
|
||||
MovingObjectPosition pos = w.rayTraceBlocks( vec3, vec31, true );
|
||||
if ( entity != null && pos != null && pos.hitVec.squareDistanceTo( Srec ) > closest )
|
||||
{
|
||||
pos = new MovingObjectPosition( entity );
|
||||
}
|
||||
else if ( entity != null && pos == null )
|
||||
{
|
||||
pos = new MovingObjectPosition( entity );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
CommonHelper.proxy.sendToAllNearExcept( null, d0, d1, d2, 128, w, new PacketMatterCannon( d0, d1, d2, (float) direction.xCoord,
|
||||
(float) direction.yCoord, (float) direction.zCoord, (byte) (pos == null ? 32 : pos.hitVec.squareDistanceTo( Srec ) + 1) ) );
|
||||
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
AELog.error( err );
|
||||
}
|
||||
|
||||
if ( pos != null )
|
||||
{
|
||||
DamageSource dmgSrc = DamageSource.causePlayerDamage( p );
|
||||
dmgSrc.damageType = "masscannon";
|
||||
|
||||
if ( pos.typeOfHit == MovingObjectType.ENTITY )
|
||||
{
|
||||
int dmg = (int) Math.ceil( penetration / 20.0f );
|
||||
if ( pos.entityHit instanceof EntityLivingBase )
|
||||
{
|
||||
EntityLivingBase el = (EntityLivingBase) pos.entityHit;
|
||||
penetration -= dmg;
|
||||
el.knockBack( p, 0, (double) -direction.xCoord, (double) -direction.zCoord );
|
||||
// el.knockBack( p, 0, vec3.xCoord,
|
||||
// vec3.zCoord );
|
||||
el.attackEntityFrom( dmgSrc, dmg );
|
||||
if ( !el.isEntityAlive() )
|
||||
hasDestroyedSomething = true;
|
||||
}
|
||||
else if ( pos.entityHit instanceof EntityItem )
|
||||
{
|
||||
hasDestroyedSomething = true;
|
||||
pos.entityHit.setDead();
|
||||
}
|
||||
else if ( pos.entityHit.attackEntityFrom( dmgSrc, dmg ) )
|
||||
{
|
||||
hasDestroyedSomething = true;
|
||||
}
|
||||
}
|
||||
else if ( pos.typeOfHit == MovingObjectType.BLOCK )
|
||||
{
|
||||
if ( !AEConfig.instance.isFeatureEnabled( AEFeature.MassCannonBlockDamage ) )
|
||||
penetration = 0;
|
||||
else
|
||||
{
|
||||
Block b = w.getBlock( pos.blockX, pos.blockY, pos.blockZ );
|
||||
// int meta = w.getBlockMetadata(
|
||||
// pos.blockX, pos.blockY, pos.blockZ );
|
||||
|
||||
float hardness = b.getBlockHardness( w, pos.blockX, pos.blockY, pos.blockZ ) * 9.0f;
|
||||
if ( hardness >= 0.0 )
|
||||
{
|
||||
if ( penetration > hardness && Platform.hasPermissions( new DimensionalCoord( w, pos.blockX, pos.blockY, pos.blockZ ), p ) )
|
||||
{
|
||||
hasDestroyedSomething = true;
|
||||
penetration -= hardness;
|
||||
penetration *= 0.60;
|
||||
w.func_147480_a( pos.blockX, pos.blockY, pos.blockZ, true );
|
||||
// w.destroyBlock( pos.blockX, pos.blockY, pos.blockZ, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean storableInStorageCell()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStorageCell(ItemStack i)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getIdleDrain()
|
||||
{
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getUpgradesInventory(ItemStack is)
|
||||
{
|
||||
return new CellUpgrades( is, 4 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getConfigInventory(ItemStack is)
|
||||
{
|
||||
return new CellConfig( is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public FuzzyMode getFuzzyMode(ItemStack is)
|
||||
{
|
||||
String fz = Platform.openNbtData( is ).getString( "FuzzyMode" );
|
||||
try
|
||||
{
|
||||
return FuzzyMode.valueOf( fz );
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
return FuzzyMode.IGNORE_ALL;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFuzzyMode(ItemStack is, FuzzyMode fzMode)
|
||||
{
|
||||
Platform.openNbtData( is ).setString( "FuzzyMode", fzMode.name() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEditable(ItemStack is)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBytes(ItemStack cellItem)
|
||||
{
|
||||
return 512;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int BytePerType(ItemStack iscellItem)
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalTypes(ItemStack cellItem)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlackListed(ItemStack cellItem, IAEItemStack requestedAddition)
|
||||
{
|
||||
float pen = AEApi.instance().registries().matterCannon().getPenetration( requestedAddition.getItemStack() );
|
||||
if ( pen > 0 )
|
||||
return false;
|
||||
|
||||
if ( requestedAddition.getItem() instanceof ItemPaintBall )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
package appeng.items.tools.powered;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.implementations.guiobjects.IGuiItem;
|
||||
import appeng.api.implementations.guiobjects.IGuiItemObject;
|
||||
import appeng.api.implementations.items.IItemGroup;
|
||||
import appeng.api.implementations.items.IStorageCell;
|
||||
import appeng.api.storage.ICellInventory;
|
||||
import appeng.api.storage.ICellInventoryHandler;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.items.contents.CellConfig;
|
||||
import appeng.items.contents.CellUpgrades;
|
||||
import appeng.items.contents.PortableCellViewer;
|
||||
import appeng.items.tools.powered.powersink.AEBasePoweredItem;
|
||||
import appeng.me.storage.CellInventoryHandler;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class ToolPortableCell extends AEBasePoweredItem implements IStorageCell, IGuiItem, IItemGroup
|
||||
{
|
||||
|
||||
public ToolPortableCell() {
|
||||
super( ToolPortableCell.class, null );
|
||||
setFeature( EnumSet.of( AEFeature.PortableCell, AEFeature.StorageCells, AEFeature.PoweredTools ) );
|
||||
maxStoredPower = AEConfig.instance.portablecell_battery;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack item, World w, EntityPlayer player)
|
||||
{
|
||||
Platform.openGUI( player, null, ForgeDirection.UNKNOWN, GuiBridge.GUI_PORTABLE_CELL );
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUse(ItemStack item, EntityPlayer player, World w, int x, int y, int z, int side,
|
||||
float hitx, float hity, float hitz)
|
||||
{
|
||||
onItemRightClick( item, w, player );
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack is, EntityPlayer player, List lines, boolean advancedItemTooltips)
|
||||
{
|
||||
super.addInformation( is, player, lines, advancedItemTooltips );
|
||||
|
||||
IMEInventory<IAEItemStack> cdi = AEApi.instance().registries().cell().getCellInventory( is, null, StorageChannel.ITEMS );
|
||||
|
||||
if ( cdi instanceof CellInventoryHandler )
|
||||
{
|
||||
ICellInventory cd = ((ICellInventoryHandler) cdi).getCellInv();
|
||||
if ( cd != null )
|
||||
{
|
||||
lines.add( cd.getUsedBytes() + " " + GuiText.Of.getLocal() + " " + cd.getTotalBytes() + " " + GuiText.BytesUsed.getLocal() );
|
||||
lines.add( cd.getStoredItemTypes() + " " + GuiText.Of.getLocal() + " " + cd.getTotalItemTypes() + " " + GuiText.Types.getLocal() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBytes(ItemStack cellItem)
|
||||
{
|
||||
return 512;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int BytePerType(ItemStack iscellItem)
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalTypes(ItemStack cellItem)
|
||||
{
|
||||
return 27;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlackListed(ItemStack cellItem, IAEItemStack requestedAddition)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean storableInStorageCell()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStorageCell(ItemStack i)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getIdleDrain()
|
||||
{
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getUpgradesInventory(ItemStack is)
|
||||
{
|
||||
return new CellUpgrades( is, 2 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getConfigInventory(ItemStack is)
|
||||
{
|
||||
return new CellConfig( is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public FuzzyMode getFuzzyMode(ItemStack is)
|
||||
{
|
||||
String fz = Platform.openNbtData( is ).getString( "FuzzyMode" );
|
||||
try
|
||||
{
|
||||
return FuzzyMode.valueOf( fz );
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
return FuzzyMode.IGNORE_ALL;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedGroupName(Set<ItemStack> others, ItemStack is)
|
||||
{
|
||||
return GuiText.StorageCells.getUnlocalized();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFuzzyMode(ItemStack is, FuzzyMode fzMode)
|
||||
{
|
||||
Platform.openNbtData( is ).setString( "FuzzyMode", fzMode.name() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEditable(ItemStack is)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGuiItemObject getGuiObject(ItemStack is, World w, int x, int y, int z)
|
||||
{
|
||||
return new PortableCellViewer( is );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package appeng.items.tools.powered;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.world.World;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.SortDir;
|
||||
import appeng.api.config.SortOrder;
|
||||
import appeng.api.config.ViewItems;
|
||||
import appeng.api.features.IWirelessTermHandler;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.items.tools.powered.powersink.AEBasePoweredItem;
|
||||
import appeng.util.ConfigManager;
|
||||
import appeng.util.IConfigManagerHost;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class ToolWirelessTerminal extends AEBasePoweredItem implements IWirelessTermHandler
|
||||
{
|
||||
|
||||
public ToolWirelessTerminal() {
|
||||
super( ToolWirelessTerminal.class, null );
|
||||
setFeature( EnumSet.of( AEFeature.WirelessAccessTerminal, AEFeature.PoweredTools ) );
|
||||
maxStoredPower = AEConfig.instance.wireless_battery;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack item, World w, EntityPlayer player)
|
||||
{
|
||||
AEApi.instance().registries().wireless().openWirelessTerminalGui( item, w, player );
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUse(ItemStack item, EntityPlayer player, World w, int x, int y, int z, int side,
|
||||
float hitx, float hity, float hitz)
|
||||
{
|
||||
onItemRightClick( item, w, player );
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack i, EntityPlayer p, List l, boolean b)
|
||||
{
|
||||
super.addInformation( i, p, l, b );
|
||||
|
||||
if ( i.hasTagCompound() )
|
||||
{
|
||||
NBTTagCompound tag = Platform.openNbtData( i );
|
||||
if ( tag != null )
|
||||
{
|
||||
String encKey = tag.getString( "encryptionKey" );
|
||||
|
||||
if ( encKey == null || encKey == "" )
|
||||
l.add( GuiText.Unlinked.getLocal() );
|
||||
else
|
||||
l.add( GuiText.Linked.getLocal() );
|
||||
}
|
||||
}
|
||||
else
|
||||
l.add( StatCollector.translateToLocal( "AppEng.GuiITooltip.Unlinked" ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHandle(ItemStack is)
|
||||
{
|
||||
return AEApi.instance().items().itemWirelessTerminal.sameAsStack( is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean usePower(EntityPlayer player, double amount, ItemStack is)
|
||||
{
|
||||
return this.extractAEPower( is, amount ) >= amount - 0.5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPower(EntityPlayer player, double amt, ItemStack is)
|
||||
{
|
||||
return getAECurrentPower( is ) >= amt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEncryptionKey(ItemStack item)
|
||||
{
|
||||
NBTTagCompound tag = Platform.openNbtData( item );
|
||||
return tag.getString( "encryptionKey" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEncryptionKey(ItemStack item, String encKey, String name)
|
||||
{
|
||||
NBTTagCompound tag = Platform.openNbtData( item );
|
||||
tag.setString( "encryptionKey", encKey );
|
||||
tag.setString( "name", name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IConfigManager getConfigManager(final ItemStack target)
|
||||
{
|
||||
final ConfigManager out = new ConfigManager( new IConfigManagerHost() {
|
||||
|
||||
@Override
|
||||
public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue)
|
||||
{
|
||||
NBTTagCompound data = Platform.openNbtData( target );
|
||||
manager.writeToNBT( data );
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
out.registerSetting( Settings.SORT_BY, SortOrder.NAME );
|
||||
out.registerSetting( Settings.VIEW_MODE, ViewItems.ALL );
|
||||
out.registerSetting( Settings.SORT_DIRECTION, SortDir.ASCENDING );
|
||||
|
||||
out.readFromNBT( (NBTTagCompound) Platform.openNbtData( target ).copy() );
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package appeng.items.tools.powered.powersink;
|
||||
|
||||
public class AEBasePoweredItem extends RedstoneFlux
|
||||
{
|
||||
|
||||
public AEBasePoweredItem(Class c, String subname) {
|
||||
super( c, subname );
|
||||
setMaxStackSize( 1 );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
package appeng.items.tools.powered.powersink;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import appeng.api.config.AccessRestriction;
|
||||
import appeng.api.config.PowerUnits;
|
||||
import appeng.api.implementations.items.IAEItemPowerStorage;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class AERootPoweredItem extends AEBaseItem implements IAEItemPowerStorage
|
||||
{
|
||||
|
||||
private enum batteryOperation
|
||||
{
|
||||
STORAGE, INJECT, EXTRACT
|
||||
};
|
||||
|
||||
public double maxStoredPower = 200000;
|
||||
|
||||
public AERootPoweredItem(Class c, String subname) {
|
||||
super( c, subname );
|
||||
setMaxDamage( 32 );
|
||||
hasSubtypes = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack is, EntityPlayer player, List lines, boolean advancedItemTooltips)
|
||||
{
|
||||
NBTTagCompound tag = is.getTagCompound();
|
||||
double internalCurrentPower = 0;
|
||||
double internalMaxPower = getAEMaxPower( is );
|
||||
|
||||
if ( tag != null )
|
||||
{
|
||||
internalCurrentPower = tag.getDouble( "internalCurrentPower" );
|
||||
}
|
||||
|
||||
double percent = internalCurrentPower / internalMaxPower;
|
||||
|
||||
lines.add( GuiText.StoredEnergy.getLocal() + ":" + MessageFormat.format( " {0,number,#} ", internalCurrentPower )
|
||||
+ Platform.gui_localize( PowerUnits.AE.unlocalizedName ) + " - " + MessageFormat.format( " {0,number,#.##%} ", percent ) );
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDamageable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDamaged(ItemStack stack)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRepairable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDamage(ItemStack stack, int damage)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
final String EnergyVar = "internalCurrentPower";
|
||||
|
||||
private double getInternalBattery(ItemStack is, batteryOperation op, double adjustment)
|
||||
{
|
||||
NBTTagCompound data = Platform.openNbtData( is );
|
||||
|
||||
double currentStorage = data.getDouble( EnergyVar );
|
||||
double maxStorage = getAEMaxPower( is );
|
||||
|
||||
switch (op)
|
||||
{
|
||||
case INJECT:
|
||||
currentStorage += adjustment;
|
||||
if ( currentStorage > maxStorage )
|
||||
{
|
||||
double diff = currentStorage - maxStorage;
|
||||
data.setDouble( EnergyVar, maxStorage );
|
||||
return diff;
|
||||
}
|
||||
data.setDouble( EnergyVar, currentStorage );
|
||||
return 0;
|
||||
case EXTRACT:
|
||||
if ( currentStorage > adjustment )
|
||||
{
|
||||
currentStorage -= adjustment;
|
||||
data.setDouble( EnergyVar, currentStorage );
|
||||
return adjustment;
|
||||
}
|
||||
data.setDouble( EnergyVar, 0 );
|
||||
return currentStorage;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return currentStorage;
|
||||
}
|
||||
|
||||
/**
|
||||
* inject external
|
||||
*/
|
||||
double injectExternalPower(PowerUnits input, ItemStack is, double amount, boolean simulate)
|
||||
{
|
||||
if ( simulate )
|
||||
{
|
||||
int requiredEU = (int) PowerUnits.AE.convertTo( PowerUnits.EU, getAEMaxPower( is ) - getAECurrentPower( is ) );
|
||||
if ( amount < requiredEU )
|
||||
return 0;
|
||||
return amount - requiredEU;
|
||||
}
|
||||
else
|
||||
{
|
||||
double powerRemainder = injectAEPower( is, PowerUnits.EU.convertTo( PowerUnits.AE, amount ) );
|
||||
return PowerUnits.AE.convertTo( PowerUnits.EU, powerRemainder );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double injectAEPower(ItemStack is, double amt)
|
||||
{
|
||||
return getInternalBattery( is, batteryOperation.INJECT, amt );
|
||||
}
|
||||
|
||||
@Override
|
||||
public double extractAEPower(ItemStack is, double amt)
|
||||
{
|
||||
return getInternalBattery( is, batteryOperation.EXTRACT, amt );
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getAEMaxPower(ItemStack is)
|
||||
{
|
||||
return maxStoredPower;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getAECurrentPower(ItemStack is)
|
||||
{
|
||||
return getInternalBattery( is, batteryOperation.STORAGE, 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessRestriction getPowerFlow(ItemStack is)
|
||||
{
|
||||
return AccessRestriction.WRITE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDisplayDamage(ItemStack is)
|
||||
{
|
||||
return 32 - (int) (32 * (getAECurrentPower( is ) / getAEMaxPower( is )));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems(Item id, CreativeTabs tab, List list)
|
||||
{
|
||||
super.getSubItems( id, tab, list );
|
||||
|
||||
ItemStack charged = new ItemStack( this, 1 );
|
||||
NBTTagCompound tag = Platform.openNbtData( charged );
|
||||
tag.setDouble( "internalCurrentPower", getAEMaxPower( charged ) );
|
||||
tag.setDouble( "internalMaxPower", getAEMaxPower( charged ) );
|
||||
list.add( charged );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
package appeng.items.tools.powered.powersink;
|
||||
|
||||
import ic2.api.item.IElectricItemManager;
|
||||
import ic2.api.item.ISpecialElectricItem;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.api.config.PowerUnits;
|
||||
import appeng.transformer.annotations.integration.Interface;
|
||||
import appeng.transformer.annotations.integration.InterfaceList;
|
||||
import appeng.transformer.annotations.integration.Method;
|
||||
|
||||
@InterfaceList(value = { @Interface(iface = "ic2.api.item.ISpecialElectricItem", iname = "IC2"),
|
||||
@Interface(iface = "ic2.api.item.IElectricItemManager", iname = "IC2") })
|
||||
public class IC2 extends AERootPoweredItem implements IElectricItemManager, ISpecialElectricItem
|
||||
{
|
||||
|
||||
public IC2(Class c, String subname) {
|
||||
super( c, subname );
|
||||
}
|
||||
|
||||
@Override
|
||||
public double charge(ItemStack is, double amount, int tier, boolean ignoreTransferLimit, boolean simulate)
|
||||
{
|
||||
double addedAmt = amount;
|
||||
double limit = getTransferLimit( is );
|
||||
|
||||
if ( !ignoreTransferLimit && amount > limit )
|
||||
addedAmt = limit;
|
||||
|
||||
return addedAmt - ((int) injectExternalPower( PowerUnits.EU, is, addedAmt, simulate ));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double discharge(ItemStack itemStack, double amount, int tier, boolean ignoreTransferLimit, boolean externally, boolean simulate)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getCharge(ItemStack is)
|
||||
{
|
||||
return (int) PowerUnits.AE.convertTo( PowerUnits.EU, getAECurrentPower( is ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(ItemStack is, double amount)
|
||||
{
|
||||
return getCharge( is ) > amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean use(ItemStack is, double amount, EntityLivingBase entity)
|
||||
{
|
||||
if ( canUse( is, amount ) )
|
||||
{
|
||||
// use the power..
|
||||
extractAEPower( is, PowerUnits.EU.convertTo( PowerUnits.AE, amount ) );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void chargeFromArmor(ItemStack itemStack, EntityLivingBase entity)
|
||||
{
|
||||
// wtf?
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getToolTip(ItemStack itemStack)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(ItemStack itemStack)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getChargedItem(ItemStack itemStack)
|
||||
{
|
||||
return itemStack.getItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getEmptyItem(ItemStack itemStack)
|
||||
{
|
||||
return itemStack.getItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxCharge(ItemStack itemStack)
|
||||
{
|
||||
return PowerUnits.AE.convertTo( PowerUnits.EU, getAEMaxPower( itemStack ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTier(ItemStack itemStack)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTransferLimit(ItemStack itemStack)
|
||||
{
|
||||
return Math.max( 32, getMaxCharge( itemStack ) / 200 );
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(iname = "IC2")
|
||||
public IElectricItemManager getManager(ItemStack itemStack)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package appeng.items.tools.powered.powersink;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.api.config.PowerUnits;
|
||||
import appeng.transformer.annotations.integration.Interface;
|
||||
import cofh.api.energy.IEnergyContainerItem;
|
||||
|
||||
@Interface(iface = "cofh.api.energy.IEnergyContainerItem", iname = "RFItem")
|
||||
public class RedstoneFlux extends IC2 implements IEnergyContainerItem
|
||||
{
|
||||
|
||||
public RedstoneFlux(Class c, String subname) {
|
||||
super( c, subname );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(ItemStack is, int maxReceive, boolean simulate)
|
||||
{
|
||||
return maxReceive - (int) injectExternalPower( PowerUnits.RF, is, maxReceive, simulate );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(ItemStack container, int maxExtract, boolean simulate)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored(ItemStack is)
|
||||
{
|
||||
return (int) PowerUnits.AE.convertTo( PowerUnits.RF, getAECurrentPower( is ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(ItemStack is)
|
||||
{
|
||||
return (int) PowerUnits.AE.convertTo( PowerUnits.RF, getAEMaxPower( is ) );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package appeng.items.tools.powered.powersink;
|
||||
|
||||
/*
|
||||
@Interface(iface = "universalelectricity.core.item.IItemElectric", modid = "IC2")
|
||||
public class UniversalElectricity extends ThermalExpansion implements IItemElectric
|
||||
{
|
||||
*
|
||||
* public UniversalElectricity(Class c, String subname) { super( c, subname ); }
|
||||
*
|
||||
* @Override public float recharge(ItemStack is, float energy, boolean
|
||||
* doRecharge) { return (float) (energy - injectExternalPower( PowerUnits.KJ,
|
||||
* is, energy, !doRecharge )); }
|
||||
*
|
||||
* @Override public float discharge(ItemStack is, float energy, boolean
|
||||
* doDischarge) { return 0; }
|
||||
*
|
||||
* @Override public float getElectricityStored(ItemStack is) { return (int)
|
||||
* PowerUnits.AE.convertTo( PowerUnits.KJ, getAECurrentPower( is ) ); }
|
||||
*
|
||||
* @Override public float getMaxElectricityStored(ItemStack is) { return (int)
|
||||
* PowerUnits.AE.convertTo( PowerUnits.KJ, getAEMaxPower( is ) ); }
|
||||
*
|
||||
* @Override public void setElectricity(ItemStack is, float joules) { double
|
||||
* currentPower = getAECurrentPower( is ); double targetPower =
|
||||
* PowerUnits.KJ.convertTo( PowerUnits.AE, joules ); if ( targetPower >
|
||||
* currentPower ) injectAEPower( is, targetPower - currentPower ); else
|
||||
* extractAEPower( is, currentPower - targetPower ); }
|
||||
*
|
||||
* @Override public float getTransfer(ItemStack is) { return (float)
|
||||
* PowerUnits.AE.convertTo( PowerUnits.KJ, getAEMaxPower( is ) -
|
||||
* getAECurrentPower( is ) ); }
|
||||
*
|
||||
* @Override public float getVoltage(ItemStack itemStack) { return 120; }
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user