Relocate Source to proper directory.
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package appeng.items;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.features.AEFeatureHandler;
|
||||
import appeng.core.features.IAEFeature;
|
||||
|
||||
public class AEBaseItem extends Item implements IAEFeature
|
||||
{
|
||||
|
||||
String FeatureFullname;
|
||||
String FeatureSubname;
|
||||
AEFeatureHandler feature;
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return FeatureFullname;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AEFeatureHandler feature()
|
||||
{
|
||||
return feature;
|
||||
}
|
||||
|
||||
public void setFeature(EnumSet<AEFeature> f)
|
||||
{
|
||||
feature = new AEFeatureHandler( f, this, FeatureSubname );
|
||||
}
|
||||
|
||||
public AEBaseItem(Class c) {
|
||||
this( c, null );
|
||||
canRepair = false;
|
||||
}
|
||||
|
||||
public AEBaseItem(Class c, String subname) {
|
||||
FeatureSubname = subname;
|
||||
FeatureFullname = AEFeatureHandler.getName( c, subname );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBookEnchantable(ItemStack itemstack1, ItemStack itemstack2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInit()
|
||||
{
|
||||
// override!
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package appeng.items.contents;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class CellConfig extends AppEngInternalInventory
|
||||
{
|
||||
|
||||
final ItemStack is;
|
||||
|
||||
public CellConfig(ItemStack is) {
|
||||
super( null, 63 );
|
||||
this.is = is;
|
||||
readFromNBT( Platform.openNbtData( is ), "list" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
writeToNBT( Platform.openNbtData( is ), "list" );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package appeng.items.contents;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.parts.automation.UpgradeInventory;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class CellUpgrades extends UpgradeInventory
|
||||
{
|
||||
|
||||
final ItemStack is;
|
||||
|
||||
public CellUpgrades(ItemStack is, int upgrades) {
|
||||
super( is.getItem(), null, upgrades );
|
||||
this.is = is;
|
||||
readFromNBT( Platform.openNbtData( is ), "upgrades" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
writeToNBT( Platform.openNbtData( is ), "upgrades" );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package appeng.items.contents;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.api.implementations.guiobjects.INetworkTool;
|
||||
import appeng.api.implementations.items.IUpgradeModule;
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class NetworkToolViewer implements INetworkTool
|
||||
{
|
||||
|
||||
final AppEngInternalInventory inv;
|
||||
final ItemStack is;
|
||||
final IGridHost gh;
|
||||
|
||||
public NetworkToolViewer(ItemStack is, IGridHost gHost) {
|
||||
this.is = is;
|
||||
gh = gHost;
|
||||
inv = new AppEngInternalInventory( null, 9 );
|
||||
if ( is.hasTagCompound() ) // prevent crash when opening network status creen.
|
||||
inv.readFromNBT( Platform.openNbtData( is ), "inv" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return inv.getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i)
|
||||
{
|
||||
return inv.getStackInSlot( i );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j)
|
||||
{
|
||||
return inv.decrStackSize( i, j );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int i)
|
||||
{
|
||||
return inv.getStackInSlotOnClosing( i );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack)
|
||||
{
|
||||
inv.setInventorySlotContents( i, itemstack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName()
|
||||
{
|
||||
return inv.getInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return inv.hasCustomInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return inv.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
inv.markDirty();
|
||||
inv.writeToNBT( Platform.openNbtData( is ), "inv" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer)
|
||||
{
|
||||
return inv.isUseableByPlayer( entityplayer );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory()
|
||||
{
|
||||
inv.openInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory()
|
||||
{
|
||||
inv.closeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
return inv.isItemValidForSlot( i, itemstack ) && itemstack.getItem() instanceof IUpgradeModule
|
||||
&& ((IUpgradeModule) itemstack.getItem()).getType( itemstack ) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
return is;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGridHost getGridHost()
|
||||
{
|
||||
return gh;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package appeng.items.contents;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.PowerMultiplier;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.SortDir;
|
||||
import appeng.api.config.SortOrder;
|
||||
import appeng.api.config.ViewItems;
|
||||
import appeng.api.implementations.guiobjects.IPortableCell;
|
||||
import appeng.api.implementations.items.IAEItemPowerStorage;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.MEMonitorHandler;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.me.storage.CellInventory;
|
||||
import appeng.util.ConfigManager;
|
||||
import appeng.util.IConfigManagerHost;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class PortableCellViewer extends MEMonitorHandler<IAEItemStack> implements IPortableCell
|
||||
{
|
||||
|
||||
private ItemStack target;
|
||||
private IAEItemPowerStorage ips;
|
||||
|
||||
public PortableCellViewer(ItemStack is) {
|
||||
super( CellInventory.getCell( is, null ) );
|
||||
ips = (IAEItemPowerStorage) is.getItem();
|
||||
target = is;
|
||||
}
|
||||
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double extractAEPower(double amt, Actionable mode, PowerMultiplier usePowerMultiplier)
|
||||
{
|
||||
amt = usePowerMultiplier.multiply( amt );
|
||||
|
||||
if ( mode == Actionable.SIMULATE )
|
||||
return usePowerMultiplier.divide( Math.min( amt, ips.getAECurrentPower( getItemStack() ) ) );
|
||||
|
||||
return usePowerMultiplier.divide( ips.extractAEPower( getItemStack(), amt ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMEMonitor<IAEItemStack> getItemInventory()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMEMonitor<IAEFluidStack> getFluidInventory()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IConfigManager getConfigManager()
|
||||
{
|
||||
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,21 @@
|
||||
package appeng.items.contents;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.api.implementations.guiobjects.IGuiItemObject;
|
||||
|
||||
public class QuartzKnifeObj implements IGuiItemObject
|
||||
{
|
||||
|
||||
final ItemStack is;
|
||||
|
||||
public QuartzKnifeObj(ItemStack o) {
|
||||
is = o;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
return is;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,416 @@
|
||||
package appeng.items.materials;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
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.Map.Entry;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.implementations.IUpgradeableHost;
|
||||
import appeng.api.implementations.items.IItemGroup;
|
||||
import appeng.api.implementations.items.IStorageComponent;
|
||||
import appeng.api.implementations.items.IUpgradeModule;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.SelectedPart;
|
||||
import appeng.client.texture.MissingIcon;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.features.AEFeatureHandler;
|
||||
import appeng.core.features.IStackSrc;
|
||||
import appeng.core.features.MaterialStackSrc;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
public class ItemMultiMaterial extends AEBaseItem implements IStorageComponent, IUpgradeModule
|
||||
{
|
||||
|
||||
HashMap<Integer, MaterialType> dmgToMaterial = new HashMap();
|
||||
|
||||
public static ItemMultiMaterial instance;
|
||||
|
||||
public ItemMultiMaterial() {
|
||||
super( ItemMultiMaterial.class );
|
||||
setFeature( EnumSet.of( AEFeature.Core ) );
|
||||
setHasSubtypes( true );
|
||||
instance = this;
|
||||
}
|
||||
|
||||
class SlightlyBetterSort implements Comparator<String>
|
||||
{
|
||||
|
||||
Pattern p;
|
||||
|
||||
public SlightlyBetterSort(Pattern p) {
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(String o1, String o2)
|
||||
{
|
||||
try
|
||||
{
|
||||
Matcher a = p.matcher( o1 );
|
||||
Matcher b = p.matcher( o2 );
|
||||
if ( a.find() && b.find() )
|
||||
{
|
||||
int ia = Integer.parseInt( a.group( 1 ) );
|
||||
int ib = Integer.parseInt( b.group( 1 ) );
|
||||
return Integer.compare( ia, ib );
|
||||
}
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
// ek!
|
||||
}
|
||||
return o1.compareTo( o2 );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack is, EntityPlayer player, List details, boolean moar)
|
||||
{
|
||||
super.addInformation( is, player, details, moar );
|
||||
|
||||
MaterialType mt = getTypeByStack( is );
|
||||
if ( mt == null )
|
||||
return;
|
||||
|
||||
if ( mt == MaterialType.NamePress )
|
||||
{
|
||||
NBTTagCompound c = Platform.openNbtData( is );
|
||||
details.add( c.getString( "InscribeName" ) );
|
||||
}
|
||||
|
||||
Upgrades u = getType( is );
|
||||
if ( u != null )
|
||||
{
|
||||
List<String> textList = new LinkedList();
|
||||
for (Entry<ItemStack, Integer> j : u.getSupported().entrySet())
|
||||
{
|
||||
String name = null;
|
||||
|
||||
int limit = j.getValue();
|
||||
|
||||
if ( j.getKey().getItem() instanceof IItemGroup )
|
||||
{
|
||||
IItemGroup ig = (IItemGroup) j.getKey().getItem();
|
||||
String str = ig.getUnlocalizedGroupName( u.getSupported().keySet(), j.getKey() );
|
||||
if ( str != null )
|
||||
name = Platform.gui_localize( str ) + (limit > 1 ? " (" + limit + ")" : "");
|
||||
}
|
||||
|
||||
if ( name == null )
|
||||
name = j.getKey().getDisplayName() + (limit > 1 ? " (" + limit + ")" : "");
|
||||
|
||||
if ( !textList.contains( name ) )
|
||||
textList.add( name );
|
||||
}
|
||||
|
||||
Pattern p = Pattern.compile( "(\\d+)[^\\d]" );
|
||||
SlightlyBetterSort s = new SlightlyBetterSort( p );
|
||||
Collections.sort( textList, s );
|
||||
details.addAll( textList );
|
||||
}
|
||||
}
|
||||
|
||||
public IStackSrc createMaterial(MaterialType mat)
|
||||
{
|
||||
if ( !mat.isRegistered() )
|
||||
{
|
||||
boolean enabled = true;
|
||||
for (AEFeature f : mat.getFeature())
|
||||
enabled = enabled && AEConfig.instance.isFeatureEnabled( f );
|
||||
|
||||
if ( enabled )
|
||||
{
|
||||
mat.itemInstance = this;
|
||||
int newMaterialNum = mat.damageValue;
|
||||
mat.markReady();
|
||||
|
||||
IStackSrc output = mat.stackSrc = new MaterialStackSrc( mat );
|
||||
|
||||
if ( dmgToMaterial.get( newMaterialNum ) == null )
|
||||
dmgToMaterial.put( newMaterialNum, mat );
|
||||
else
|
||||
throw new RuntimeException( "Meta Overlap detected." );
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
else
|
||||
throw new RuntimeException( "Cannot create the same material twice..." );
|
||||
}
|
||||
|
||||
public void unduplicate()
|
||||
{
|
||||
for (MaterialType mt : ImmutableSet.copyOf( dmgToMaterial.values() ))
|
||||
{
|
||||
if ( mt.getOreName() != null )
|
||||
{
|
||||
ItemStack replacement = null;
|
||||
|
||||
String names[] = mt.getOreName().split( "," );
|
||||
|
||||
for (String name : names)
|
||||
{
|
||||
if ( replacement != null )
|
||||
break;
|
||||
|
||||
ArrayList<ItemStack> options = OreDictionary.getOres( name );
|
||||
if ( options != null && options.size() > 0 )
|
||||
{
|
||||
for (ItemStack is : options)
|
||||
{
|
||||
if ( is != null && is.getItem() != null )
|
||||
{
|
||||
replacement = is.copy();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( replacement == null || AEConfig.instance.useAEVersion( mt ) )
|
||||
{
|
||||
// continue using the AE2 item.
|
||||
for (String name : names)
|
||||
OreDictionary.registerOre( name, mt.stack( 1 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( mt.itemInstance == this )
|
||||
dmgToMaterial.remove( mt.damageValue );
|
||||
|
||||
mt.itemInstance = replacement.getItem();
|
||||
mt.damageValue = replacement.getItemDamage();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public MaterialType getTypeByStack(ItemStack is)
|
||||
{
|
||||
if ( dmgToMaterial.containsKey( is.getItemDamage() ) )
|
||||
return dmgToMaterial.get( is.getItemDamage() );
|
||||
return MaterialType.InvalidType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIconFromDamage(int dmg)
|
||||
{
|
||||
if ( dmgToMaterial.containsKey( dmg ) )
|
||||
return dmgToMaterial.get( dmg ).IIcon;
|
||||
return new MissingIcon( this );
|
||||
}
|
||||
|
||||
private String nameOf(ItemStack is)
|
||||
{
|
||||
if ( is == null )
|
||||
return "null";
|
||||
|
||||
MaterialType mt = getTypeByStack( is );
|
||||
if ( mt == null )
|
||||
return "null";
|
||||
|
||||
return AEFeatureHandler.getName( ItemMultiMaterial.class, mt.name() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack is)
|
||||
{
|
||||
return "item.appliedenergistics2." + nameOf( is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerIcons(IIconRegister icoRegister)
|
||||
{
|
||||
for (MaterialType mat : MaterialType.values())
|
||||
{
|
||||
if ( mat.damageValue != -1 )
|
||||
{
|
||||
ItemStack what = new ItemStack( this, 1, mat.damageValue );
|
||||
if ( getTypeByStack( what ) != MaterialType.InvalidType )
|
||||
{
|
||||
String tex = "appliedenergistics2:" + nameOf( what );
|
||||
mat.IIcon = icoRegister.registerIcon( tex );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomEntity(ItemStack is)
|
||||
{
|
||||
return getTypeByStack( is ).hasCustomEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity createEntity(World w, Entity location, ItemStack itemstack)
|
||||
{
|
||||
Class<? extends Entity> droppedEntity = getTypeByStack( itemstack ).getCustomEntityClass();
|
||||
Entity eqi;
|
||||
|
||||
try
|
||||
{
|
||||
eqi = droppedEntity.getConstructor( World.class, double.class, double.class, double.class, ItemStack.class ).newInstance( w, location.posX,
|
||||
location.posY, location.posZ, itemstack );
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
throw new RuntimeException( t );
|
||||
}
|
||||
|
||||
eqi.motionX = location.motionX;
|
||||
eqi.motionY = location.motionY;
|
||||
eqi.motionZ = location.motionZ;
|
||||
|
||||
if ( location instanceof EntityItem && eqi instanceof EntityItem )
|
||||
((EntityItem) eqi).delayBeforeCanPickup = ((EntityItem) location).delayBeforeCanPickup;
|
||||
|
||||
return eqi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBytes(ItemStack is)
|
||||
{
|
||||
switch (getTypeByStack( is ))
|
||||
{
|
||||
case Cell1kPart:
|
||||
return 1024;
|
||||
case Cell4kPart:
|
||||
return 1024 * 4;
|
||||
case Cell16kPart:
|
||||
return 1024 * 16;
|
||||
case Cell64kPart:
|
||||
return 1024 * 64;
|
||||
default:
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStorageComponent(ItemStack is)
|
||||
{
|
||||
switch (getTypeByStack( is ))
|
||||
{
|
||||
case Cell1kPart:
|
||||
case Cell4kPart:
|
||||
case Cell16kPart:
|
||||
case Cell64kPart:
|
||||
return true;
|
||||
default:
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Upgrades getType(ItemStack itemstack)
|
||||
{
|
||||
switch (getTypeByStack( itemstack ))
|
||||
{
|
||||
case CardCapacity:
|
||||
return Upgrades.CAPACITY;
|
||||
case CardFuzzy:
|
||||
return Upgrades.FUZZY;
|
||||
case CardRedstone:
|
||||
return Upgrades.REDSTONE;
|
||||
case CardSpeed:
|
||||
return Upgrades.SPEED;
|
||||
case CardInverter:
|
||||
return Upgrades.INVERTER;
|
||||
case CardCrafting:
|
||||
return Upgrades.CRAFTING;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUseFirst(ItemStack is, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if ( player.isSneaking() )
|
||||
{
|
||||
TileEntity te = world.getTileEntity( x, y, z );
|
||||
IInventory upgrades = null;
|
||||
|
||||
if ( te instanceof IPartHost )
|
||||
{
|
||||
SelectedPart sp = ((IPartHost) te).selectPart( Vec3.createVectorHelper( hitX, hitY, hitZ ) );
|
||||
if ( sp.part instanceof IUpgradeableHost )
|
||||
upgrades = ((IUpgradeableHost) sp.part).getInventoryByName( "upgrades" );
|
||||
}
|
||||
else if ( te instanceof IUpgradeableHost )
|
||||
upgrades = ((IUpgradeableHost) te).getInventoryByName( "upgrades" );
|
||||
|
||||
if ( upgrades != null && is != null && is.getItem() instanceof IUpgradeModule )
|
||||
{
|
||||
IUpgradeModule um = (IUpgradeModule) is.getItem();
|
||||
Upgrades u = um.getType( is );
|
||||
|
||||
if ( u != null )
|
||||
{
|
||||
InventoryAdaptor ad = InventoryAdaptor.getAdaptor( upgrades, ForgeDirection.UNKNOWN );
|
||||
if ( ad != null )
|
||||
{
|
||||
if ( player.worldObj.isRemote )
|
||||
return false;
|
||||
|
||||
player.inventory.setInventorySlotContents( player.inventory.currentItem, ad.addItems( is ) );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return super.onItemUseFirst( is, player, world, x, y, z, side, hitX, hitY, hitZ );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems(Item par1, CreativeTabs par2CreativeTabs, List cList)
|
||||
{
|
||||
List<MaterialType> types = Arrays.asList( MaterialType.values() );
|
||||
Collections.sort( types, new Comparator<MaterialType>() {
|
||||
|
||||
@Override
|
||||
public int compare(MaterialType o1, MaterialType o2)
|
||||
{
|
||||
return o1.name().compareTo( o2.name() );
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
for (MaterialType mat : types)
|
||||
{
|
||||
if ( mat.damageValue >= 0 && mat.isRegistered() && mat.itemInstance == this )
|
||||
cList.add( new ItemStack( this, 1, mat.damageValue ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
package appeng.items.materials;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.features.MaterialStackSrc;
|
||||
import appeng.entity.EntityChargedQuartz;
|
||||
import appeng.entity.EntityIds;
|
||||
import appeng.entity.EntitySingularity;
|
||||
import cpw.mods.fml.common.registry.EntityRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public enum MaterialType
|
||||
{
|
||||
InvalidType(-1, AEFeature.Core),
|
||||
|
||||
CertusQuartzCrystal(0, AEFeature.Core, "crystalCertusQuartz"), CertusQuartzCrystalCharged(1, AEFeature.Core, EntityChargedQuartz.class),
|
||||
|
||||
CertusQuartzDust(2, AEFeature.Core, "dustCertusQuartz"), NetherQuartzDust(3, AEFeature.Core, "dustNetherQuartz"), Flour(4, AEFeature.Flour, "dustWheat"), GoldDust(
|
||||
51, AEFeature.Core, "dustGold"), IronDust(49, AEFeature.Core, "dustIron"), IronNugget(50, AEFeature.Core, "nuggetIron"),
|
||||
|
||||
Silicon(5, AEFeature.Core, "itemSilicon"), MatterBall(6),
|
||||
|
||||
FluixCrystal(7, AEFeature.Core, "crystalFluix"), FluixDust(8, AEFeature.Core, "dustFluix"), FluixPearl(9, AEFeature.Core, "pearlFluix"),
|
||||
|
||||
PurifiedCertusQuartzCrystal(10), PurifiedNetherQuartzCrystal(11), PurifiedFluixCrystal(12),
|
||||
|
||||
CalcProcessorPress(13), EngProcessorPress(14), LogicProcessorPress(15),
|
||||
|
||||
CalcProcessorPrint(16), EngProcessorPrint(17), LogicProcessorPrint(18),
|
||||
|
||||
SiliconPress(19), SiliconPrint(20),
|
||||
|
||||
NamePress(21),
|
||||
|
||||
LogicProcessor(22), CalcProcessor(23), EngProcessor(24),
|
||||
|
||||
// Basic Cards
|
||||
BasicCard(25), CardRedstone(26), CardCapacity(27),
|
||||
|
||||
// Adv Cards
|
||||
AdvCard(28), CardFuzzy(29), CardSpeed(30), CardInverter(31),
|
||||
|
||||
Cell2SpatialPart(32, AEFeature.SpatialIO), Cell16SpatialPart(33, AEFeature.SpatialIO), Cell128SpatialPart(34, AEFeature.SpatialIO),
|
||||
|
||||
Cell1kPart(35, AEFeature.StorageCells), Cell4kPart(36, AEFeature.StorageCells), Cell16kPart(37, AEFeature.StorageCells), Cell64kPart(38,
|
||||
AEFeature.StorageCells), EmptyStorageCell(39, AEFeature.StorageCells),
|
||||
|
||||
WoodenGear(40, AEFeature.GrindStone, "gearWood"),
|
||||
|
||||
Wireless(41, AEFeature.WirelessAccessTerminal), WirelessBooster(42, AEFeature.WirelessAccessTerminal),
|
||||
|
||||
FormationCore(43), AnnihilationCore(44),
|
||||
|
||||
SkyDust(45, AEFeature.Core),
|
||||
|
||||
EnderDust(46, AEFeature.QuantumNetworkBridge, "dustEnder,dustEnderPearl", EntitySingularity.class), Singularity(47, AEFeature.QuantumNetworkBridge,
|
||||
EntitySingularity.class), QESingularity(48, AEFeature.QuantumNetworkBridge, EntitySingularity.class),
|
||||
|
||||
BlankPattern(52), CardCrafting(53);
|
||||
|
||||
private String oreName;
|
||||
private EnumSet<AEFeature> features;
|
||||
private Class<? extends Entity> droppedEntity;
|
||||
|
||||
// IIcon for the material.
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon IIcon;
|
||||
|
||||
public Item itemInstance;
|
||||
public int damageValue;
|
||||
|
||||
private boolean isRegistered = false;
|
||||
|
||||
// stack!
|
||||
public MaterialStackSrc stackSrc;
|
||||
|
||||
MaterialType(int metaValue) {
|
||||
damageValue = metaValue;
|
||||
features = EnumSet.of( AEFeature.Core );
|
||||
}
|
||||
|
||||
MaterialType(int metaValue, AEFeature part) {
|
||||
damageValue = metaValue;
|
||||
features = EnumSet.of( part );
|
||||
}
|
||||
|
||||
MaterialType(int metaValue, AEFeature part, Class<? extends Entity> c) {
|
||||
features = EnumSet.of( part );
|
||||
damageValue = metaValue;
|
||||
droppedEntity = c;
|
||||
|
||||
EntityRegistry.registerModEntity( droppedEntity, droppedEntity.getSimpleName(), EntityIds.get( droppedEntity ), AppEng.instance, 16, 4, true );
|
||||
}
|
||||
|
||||
MaterialType(int metaValue, AEFeature part, String oreDictionary, Class<? extends Entity> c) {
|
||||
features = EnumSet.of( part );
|
||||
damageValue = metaValue;
|
||||
oreName = oreDictionary;
|
||||
droppedEntity = c;
|
||||
EntityRegistry.registerModEntity( droppedEntity, droppedEntity.getSimpleName(), EntityIds.get( droppedEntity ), AppEng.instance, 16, 4, true );
|
||||
}
|
||||
|
||||
MaterialType(int metaValue, AEFeature part, String oreDictionary) {
|
||||
features = EnumSet.of( part );
|
||||
damageValue = metaValue;
|
||||
oreName = oreDictionary;
|
||||
}
|
||||
|
||||
public ItemStack stack(int size)
|
||||
{
|
||||
return new ItemStack( itemInstance, size, damageValue );
|
||||
}
|
||||
|
||||
public EnumSet<AEFeature> getFeature()
|
||||
{
|
||||
return features;
|
||||
}
|
||||
|
||||
public String getOreName()
|
||||
{
|
||||
return oreName;
|
||||
}
|
||||
|
||||
public boolean hasCustomEntity()
|
||||
{
|
||||
return droppedEntity != null;
|
||||
}
|
||||
|
||||
public Class<? extends Entity> getCustomEntityClass()
|
||||
{
|
||||
return droppedEntity;
|
||||
}
|
||||
|
||||
public boolean isRegistered()
|
||||
{
|
||||
return isRegistered;
|
||||
}
|
||||
|
||||
public void markReady()
|
||||
{
|
||||
isRegistered = true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,263 @@
|
||||
package appeng.items.misc;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.implementations.items.IGrowableCrystal;
|
||||
import appeng.api.recipes.ResolverResult;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.localization.ButtonToolTips;
|
||||
import appeng.entity.EntityGrowingCrystal;
|
||||
import appeng.entity.EntityIds;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.common.registry.EntityRegistry;
|
||||
|
||||
public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
|
||||
{
|
||||
|
||||
public static final int LEVEL_OFFSET = 200;
|
||||
public static final int SINGLE_OFFSET = LEVEL_OFFSET * 3;
|
||||
|
||||
public static final int Certus = 0;
|
||||
public static final int Nether = SINGLE_OFFSET;
|
||||
public static final int Fluix = SINGLE_OFFSET * 2;
|
||||
public static final int END = SINGLE_OFFSET * 3;
|
||||
|
||||
IIcon certus[] = new IIcon[3];
|
||||
IIcon fluix[] = new IIcon[3];
|
||||
IIcon nether[] = new IIcon[3];
|
||||
|
||||
private int getProgress(ItemStack is)
|
||||
{
|
||||
if ( is.hasTagCompound() )
|
||||
{
|
||||
return is.getTagCompound().getInteger( "progress" );
|
||||
}
|
||||
else
|
||||
{
|
||||
int progress;
|
||||
NBTTagCompound comp = Platform.openNbtData( is );
|
||||
comp.setInteger( "progress", progress = is.getItemDamage() );
|
||||
is.setItemDamage( (is.getItemDamage() / SINGLE_OFFSET) * SINGLE_OFFSET );
|
||||
return progress;
|
||||
}
|
||||
}
|
||||
|
||||
private void setProgress(ItemStack is, int newDamage)
|
||||
{
|
||||
NBTTagCompound comp = Platform.openNbtData( is );
|
||||
comp.setInteger( "progress", newDamage );
|
||||
is.setItemDamage( (int) (is.getItemDamage() / LEVEL_OFFSET) * LEVEL_OFFSET );
|
||||
}
|
||||
|
||||
public ItemCrystalSeed() {
|
||||
super( ItemCrystalSeed.class );
|
||||
setHasSubtypes( true );
|
||||
setFeature( EnumSet.of( AEFeature.Core ) );
|
||||
|
||||
EntityRegistry.registerModEntity( EntityGrowingCrystal.class, EntityGrowingCrystal.class.getSimpleName(), EntityIds.get( EntityGrowingCrystal.class ),
|
||||
AppEng.instance, 16, 4, true );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEntityLifespan(ItemStack itemStack, World world)
|
||||
{
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack is)
|
||||
{
|
||||
int damage = getProgress( is );
|
||||
|
||||
if ( damage < Certus + SINGLE_OFFSET )
|
||||
return getUnlocalizedName() + ".Certus";
|
||||
|
||||
if ( damage < Nether + SINGLE_OFFSET )
|
||||
return getUnlocalizedName() + ".Nether";
|
||||
|
||||
if ( damage < Fluix + SINGLE_OFFSET )
|
||||
return getUnlocalizedName() + ".Fluix";
|
||||
|
||||
return getUnlocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack triggerGrowth(ItemStack is)
|
||||
{
|
||||
int newDamage = getProgress( is ) + 1;
|
||||
|
||||
if ( newDamage == Certus + SINGLE_OFFSET )
|
||||
return AEApi.instance().materials().materialPurifiedCertusQuartzCrystal.stack( is.stackSize );
|
||||
if ( newDamage == Nether + SINGLE_OFFSET )
|
||||
return AEApi.instance().materials().materialPurifiedNetherQuartzCrystal.stack( is.stackSize );
|
||||
if ( newDamage == Fluix + SINGLE_OFFSET )
|
||||
return AEApi.instance().materials().materialPurifiedFluixCrystal.stack( is.stackSize );
|
||||
if ( newDamage > END )
|
||||
return null;
|
||||
|
||||
setProgress( is, newDamage );
|
||||
return is;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDamageable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, EntityPlayer p, List l, boolean b)
|
||||
{
|
||||
l.add( ButtonToolTips.DoesntDespawn.getLocal() );
|
||||
int progress = getProgress( stack ) % SINGLE_OFFSET;
|
||||
l.add( Math.floor( (float) progress / (float) (SINGLE_OFFSET / 100) ) + "%" );
|
||||
super.addInformation( stack, p, l, b );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDamaged(ItemStack stack)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxDamage(ItemStack stack)
|
||||
{
|
||||
return END;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(ItemStack stack, int pass)
|
||||
{
|
||||
return getIconIndex( stack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIconIndex(ItemStack stack)
|
||||
{
|
||||
IIcon list[] = null;
|
||||
|
||||
int damage = getProgress( stack );
|
||||
|
||||
if ( damage < Certus + SINGLE_OFFSET )
|
||||
list = certus;
|
||||
|
||||
else if ( damage < Nether + SINGLE_OFFSET )
|
||||
{
|
||||
damage -= Nether;
|
||||
list = nether;
|
||||
}
|
||||
|
||||
else if ( damage < Fluix + SINGLE_OFFSET )
|
||||
{
|
||||
damage -= Fluix;
|
||||
list = fluix;
|
||||
}
|
||||
|
||||
if ( list == null )
|
||||
return Items.diamond.getIconFromDamage( 0 );
|
||||
|
||||
if ( damage < LEVEL_OFFSET )
|
||||
return list[0];
|
||||
else if ( damage < LEVEL_OFFSET * 2 )
|
||||
return list[1];
|
||||
else
|
||||
return list[2];
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMultiplier(Block blk, Material mat)
|
||||
{
|
||||
return 0.5f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerIcons(IIconRegister ir)
|
||||
{
|
||||
String preFix = "appliedenergistics2:ItemCrystalSeed.";
|
||||
|
||||
certus[0] = ir.registerIcon( preFix + "Certus" );
|
||||
certus[1] = ir.registerIcon( preFix + "Certus2" );
|
||||
certus[2] = ir.registerIcon( preFix + "Certus3" );
|
||||
|
||||
nether[0] = ir.registerIcon( preFix + "Nether" );
|
||||
nether[1] = ir.registerIcon( preFix + "Nether2" );
|
||||
nether[2] = ir.registerIcon( preFix + "Nether3" );
|
||||
|
||||
fluix[0] = ir.registerIcon( preFix + "Fluix" );
|
||||
fluix[1] = ir.registerIcon( preFix + "Fluix2" );
|
||||
fluix[2] = ir.registerIcon( preFix + "Fluix3" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomEntity(ItemStack stack)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity createEntity(World world, Entity location, ItemStack itemstack)
|
||||
{
|
||||
EntityGrowingCrystal egc = new EntityGrowingCrystal( world, location.posX, location.posY, location.posZ, itemstack );
|
||||
|
||||
egc.motionX = location.motionX;
|
||||
egc.motionY = location.motionY;
|
||||
egc.motionZ = location.motionZ;
|
||||
|
||||
if ( location instanceof EntityItem && egc instanceof EntityItem )
|
||||
((EntityItem) egc).delayBeforeCanPickup = ((EntityItem) location).delayBeforeCanPickup;
|
||||
|
||||
return egc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems(Item i, CreativeTabs t, List l)
|
||||
{
|
||||
// lvl 0
|
||||
l.add( newStyle( new ItemStack( this, 1, Certus ) ) );
|
||||
l.add( newStyle( new ItemStack( this, 1, Nether ) ) );
|
||||
l.add( newStyle( new ItemStack( this, 1, Fluix ) ) );
|
||||
|
||||
// lvl 1
|
||||
l.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET + Certus ) ) );
|
||||
l.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET + Nether ) ) );
|
||||
l.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET + Fluix ) ) );
|
||||
|
||||
// lvl 2
|
||||
l.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET * 2 + Certus ) ) );
|
||||
l.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET * 2 + Nether ) ) );
|
||||
l.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET * 2 + Fluix ) ) );
|
||||
}
|
||||
|
||||
private static ItemStack newStyle(ItemStack itemStack)
|
||||
{
|
||||
((ItemCrystalSeed) itemStack.getItem()).getProgress( itemStack );
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public static ResolverResult getResolver(int certus2)
|
||||
{
|
||||
ItemStack is = AEApi.instance().items().itemCrystalSeed.stack( 1 );
|
||||
is.setItemDamage( certus2 );
|
||||
is = newStyle( is );
|
||||
return new ResolverResult( "ItemCrystalSeed", is.getItemDamage(), is.getTagCompound() );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
package appeng.items.misc;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.implementations.ICraftingPatternItem;
|
||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.client.render.items.ItemEncodedPatternRenderer;
|
||||
import appeng.core.CommonHelper;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.helpers.PatternHelper;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class ItemEncodedPattern extends AEBaseItem implements ICraftingPatternItem
|
||||
{
|
||||
|
||||
public ItemEncodedPattern() {
|
||||
super( ItemEncodedPattern.class );
|
||||
setFeature( EnumSet.of( AEFeature.Patterns ) );
|
||||
setMaxStackSize( 1 );
|
||||
if ( Platform.isClient() )
|
||||
MinecraftForgeClient.registerItemRenderer( this, new ItemEncodedPatternRenderer() );
|
||||
}
|
||||
|
||||
private boolean clearPattern(ItemStack stack, EntityPlayer player)
|
||||
{
|
||||
if ( player.isSneaking() )
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
return false;
|
||||
|
||||
InventoryPlayer inv = player.inventory;
|
||||
|
||||
for (int s = 0; s < player.inventory.getSizeInventory(); s++)
|
||||
{
|
||||
if ( inv.getStackInSlot( s ) == stack )
|
||||
{
|
||||
inv.setInventorySlotContents( s, AEApi.instance().materials().materialBlankPattern.stack( stack.stackSize ) );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
return clearPattern( stack, player );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack stack, World w, EntityPlayer player)
|
||||
{
|
||||
clearPattern( stack, player );
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack is, EntityPlayer p, List l, boolean more)
|
||||
{
|
||||
ICraftingPatternDetails details = getPatternForItem( is, p.worldObj );
|
||||
|
||||
if ( details == null )
|
||||
{
|
||||
l.add( EnumChatFormatting.RED + GuiText.InvalidPattern.getLocal() );
|
||||
return;
|
||||
}
|
||||
|
||||
boolean isCrafting = details.isCraftable();
|
||||
|
||||
IAEItemStack[] in = details.getCondensedInputs();
|
||||
IAEItemStack[] out = details.getCondensedOutputs();
|
||||
|
||||
String label = (isCrafting ? GuiText.Crafts.getLocal() : GuiText.Creates.getLocal()) + ": ";
|
||||
String and = " " + GuiText.And.getLocal() + " ";
|
||||
String with = GuiText.With.getLocal() + ": ";
|
||||
|
||||
boolean first = true;
|
||||
for (int x = 0; x < out.length; x++)
|
||||
{
|
||||
if ( out[x] == null )
|
||||
continue;
|
||||
|
||||
l.add( (first ? label : and) + out[x].getStackSize() + " " + Platform.getItemDisplayName( out[x] ) );
|
||||
first = false;
|
||||
}
|
||||
|
||||
first = true;
|
||||
for (int x = 0; x < in.length; x++)
|
||||
{
|
||||
if ( in[x] == null )
|
||||
continue;
|
||||
|
||||
l.add( (first ? with : and) + in[x].getStackSize() + " " + Platform.getItemDisplayName( in[x] ) );
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
|
||||
// rather simple client side caching.
|
||||
static WeakHashMap<ItemStack, ItemStack> simpleCache = new WeakHashMap<ItemStack, ItemStack>();
|
||||
|
||||
public ItemStack getOutput(ItemStack item)
|
||||
{
|
||||
ItemStack out = simpleCache.get( item );
|
||||
if ( out != null )
|
||||
return out;
|
||||
|
||||
World w = CommonHelper.proxy.getWorld();
|
||||
if ( w == null )
|
||||
return null;
|
||||
|
||||
ICraftingPatternDetails details = getPatternForItem( item, w );
|
||||
|
||||
if ( details == null )
|
||||
return null;
|
||||
|
||||
simpleCache.put( item, out = details.getCondensedOutputs()[0].getItemStack() );
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICraftingPatternDetails getPatternForItem(ItemStack is, World w)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new PatternHelper( is, w );
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package appeng.items.misc;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.client.render.items.PaintBallRender;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class ItemPaintBall extends AEBaseItem
|
||||
{
|
||||
|
||||
public ItemPaintBall() {
|
||||
super( ItemPaintBall.class );
|
||||
setFeature( EnumSet.of( AEFeature.PaintBalls ) );
|
||||
hasSubtypes = true;
|
||||
if ( Platform.isClient() )
|
||||
MinecraftForgeClient.registerItemRenderer( this, new PaintBallRender() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemStackDisplayName(ItemStack is)
|
||||
{
|
||||
return super.getItemStackDisplayName( is ) + " - " + getExtraName( is );
|
||||
}
|
||||
|
||||
public String getExtraName(ItemStack is)
|
||||
{
|
||||
return (is.getItemDamage() >= 20 ? GuiText.Lumen.getLocal() + " " : "") + getColor( is );
|
||||
}
|
||||
|
||||
public AEColor getColor(ItemStack is)
|
||||
{
|
||||
int dmg = is.getItemDamage();
|
||||
if ( dmg >= 20 )
|
||||
dmg -= 20;
|
||||
|
||||
if ( dmg >= AEColor.values().length )
|
||||
return AEColor.Transparent;
|
||||
|
||||
return AEColor.values()[dmg];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems(Item i, CreativeTabs ct, List l)
|
||||
{
|
||||
for (AEColor c : AEColor.values())
|
||||
if ( c != AEColor.Transparent )
|
||||
l.add( new ItemStack( this, 1, c.ordinal() ) );
|
||||
|
||||
for (AEColor c : AEColor.values())
|
||||
if ( c != AEColor.Transparent )
|
||||
l.add( new ItemStack( this, 1, 20 + c.ordinal() ) );
|
||||
}
|
||||
|
||||
public boolean isLumen(ItemStack is)
|
||||
{
|
||||
int dmg = is.getItemDamage();
|
||||
return dmg >= 20;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
package appeng.items.parts;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockGlass;
|
||||
import net.minecraft.block.BlockStainedGlass;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.parts.IAlphaPassItem;
|
||||
import appeng.block.solids.OreQuartz;
|
||||
import appeng.client.render.BusRenderer;
|
||||
import appeng.core.FacadeConfig;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.facade.FacadePart;
|
||||
import appeng.facade.IFacadeItem;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemFacade extends AEBaseItem implements IFacadeItem, IAlphaPassItem
|
||||
{
|
||||
|
||||
public ItemFacade() {
|
||||
super( ItemFacade.class );
|
||||
setFeature( EnumSet.of( AEFeature.Facades ) );
|
||||
setHasSubtypes( true );
|
||||
if ( Platform.isClient() )
|
||||
MinecraftForgeClient.registerItemRenderer( this, BusRenderer.instance );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getSpriteNumber()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUse(ItemStack is, EntityPlayer player, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
return AEApi.instance().partHelper().placeBus( is, x, y, z, side, player, w );
|
||||
}
|
||||
|
||||
@Override
|
||||
public FacadePart createPartFromItemStack(ItemStack is, ForgeDirection side)
|
||||
{
|
||||
ItemStack in = getTextureItem( is );
|
||||
if ( in != null )
|
||||
return new FacadePart( is, side );
|
||||
return null;
|
||||
}
|
||||
|
||||
List<ItemStack> subTypes = null;
|
||||
|
||||
public List<ItemStack> getFacades()
|
||||
{
|
||||
calculateSubTypes();
|
||||
return subTypes;
|
||||
}
|
||||
|
||||
public ItemStack getCreativeTabIcon()
|
||||
{
|
||||
calculateSubTypes();
|
||||
if ( subTypes.isEmpty() )
|
||||
return new ItemStack( Items.cake );
|
||||
return subTypes.get( 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems(Item number, CreativeTabs tab, List list)
|
||||
{
|
||||
calculateSubTypes();
|
||||
list.addAll( subTypes );
|
||||
}
|
||||
|
||||
public ItemStack createFromInts(int[] ids)
|
||||
{
|
||||
ItemStack is = new ItemStack( AEApi.instance().items().itemFacade.item() );
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setIntArray( "x", ids.clone() );
|
||||
is.setTagCompound( data );
|
||||
return is;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getTextureItem(ItemStack is)
|
||||
{
|
||||
Block blk = getBlock( is );
|
||||
if ( blk != null )
|
||||
return new ItemStack( blk, 1, getMeta( is ) );
|
||||
return null;
|
||||
}
|
||||
|
||||
private void calculateSubTypes()
|
||||
{
|
||||
if ( subTypes == null )
|
||||
{
|
||||
subTypes = new ArrayList();
|
||||
for (Object blk : Block.blockRegistry)
|
||||
{
|
||||
Block b = (Block) blk;
|
||||
try
|
||||
{
|
||||
Item item = Item.getItemFromBlock( b );
|
||||
|
||||
List<ItemStack> tmpList = new ArrayList();
|
||||
b.getSubBlocks( item, b.getCreativeTabToDisplayOn(), tmpList );
|
||||
for (ItemStack l : tmpList)
|
||||
{
|
||||
ItemStack facade = createFacadeForItem( l, false );
|
||||
if ( facade != null )
|
||||
subTypes.add( facade );
|
||||
}
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
// just absorb..
|
||||
}
|
||||
}
|
||||
|
||||
if ( FacadeConfig.instance.hasChanged() )
|
||||
FacadeConfig.instance.save();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ItemStack createFacadeForItem(ItemStack l, boolean returnItem)
|
||||
{
|
||||
if ( l == null )
|
||||
return null;
|
||||
|
||||
Block b = Block.getBlockFromItem( l.getItem() );
|
||||
if ( b == null || l.hasTagCompound() )
|
||||
return null;
|
||||
|
||||
int metadata = l.getItem().getMetadata( l.getItemDamage() );
|
||||
|
||||
boolean hasTile = b.hasTileEntity( metadata );
|
||||
boolean enableGlass = b instanceof BlockGlass || b instanceof BlockStainedGlass;
|
||||
boolean disableOre = b instanceof OreQuartz;
|
||||
|
||||
boolean defaultValue = (b.isOpaqueCube() && !b.getTickRandomly() && !hasTile && !disableOre) || enableGlass;
|
||||
if ( FacadeConfig.instance.checkEnabled( b, metadata, defaultValue ) )
|
||||
{
|
||||
if ( returnItem )
|
||||
return l;
|
||||
|
||||
ItemStack is = new ItemStack( this );
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
int[] ds = new int[2];
|
||||
ds[0] = Item.getIdFromItem( l.getItem() );
|
||||
ds[1] = metadata;
|
||||
data.setIntArray( "x", ds );
|
||||
UniqueIdentifier ui = GameRegistry.findUniqueIdentifierFor( l.getItem() );
|
||||
data.setString( "modid", ui.modId );
|
||||
data.setString( "itemname", ui.name );
|
||||
is.setTagCompound( data );
|
||||
return is;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getBlock(ItemStack is)
|
||||
{
|
||||
NBTTagCompound data = is.getTagCompound();
|
||||
if ( data != null )
|
||||
{
|
||||
if ( data.hasKey( "modid" ) && data.hasKey( "itemname" ) )
|
||||
{
|
||||
return GameRegistry.findBlock( data.getString( "modid" ), data.getString( "itemname" ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
int[] blk = data.getIntArray( "x" );
|
||||
if ( blk != null && blk.length == 2 )
|
||||
return Block.getBlockById( blk[0] );
|
||||
}
|
||||
}
|
||||
return Blocks.glass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMeta(ItemStack is)
|
||||
{
|
||||
NBTTagCompound data = is.getTagCompound();
|
||||
if ( data != null )
|
||||
{
|
||||
int[] blk = data.getIntArray( "x" );
|
||||
if ( blk != null && blk.length == 2 )
|
||||
return blk[1];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemStackDisplayName(ItemStack is)
|
||||
{
|
||||
try
|
||||
{
|
||||
ItemStack in = getTextureItem( is );
|
||||
if ( in != null )
|
||||
{
|
||||
return super.getItemStackDisplayName( is ) + " - " + in.getDisplayName();
|
||||
}
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return super.getItemStackDisplayName( is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAlphaPass(ItemStack is)
|
||||
{
|
||||
ItemStack out = getTextureItem( is );
|
||||
|
||||
if ( out == null || out.getItem() == null )
|
||||
return false;
|
||||
|
||||
Block blk = Block.getBlockFromItem( out.getItem() );
|
||||
if ( blk != null && blk.canRenderInPass( 1 ) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,273 @@
|
||||
package appeng.items.parts;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.implementations.items.IItemGroup;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartItem;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.features.AEFeatureHandler;
|
||||
import appeng.core.features.ItemStackSrc;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.items.AEBaseItem;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemMultiPart extends AEBaseItem implements IPartItem, IItemGroup
|
||||
{
|
||||
|
||||
class PartTypeIst
|
||||
{
|
||||
|
||||
PartType part;
|
||||
int variant;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
IIcon ico;
|
||||
};
|
||||
|
||||
HashMap<Integer, PartTypeIst> dmgToPart = new HashMap();
|
||||
|
||||
public static ItemMultiPart instance;
|
||||
|
||||
public ItemMultiPart() {
|
||||
super( ItemMultiPart.class );
|
||||
setFeature( EnumSet.of( AEFeature.Core ) );
|
||||
AEApi.instance().partHelper().setItemBusRenderer( this );
|
||||
setHasSubtypes( true );
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public ItemStackSrc createPart(PartType mat, Enum variant)
|
||||
{
|
||||
try
|
||||
{
|
||||
// I think this still works?
|
||||
ItemStack is = new ItemStack( this );
|
||||
mat.getPart().getConstructor( ItemStack.class ).newInstance( is );
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
AELog.integration( e );
|
||||
return null; // part not supported..
|
||||
}
|
||||
|
||||
int varID = variant == null ? 0 : variant.ordinal();
|
||||
|
||||
// verify
|
||||
for (PartTypeIst p : dmgToPart.values())
|
||||
{
|
||||
if ( p.part == mat && p.variant == varID )
|
||||
throw new RuntimeException( "Cannot create the same material twice..." );
|
||||
}
|
||||
|
||||
boolean enabled = true;
|
||||
for (AEFeature f : mat.getFeature())
|
||||
enabled = enabled && AEConfig.instance.isFeatureEnabled( f );
|
||||
|
||||
if ( enabled )
|
||||
{
|
||||
int newPartNum = mat.baseDamage + varID;
|
||||
ItemStackSrc output = new ItemStackSrc( this, newPartNum );
|
||||
|
||||
PartTypeIst pti = new PartTypeIst();
|
||||
pti.part = mat;
|
||||
pti.variant = varID;
|
||||
|
||||
if ( dmgToPart.get( newPartNum ) == null )
|
||||
{
|
||||
dmgToPart.put( newPartNum, pti );
|
||||
return output;
|
||||
}
|
||||
else
|
||||
throw new RuntimeException( "Meta Overlap detected." );
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getDamageByType(PartType t)
|
||||
{
|
||||
for (Entry<Integer, PartTypeIst> pt : dmgToPart.entrySet())
|
||||
{
|
||||
if ( pt.getValue().part == t )
|
||||
return pt.getKey();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public PartType getTypeByStack(ItemStack is)
|
||||
{
|
||||
if ( is == null )
|
||||
return null;
|
||||
|
||||
PartTypeIst pt = dmgToPart.get( is.getItemDamage() );
|
||||
if ( pt != null )
|
||||
return pt.part;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getSpriteNumber()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIconFromDamage(int dmg)
|
||||
{
|
||||
IIcon ico = dmgToPart.get( dmg ).ico;
|
||||
return ico;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack is)
|
||||
{
|
||||
return "item.appliedenergistics2." + getname( is );
|
||||
}
|
||||
|
||||
public String getname(ItemStack is)
|
||||
{
|
||||
return AEFeatureHandler.getName( ItemMultiPart.class, getTypeByStack( is ).name() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemStackDisplayName(ItemStack is)
|
||||
{
|
||||
PartType pt = getTypeByStack( is );
|
||||
if ( pt == null )
|
||||
return "Unnamed";
|
||||
|
||||
Enum[] variants = pt.getVariants();
|
||||
|
||||
if ( variants != null )
|
||||
return super.getItemStackDisplayName( is ) + " - " + variants[dmgToPart.get( is.getItemDamage() ).variant].toString();
|
||||
|
||||
if ( pt.getExtraName() != null )
|
||||
return super.getItemStackDisplayName( is ) + " - " + pt.getExtraName().getLocal();
|
||||
|
||||
return super.getItemStackDisplayName( is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerIcons(IIconRegister par1IconRegister)
|
||||
{
|
||||
for (Entry<Integer, PartTypeIst> part : dmgToPart.entrySet())
|
||||
{
|
||||
String tex = "appliedenergistics2:" + getname( new ItemStack( this, 1, part.getKey() ) );
|
||||
part.getValue().ico = par1IconRegister.registerIcon( tex );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUse(ItemStack is, EntityPlayer player, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
return AEApi.instance().partHelper().placeBus( is, x, y, z, side, player, w );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPart createPartFromItemStack(ItemStack is)
|
||||
{
|
||||
try
|
||||
{
|
||||
PartType t = getTypeByStack( is );
|
||||
if ( t != null )
|
||||
{
|
||||
if ( t.constructor == null )
|
||||
t.constructor = t.getPart().getConstructor( ItemStack.class );
|
||||
|
||||
return t.constructor.newInstance( is );
|
||||
}
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
throw new RuntimeException( "Unable to construct IBusPart from IBusItem : " + getTypeByStack( is ).getPart().getName()
|
||||
+ " ; Possibly didn't have correct constructor( ItemStack )", e );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems(Item number, CreativeTabs tab, List cList)
|
||||
{
|
||||
List<Entry<Integer, PartTypeIst>> types = new ArrayList( dmgToPart.entrySet() );
|
||||
Collections.sort( types, new Comparator<Entry<Integer, PartTypeIst>>() {
|
||||
|
||||
@Override
|
||||
public int compare(Entry<Integer, PartTypeIst> o1, Entry<Integer, PartTypeIst> o2)
|
||||
{
|
||||
return o1.getValue().part.name().compareTo( o2.getValue().part.name() );
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
for (Entry<Integer, PartTypeIst> part : types)
|
||||
cList.add( new ItemStack( this, 1, part.getKey() ) );
|
||||
}
|
||||
|
||||
public int variantOf(int itemDamage)
|
||||
{
|
||||
if ( dmgToPart.containsKey( itemDamage ) )
|
||||
return dmgToPart.get( itemDamage ).variant;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedGroupName(Set<ItemStack> others, ItemStack is)
|
||||
{
|
||||
boolean importBus = false, exportBus = false, group = false;
|
||||
|
||||
PartType u = getTypeByStack( is );
|
||||
|
||||
for (ItemStack stack : others)
|
||||
{
|
||||
if ( stack.getItem() == this )
|
||||
{
|
||||
PartType pt = getTypeByStack( stack );
|
||||
switch (pt)
|
||||
{
|
||||
case ImportBus:
|
||||
importBus = true;
|
||||
if ( u == pt )
|
||||
group = true;
|
||||
break;
|
||||
case ExportBus:
|
||||
exportBus = true;
|
||||
if ( u == pt )
|
||||
group = true;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( group && importBus && exportBus )
|
||||
return GuiText.IOBuses.getUnlocalized();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ItemStack getStackFromTypeAndVarient(PartType mt, int variant)
|
||||
{
|
||||
return new ItemStack( this, 1, mt.baseDamage + variant );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package appeng.items.parts;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.util.AEColor;
|
||||
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;
|
||||
import appeng.parts.misc.PartInterface;
|
||||
import appeng.parts.misc.PartInvertedToggleBus;
|
||||
import appeng.parts.misc.PartStorageBus;
|
||||
import appeng.parts.misc.PartToggleBus;
|
||||
import appeng.parts.networking.PartCableCovered;
|
||||
import appeng.parts.networking.PartCableGlass;
|
||||
import appeng.parts.networking.PartCableSmart;
|
||||
import appeng.parts.networking.PartDenseCable;
|
||||
import appeng.parts.networking.PartQuartzFiber;
|
||||
import appeng.parts.p2p.PartP2PBCPower;
|
||||
import appeng.parts.p2p.PartP2PIC2Power;
|
||||
import appeng.parts.p2p.PartP2PItems;
|
||||
import appeng.parts.p2p.PartP2PLight;
|
||||
import appeng.parts.p2p.PartP2PLiquids;
|
||||
import appeng.parts.p2p.PartP2PRFPower;
|
||||
import appeng.parts.p2p.PartP2PRedstone;
|
||||
import appeng.parts.p2p.PartP2PTunnelME;
|
||||
import appeng.parts.reporting.PartConversionMonitor;
|
||||
import appeng.parts.reporting.PartCraftingTerminal;
|
||||
import appeng.parts.reporting.PartDarkMonitor;
|
||||
import appeng.parts.reporting.PartInterfaceTerminal;
|
||||
import appeng.parts.reporting.PartMonitor;
|
||||
import appeng.parts.reporting.PartPatternTerminal;
|
||||
import appeng.parts.reporting.PartSemiDarkMonitor;
|
||||
import appeng.parts.reporting.PartStorageMonitor;
|
||||
import appeng.parts.reporting.PartTerminal;
|
||||
|
||||
public enum PartType
|
||||
{
|
||||
InvalidType(-1, AEFeature.Core, null),
|
||||
|
||||
CableGlass(0, AEFeature.Core, PartCableGlass.class),
|
||||
|
||||
CableCovered(20, AEFeature.Core, PartCableCovered.class),
|
||||
|
||||
CableSmart(40, AEFeature.Channels, PartCableSmart.class),
|
||||
|
||||
CableDense(60, AEFeature.Channels, PartDenseCable.class),
|
||||
|
||||
ToggleBus(80, AEFeature.Core, PartToggleBus.class),
|
||||
|
||||
InvertedToggleBus(100, AEFeature.Core, PartInvertedToggleBus.class),
|
||||
|
||||
CableAnchor(120, AEFeature.Core, PartCableAnchor.class),
|
||||
|
||||
QuartzFiber(140, AEFeature.Core, PartQuartzFiber.class),
|
||||
|
||||
Monitor(160, AEFeature.Core, PartMonitor.class),
|
||||
|
||||
SemiDarkMonitor(180, AEFeature.Core, PartSemiDarkMonitor.class),
|
||||
|
||||
DarkMonitor(200, AEFeature.Core, PartDarkMonitor.class),
|
||||
|
||||
StorageBus(220, AEFeature.StorageBus, PartStorageBus.class),
|
||||
|
||||
ImportBus(240, AEFeature.ImportBus, PartImportBus.class),
|
||||
|
||||
ExportBus(260, AEFeature.ExportBus, PartExportBus.class),
|
||||
|
||||
LevelEmitter(280, AEFeature.LevelEmitter, PartLevelEmitter.class),
|
||||
|
||||
AnnihilationPlane(300, AEFeature.AnnihilationPlane, PartAnnihilationPlane.class),
|
||||
|
||||
FormationPlane(320, AEFeature.FormationPlane, PartFormationPlane.class),
|
||||
|
||||
PatternTerminal(340, AEFeature.Patterns, PartPatternTerminal.class),
|
||||
|
||||
CraftingTerminal(360, AEFeature.CraftingTerminal, PartCraftingTerminal.class),
|
||||
|
||||
Terminal(380, AEFeature.Core, PartTerminal.class),
|
||||
|
||||
StorageMonitor(400, AEFeature.StorageMonitor, PartStorageMonitor.class),
|
||||
|
||||
ConversionMonitor(420, AEFeature.PartConversionMonitor, PartConversionMonitor.class),
|
||||
|
||||
Interface(440, AEFeature.Core, PartInterface.class),
|
||||
|
||||
P2PTunnelME(460, AEFeature.P2PTunnelME, PartP2PTunnelME.class, GuiText.METunnel),
|
||||
|
||||
P2PTunnelRedstone(461, AEFeature.P2PTunnelRedstone, PartP2PRedstone.class, GuiText.RedstoneTunnel),
|
||||
|
||||
P2PTunnelItems(462, AEFeature.P2PTunnelItems, PartP2PItems.class, GuiText.ItemTunnel),
|
||||
|
||||
P2PTunnelLiquids(463, AEFeature.P2PTunnelLiquids, PartP2PLiquids.class, GuiText.FluidTunnel),
|
||||
|
||||
P2PTunnelMJ(464, AEFeature.P2PTunnelMJ, PartP2PBCPower.class, GuiText.MJTunnel),
|
||||
|
||||
P2PTunnelEU(465, AEFeature.P2PTunnelEU, PartP2PIC2Power.class, GuiText.EUTunnel),
|
||||
|
||||
P2PTunnelRF(466, AEFeature.P2PTunnelRF, PartP2PRFPower.class, GuiText.RFTunnel),
|
||||
|
||||
P2PTunnelLight(467, AEFeature.P2PTunnelLight, PartP2PLight.class, GuiText.LightTunnel),
|
||||
|
||||
InterfaceTerminal(480, AEFeature.InterfaceTerminal, PartInterfaceTerminal.class);
|
||||
|
||||
private final EnumSet<AEFeature> features;
|
||||
private final Class<? extends IPart> myPart;
|
||||
private final GuiText extraName;
|
||||
public final int baseDamage;
|
||||
|
||||
public Constructor<? extends IPart> constructor;
|
||||
|
||||
PartType(int baseMetaValue, AEFeature part, Class<? extends IPart> c) {
|
||||
this( baseMetaValue, part, c, null );
|
||||
}
|
||||
|
||||
PartType(int baseMetaValue, AEFeature part, Class<? extends IPart> c, GuiText en) {
|
||||
features = EnumSet.of( part );
|
||||
myPart = c;
|
||||
extraName = en;
|
||||
baseDamage = baseMetaValue;
|
||||
}
|
||||
|
||||
public Enum[] getVariants()
|
||||
{
|
||||
if ( this == CableSmart || this == CableCovered || this == CableGlass || this == CableDense )
|
||||
return AEColor.values();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public EnumSet<AEFeature> getFeature()
|
||||
{
|
||||
return features;
|
||||
}
|
||||
|
||||
public Class<? extends IPart> getPart()
|
||||
{
|
||||
return myPart;
|
||||
}
|
||||
|
||||
public GuiText getExtraName()
|
||||
{
|
||||
return extraName;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
package appeng.items.storage;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
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.config.IncludeExclude;
|
||||
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.api.storage.data.IItemList;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.items.contents.CellConfig;
|
||||
import appeng.items.contents.CellUpgrades;
|
||||
import appeng.items.materials.MaterialType;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class ItemBasicStorageCell extends AEBaseItem implements IStorageCell, IItemGroup
|
||||
{
|
||||
|
||||
final MaterialType component;
|
||||
final int totalBytes;
|
||||
final int perType;
|
||||
final double idleDrain;
|
||||
|
||||
public ItemBasicStorageCell(MaterialType whichCell, int Kilobytes) {
|
||||
super( ItemBasicStorageCell.class, Kilobytes + "k" );
|
||||
setFeature( EnumSet.of( AEFeature.StorageCells ) );
|
||||
setMaxStackSize( 1 );
|
||||
totalBytes = Kilobytes * 1024;
|
||||
component = whichCell;
|
||||
|
||||
switch (component)
|
||||
{
|
||||
case Cell1kPart:
|
||||
idleDrain = 0.5;
|
||||
perType = 8;
|
||||
break;
|
||||
case Cell4kPart:
|
||||
idleDrain = 1.0;
|
||||
perType = 32;
|
||||
break;
|
||||
case Cell16kPart:
|
||||
idleDrain = 1.5;
|
||||
perType = 128;
|
||||
break;
|
||||
case Cell64kPart:
|
||||
idleDrain = 2.0;
|
||||
perType = 512;
|
||||
break;
|
||||
default:
|
||||
idleDrain = 0.0;
|
||||
perType = 8;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack i, EntityPlayer p, List l, boolean b)
|
||||
{
|
||||
IMEInventory<IAEItemStack> cdi = AEApi.instance().registries().cell().getCellInventory( i, null, StorageChannel.ITEMS );
|
||||
|
||||
if ( cdi instanceof ICellInventoryHandler )
|
||||
{
|
||||
ICellInventoryHandler CI = (ICellInventoryHandler) cdi;
|
||||
|
||||
ICellInventory cd = ((ICellInventoryHandler) cdi).getCellInv();
|
||||
if (cd != null)
|
||||
{
|
||||
l.add(cd.getUsedBytes() + " " + GuiText.Of.getLocal() + " "
|
||||
+ cd.getTotalBytes() + " "
|
||||
+ GuiText.BytesUsed.getLocal());
|
||||
|
||||
l.add(cd.getStoredItemTypes() + " " + GuiText.Of.getLocal()
|
||||
+ " " + cd.getTotalItemTypes() + " "
|
||||
+ GuiText.Types.getLocal());
|
||||
|
||||
if ( CI.isPreformatted() )
|
||||
{
|
||||
String List = (CI.getIncludeExcludeMode() == IncludeExclude.WHITELIST ? GuiText.Included
|
||||
: GuiText.Excluded ).getLocal();
|
||||
|
||||
if ( CI.isFuzzy() )
|
||||
l.add( GuiText.Partitioned.getLocal() + " - " + List + " " + GuiText.Fuzzy.getLocal() );
|
||||
else
|
||||
l.add( GuiText.Partitioned.getLocal() + " - " + List + " " + GuiText.Precise.getLocal() );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBytes(ItemStack cellItem) {
|
||||
return totalBytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int BytePerType(ItemStack iscellItem)
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalTypes(ItemStack cellItem)
|
||||
{
|
||||
return 63;
|
||||
}
|
||||
|
||||
@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 idleDrain;
|
||||
}
|
||||
|
||||
@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 void setFuzzyMode(ItemStack is, FuzzyMode fzMode)
|
||||
{
|
||||
Platform.openNbtData( is ).setString( "FuzzyMode", fzMode.name() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedGroupName(Set<ItemStack> others, ItemStack is)
|
||||
{
|
||||
return GuiText.StorageCells.getUnlocalized();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEditable(ItemStack is)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean disassembleDrive(ItemStack stack, World world, EntityPlayer player)
|
||||
{
|
||||
if ( player.isSneaking() )
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
return false;
|
||||
|
||||
InventoryPlayer pinv = player.inventory;
|
||||
IMEInventory<IAEItemStack> inv = AEApi.instance().registries().cell().getCellInventory( stack, null, StorageChannel.ITEMS );
|
||||
if ( inv != null && pinv.getCurrentItem() == stack )
|
||||
{
|
||||
InventoryAdaptor ia = InventoryAdaptor.getAdaptor( player, ForgeDirection.UNKNOWN );
|
||||
IItemList<IAEItemStack> list = inv.getAvailableItems( StorageChannel.ITEMS.createList() );
|
||||
if ( list.isEmpty() && ia != null )
|
||||
{
|
||||
pinv.setInventorySlotContents( pinv.currentItem, null );
|
||||
|
||||
ItemStack extraB = ia.addItems( component.stack( 1 ) );
|
||||
ItemStack extraA = ia.addItems( AEApi.instance().materials().materialEmptyStorageCell.stack( 1 ) );
|
||||
|
||||
if ( extraA != null )
|
||||
player.dropPlayerItemWithRandomChoice( extraA, false );
|
||||
if ( extraB != null )
|
||||
player.dropPlayerItemWithRandomChoice( extraB, false );
|
||||
|
||||
if ( player.inventoryContainer != null )
|
||||
player.inventoryContainer.detectAndSendChanges();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
||||
{
|
||||
disassembleDrive( stack, world, player );
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
return disassembleDrive( stack, world, player );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContainerItem()
|
||||
{
|
||||
return AEConfig.instance.isFeatureEnabled( AEFeature.enableDisassemblyCrafting );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getContainerItem(ItemStack itemStack)
|
||||
{
|
||||
return AEApi.instance().materials().materialEmptyStorageCell.stack( 1 );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package appeng.items.storage;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.ICellWorkbenchItem;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.items.contents.CellConfig;
|
||||
|
||||
public class ItemCreativeStorageCell extends AEBaseItem implements ICellWorkbenchItem
|
||||
{
|
||||
|
||||
public ItemCreativeStorageCell() {
|
||||
super( ItemCreativeStorageCell.class );
|
||||
setFeature( EnumSet.of( AEFeature.StorageCells, AEFeature.Creative ) );
|
||||
setMaxStackSize( 1 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEditable(ItemStack is)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getUpgradesInventory(ItemStack is)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getConfigInventory(ItemStack is)
|
||||
{
|
||||
return new CellConfig( is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public FuzzyMode getFuzzyMode(ItemStack is)
|
||||
{
|
||||
return FuzzyMode.IGNORE_ALL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFuzzyMode(ItemStack is, FuzzyMode fzMode)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
package appeng.items.storage;
|
||||
|
||||
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.world.World;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import appeng.api.implementations.TransitionResult;
|
||||
import appeng.api.implementations.items.ISpatialStorageCell;
|
||||
import appeng.api.util.WorldCoord;
|
||||
import appeng.core.WorldSettings;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.items.materials.MaterialType;
|
||||
import appeng.spatial.StorageHelper;
|
||||
import appeng.spatial.StorageWorldProvider;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorageCell
|
||||
{
|
||||
|
||||
final MaterialType component;
|
||||
final int maxRegion;
|
||||
|
||||
public ItemSpatialStorageCell(MaterialType whichCell, int spatialScale) {
|
||||
super( ItemSpatialStorageCell.class, spatialScale + "Cubed" );
|
||||
setFeature( EnumSet.of( AEFeature.SpatialIO ) );
|
||||
setMaxStackSize( 1 );
|
||||
maxRegion = spatialScale;
|
||||
component = whichCell;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack is, EntityPlayer player, List list, boolean adv)
|
||||
{
|
||||
WorldCoord wc = getStoredSize( is );
|
||||
if ( wc.x > 0 )
|
||||
list.add( GuiText.StoredSize.getLocal() + ": " + wc.x + " x " + wc.y + " x " + wc.z );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSpatialStorage(ItemStack is)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStoredDim(ItemStack is)
|
||||
{
|
||||
return maxRegion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld(ItemStack is)
|
||||
{
|
||||
if ( is.hasTagCompound() )
|
||||
{
|
||||
NBTTagCompound c = is.getTagCompound();
|
||||
int dim = c.getInteger( "StorageDim" );
|
||||
World w = DimensionManager.getWorld( dim );
|
||||
if ( w == null )
|
||||
{
|
||||
DimensionManager.initDimension( dim );
|
||||
w = DimensionManager.getWorld( dim );
|
||||
}
|
||||
|
||||
if ( w != null )
|
||||
{
|
||||
if ( w.provider instanceof StorageWorldProvider )
|
||||
{
|
||||
return w;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void setStoredSize(ItemStack is, int targetX, int targetY, int targetZ)
|
||||
{
|
||||
if ( is.hasTagCompound() )
|
||||
{
|
||||
NBTTagCompound c = is.getTagCompound();
|
||||
int dim = c.getInteger( "StorageDim" );
|
||||
c.setInteger( "sizeX", targetX );
|
||||
c.setInteger( "sizeY", targetY );
|
||||
c.setInteger( "sizeZ", targetZ );
|
||||
WorldSettings.getInstance().setStoredSize( dim, targetX, targetY, targetZ );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldCoord getStoredSize(ItemStack is)
|
||||
{
|
||||
if ( is.hasTagCompound() )
|
||||
{
|
||||
NBTTagCompound c = is.getTagCompound();
|
||||
if ( Platform.isServer() )
|
||||
{
|
||||
int dim = c.getInteger( "StorageDim" );
|
||||
return WorldSettings.getInstance().getStoredSize( dim );
|
||||
}
|
||||
else
|
||||
return new WorldCoord( c.getInteger( "sizeX" ), c.getInteger( "sizeY" ), c.getInteger( "sizeZ" ) );
|
||||
}
|
||||
return new WorldCoord( 0, 0, 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldCoord getMin(ItemStack is)
|
||||
{
|
||||
World w = getWorld( is );
|
||||
if ( w != null )
|
||||
{
|
||||
NBTTagCompound info = (NBTTagCompound) w.getWorldInfo().getAdditionalProperty( "storageCell" );
|
||||
if ( info != null )
|
||||
{
|
||||
return new WorldCoord( info.getInteger( "minX" ), info.getInteger( "minY" ), info.getInteger( "minZ" ) );
|
||||
}
|
||||
}
|
||||
return new WorldCoord( 0, 0, 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldCoord getMax(ItemStack is)
|
||||
{
|
||||
World w = getWorld( is );
|
||||
if ( w != null )
|
||||
{
|
||||
NBTTagCompound info = (NBTTagCompound) w.getWorldInfo().getAdditionalProperty( "storageCell" );
|
||||
if ( info != null )
|
||||
{
|
||||
return new WorldCoord( info.getInteger( "maxX" ), info.getInteger( "maxY" ), info.getInteger( "maxZ" ) );
|
||||
}
|
||||
}
|
||||
return new WorldCoord( 0, 0, 0 );
|
||||
}
|
||||
|
||||
public World createNewWorld(ItemStack is)
|
||||
{
|
||||
NBTTagCompound c = Platform.openNbtData( is );
|
||||
int newDim = DimensionManager.getNextFreeDimId();
|
||||
c.setInteger( "StorageDim", newDim );
|
||||
WorldSettings.getInstance().addStorageCellDim( newDim );
|
||||
DimensionManager.initDimension( newDim );
|
||||
return DimensionManager.getWorld( newDim );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransitionResult doSpatialTransition(ItemStack is, World w, WorldCoord min, WorldCoord max, boolean doTransition)
|
||||
{
|
||||
WorldCoord scale = getStoredSize( is );
|
||||
|
||||
int targetX = max.x - min.x - 1;
|
||||
int targetY = max.y - min.y - 1;
|
||||
int targetZ = max.z - min.z - 1;
|
||||
int maxSize = getMaxStoredDim( is );
|
||||
|
||||
int floorBuffer = 64;
|
||||
World dest = getWorld( is );
|
||||
|
||||
if ( (scale.x == 0 && scale.y == 0 && scale.z == 0) || (scale.x == targetX && scale.y == targetY && scale.z == targetZ) )
|
||||
{
|
||||
if ( targetX <= maxSize && targetY <= maxSize && targetZ <= maxSize )
|
||||
{
|
||||
if ( dest == null )
|
||||
dest = createNewWorld( is );
|
||||
|
||||
StorageHelper.getInstance()
|
||||
.swapRegions( w, dest, min.x + 1, min.y + 1, min.z + 1, 1, floorBuffer + 1, 1, targetX - 1, targetY - 1, targetZ - 1 );
|
||||
setStoredSize( is, targetX, targetY, targetZ );
|
||||
|
||||
return new TransitionResult( true, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
return new TransitionResult( false, 0 );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package appeng.items.storage;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.implementations.items.IUpgradeModule;
|
||||
import appeng.api.storage.ICellWorkbenchItem;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.items.contents.CellConfig;
|
||||
import appeng.items.contents.CellUpgrades;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import appeng.util.prioitylist.FuzzyPriorityList;
|
||||
import appeng.util.prioitylist.IPartitionList;
|
||||
import appeng.util.prioitylist.MergedPriorityList;
|
||||
import appeng.util.prioitylist.PrecisePriorityList;
|
||||
|
||||
public class ItemViewCell extends AEBaseItem implements ICellWorkbenchItem
|
||||
{
|
||||
|
||||
public ItemViewCell()
|
||||
{
|
||||
super( ItemViewCell.class );
|
||||
setFeature( EnumSet.of( AEFeature.Core ) );
|
||||
setMaxStackSize( 1 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEditable(ItemStack is)
|
||||
{
|
||||
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 void setFuzzyMode(ItemStack is, FuzzyMode fzMode)
|
||||
{
|
||||
Platform.openNbtData( is ).setString( "FuzzyMode", fzMode.name() );
|
||||
}
|
||||
|
||||
public static IPartitionList<IAEItemStack> createFilter(ItemStack[] list)
|
||||
{
|
||||
IPartitionList<IAEItemStack> myPartitionList = null;
|
||||
|
||||
MergedPriorityList<IAEItemStack> myMergedList = new MergedPriorityList<IAEItemStack>();
|
||||
|
||||
for (ItemStack currentViewCell : list)
|
||||
{
|
||||
if ( currentViewCell == null )
|
||||
continue;
|
||||
|
||||
if ( (currentViewCell.getItem() instanceof ItemViewCell) )
|
||||
{
|
||||
boolean hasInverter = false;
|
||||
boolean hasFuzzy = false;
|
||||
IItemList<IAEItemStack> priorityList = AEApi.instance().storage().createItemList();
|
||||
|
||||
ItemViewCell vc = (ItemViewCell) currentViewCell.getItem();
|
||||
IInventory upgrades = vc.getUpgradesInventory( currentViewCell );
|
||||
IInventory config = vc.getConfigInventory( currentViewCell );
|
||||
FuzzyMode fzMode = vc.getFuzzyMode( currentViewCell );
|
||||
|
||||
hasInverter = false;
|
||||
hasFuzzy = false;
|
||||
|
||||
for (int x = 0; x < upgrades.getSizeInventory(); x++)
|
||||
{
|
||||
ItemStack is = upgrades.getStackInSlot( x );
|
||||
if ( is != null && is.getItem() instanceof IUpgradeModule )
|
||||
{
|
||||
Upgrades u = ((IUpgradeModule) is.getItem()).getType( is );
|
||||
if ( u != null )
|
||||
{
|
||||
switch (u)
|
||||
{
|
||||
case FUZZY:
|
||||
hasFuzzy = true;
|
||||
break;
|
||||
case INVERTER:
|
||||
hasInverter = true;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int x = 0; x < config.getSizeInventory(); x++)
|
||||
{
|
||||
ItemStack is = config.getStackInSlot( x );
|
||||
if ( is != null )
|
||||
priorityList.add( AEItemStack.create( is ) );
|
||||
}
|
||||
|
||||
if ( !priorityList.isEmpty() )
|
||||
{
|
||||
if ( hasFuzzy )
|
||||
myMergedList.addNewList( new FuzzyPriorityList<IAEItemStack>( priorityList, fzMode ), !hasInverter );
|
||||
else
|
||||
myMergedList.addNewList( new PrecisePriorityList<IAEItemStack>( priorityList ), !hasInverter );
|
||||
|
||||
myPartitionList = myMergedList;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return myPartitionList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
package appeng.items.tools;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.features.IPlayerRegistry;
|
||||
import appeng.api.implementations.items.IBiometricCard;
|
||||
import appeng.api.networking.security.ISecurityRegistry;
|
||||
import appeng.client.render.items.ToolBiometricCardRender;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.util.Platform;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
public class ToolBiometricCard extends AEBaseItem implements IBiometricCard
|
||||
{
|
||||
|
||||
public ToolBiometricCard() {
|
||||
super( ToolBiometricCard.class );
|
||||
setFeature( EnumSet.of( AEFeature.Security ) );
|
||||
setMaxStackSize( 1 );
|
||||
if ( Platform.isClient() )
|
||||
MinecraftForgeClient.registerItemRenderer( this, new ToolBiometricCardRender() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemStackDisplayName(ItemStack is)
|
||||
{
|
||||
GameProfile username = getProfile( is );
|
||||
return username != null ? super.getItemStackDisplayName( is ) + " - " + username.getName() : super.getItemStackDisplayName( is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean itemInteractionForEntity(ItemStack is, EntityPlayer par2EntityPlayer, EntityLivingBase target)
|
||||
{
|
||||
if ( target instanceof EntityPlayer && !par2EntityPlayer.isSneaking() )
|
||||
{
|
||||
if ( par2EntityPlayer.capabilities.isCreativeMode )
|
||||
is = par2EntityPlayer.getCurrentEquippedItem();
|
||||
encode( is, (EntityPlayer) target );
|
||||
par2EntityPlayer.swingItem();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack is, World w, EntityPlayer p)
|
||||
{
|
||||
if ( p.isSneaking() )
|
||||
{
|
||||
encode( is, p );
|
||||
p.swingItem();
|
||||
return is;
|
||||
}
|
||||
|
||||
return is;
|
||||
}
|
||||
|
||||
private void encode(ItemStack is, EntityPlayer p)
|
||||
{
|
||||
GameProfile username = getProfile( is );
|
||||
|
||||
if (username != null && username.equals(p.getGameProfile()))
|
||||
setProfile( is, null );
|
||||
else
|
||||
setProfile( is, p.getGameProfile() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack is, EntityPlayer p, List l, boolean b)
|
||||
{
|
||||
EnumSet<SecurityPermissions> perms = getPermissions( is );
|
||||
if ( perms.isEmpty() )
|
||||
l.add( GuiText.NoPermissions.getLocal() );
|
||||
else
|
||||
{
|
||||
String msg = null;
|
||||
|
||||
for (SecurityPermissions sp : perms)
|
||||
{
|
||||
if ( msg == null )
|
||||
msg = Platform.gui_localize( sp.getUnlocalizedName() );
|
||||
else
|
||||
msg = msg + ", " + Platform.gui_localize( sp.getUnlocalizedName() );
|
||||
}
|
||||
l.add( msg );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameProfile getProfile(ItemStack is)
|
||||
{
|
||||
NBTTagCompound tag = Platform.openNbtData( is );
|
||||
if ( tag.hasKey("profile") )
|
||||
return NBTUtil.func_152459_a(tag.getCompoundTag("profile") );
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<SecurityPermissions> getPermissions(ItemStack is)
|
||||
{
|
||||
NBTTagCompound tag = Platform.openNbtData( is );
|
||||
EnumSet<SecurityPermissions> result = EnumSet.noneOf( SecurityPermissions.class );
|
||||
|
||||
for (SecurityPermissions sp : SecurityPermissions.values())
|
||||
{
|
||||
if ( tag.getBoolean( sp.name() ) )
|
||||
result.add( sp );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(ItemStack is, SecurityPermissions permission)
|
||||
{
|
||||
NBTTagCompound tag = Platform.openNbtData( is );
|
||||
return tag.getBoolean( permission.name() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProfile(ItemStack itemStack, GameProfile profile)
|
||||
{
|
||||
NBTTagCompound tag = Platform.openNbtData( itemStack );
|
||||
|
||||
if ( profile!= null )
|
||||
{
|
||||
NBTTagCompound pNBT = new NBTTagCompound();
|
||||
NBTUtil.func_152460_a( pNBT, profile );
|
||||
tag.setTag( "profile", pNBT );
|
||||
}
|
||||
else
|
||||
tag.removeTag("profile");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePermission(ItemStack itemStack, SecurityPermissions permission)
|
||||
{
|
||||
NBTTagCompound tag = Platform.openNbtData( itemStack );
|
||||
if ( tag.hasKey( permission.name() ) )
|
||||
tag.removeTag( permission.name() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPermission(ItemStack itemStack, SecurityPermissions permission)
|
||||
{
|
||||
NBTTagCompound tag = Platform.openNbtData( itemStack );
|
||||
tag.setBoolean( permission.name(), true );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPermissions(ISecurityRegistry register, IPlayerRegistry pr, ItemStack is)
|
||||
{
|
||||
register.addPlayer( pr.getID( getProfile( is ) ), getPermissions( is ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package appeng.items.tools;
|
||||
|
||||
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.implementations.items.IMemoryCard;
|
||||
import appeng.api.implementations.items.MemoryCardMessages;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.localization.PlayerMessages;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class ToolMemoryCard extends AEBaseItem implements IMemoryCard
|
||||
{
|
||||
|
||||
public ToolMemoryCard() {
|
||||
super( ToolMemoryCard.class );
|
||||
setFeature( EnumSet.of( AEFeature.Core ) );
|
||||
setMaxStackSize( 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the localized string...
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
private String getLocalizedName(String... name)
|
||||
{
|
||||
for (String n : name)
|
||||
{
|
||||
String l = StatCollector.translateToLocal( n );
|
||||
if ( !l.equals( n ) )
|
||||
return l;
|
||||
}
|
||||
|
||||
for (String n : name)
|
||||
return n;
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack i, EntityPlayer p, List l, boolean b)
|
||||
{
|
||||
l.add( getLocalizedName( getSettingsName( i ) + ".name", getSettingsName( i ) ) );
|
||||
|
||||
NBTTagCompound data = getData( i );
|
||||
if ( data.hasKey( "tooltip" ) )
|
||||
l.add( StatCollector.translateToLocal( getLocalizedName( data.getString( "tooltip" ) + ".name", data.getString( "tooltip" ) ) ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesSneakBypassUse(World world, int x, int y, int z, EntityPlayer player)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMemoryCardContents(ItemStack is, String SettingsName, NBTTagCompound data)
|
||||
{
|
||||
NBTTagCompound c = Platform.openNbtData( is );
|
||||
c.setString( "Config", SettingsName );
|
||||
c.setTag( "Data", data );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSettingsName(ItemStack is)
|
||||
{
|
||||
NBTTagCompound c = Platform.openNbtData( is );
|
||||
String name = c.getString( "Config" );
|
||||
return name == null || name == "" ? GuiText.Blank.getUnlocalized() : name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getData(ItemStack is)
|
||||
{
|
||||
NBTTagCompound c = Platform.openNbtData( is );
|
||||
NBTTagCompound o = c.getCompoundTag( "Data" );
|
||||
if ( o == null )
|
||||
o = new NBTTagCompound();
|
||||
return (NBTTagCompound) o.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUse(ItemStack is, EntityPlayer player, World w, int x, int y, int z, int side, float hx, float hy, float hz)
|
||||
{
|
||||
if ( player.isSneaking() && !w.isRemote )
|
||||
{
|
||||
IMemoryCard mem = (IMemoryCard) is.getItem();
|
||||
mem.notifyUser( player, MemoryCardMessages.SETTINGS_CLEARED );
|
||||
is.setTagCompound( null );
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return super.onItemUse( is, player, w, x, y, z, side, hx, hy, hz );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyUser(EntityPlayer player, MemoryCardMessages msg)
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
return;
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case SETTINGS_CLEARED:
|
||||
player.addChatMessage( PlayerMessages.SettingCleared.get() );
|
||||
break;
|
||||
case INVALID_MACHINE:
|
||||
player.addChatMessage( PlayerMessages.InvalidMachine.get() );
|
||||
break;
|
||||
case SETTINGS_LOADED:
|
||||
player.addChatMessage( PlayerMessages.LoadedSettings.get() );
|
||||
break;
|
||||
case SETTINGS_SAVED:
|
||||
player.addChatMessage( PlayerMessages.SavedSettings.get() );
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
package appeng.items.tools;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.implementations.guiobjects.IGuiItem;
|
||||
import appeng.api.implementations.guiobjects.IGuiItemObject;
|
||||
import appeng.api.implementations.items.IAEWrench;
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.SelectedPart;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.api.util.INetworkToolAgent;
|
||||
import appeng.client.ClientHelper;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketClick;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.items.contents.NetworkToolViewer;
|
||||
import appeng.transformer.annotations.integration.Interface;
|
||||
import appeng.util.Platform;
|
||||
import buildcraft.api.tools.IToolWrench;
|
||||
|
||||
@Interface(iface = "buildcraft.api.tools.IToolWrench", iname = "BC")
|
||||
public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench, IToolWrench
|
||||
{
|
||||
|
||||
public ToolNetworkTool() {
|
||||
super( ToolNetworkTool.class, null );
|
||||
setFeature( EnumSet.of( AEFeature.NetworkTool ) );
|
||||
setMaxStackSize( 1 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGuiItemObject getGuiObject(ItemStack is, World world, int x, int y, int z)
|
||||
{
|
||||
TileEntity te = world.getTileEntity( x, y, z );
|
||||
return new NetworkToolViewer( is, (IGridHost) (te instanceof IGridHost ? te : null) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack it, World w, EntityPlayer p)
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
{
|
||||
MovingObjectPosition mop = ClientHelper.proxy.getMOP();
|
||||
|
||||
if ( mop == null )
|
||||
{
|
||||
onItemUseFirst( it, p, w, 0, 0, 0, -1, 0, 0, 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
int i = mop.blockX;
|
||||
int j = mop.blockY;
|
||||
int k = mop.blockZ;
|
||||
|
||||
if ( w.getBlock( i, j, k ).isAir( w, i, j, k ) )
|
||||
onItemUseFirst( it, p, w, 0, 0, 0, -1, 0, 0, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
return it;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUseFirst(ItemStack is, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
MovingObjectPosition mop = new MovingObjectPosition( x, y, z, side, Vec3.createVectorHelper( hitX, hitY, hitZ ) );
|
||||
TileEntity te = world.getTileEntity( x, y, z );
|
||||
if ( te instanceof IPartHost )
|
||||
{
|
||||
SelectedPart part = ((IPartHost) te).selectPart( mop.hitVec );
|
||||
if ( part.part != null )
|
||||
{
|
||||
if ( part.part instanceof INetworkToolAgent && !((INetworkToolAgent) part.part).showNetworkInfo( mop ) )
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if ( te instanceof INetworkToolAgent && !((INetworkToolAgent) te).showNetworkInfo( mop ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( Platform.isClient() )
|
||||
{
|
||||
try
|
||||
{
|
||||
NetworkHandler.instance.sendToServer( new PacketClick( x, y, z, side, hitX, hitY, hitZ ) );
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean serverSideToolLogic(ItemStack is, EntityPlayer p, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if ( side >= 0 )
|
||||
{
|
||||
if ( !Platform.hasPermissions( new DimensionalCoord( w, x, y, z ), p ) )
|
||||
return false;
|
||||
|
||||
Block b = w.getBlock( x, y, z );
|
||||
if ( b != null && !p.isSneaking() )
|
||||
{
|
||||
TileEntity te = w.getTileEntity( x, y, z );
|
||||
if ( !(te instanceof IGridHost) )
|
||||
{
|
||||
if ( b.rotateBlock( w, x, y, z, ForgeDirection.getOrientation( side ) ) )
|
||||
{
|
||||
b.onNeighborBlockChange( w, x, y, z, Platform.air );
|
||||
p.swingItem();
|
||||
return !w.isRemote;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( !p.isSneaking() )
|
||||
{
|
||||
if ( p.openContainer instanceof AEBaseContainer )
|
||||
return true;
|
||||
|
||||
TileEntity te = w.getTileEntity( x, y, z );
|
||||
|
||||
if ( te instanceof IGridHost )
|
||||
Platform.openGUI( p, te, ForgeDirection.getOrientation( side ), GuiBridge.GUI_NETWORK_STATUS );
|
||||
else
|
||||
Platform.openGUI( p, null, ForgeDirection.UNKNOWN, GuiBridge.GUI_NETWORK_TOOL );
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
b.onBlockActivated( w, x, y, z, p, side, hitX, hitY, hitZ );
|
||||
}
|
||||
else
|
||||
Platform.openGUI( p, null, ForgeDirection.UNKNOWN, GuiBridge.GUI_NETWORK_TOOL );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesSneakBypassUse(World world, int x, int y, int z, EntityPlayer player)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWrench(ItemStack is, EntityPlayer player, int x, int y, int z)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWrench(EntityPlayer player, int x, int y, int z)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void wrenchUsed(EntityPlayer player, int x, int y, int z)
|
||||
{
|
||||
player.swingItem();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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; }
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package appeng.items.tools.quartz;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.item.ItemAxe;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.features.AEFeatureHandler;
|
||||
import appeng.core.features.IAEFeature;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class ToolQuartzAxe extends ItemAxe implements IAEFeature
|
||||
{
|
||||
|
||||
final AEFeature type;
|
||||
final AEFeatureHandler feature;
|
||||
|
||||
@Override
|
||||
public AEFeatureHandler feature()
|
||||
{
|
||||
return feature;
|
||||
}
|
||||
|
||||
public boolean getIsRepairable(ItemStack a, ItemStack b)
|
||||
{
|
||||
return Platform.canRepair( type, a, b );
|
||||
}
|
||||
|
||||
public ToolQuartzAxe(AEFeature Type) {
|
||||
super( ToolMaterial.IRON );
|
||||
feature = new AEFeatureHandler( EnumSet.of( type = Type, AEFeature.QuartzAxe ), this, Type.name() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInit()
|
||||
{
|
||||
// override!
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package appeng.items.tools.quartz;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.implementations.guiobjects.IGuiItem;
|
||||
import appeng.api.implementations.guiobjects.IGuiItemObject;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.items.contents.QuartzKnifeObj;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class ToolQuartzCuttingKnife extends AEBaseItem implements IGuiItem
|
||||
{
|
||||
|
||||
final AEFeature type;
|
||||
|
||||
public ToolQuartzCuttingKnife(AEFeature Type) {
|
||||
super( ToolQuartzCuttingKnife.class, Type.name() );
|
||||
setFeature( EnumSet.of( type = Type, AEFeature.QuartzKnife ) );
|
||||
setMaxDamage( 50 );
|
||||
setMaxStackSize( 1 );
|
||||
}
|
||||
|
||||
public boolean getIsRepairable(ItemStack a, ItemStack b)
|
||||
{
|
||||
return Platform.canRepair( type, a, b );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRepairable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesContainerItemLeaveCraftingGrid(ItemStack par1ItemStack)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContainerItem()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack it, World w, EntityPlayer p)
|
||||
{
|
||||
if ( Platform.isServer() )
|
||||
Platform.openGUI( p, null, ForgeDirection.UNKNOWN, GuiBridge.GUI_QUARTZ_KNIFE );
|
||||
p.swingItem();
|
||||
return it;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUse(ItemStack is, EntityPlayer p, World w, int x, int y, int z, int s, float hitx, float hity, float hitz)
|
||||
{
|
||||
if ( Platform.isServer() )
|
||||
Platform.openGUI( p, null, ForgeDirection.UNKNOWN, GuiBridge.GUI_QUARTZ_KNIFE );
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getContainerItem(ItemStack itemStack)
|
||||
{
|
||||
itemStack.setItemDamage( itemStack.getItemDamage() + 1 );
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGuiItemObject getGuiObject(ItemStack is, World world, int x, int y, int z)
|
||||
{
|
||||
return new QuartzKnifeObj( is );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package appeng.items.tools.quartz;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.item.ItemHoe;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.features.AEFeatureHandler;
|
||||
import appeng.core.features.IAEFeature;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class ToolQuartzHoe extends ItemHoe implements IAEFeature
|
||||
{
|
||||
|
||||
final AEFeature type;
|
||||
final AEFeatureHandler feature;
|
||||
|
||||
@Override
|
||||
public AEFeatureHandler feature()
|
||||
{
|
||||
return feature;
|
||||
}
|
||||
|
||||
public boolean getIsRepairable(ItemStack a, ItemStack b)
|
||||
{
|
||||
return Platform.canRepair( type, a, b );
|
||||
}
|
||||
|
||||
public ToolQuartzHoe(AEFeature Type) {
|
||||
super( ToolMaterial.IRON );
|
||||
feature = new AEFeatureHandler( EnumSet.of( type = Type, AEFeature.QuartzHoe ), this, Type.name() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInit()
|
||||
{
|
||||
// override!
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package appeng.items.tools.quartz;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.item.ItemPickaxe;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.features.AEFeatureHandler;
|
||||
import appeng.core.features.IAEFeature;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class ToolQuartzPickaxe extends ItemPickaxe implements IAEFeature
|
||||
{
|
||||
|
||||
final AEFeature type;
|
||||
final AEFeatureHandler feature;
|
||||
|
||||
@Override
|
||||
public AEFeatureHandler feature()
|
||||
{
|
||||
return feature;
|
||||
}
|
||||
|
||||
public boolean getIsRepairable(ItemStack a, ItemStack b)
|
||||
{
|
||||
return Platform.canRepair( type, a, b );
|
||||
}
|
||||
|
||||
public ToolQuartzPickaxe(AEFeature Type) {
|
||||
super( ToolMaterial.IRON );
|
||||
feature = new AEFeatureHandler( EnumSet.of( type = Type, AEFeature.QuartzPickaxe ), this, Type.name() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInit()
|
||||
{
|
||||
// override!
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package appeng.items.tools.quartz;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.item.ItemSpade;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.features.AEFeatureHandler;
|
||||
import appeng.core.features.IAEFeature;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class ToolQuartzSpade extends ItemSpade implements IAEFeature
|
||||
{
|
||||
|
||||
final AEFeature type;
|
||||
final AEFeatureHandler feature;
|
||||
|
||||
@Override
|
||||
public AEFeatureHandler feature()
|
||||
{
|
||||
return feature;
|
||||
}
|
||||
|
||||
public boolean getIsRepairable(ItemStack a, ItemStack b)
|
||||
{
|
||||
return Platform.canRepair( type, a, b );
|
||||
}
|
||||
|
||||
public ToolQuartzSpade(AEFeature Type) {
|
||||
super( ToolMaterial.IRON );
|
||||
feature = new AEFeatureHandler( EnumSet.of( type = Type, AEFeature.QuartzSpade ), this, Type.name() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInit()
|
||||
{
|
||||
// override!
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package appeng.items.tools.quartz;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemSword;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.features.AEFeatureHandler;
|
||||
import appeng.core.features.IAEFeature;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class ToolQuartzSword extends ItemSword implements IAEFeature
|
||||
{
|
||||
|
||||
final AEFeature type;
|
||||
final AEFeatureHandler feature;
|
||||
|
||||
@Override
|
||||
public AEFeatureHandler feature()
|
||||
{
|
||||
return feature;
|
||||
}
|
||||
|
||||
public boolean getIsRepairable(ItemStack a, ItemStack b)
|
||||
{
|
||||
return Platform.canRepair( type, a, b );
|
||||
}
|
||||
|
||||
public ToolQuartzSword(AEFeature Type) {
|
||||
super( ToolMaterial.IRON );
|
||||
feature = new AEFeatureHandler( EnumSet.of( type = Type, AEFeature.QuartzSword ), this, Type.name() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInit()
|
||||
{
|
||||
// override!
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package appeng.items.tools.quartz;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.implementations.items.IAEWrench;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.transformer.annotations.integration.Interface;
|
||||
import appeng.util.Platform;
|
||||
import buildcraft.api.tools.IToolWrench;
|
||||
|
||||
@Interface(iface = "buildcraft.api.tools.IToolWrench", iname = "BC")
|
||||
public class ToolQuartzWrench extends AEBaseItem implements IAEWrench, IToolWrench
|
||||
{
|
||||
|
||||
public ToolQuartzWrench(AEFeature type) {
|
||||
super( ToolQuartzWrench.class, type.name() );
|
||||
setFeature( EnumSet.of( type, AEFeature.QuartzWrench ) );
|
||||
setMaxStackSize( 1 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUseFirst(ItemStack is, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
Block b = world.getBlock( x, y, z );
|
||||
if ( b != null && !player.isSneaking() && Platform.hasPermissions( new DimensionalCoord( world, x, y, z ), player ) )
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
return !world.isRemote;
|
||||
|
||||
ForgeDirection mySide = ForgeDirection.getOrientation( side );
|
||||
if ( b.rotateBlock( world, x, y, z, mySide ) )
|
||||
{
|
||||
b.onNeighborBlockChange( world, x, y, z, Platform.air );
|
||||
player.swingItem();
|
||||
return !world.isRemote;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
// public boolean shouldPassSneakingClickToBlock(World w, int x, int y, int z)
|
||||
public boolean doesSneakBypassUse(World world, int x, int y, int z, EntityPlayer player)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWrench(ItemStack is, EntityPlayer player, int x, int y, int z)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWrench(EntityPlayer player, int x, int y, int z)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void wrenchUsed(EntityPlayer player, int x, int y, int z)
|
||||
{
|
||||
player.swingItem();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user