reformatted all src files (#141)

This commit is contained in:
YoungOnion
2022-09-17 05:08:02 -06:00
committed by GitHub
parent 3328bfcda2
commit 9011273229
1056 changed files with 88127 additions and 110597 deletions
+34 -43
View File
@@ -19,8 +19,6 @@
package appeng.items;
import java.util.List;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
@@ -30,54 +28,47 @@ import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.List;
public abstract class AEBaseItem extends Item
{
public AEBaseItem()
{
this.setNoRepair();
}
public abstract class AEBaseItem extends Item {
@Override
public String toString()
{
String regName = this.getRegistryName() != null ? this.getRegistryName().getResourcePath() : "unregistered";
return this.getClass().getSimpleName() + "[" + regName + "]";
}
public AEBaseItem() {
this.setNoRepair();
}
@SideOnly( Side.CLIENT )
@Override
@SuppressWarnings( "unchecked" )
public final void addInformation( final ItemStack stack, final World world, final List lines, final ITooltipFlag advancedTooltips )
{
this.addCheckedInformation( stack, world, lines, advancedTooltips );
}
@Override
public String toString() {
String regName = this.getRegistryName() != null ? this.getRegistryName().getResourcePath() : "unregistered";
return this.getClass().getSimpleName() + "[" + regName + "]";
}
@Override
public final void getSubItems( final CreativeTabs creativeTab, final NonNullList<ItemStack> itemStacks )
{
if( this.isInCreativeTab( creativeTab ) )
{
this.getCheckedSubItems( creativeTab, itemStacks );
}
}
@SideOnly(Side.CLIENT)
@Override
@SuppressWarnings("unchecked")
public final void addInformation(final ItemStack stack, final World world, final List lines, final ITooltipFlag advancedTooltips) {
this.addCheckedInformation(stack, world, lines, advancedTooltips);
}
@Override
public boolean isBookEnchantable( final ItemStack itemstack1, final ItemStack itemstack2 )
{
return false;
}
@Override
public final void getSubItems(final CreativeTabs creativeTab, final NonNullList<ItemStack> itemStacks) {
if (this.isInCreativeTab(creativeTab)) {
this.getCheckedSubItems(creativeTab, itemStacks);
}
}
@SideOnly( Side.CLIENT )
protected void addCheckedInformation( final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips )
{
super.addInformation( stack, world, lines, advancedTooltips );
}
@Override
public boolean isBookEnchantable(final ItemStack itemstack1, final ItemStack itemstack2) {
return false;
}
protected void getCheckedSubItems( final CreativeTabs creativeTab, final NonNullList<ItemStack> itemStacks )
{
super.getSubItems( creativeTab, itemStacks );
}
@SideOnly(Side.CLIENT)
protected void addCheckedInformation(final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips) {
super.addInformation(stack, world, lines, advancedTooltips);
}
protected void getCheckedSubItems(final CreativeTabs creativeTab, final NonNullList<ItemStack> itemStacks) {
super.getSubItems(creativeTab, itemStacks);
}
}
@@ -19,27 +19,23 @@
package appeng.items.contents;
import net.minecraft.item.ItemStack;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.util.Platform;
import net.minecraft.item.ItemStack;
public class CellConfig extends AppEngInternalInventory
{
public class CellConfig extends AppEngInternalInventory {
private final ItemStack is;
private final ItemStack is;
public CellConfig( final ItemStack is )
{
super( null, 63 );
this.is = is;
this.readFromNBT( Platform.openNbtData( is ), "list" );
}
public CellConfig(final ItemStack is) {
super(null, 63);
this.is = is;
this.readFromNBT(Platform.openNbtData(is), "list");
}
@Override
protected void onContentsChanged( int slot )
{
this.writeToNBT( Platform.openNbtData( this.is ), "list" );
}
@Override
protected void onContentsChanged(int slot) {
this.writeToNBT(Platform.openNbtData(this.is), "list");
}
}
@@ -19,26 +19,22 @@
package appeng.items.contents;
import net.minecraft.item.ItemStack;
import appeng.parts.automation.StackUpgradeInventory;
import appeng.util.Platform;
import net.minecraft.item.ItemStack;
public final class CellUpgrades extends StackUpgradeInventory
{
private final ItemStack is;
public final class CellUpgrades extends StackUpgradeInventory {
private final ItemStack is;
public CellUpgrades( final ItemStack is, final int upgrades )
{
super( is, null, upgrades );
this.is = is;
this.readFromNBT( Platform.openNbtData( is ), "upgrades" );
}
public CellUpgrades(final ItemStack is, final int upgrades) {
super(is, null, upgrades);
this.is = is;
this.readFromNBT(Platform.openNbtData(is), "upgrades");
}
@Override
protected void onContentsChanged( int slot )
{
this.writeToNBT( Platform.openNbtData( this.is ), "upgrades" );
}
@Override
protected void onContentsChanged(int slot) {
this.writeToNBT(Platform.openNbtData(this.is), "upgrades");
}
}
@@ -19,9 +19,6 @@
package appeng.items.contents;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import appeng.api.implementations.guiobjects.INetworkTool;
import appeng.api.implementations.items.IUpgradeModule;
import appeng.api.networking.IGridHost;
@@ -30,73 +27,64 @@ import appeng.util.Platform;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
import appeng.util.inv.filter.IAEItemFilter;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
public class NetworkToolViewer implements INetworkTool, IAEAppEngInventory
{
public class NetworkToolViewer implements INetworkTool, IAEAppEngInventory {
private final AppEngInternalInventory inv;
private final ItemStack is;
private final IGridHost gh;
private final AppEngInternalInventory inv;
private final ItemStack is;
private final IGridHost gh;
public NetworkToolViewer( final ItemStack is, final IGridHost gHost )
{
this.is = is;
this.gh = gHost;
this.inv = new AppEngInternalInventory( this, 9 );
this.inv.setFilter( new NetworkToolInventoryFilter() );
if( is.hasTagCompound() ) // prevent crash when opening network status screen.
{
this.inv.readFromNBT( Platform.openNbtData( is ), "inv" );
}
}
public NetworkToolViewer(final ItemStack is, final IGridHost gHost) {
this.is = is;
this.gh = gHost;
this.inv = new AppEngInternalInventory(this, 9);
this.inv.setFilter(new NetworkToolInventoryFilter());
if (is.hasTagCompound()) // prevent crash when opening network status screen.
{
this.inv.readFromNBT(Platform.openNbtData(is), "inv");
}
}
@Override
public void saveChanges()
{
this.inv.writeToNBT( Platform.openNbtData( this.is ), "inv" );
}
@Override
public void saveChanges() {
this.inv.writeToNBT(Platform.openNbtData(this.is), "inv");
}
@Override
public void onChangeInventory( IItemHandler inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack )
{
}
@Override
public void onChangeInventory(IItemHandler inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack) {
}
@Override
public ItemStack getItemStack()
{
return this.is;
}
@Override
public ItemStack getItemStack() {
return this.is;
}
@Override
public IGridHost getGridHost()
{
return this.gh;
}
@Override
public IGridHost getGridHost() {
return this.gh;
}
private static class NetworkToolInventoryFilter implements IAEItemFilter
{
@Override
public boolean allowExtract( IItemHandler inv, int slot, int amount )
{
return true;
}
private static class NetworkToolInventoryFilter implements IAEItemFilter {
@Override
public boolean allowExtract(IItemHandler inv, int slot, int amount) {
return true;
}
@Override
public boolean allowInsert( IItemHandler inv, int slot, ItemStack stack )
{
return stack.getItem() instanceof IUpgradeModule && ( (IUpgradeModule) stack.getItem() ).getType( stack ) != null;
}
}
@Override
public boolean allowInsert(IItemHandler inv, int slot, ItemStack stack) {
return stack.getItem() instanceof IUpgradeModule && ((IUpgradeModule) stack.getItem()).getType(stack) != null;
}
}
public IItemHandler getInternalInventory()
{
return this.inv;
}
public IItemHandler getInternalInventory() {
return this.inv;
}
@Override
public IItemHandler getInventory()
{
return this.inv;
}
@Override
public IItemHandler getInventory() {
return this.inv;
}
}
@@ -19,19 +19,11 @@
package appeng.items.contents;
import appeng.api.networking.security.IActionSource;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import appeng.api.AEApi;
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.config.*;
import appeng.api.implementations.guiobjects.IPortableCell;
import appeng.api.implementations.items.IAEItemPowerStorage;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
@@ -42,102 +34,91 @@ import appeng.container.interfaces.IInventorySlotAware;
import appeng.me.helpers.MEMonitorHandler;
import appeng.util.ConfigManager;
import appeng.util.Platform;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import java.util.Collections;
public class PortableCellViewer extends MEMonitorHandler<IAEItemStack> implements IPortableCell, IInventorySlotAware
{
public class PortableCellViewer extends MEMonitorHandler<IAEItemStack> implements IPortableCell, IInventorySlotAware {
private final ItemStack target;
private final IAEItemPowerStorage ips;
private final int inventorySlot;
private final ItemStack target;
private final IAEItemPowerStorage ips;
private final int inventorySlot;
public PortableCellViewer( final ItemStack is, final int slot )
{
super( AEApi.instance().registries().cell().getCellInventory( is, null, AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ) );
this.ips = (IAEItemPowerStorage) is.getItem();
this.target = is;
this.inventorySlot = slot;
}
public PortableCellViewer(final ItemStack is, final int slot) {
super(AEApi.instance().registries().cell().getCellInventory(is, null, AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)));
this.ips = (IAEItemPowerStorage) is.getItem();
this.target = is;
this.inventorySlot = slot;
}
@Override
public int getInventorySlot()
{
return this.inventorySlot;
}
@Override
public int getInventorySlot() {
return this.inventorySlot;
}
@Override
public ItemStack getItemStack()
{
return this.target;
}
@Override
public ItemStack getItemStack() {
return this.target;
}
@Override
public double extractAEPower( double amt, final Actionable mode, final PowerMultiplier usePowerMultiplier )
{
amt = usePowerMultiplier.multiply( amt );
@Override
public double extractAEPower(double amt, final Actionable mode, final PowerMultiplier usePowerMultiplier) {
amt = usePowerMultiplier.multiply(amt);
if( mode == Actionable.SIMULATE )
{
return usePowerMultiplier.divide( Math.min( amt, this.ips.getAECurrentPower( this.target ) ) );
}
if (mode == Actionable.SIMULATE) {
return usePowerMultiplier.divide(Math.min(amt, this.ips.getAECurrentPower(this.target)));
}
return usePowerMultiplier.divide( this.ips.extractAEPower( this.target, amt, Actionable.MODULATE ) );
}
return usePowerMultiplier.divide(this.ips.extractAEPower(this.target, amt, Actionable.MODULATE));
}
@Override
public IAEItemStack injectItems( IAEItemStack input, Actionable mode, IActionSource src )
{
final long size = input.getStackSize();
@Override
public IAEItemStack injectItems(IAEItemStack input, Actionable mode, IActionSource src) {
final long size = input.getStackSize();
final IAEItemStack injected = super.injectItems( input, mode, src );
final IAEItemStack injected = super.injectItems(input, mode, src);
if( mode == Actionable.MODULATE && ( injected == null || injected.getStackSize() != size ) )
{
this.notifyListenersOfChange( Collections.singletonList( input.copy().setStackSize( input.getStackSize() - ( injected == null ? 0 : injected.getStackSize() ) ) ), null);
}
if (mode == Actionable.MODULATE && (injected == null || injected.getStackSize() != size)) {
this.notifyListenersOfChange(Collections.singletonList(input.copy().setStackSize(input.getStackSize() - (injected == null ? 0 : injected.getStackSize()))), null);
}
return injected;
}
return injected;
}
@Override
public IAEItemStack extractItems( IAEItemStack request, Actionable mode, IActionSource src )
{
final IAEItemStack extractable = super.extractItems( request, mode, src );
@Override
public IAEItemStack extractItems(IAEItemStack request, Actionable mode, IActionSource src) {
final IAEItemStack extractable = super.extractItems(request, mode, src);
if( mode == Actionable.MODULATE && extractable != null )
{
this.notifyListenersOfChange( Collections.singletonList( request.copy().setStackSize( -extractable.getStackSize() ) ), null );
}
if (mode == Actionable.MODULATE && extractable != null) {
this.notifyListenersOfChange(Collections.singletonList(request.copy().setStackSize(-extractable.getStackSize())), null);
}
return extractable;
}
return extractable;
}
@Override
public <T extends IAEStack<T>> IMEMonitor<T> getInventory( IStorageChannel<T> channel )
{
if( channel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
{
return (IMEMonitor<T>) this;
}
return null;
}
@Override
public <T extends IAEStack<T>> IMEMonitor<T> getInventory(IStorageChannel<T> channel) {
if (channel == AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)) {
return (IMEMonitor<T>) this;
}
return null;
}
@Override
public IConfigManager getConfigManager()
{
final ConfigManager out = new ConfigManager( ( manager, settingName, newValue ) ->
{
final NBTTagCompound data = Platform.openNbtData( PortableCellViewer.this.target );
manager.writeToNBT( data );
} );
@Override
public IConfigManager getConfigManager() {
final ConfigManager out = new ConfigManager((manager, settingName, newValue) ->
{
final NBTTagCompound data = Platform.openNbtData(PortableCellViewer.this.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.registerSetting(Settings.SORT_BY, SortOrder.NAME);
out.registerSetting(Settings.VIEW_MODE, ViewItems.ALL);
out.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING);
out.readFromNBT( Platform.openNbtData( this.target ).copy() );
return out;
}
out.readFromNBT(Platform.openNbtData(this.target).copy());
return out;
}
}
@@ -19,24 +19,20 @@
package appeng.items.contents;
import appeng.api.implementations.guiobjects.IGuiItemObject;
import net.minecraft.item.ItemStack;
import appeng.api.implementations.guiobjects.IGuiItemObject;
public class QuartzKnifeObj implements IGuiItemObject {
public class QuartzKnifeObj implements IGuiItemObject
{
private final ItemStack is;
private final ItemStack is;
public QuartzKnifeObj(final ItemStack o) {
this.is = o;
}
public QuartzKnifeObj( final ItemStack o )
{
this.is = o;
}
@Override
public ItemStack getItemStack()
{
return this.is;
}
@Override
public ItemStack getItemStack() {
return this.is;
}
}
@@ -19,20 +19,24 @@
package appeng.items.materials;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
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.implementations.tiles.ISegmentedInventory;
import appeng.api.parts.IPartHost;
import appeng.api.parts.SelectedPart;
import appeng.core.AEConfig;
import appeng.core.features.AEFeature;
import appeng.core.features.IStackSrc;
import appeng.core.features.MaterialStackSrc;
import appeng.items.AEBaseItem;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.inv.AdaptorItemHandler;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
@@ -53,350 +57,280 @@ import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
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.implementations.tiles.ISegmentedInventory;
import appeng.api.parts.IPartHost;
import appeng.api.parts.SelectedPart;
import appeng.core.AEConfig;
import appeng.core.features.AEFeature;
import appeng.core.features.IStackSrc;
import appeng.core.features.MaterialStackSrc;
import appeng.items.AEBaseItem;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.inv.AdaptorItemHandler;
import java.util.*;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public final class ItemMaterial extends AEBaseItem implements IStorageComponent, IUpgradeModule
{
public static ItemMaterial instance;
public final class ItemMaterial extends AEBaseItem implements IStorageComponent, IUpgradeModule {
public static ItemMaterial instance;
private static final int KILO_SCALAR = 1024;
private static final int KILO_SCALAR = 1024;
private final Map<Integer, MaterialType> dmgToMaterial = new HashMap<>();
private final Map<Integer, MaterialType> dmgToMaterial = new HashMap<>();
public ItemMaterial()
{
this.setHasSubtypes( true );
instance = this;
}
public ItemMaterial() {
this.setHasSubtypes(true);
instance = this;
}
@SideOnly( Side.CLIENT )
@Override
public void addCheckedInformation( final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips )
{
super.addCheckedInformation( stack, world, lines, advancedTooltips );
@SideOnly(Side.CLIENT)
@Override
public void addCheckedInformation(final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips) {
super.addCheckedInformation(stack, world, lines, advancedTooltips);
final MaterialType mt = this.getTypeByStack( stack );
if( mt == null )
{
return;
}
final MaterialType mt = this.getTypeByStack(stack);
if (mt == null) {
return;
}
if( mt == MaterialType.NAME_PRESS )
{
final NBTTagCompound c = Platform.openNbtData( stack );
lines.add( c.getString( "InscribeName" ) );
}
if (mt == MaterialType.NAME_PRESS) {
final NBTTagCompound c = Platform.openNbtData(stack);
lines.add(c.getString("InscribeName"));
}
final Upgrades u = this.getType( stack );
if( u != null )
{
final List<String> textList = new ArrayList<>();
for( final Entry<ItemStack, Integer> j : u.getSupported().entrySet() )
{
String name = null;
final Upgrades u = this.getType(stack);
if (u != null) {
final List<String> textList = new ArrayList<>();
for (final Entry<ItemStack, Integer> j : u.getSupported().entrySet()) {
String name = null;
final int limit = j.getValue();
final int limit = j.getValue();
if( j.getKey().getItem() instanceof IItemGroup )
{
final IItemGroup ig = (IItemGroup) j.getKey().getItem();
final String str = ig.getUnlocalizedGroupName( u.getSupported().keySet(), j.getKey() );
if( str != null )
{
name = Platform.gui_localize( str ) + ( limit > 1 ? " (" + limit + ')' : "" );
}
}
if (j.getKey().getItem() instanceof IItemGroup) {
final IItemGroup ig = (IItemGroup) j.getKey().getItem();
final 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 (name == null) {
name = j.getKey().getDisplayName() + (limit > 1 ? " (" + limit + ')' : "");
}
if( !textList.contains( name ) )
{
textList.add( name );
}
}
if (!textList.contains(name)) {
textList.add(name);
}
}
final Pattern p = Pattern.compile( "(\\d+)[^\\d]" );
final SlightlyBetterSort s = new SlightlyBetterSort( p );
Collections.sort( textList, s );
lines.addAll( textList );
}
}
final Pattern p = Pattern.compile("(\\d+)[^\\d]");
final SlightlyBetterSort s = new SlightlyBetterSort(p);
Collections.sort(textList, s);
lines.addAll(textList);
}
}
public MaterialType getTypeByStack( final ItemStack is )
{
MaterialType type = this.dmgToMaterial.get( is.getItemDamage() );
return ( type != null ) ? type : MaterialType.INVALID_TYPE;
}
public MaterialType getTypeByStack(final ItemStack is) {
MaterialType type = this.dmgToMaterial.get(is.getItemDamage());
return (type != null) ? type : MaterialType.INVALID_TYPE;
}
@Override
public Upgrades getType( final ItemStack itemstack )
{
switch( this.getTypeByStack( itemstack ) )
{
case CARD_CAPACITY:
return Upgrades.CAPACITY;
case CARD_FUZZY:
return Upgrades.FUZZY;
case CARD_REDSTONE:
return Upgrades.REDSTONE;
case CARD_SPEED:
return Upgrades.SPEED;
case CARD_INVERTER:
return Upgrades.INVERTER;
case CARD_CRAFTING:
return Upgrades.CRAFTING;
case CARD_PATTERN_EXPANSION:
return Upgrades.PATTERN_EXPANSION;
default:
return null;
}
}
@Override
public Upgrades getType(final ItemStack itemstack) {
switch (this.getTypeByStack(itemstack)) {
case CARD_CAPACITY:
return Upgrades.CAPACITY;
case CARD_FUZZY:
return Upgrades.FUZZY;
case CARD_REDSTONE:
return Upgrades.REDSTONE;
case CARD_SPEED:
return Upgrades.SPEED;
case CARD_INVERTER:
return Upgrades.INVERTER;
case CARD_CRAFTING:
return Upgrades.CRAFTING;
case CARD_PATTERN_EXPANSION:
return Upgrades.PATTERN_EXPANSION;
default:
return null;
}
}
public IStackSrc createMaterial( final MaterialType mat )
{
Preconditions.checkState( !mat.isRegistered(), "Cannot create the same material twice." );
public IStackSrc createMaterial(final MaterialType mat) {
Preconditions.checkState(!mat.isRegistered(), "Cannot create the same material twice.");
boolean enabled = true;
boolean enabled = true;
for( final AEFeature f : mat.getFeature() )
{
enabled = enabled && AEConfig.instance().isFeatureEnabled( f );
}
for (final AEFeature f : mat.getFeature()) {
enabled = enabled && AEConfig.instance().isFeatureEnabled(f);
}
mat.setStackSrc( new MaterialStackSrc( mat, enabled ) );
mat.setStackSrc(new MaterialStackSrc(mat, enabled));
if( enabled )
{
mat.setItemInstance( this );
mat.markReady();
final int newMaterialNum = mat.getDamageValue();
if (enabled) {
mat.setItemInstance(this);
mat.markReady();
final int newMaterialNum = mat.getDamageValue();
if( this.dmgToMaterial.get( newMaterialNum ) == null )
{
this.dmgToMaterial.put( newMaterialNum, mat );
}
else
if (this.dmgToMaterial.get(newMaterialNum) == null) {
this.dmgToMaterial.put(newMaterialNum, mat);
} else {
throw new IllegalStateException("Meta Overlap detected.");
}
}
{
throw new IllegalStateException( "Meta Overlap detected." );
}
}
return mat.getStackSrc();
}
return mat.getStackSrc();
}
public void registerOredicts() {
for (final MaterialType mt : ImmutableSet.copyOf(this.dmgToMaterial.values())) {
if (mt.getOreName() != null) {
final String[] names = mt.getOreName().split(",");
public void registerOredicts()
{
for( final MaterialType mt : ImmutableSet.copyOf( this.dmgToMaterial.values() ) )
{
if( mt.getOreName() != null )
{
final String[] names = mt.getOreName().split( "," );
for (final String name : names) {
OreDictionary.registerOre(name, mt.stack(1));
}
}
}
}
for( final String name : names )
{
OreDictionary.registerOre( name, mt.stack( 1 ) );
}
}
}
}
@Override
public String getUnlocalizedName(final ItemStack is) {
return "item.appliedenergistics2.material." + this.nameOf(is).toLowerCase();
}
@Override
public String getUnlocalizedName( final ItemStack is )
{
return "item.appliedenergistics2.material." + this.nameOf( is ).toLowerCase();
}
@Override
protected void getCheckedSubItems(final CreativeTabs creativeTab, final NonNullList<ItemStack> itemStacks) {
final List<MaterialType> types = Arrays.asList(MaterialType.values());
Collections.sort(types, (o1, o2) -> o1.name().compareTo(o2.name()));
@Override
protected void getCheckedSubItems( final CreativeTabs creativeTab, final NonNullList<ItemStack> itemStacks )
{
final List<MaterialType> types = Arrays.asList( MaterialType.values() );
Collections.sort( types, ( o1, o2 ) -> o1.name().compareTo( o2.name() ) );
for (final MaterialType mat : types) {
if (mat.getDamageValue() >= 0 && mat.isRegistered() && mat.getItemInstance() == this) {
itemStacks.add(new ItemStack(this, 1, mat.getDamageValue()));
}
}
}
for( final MaterialType mat : types )
{
if( mat.getDamageValue() >= 0 && mat.isRegistered() && mat.getItemInstance() == this )
{
itemStacks.add( new ItemStack( this, 1, mat.getDamageValue() ) );
}
}
}
@Override
public EnumActionResult onItemUseFirst(final EntityPlayer player, final World world, final BlockPos pos, final EnumFacing side, final float hitX, final float hitY, final float hitZ, final EnumHand hand) {
if (player.isSneaking()) {
final TileEntity te = world.getTileEntity(pos);
IItemHandler upgrades = null;
@Override
public EnumActionResult onItemUseFirst( final EntityPlayer player, final World world, final BlockPos pos, final EnumFacing side, final float hitX, final float hitY, final float hitZ, final EnumHand hand )
{
if( player.isSneaking() )
{
final TileEntity te = world.getTileEntity( pos );
IItemHandler upgrades = null;
if (te instanceof IPartHost) {
final SelectedPart sp = ((IPartHost) te).selectPart(new Vec3d(hitX, hitY, hitZ));
if (sp.part instanceof IUpgradeableHost) {
upgrades = ((ISegmentedInventory) sp.part).getInventoryByName("upgrades");
}
} else if (te instanceof IUpgradeableHost) {
upgrades = ((ISegmentedInventory) te).getInventoryByName("upgrades");
}
if( te instanceof IPartHost )
{
final SelectedPart sp = ( (IPartHost) te ).selectPart( new Vec3d( hitX, hitY, hitZ ) );
if( sp.part instanceof IUpgradeableHost )
{
upgrades = ( (ISegmentedInventory) sp.part ).getInventoryByName( "upgrades" );
}
}
else if( te instanceof IUpgradeableHost )
{
upgrades = ( (ISegmentedInventory) te ).getInventoryByName( "upgrades" );
}
if (upgrades != null && !player.getHeldItem(hand).isEmpty() && player.getHeldItem(hand).getItem() instanceof IUpgradeModule) {
final IUpgradeModule um = (IUpgradeModule) player.getHeldItem(hand).getItem();
final Upgrades u = um.getType(player.getHeldItem(hand));
if( upgrades != null && !player.getHeldItem( hand ).isEmpty() && player.getHeldItem( hand ).getItem() instanceof IUpgradeModule )
{
final IUpgradeModule um = (IUpgradeModule) player.getHeldItem( hand ).getItem();
final Upgrades u = um.getType( player.getHeldItem( hand ) );
if (u != null) {
if (player.world.isRemote) {
return EnumActionResult.PASS;
}
if( u != null )
{
if( player.world.isRemote )
{
return EnumActionResult.PASS;
}
final InventoryAdaptor ad = new AdaptorItemHandler(upgrades);
player.setHeldItem(hand, ad.addItems(player.getHeldItem(hand)));
return EnumActionResult.SUCCESS;
}
}
}
final InventoryAdaptor ad = new AdaptorItemHandler( upgrades );
player.setHeldItem( hand, ad.addItems( player.getHeldItem( hand ) ) );
return EnumActionResult.SUCCESS;
}
}
}
return super.onItemUseFirst(player, world, pos, side, hitX, hitY, hitZ, hand);
}
return super.onItemUseFirst( player, world, pos, side, hitX, hitY, hitZ, hand );
}
@Override
public boolean hasCustomEntity(final ItemStack is) {
return this.getTypeByStack(is).hasCustomEntity();
}
@Override
public boolean hasCustomEntity( final ItemStack is )
{
return this.getTypeByStack( is ).hasCustomEntity();
}
@Override
public Entity createEntity(final World w, final Entity location, final ItemStack itemstack) {
final Class<? extends Entity> droppedEntity = this.getTypeByStack(itemstack).getCustomEntityClass();
final Entity eqi;
@Override
public Entity createEntity( final World w, final Entity location, final ItemStack itemstack )
{
final Class<? extends Entity> droppedEntity = this.getTypeByStack( itemstack ).getCustomEntityClass();
final 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 (final Throwable t) {
throw new IllegalStateException(t);
}
try
{
eqi = droppedEntity.getConstructor( World.class, double.class, double.class, double.class, ItemStack.class )
.newInstance( w, location.posX,
location.posY, location.posZ, itemstack );
}
catch( final Throwable t )
{
throw new IllegalStateException( t );
}
eqi.motionX = location.motionX;
eqi.motionY = location.motionY;
eqi.motionZ = location.motionZ;
eqi.motionX = location.motionX;
eqi.motionY = location.motionY;
eqi.motionZ = location.motionZ;
if (location instanceof EntityItem && eqi instanceof EntityItem) {
((EntityItem) eqi).setDefaultPickupDelay();
}
if( location instanceof EntityItem && eqi instanceof EntityItem )
{
( (EntityItem) eqi ).setDefaultPickupDelay();
}
return eqi;
}
return eqi;
}
private String nameOf(final ItemStack is) {
if (is.isEmpty()) {
return "null";
}
private String nameOf( final ItemStack is )
{
if( is.isEmpty() )
{
return "null";
}
final MaterialType mt = this.getTypeByStack(is);
if (mt == null) {
return "null";
}
final MaterialType mt = this.getTypeByStack( is );
if( mt == null )
{
return "null";
}
return mt.name();
}
return mt.name();
}
@Override
public int getBytes(final ItemStack is) {
switch (this.getTypeByStack(is)) {
case CELL1K_PART:
return KILO_SCALAR;
case CELL4K_PART:
return KILO_SCALAR * 4;
case CELL16K_PART:
return KILO_SCALAR * 16;
case CELL64K_PART:
return KILO_SCALAR * 64;
default:
}
return 0;
}
@Override
public int getBytes( final ItemStack is )
{
switch( this.getTypeByStack( is ) )
{
case CELL1K_PART:
return KILO_SCALAR;
case CELL4K_PART:
return KILO_SCALAR * 4;
case CELL16K_PART:
return KILO_SCALAR * 16;
case CELL64K_PART:
return KILO_SCALAR * 64;
default:
}
return 0;
}
@Override
public boolean isStorageComponent(final ItemStack is) {
switch (this.getTypeByStack(is)) {
case CELL1K_PART:
case CELL4K_PART:
case CELL16K_PART:
case CELL64K_PART:
return true;
default:
}
return false;
}
@Override
public boolean isStorageComponent( final ItemStack is )
{
switch( this.getTypeByStack( is ) )
{
case CELL1K_PART:
case CELL4K_PART:
case CELL16K_PART:
case CELL64K_PART:
return true;
default:
}
return false;
}
private static class SlightlyBetterSort implements Comparator<String> {
private final Pattern pattern;
private static class SlightlyBetterSort implements Comparator<String>
{
private final Pattern pattern;
public SlightlyBetterSort(final Pattern pattern) {
this.pattern = pattern;
}
public SlightlyBetterSort( final Pattern pattern )
{
this.pattern = pattern;
}
@Override
public int compare( final String o1, final String o2 )
{
try
{
final Matcher a = this.pattern.matcher( o1 );
final Matcher b = this.pattern.matcher( o2 );
if( a.find() && b.find() )
{
final int ia = Integer.parseInt( a.group( 1 ) );
final int ib = Integer.parseInt( b.group( 1 ) );
return Integer.compare( ia, ib );
}
}
catch( final Throwable t )
{
// ek!
}
return o1.compareTo( o2 );
}
}
@Override
public int compare(final String o1, final String o2) {
try {
final Matcher a = this.pattern.matcher(o1);
final Matcher b = this.pattern.matcher(o2);
if (a.find() && b.find()) {
final int ia = Integer.parseInt(a.group(1));
final int ib = Integer.parseInt(b.group(1));
return Integer.compare(ia, ib);
}
} catch (final Throwable t) {
// ek!
}
return o1.compareTo(o2);
}
}
}
@@ -19,219 +19,198 @@
package appeng.items.materials;
import java.util.EnumSet;
import java.util.Set;
import appeng.core.AppEng;
import appeng.core.features.AEFeature;
import appeng.core.features.MaterialStackSrc;
import appeng.entity.EntityChargedQuartz;
import appeng.entity.EntitySingularity;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.entity.Entity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import appeng.core.AppEng;
import appeng.core.features.AEFeature;
import appeng.core.features.MaterialStackSrc;
import appeng.entity.EntityChargedQuartz;
import appeng.entity.EntitySingularity;
import java.util.EnumSet;
import java.util.Set;
public enum MaterialType
{
INVALID_TYPE( -1, "material_invalid_type" ),
public enum MaterialType {
INVALID_TYPE(-1, "material_invalid_type"),
CERTUS_QUARTZ_CRYSTAL( 0, "material_certus_quartz_crystal", EnumSet.of( AEFeature.CERTUS ), "crystalCertusQuartz" ),
CERTUS_QUARTZ_CRYSTAL_CHARGED( 1, "material_certus_quartz_crystal_charged", EnumSet.of( AEFeature.CERTUS ), EntityChargedQuartz.class ),
CERTUS_QUARTZ_CRYSTAL(0, "material_certus_quartz_crystal", EnumSet.of(AEFeature.CERTUS), "crystalCertusQuartz"),
CERTUS_QUARTZ_CRYSTAL_CHARGED(1, "material_certus_quartz_crystal_charged", EnumSet.of(AEFeature.CERTUS), EntityChargedQuartz.class),
CERTUS_QUARTZ_DUST( 2, "material_certus_quartz_dust", EnumSet.of( AEFeature.DUSTS, AEFeature.CERTUS ), "dustCertusQuartz" ),
NETHER_QUARTZ_DUST( 3, "material_nether_quartz_dust", EnumSet.of( AEFeature.DUSTS ), "dustNetherQuartz,dustQuartz" ),
FLOUR( 4, "material_flour", EnumSet.of( AEFeature.FLOUR ), "dustWheat" ),
GOLD_DUST( 51, "material_gold_dust", EnumSet.of( AEFeature.DUSTS ), "dustGold" ),
IRON_DUST( 49, "material_iron_dust", EnumSet.of( AEFeature.DUSTS ), "dustIron" ),
CERTUS_QUARTZ_DUST(2, "material_certus_quartz_dust", EnumSet.of(AEFeature.DUSTS, AEFeature.CERTUS), "dustCertusQuartz"),
NETHER_QUARTZ_DUST(3, "material_nether_quartz_dust", EnumSet.of(AEFeature.DUSTS), "dustNetherQuartz,dustQuartz"),
FLOUR(4, "material_flour", EnumSet.of(AEFeature.FLOUR), "dustWheat"),
GOLD_DUST(51, "material_gold_dust", EnumSet.of(AEFeature.DUSTS), "dustGold"),
IRON_DUST(49, "material_iron_dust", EnumSet.of(AEFeature.DUSTS), "dustIron"),
SILICON( 5, "material_silicon", EnumSet.of( AEFeature.SILICON ), "itemSilicon" ),
MATTER_BALL( 6, "material_matter_ball", EnumSet.of( AEFeature.MATTER_BALL ) ),
SILICON(5, "material_silicon", EnumSet.of(AEFeature.SILICON), "itemSilicon"),
MATTER_BALL(6, "material_matter_ball", EnumSet.of(AEFeature.MATTER_BALL)),
FLUIX_CRYSTAL( 7, "material_fluix_crystal", EnumSet.of( AEFeature.FLUIX ), "crystalFluix" ),
FLUIX_DUST( 8, "material_fluix_dust", EnumSet.of( AEFeature.FLUIX, AEFeature.DUSTS ), "dustFluix" ),
FLUIX_PEARL( 9, "material_fluix_pearl", EnumSet.of( AEFeature.FLUIX ), "pearlFluix" ),
FLUIX_CRYSTAL(7, "material_fluix_crystal", EnumSet.of(AEFeature.FLUIX), "crystalFluix"),
FLUIX_DUST(8, "material_fluix_dust", EnumSet.of(AEFeature.FLUIX, AEFeature.DUSTS), "dustFluix"),
FLUIX_PEARL(9, "material_fluix_pearl", EnumSet.of(AEFeature.FLUIX), "pearlFluix"),
PURIFIED_CERTUS_QUARTZ_CRYSTAL( 10, "material_purified_certus_quartz_crystal", EnumSet.of( AEFeature.CERTUS,
AEFeature.PURE_CRYSTALS ), "crystalPureCertusQuartz" ),
PURIFIED_NETHER_QUARTZ_CRYSTAL( 11, "material_purified_nether_quartz_crystal", EnumSet.of( AEFeature.PURE_CRYSTALS ), "crystalPureNetherQuartz" ),
PURIFIED_FLUIX_CRYSTAL( 12, "material_purified_fluix_crystal", EnumSet.of( AEFeature.FLUIX, AEFeature.PURE_CRYSTALS ), "crystalPureFluix" ),
PURIFIED_CERTUS_QUARTZ_CRYSTAL(10, "material_purified_certus_quartz_crystal", EnumSet.of(AEFeature.CERTUS,
AEFeature.PURE_CRYSTALS), "crystalPureCertusQuartz"),
PURIFIED_NETHER_QUARTZ_CRYSTAL(11, "material_purified_nether_quartz_crystal", EnumSet.of(AEFeature.PURE_CRYSTALS), "crystalPureNetherQuartz"),
PURIFIED_FLUIX_CRYSTAL(12, "material_purified_fluix_crystal", EnumSet.of(AEFeature.FLUIX, AEFeature.PURE_CRYSTALS), "crystalPureFluix"),
CALCULATION_PROCESSOR_PRESS( 13, "material_calculation_processor_press", EnumSet.of( AEFeature.PRESSES ) ),
ENGINEERING_PROCESSOR_PRESS( 14, "material_engineering_processor_press", EnumSet.of( AEFeature.PRESSES ) ),
LOGIC_PROCESSOR_PRESS( 15, "material_logic_processor_press", EnumSet.of( AEFeature.PRESSES ) ),
CALCULATION_PROCESSOR_PRESS(13, "material_calculation_processor_press", EnumSet.of(AEFeature.PRESSES)),
ENGINEERING_PROCESSOR_PRESS(14, "material_engineering_processor_press", EnumSet.of(AEFeature.PRESSES)),
LOGIC_PROCESSOR_PRESS(15, "material_logic_processor_press", EnumSet.of(AEFeature.PRESSES)),
CALCULATION_PROCESSOR_PRINT( 16, "material_calculation_processor_print", EnumSet.of( AEFeature.PRINTED_CIRCUITS ) ),
ENGINEERING_PROCESSOR_PRINT( 17, "material_engineering_processor_print", EnumSet.of( AEFeature.PRINTED_CIRCUITS ) ),
LOGIC_PROCESSOR_PRINT( 18, "material_logic_processor_print", EnumSet.of( AEFeature.PRINTED_CIRCUITS ) ),
CALCULATION_PROCESSOR_PRINT(16, "material_calculation_processor_print", EnumSet.of(AEFeature.PRINTED_CIRCUITS)),
ENGINEERING_PROCESSOR_PRINT(17, "material_engineering_processor_print", EnumSet.of(AEFeature.PRINTED_CIRCUITS)),
LOGIC_PROCESSOR_PRINT(18, "material_logic_processor_print", EnumSet.of(AEFeature.PRINTED_CIRCUITS)),
SILICON_PRESS( 19, "material_silicon_press", EnumSet.of( AEFeature.PRESSES ) ),
SILICON_PRINT( 20, "material_silicon_print", EnumSet.of( AEFeature.PRINTED_CIRCUITS ) ),
SILICON_PRESS(19, "material_silicon_press", EnumSet.of(AEFeature.PRESSES)),
SILICON_PRINT(20, "material_silicon_print", EnumSet.of(AEFeature.PRINTED_CIRCUITS)),
NAME_PRESS( 21, "material_name_press", EnumSet.of( AEFeature.PRESSES ) ),
NAME_PRESS(21, "material_name_press", EnumSet.of(AEFeature.PRESSES)),
LOGIC_PROCESSOR( 22, "material_logic_processor", EnumSet.of( AEFeature.PROCESSORS ) ),
CALCULATION_PROCESSOR( 23, "material_calculation_processor", EnumSet.of( AEFeature.PROCESSORS ) ),
ENGINEERING_PROCESSOR( 24, "material_engineering_processor", EnumSet.of( AEFeature.PROCESSORS ) ),
LOGIC_PROCESSOR(22, "material_logic_processor", EnumSet.of(AEFeature.PROCESSORS)),
CALCULATION_PROCESSOR(23, "material_calculation_processor", EnumSet.of(AEFeature.PROCESSORS)),
ENGINEERING_PROCESSOR(24, "material_engineering_processor", EnumSet.of(AEFeature.PROCESSORS)),
// Basic Cards
BASIC_CARD( 25, "material_basic_card", EnumSet.of( AEFeature.BASIC_CARDS ) ),
CARD_REDSTONE( 26, "material_card_redstone", EnumSet.of( AEFeature.BASIC_CARDS ) ),
CARD_CAPACITY( 27, "material_card_capacity", EnumSet.of( AEFeature.BASIC_CARDS ) ),
// Basic Cards
BASIC_CARD(25, "material_basic_card", EnumSet.of(AEFeature.BASIC_CARDS)),
CARD_REDSTONE(26, "material_card_redstone", EnumSet.of(AEFeature.BASIC_CARDS)),
CARD_CAPACITY(27, "material_card_capacity", EnumSet.of(AEFeature.BASIC_CARDS)),
// Adv Cards
ADVANCED_CARD( 28, "material_advanced_card", EnumSet.of( AEFeature.ADVANCED_CARDS ) ),
CARD_FUZZY( 29, "material_card_fuzzy", EnumSet.of( AEFeature.ADVANCED_CARDS ) ),
CARD_SPEED( 30, "material_card_speed", EnumSet.of( AEFeature.ADVANCED_CARDS ) ),
CARD_INVERTER( 31, "material_card_inverter", EnumSet.of( AEFeature.ADVANCED_CARDS ) ),
// Adv Cards
ADVANCED_CARD(28, "material_advanced_card", EnumSet.of(AEFeature.ADVANCED_CARDS)),
CARD_FUZZY(29, "material_card_fuzzy", EnumSet.of(AEFeature.ADVANCED_CARDS)),
CARD_SPEED(30, "material_card_speed", EnumSet.of(AEFeature.ADVANCED_CARDS)),
CARD_INVERTER(31, "material_card_inverter", EnumSet.of(AEFeature.ADVANCED_CARDS)),
CELL2_SPATIAL_PART( 32, "material_cell2_spatial_part", EnumSet.of( AEFeature.SPATIAL_IO ) ),
CELL16_SPATIAL_PART( 33, "material_cell16_spatial_part", EnumSet.of( AEFeature.SPATIAL_IO ) ),
CELL128_SPATIAL_PART( 34, "material_cell128_spatial_part", EnumSet.of( AEFeature.SPATIAL_IO ) ),
CELL2_SPATIAL_PART(32, "material_cell2_spatial_part", EnumSet.of(AEFeature.SPATIAL_IO)),
CELL16_SPATIAL_PART(33, "material_cell16_spatial_part", EnumSet.of(AEFeature.SPATIAL_IO)),
CELL128_SPATIAL_PART(34, "material_cell128_spatial_part", EnumSet.of(AEFeature.SPATIAL_IO)),
CELL1K_PART( 35, "material_cell1k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
CELL4K_PART( 36, "material_cell4k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
CELL16K_PART( 37, "material_cell16k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
CELL64K_PART( 38, "material_cell64k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
EMPTY_STORAGE_CELL( 39, "material_empty_storage_cell", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
CELL1K_PART(35, "material_cell1k_part", EnumSet.of(AEFeature.STORAGE_CELLS)),
CELL4K_PART(36, "material_cell4k_part", EnumSet.of(AEFeature.STORAGE_CELLS)),
CELL16K_PART(37, "material_cell16k_part", EnumSet.of(AEFeature.STORAGE_CELLS)),
CELL64K_PART(38, "material_cell64k_part", EnumSet.of(AEFeature.STORAGE_CELLS)),
EMPTY_STORAGE_CELL(39, "material_empty_storage_cell", EnumSet.of(AEFeature.STORAGE_CELLS)),
WOODEN_GEAR( 40, "material_wooden_gear", EnumSet.of( AEFeature.GRIND_STONE ), "gearWood" ),
WOODEN_GEAR(40, "material_wooden_gear", EnumSet.of(AEFeature.GRIND_STONE), "gearWood"),
WIRELESS( 41, "material_wireless", EnumSet.of( AEFeature.WIRELESS_ACCESS_TERMINAL ) ),
WIRELESS_BOOSTER( 42, "material_wireless_booster", EnumSet.of( AEFeature.WIRELESS_ACCESS_TERMINAL ) ),
WIRELESS(41, "material_wireless", EnumSet.of(AEFeature.WIRELESS_ACCESS_TERMINAL)),
WIRELESS_BOOSTER(42, "material_wireless_booster", EnumSet.of(AEFeature.WIRELESS_ACCESS_TERMINAL)),
FORMATION_CORE( 43, "material_formation_core", EnumSet.of( AEFeature.CORES ) ),
ANNIHILATION_CORE( 44, "material_annihilation_core", EnumSet.of( AEFeature.CORES ) ),
FORMATION_CORE(43, "material_formation_core", EnumSet.of(AEFeature.CORES)),
ANNIHILATION_CORE(44, "material_annihilation_core", EnumSet.of(AEFeature.CORES)),
SKY_DUST( 45, "material_sky_dust", EnumSet.of( AEFeature.DUSTS ) ),
SKY_DUST(45, "material_sky_dust", EnumSet.of(AEFeature.DUSTS)),
ENDER_DUST( 46, "material_ender_dust", EnumSet.of( AEFeature.QUANTUM_NETWORK_BRIDGE ), "dustEnder,dustEnderPearl", EntitySingularity.class ),
SINGULARITY( 47, "material_singularity", EnumSet.of( AEFeature.QUANTUM_NETWORK_BRIDGE ), EntitySingularity.class ),
QUANTUM_ENTANGLED_SINGULARITY( 48, "material_quantum_entangled_singularity", EnumSet.of( AEFeature.QUANTUM_NETWORK_BRIDGE ), EntitySingularity.class ),
ENDER_DUST(46, "material_ender_dust", EnumSet.of(AEFeature.QUANTUM_NETWORK_BRIDGE), "dustEnder,dustEnderPearl", EntitySingularity.class),
SINGULARITY(47, "material_singularity", EnumSet.of(AEFeature.QUANTUM_NETWORK_BRIDGE), EntitySingularity.class),
QUANTUM_ENTANGLED_SINGULARITY(48, "material_quantum_entangled_singularity", EnumSet.of(AEFeature.QUANTUM_NETWORK_BRIDGE), EntitySingularity.class),
BLANK_PATTERN( 52, "material_blank_pattern", EnumSet.of( AEFeature.PATTERNS ) ),
CARD_CRAFTING( 53, "material_card_crafting", EnumSet.of( AEFeature.ADVANCED_CARDS, AEFeature.CRAFTING_CPU ) ),
BLANK_PATTERN(52, "material_blank_pattern", EnumSet.of(AEFeature.PATTERNS)),
CARD_CRAFTING(53, "material_card_crafting", EnumSet.of(AEFeature.ADVANCED_CARDS, AEFeature.CRAFTING_CPU)),
FLUID_CELL1K_PART( 54, "material_fluid_cell1k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
FLUID_CELL4K_PART( 55, "material_fluid_cell4k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
FLUID_CELL16K_PART( 56, "material_fluid_cell16k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
FLUID_CELL64K_PART( 57, "material_fluid_cell64k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
FLUID_CELL1K_PART(54, "material_fluid_cell1k_part", EnumSet.of(AEFeature.STORAGE_CELLS)),
FLUID_CELL4K_PART(55, "material_fluid_cell4k_part", EnumSet.of(AEFeature.STORAGE_CELLS)),
FLUID_CELL16K_PART(56, "material_fluid_cell16k_part", EnumSet.of(AEFeature.STORAGE_CELLS)),
FLUID_CELL64K_PART(57, "material_fluid_cell64k_part", EnumSet.of(AEFeature.STORAGE_CELLS)),
CARD_PATTERN_EXPANSION( 58, "material_card_pattern_expansion", EnumSet.of( AEFeature.ADVANCED_CARDS ) );
CARD_PATTERN_EXPANSION(58, "material_card_pattern_expansion", EnumSet.of(AEFeature.ADVANCED_CARDS));
private final Set<AEFeature> features;
private final ModelResourceLocation model;
private Item itemInstance;
private int damageValue;
// stack!
private MaterialStackSrc stackSrc;
private String oreName;
private Class<? extends Entity> droppedEntity;
private boolean isRegistered = false;
private final Set<AEFeature> features;
private final ModelResourceLocation model;
private Item itemInstance;
private int damageValue;
// stack!
private MaterialStackSrc stackSrc;
private String oreName;
private Class<? extends Entity> droppedEntity;
private boolean isRegistered = false;
MaterialType( final int metaValue, String modelName )
{
this( metaValue, modelName, EnumSet.of( AEFeature.CORE ) );
}
MaterialType(final int metaValue, String modelName) {
this(metaValue, modelName, EnumSet.of(AEFeature.CORE));
}
MaterialType( final int metaValue, String modelName, final Set<AEFeature> features )
{
this.setDamageValue( metaValue );
this.features = features;
this.model = new ModelResourceLocation( new ResourceLocation( AppEng.MOD_ID, modelName ), "inventory" );
}
MaterialType(final int metaValue, String modelName, final Set<AEFeature> features) {
this.setDamageValue(metaValue);
this.features = features;
this.model = new ModelResourceLocation(new ResourceLocation(AppEng.MOD_ID, modelName), "inventory");
}
MaterialType( final int metaValue, String modelName, final Set<AEFeature> features, final Class<? extends Entity> c )
{
this( metaValue, modelName, features );
this.droppedEntity = c;
}
MaterialType(final int metaValue, String modelName, final Set<AEFeature> features, final Class<? extends Entity> c) {
this(metaValue, modelName, features);
this.droppedEntity = c;
}
MaterialType( final int metaValue, String modelName, final Set<AEFeature> features, final String oreDictionary, final Class<? extends Entity> c )
{
this( metaValue, modelName, features );
this.oreName = oreDictionary;
this.droppedEntity = c;
}
MaterialType(final int metaValue, String modelName, final Set<AEFeature> features, final String oreDictionary, final Class<? extends Entity> c) {
this(metaValue, modelName, features);
this.oreName = oreDictionary;
this.droppedEntity = c;
}
MaterialType( final int metaValue, String modelName, final Set<AEFeature> features, final String oreDictionary )
{
this( metaValue, modelName, features );
this.oreName = oreDictionary;
}
MaterialType(final int metaValue, String modelName, final Set<AEFeature> features, final String oreDictionary) {
this(metaValue, modelName, features);
this.oreName = oreDictionary;
}
public ItemStack stack( final int size )
{
return new ItemStack( this.getItemInstance(), size, this.getDamageValue() );
}
public ItemStack stack(final int size) {
return new ItemStack(this.getItemInstance(), size, this.getDamageValue());
}
Set<AEFeature> getFeature()
{
return this.features;
}
Set<AEFeature> getFeature() {
return this.features;
}
public String getOreName()
{
return this.oreName;
}
public String getOreName() {
return this.oreName;
}
boolean hasCustomEntity()
{
return this.droppedEntity != null;
}
boolean hasCustomEntity() {
return this.droppedEntity != null;
}
Class<? extends Entity> getCustomEntityClass()
{
return this.droppedEntity;
}
Class<? extends Entity> getCustomEntityClass() {
return this.droppedEntity;
}
public boolean isRegistered()
{
return this.isRegistered;
}
public boolean isRegistered() {
return this.isRegistered;
}
void markReady()
{
this.isRegistered = true;
}
void markReady() {
this.isRegistered = true;
}
public int getDamageValue()
{
return this.damageValue;
}
public int getDamageValue() {
return this.damageValue;
}
void setDamageValue( final int damageValue )
{
this.damageValue = damageValue;
}
void setDamageValue(final int damageValue) {
this.damageValue = damageValue;
}
public Item getItemInstance()
{
return this.itemInstance;
}
public Item getItemInstance() {
return this.itemInstance;
}
void setItemInstance( final Item itemInstance )
{
this.itemInstance = itemInstance;
}
void setItemInstance(final Item itemInstance) {
this.itemInstance = itemInstance;
}
MaterialStackSrc getStackSrc()
{
return this.stackSrc;
}
MaterialStackSrc getStackSrc() {
return this.stackSrc;
}
void setStackSrc( final MaterialStackSrc stackSrc )
{
this.stackSrc = stackSrc;
}
void setStackSrc(final MaterialStackSrc stackSrc) {
this.stackSrc = stackSrc;
}
public ModelResourceLocation getModel()
{
return this.model;
}
public ModelResourceLocation getModel() {
return this.model;
}
}
@@ -19,11 +19,14 @@
package appeng.items.misc;
import java.util.List;
import java.util.Optional;
import javax.annotation.Nullable;
import appeng.api.AEApi;
import appeng.api.definitions.IMaterials;
import appeng.api.implementations.items.IGrowableCrystal;
import appeng.api.recipes.ResolverResult;
import appeng.core.localization.ButtonToolTips;
import appeng.entity.EntityGrowingCrystal;
import appeng.items.AEBaseItem;
import appeng.util.Platform;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.util.ITooltipFlag;
@@ -36,225 +39,190 @@ import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.AEApi;
import appeng.api.definitions.IMaterials;
import appeng.api.implementations.items.IGrowableCrystal;
import appeng.api.recipes.ResolverResult;
import appeng.core.localization.ButtonToolTips;
import appeng.entity.EntityGrowingCrystal;
import appeng.items.AEBaseItem;
import appeng.util.Platform;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Optional;
public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
{
public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal {
static final int LEVEL_OFFSET = 200;
static final int SINGLE_OFFSET = LEVEL_OFFSET * 3;
static final int LEVEL_OFFSET = 200;
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 FINAL_STAGE = SINGLE_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 FINAL_STAGE = SINGLE_OFFSET * 3;
public ItemCrystalSeed()
{
this.setHasSubtypes( true );
}
public ItemCrystalSeed() {
this.setHasSubtypes(true);
}
@Nullable
public static ResolverResult getResolver( final int certus2 )
{
@Nullable
public static ResolverResult getResolver(final int certus2) {
return AEApi.instance()
.definitions()
.items()
.crystalSeed()
.maybeStack( 1 )
.map( crystalSeedStack ->
{
crystalSeedStack.setItemDamage( certus2 );
crystalSeedStack = newStyle( crystalSeedStack );
String itemName = crystalSeedStack.getItem().getRegistryName().getResourcePath();
return new ResolverResult( itemName, crystalSeedStack.getItemDamage(), crystalSeedStack.getTagCompound() );
} )
.orElse( null );
return AEApi.instance()
.definitions()
.items()
.crystalSeed()
.maybeStack(1)
.map(crystalSeedStack ->
{
crystalSeedStack.setItemDamage(certus2);
crystalSeedStack = newStyle(crystalSeedStack);
String itemName = crystalSeedStack.getItem().getRegistryName().getResourcePath();
return new ResolverResult(itemName, crystalSeedStack.getItemDamage(), crystalSeedStack.getTagCompound());
})
.orElse(null);
}
}
private static ItemStack newStyle( final ItemStack itemStack )
{
getProgress( itemStack );
return itemStack;
}
private static ItemStack newStyle(final ItemStack itemStack) {
getProgress(itemStack);
return itemStack;
}
static int getProgress( final ItemStack is )
{
if( is.hasTagCompound() )
{
return is.getTagCompound().getInteger( "progress" );
}
else
{
final int progress;
final NBTTagCompound comp = Platform.openNbtData( is );
comp.setInteger( "progress", progress = is.getItemDamage() );
is.setItemDamage( ( is.getItemDamage() / SINGLE_OFFSET ) * SINGLE_OFFSET );
return progress;
}
}
static int getProgress(final ItemStack is) {
if (is.hasTagCompound()) {
return is.getTagCompound().getInteger("progress");
} else {
final int progress;
final NBTTagCompound comp = Platform.openNbtData(is);
comp.setInteger("progress", progress = is.getItemDamage());
is.setItemDamage((is.getItemDamage() / SINGLE_OFFSET) * SINGLE_OFFSET);
return progress;
}
}
@Nullable
@Override
public ItemStack triggerGrowth( final ItemStack is )
{
final int newDamage = getProgress( is ) + 1;
final IMaterials materials = AEApi.instance().definitions().materials();
final int size = is.getCount();
@Nullable
@Override
public ItemStack triggerGrowth(final ItemStack is) {
final int newDamage = getProgress(is) + 1;
final IMaterials materials = AEApi.instance().definitions().materials();
final int size = is.getCount();
if( newDamage == CERTUS + SINGLE_OFFSET )
{
Optional<ItemStack> quartzStack = materials.purifiedCertusQuartzCrystal().maybeStack( size );
if( quartzStack.isPresent() )
{
return quartzStack.get();
}
}
if( newDamage == NETHER + SINGLE_OFFSET )
{
Optional<ItemStack> quartzStack = materials.purifiedNetherQuartzCrystal().maybeStack( size );
if( quartzStack.isPresent() )
{
return quartzStack.get();
}
}
if( newDamage == FLUIX + SINGLE_OFFSET )
{
Optional<ItemStack> quartzStack = materials.purifiedFluixCrystal().maybeStack( size );
if( quartzStack.isPresent() )
{
return quartzStack.get();
}
}
if( newDamage > FINAL_STAGE )
{
return ItemStack.EMPTY;
}
if (newDamage == CERTUS + SINGLE_OFFSET) {
Optional<ItemStack> quartzStack = materials.purifiedCertusQuartzCrystal().maybeStack(size);
if (quartzStack.isPresent()) {
return quartzStack.get();
}
}
if (newDamage == NETHER + SINGLE_OFFSET) {
Optional<ItemStack> quartzStack = materials.purifiedNetherQuartzCrystal().maybeStack(size);
if (quartzStack.isPresent()) {
return quartzStack.get();
}
}
if (newDamage == FLUIX + SINGLE_OFFSET) {
Optional<ItemStack> quartzStack = materials.purifiedFluixCrystal().maybeStack(size);
if (quartzStack.isPresent()) {
return quartzStack.get();
}
}
if (newDamage > FINAL_STAGE) {
return ItemStack.EMPTY;
}
this.setProgress( is, newDamage );
return is;
}
this.setProgress(is, newDamage);
return is;
}
private void setProgress( final ItemStack is, final int newDamage )
{
final NBTTagCompound comp = Platform.openNbtData( is );
comp.setInteger( "progress", newDamage );
is.setItemDamage( is.getItemDamage() / LEVEL_OFFSET * LEVEL_OFFSET );
}
private void setProgress(final ItemStack is, final int newDamage) {
final NBTTagCompound comp = Platform.openNbtData(is);
comp.setInteger("progress", newDamage);
is.setItemDamage(is.getItemDamage() / LEVEL_OFFSET * LEVEL_OFFSET);
}
@Override
public float getMultiplier( final Block blk, final Material mat )
{
return 0.5f;
}
@Override
public float getMultiplier(final Block blk, final Material mat) {
return 0.5f;
}
@Override
@SideOnly( Side.CLIENT )
public void addCheckedInformation( final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips )
{
lines.add( ButtonToolTips.DoesntDespawn.getLocal() );
final int progress = getProgress( stack ) % SINGLE_OFFSET;
lines.add( Math.floor( (float) progress / (float) ( SINGLE_OFFSET / 100 ) ) + "%" );
@Override
@SideOnly(Side.CLIENT)
public void addCheckedInformation(final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips) {
lines.add(ButtonToolTips.DoesntDespawn.getLocal());
final int progress = getProgress(stack) % SINGLE_OFFSET;
lines.add(Math.floor((float) progress / (float) (SINGLE_OFFSET / 100)) + "%");
super.addCheckedInformation( stack, world, lines, advancedTooltips );
}
super.addCheckedInformation(stack, world, lines, advancedTooltips);
}
@Override
public int getEntityLifespan( final ItemStack itemStack, final World world )
{
return Integer.MAX_VALUE;
}
@Override
public int getEntityLifespan(final ItemStack itemStack, final World world) {
return Integer.MAX_VALUE;
}
@Override
public String getUnlocalizedName( final ItemStack is )
{
final int damage = getProgress( is );
@Override
public String getUnlocalizedName(final ItemStack is) {
final int damage = getProgress(is);
if( damage < CERTUS + SINGLE_OFFSET )
{
return this.getUnlocalizedName() + ".certus";
}
if (damage < CERTUS + SINGLE_OFFSET) {
return this.getUnlocalizedName() + ".certus";
}
if( damage < NETHER + SINGLE_OFFSET )
{
return this.getUnlocalizedName() + ".nether";
}
if (damage < NETHER + SINGLE_OFFSET) {
return this.getUnlocalizedName() + ".nether";
}
if( damage < FLUIX + SINGLE_OFFSET )
{
return this.getUnlocalizedName() + ".fluix";
}
if (damage < FLUIX + SINGLE_OFFSET) {
return this.getUnlocalizedName() + ".fluix";
}
return this.getUnlocalizedName();
}
return this.getUnlocalizedName();
}
@Override
public boolean isDamageable()
{
return false;
}
@Override
public boolean isDamageable() {
return false;
}
@Override
public boolean isDamaged( final ItemStack stack )
{
return false;
}
@Override
public boolean isDamaged(final ItemStack stack) {
return false;
}
@Override
public int getMaxDamage( final ItemStack stack )
{
return FINAL_STAGE;
}
@Override
public int getMaxDamage(final ItemStack stack) {
return FINAL_STAGE;
}
@Override
public boolean hasCustomEntity( final ItemStack stack )
{
return true;
}
@Override
public boolean hasCustomEntity(final ItemStack stack) {
return true;
}
@Override
public Entity createEntity( final World world, final Entity location, final ItemStack itemstack )
{
final EntityGrowingCrystal egc = new EntityGrowingCrystal( world, location.posX, location.posY, location.posZ, itemstack );
@Override
public Entity createEntity(final World world, final Entity location, final ItemStack itemstack) {
final EntityGrowingCrystal egc = new EntityGrowingCrystal(world, location.posX, location.posY, location.posZ, itemstack);
egc.motionX = location.motionX;
egc.motionY = location.motionY;
egc.motionZ = location.motionZ;
egc.motionX = location.motionX;
egc.motionY = location.motionY;
egc.motionZ = location.motionZ;
// Cannot read the pickup delay of the original item, so we
// use the pickup delay used for items dropped by a player instead
egc.setPickupDelay( 40 );
// Cannot read the pickup delay of the original item, so we
// use the pickup delay used for items dropped by a player instead
egc.setPickupDelay(40);
return egc;
}
return egc;
}
@Override
protected void getCheckedSubItems( final CreativeTabs creativeTab, final NonNullList<ItemStack> itemStacks )
{
// lvl 0
itemStacks.add( newStyle( new ItemStack( this, 1, CERTUS ) ) );
itemStacks.add( newStyle( new ItemStack( this, 1, NETHER ) ) );
itemStacks.add( newStyle( new ItemStack( this, 1, FLUIX ) ) );
@Override
protected void getCheckedSubItems(final CreativeTabs creativeTab, final NonNullList<ItemStack> itemStacks) {
// lvl 0
itemStacks.add(newStyle(new ItemStack(this, 1, CERTUS)));
itemStacks.add(newStyle(new ItemStack(this, 1, NETHER)));
itemStacks.add(newStyle(new ItemStack(this, 1, FLUIX)));
// lvl 1
itemStacks.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET + CERTUS ) ) );
itemStacks.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET + NETHER ) ) );
itemStacks.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET + FLUIX ) ) );
// lvl 1
itemStacks.add(newStyle(new ItemStack(this, 1, LEVEL_OFFSET + CERTUS)));
itemStacks.add(newStyle(new ItemStack(this, 1, LEVEL_OFFSET + NETHER)));
itemStacks.add(newStyle(new ItemStack(this, 1, LEVEL_OFFSET + FLUIX)));
// lvl 2
itemStacks.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET * 2 + CERTUS ) ) );
itemStacks.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET * 2 + NETHER ) ) );
itemStacks.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET * 2 + FLUIX ) ) );
}
// lvl 2
itemStacks.add(newStyle(new ItemStack(this, 1, LEVEL_OFFSET * 2 + CERTUS)));
itemStacks.add(newStyle(new ItemStack(this, 1, LEVEL_OFFSET * 2 + NETHER)));
itemStacks.add(newStyle(new ItemStack(this, 1, LEVEL_OFFSET * 2 + FLUIX)));
}
}
@@ -19,85 +19,76 @@
package appeng.items.misc;
import appeng.bootstrap.IItemRendering;
import appeng.bootstrap.ItemRenderingCustomizer;
import com.google.common.collect.ImmutableList;
import net.minecraft.client.renderer.ItemMeshDefinition;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.bootstrap.IItemRendering;
import appeng.bootstrap.ItemRenderingCustomizer;
public class ItemCrystalSeedRendering extends ItemRenderingCustomizer {
public class ItemCrystalSeedRendering extends ItemRenderingCustomizer
{
private static final ModelResourceLocation[] MODELS_CERTUS = {
new ModelResourceLocation("appliedenergistics2:crystal_seed_certus"),
new ModelResourceLocation("appliedenergistics2:crystal_seed_certus2"),
new ModelResourceLocation("appliedenergistics2:crystal_seed_certus3")
};
private static final ModelResourceLocation[] MODELS_FLUIX = {
new ModelResourceLocation("appliedenergistics2:crystal_seed_fluix"),
new ModelResourceLocation("appliedenergistics2:crystal_seed_fluix2"),
new ModelResourceLocation("appliedenergistics2:crystal_seed_fluix3")
};
private static final ModelResourceLocation[] MODELS_NETHER = {
new ModelResourceLocation("appliedenergistics2:crystal_seed_nether"),
new ModelResourceLocation("appliedenergistics2:crystal_seed_nether2"),
new ModelResourceLocation("appliedenergistics2:crystal_seed_nether3")
};
private static final ModelResourceLocation[] MODELS_CERTUS = {
new ModelResourceLocation( "appliedenergistics2:crystal_seed_certus" ),
new ModelResourceLocation( "appliedenergistics2:crystal_seed_certus2" ),
new ModelResourceLocation( "appliedenergistics2:crystal_seed_certus3" )
};
private static final ModelResourceLocation[] MODELS_FLUIX = {
new ModelResourceLocation( "appliedenergistics2:crystal_seed_fluix" ),
new ModelResourceLocation( "appliedenergistics2:crystal_seed_fluix2" ),
new ModelResourceLocation( "appliedenergistics2:crystal_seed_fluix3" )
};
private static final ModelResourceLocation[] MODELS_NETHER = {
new ModelResourceLocation( "appliedenergistics2:crystal_seed_nether" ),
new ModelResourceLocation( "appliedenergistics2:crystal_seed_nether2" ),
new ModelResourceLocation( "appliedenergistics2:crystal_seed_nether3" )
};
@Override
@SideOnly(Side.CLIENT)
public void customize(IItemRendering rendering) {
rendering.variants(ImmutableList.<ResourceLocation>builder().add(MODELS_CERTUS).add(MODELS_FLUIX).add(MODELS_NETHER).build());
rendering.meshDefinition(this.getItemMeshDefinition());
}
@Override
@SideOnly( Side.CLIENT )
public void customize( IItemRendering rendering )
{
rendering.variants( ImmutableList.<ResourceLocation>builder().add( MODELS_CERTUS ).add( MODELS_FLUIX ).add( MODELS_NETHER ).build() );
rendering.meshDefinition( this.getItemMeshDefinition() );
}
private ItemMeshDefinition getItemMeshDefinition() {
return is ->
{
int damage = ItemCrystalSeed.getProgress(is);
private ItemMeshDefinition getItemMeshDefinition()
{
return is ->
{
int damage = ItemCrystalSeed.getProgress( is );
// Split the damage value into crystal type and growth level
int type = damage / ItemCrystalSeed.SINGLE_OFFSET;
int level = (damage % ItemCrystalSeed.SINGLE_OFFSET) / ItemCrystalSeed.LEVEL_OFFSET;
// Split the damage value into crystal type and growth level
int type = damage / ItemCrystalSeed.SINGLE_OFFSET;
int level = ( damage % ItemCrystalSeed.SINGLE_OFFSET ) / ItemCrystalSeed.LEVEL_OFFSET;
// Determine which list of models to use based on the type of crystal
ModelResourceLocation[] models;
switch (type) {
case 0:
models = MODELS_CERTUS;
break;
case 1:
models = MODELS_NETHER;
break;
case 2:
models = MODELS_FLUIX;
break;
default:
// We use this as the fallback for broken items
models = MODELS_CERTUS;
break;
}
// Determine which list of models to use based on the type of crystal
ModelResourceLocation[] models;
switch( type )
{
case 0:
models = MODELS_CERTUS;
break;
case 1:
models = MODELS_NETHER;
break;
case 2:
models = MODELS_FLUIX;
break;
default:
// We use this as the fallback for broken items
models = MODELS_CERTUS;
break;
}
// Return one of the 3 models based on the level
if (level < 0) {
level = 0;
} else if (level >= models.length) {
level = models.length - 1;
}
// Return one of the 3 models based on the level
if( level < 0 )
{
level = 0;
}
else if( level >= models.length )
{
level = models.length - 1;
}
return models[level];
};
}
return models[level];
};
}
}
@@ -19,10 +19,16 @@
package appeng.items.misc;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import appeng.api.AEApi;
import appeng.api.implementations.ICraftingPatternItem;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.storage.data.IAEItemStack;
import appeng.core.AppEng;
import appeng.core.localization.GuiText;
import appeng.helpers.InvalidPatternHelper;
import appeng.helpers.PatternHelper;
import appeng.items.AEBaseItem;
import appeng.util.Platform;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
@@ -37,197 +43,161 @@ import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.AEApi;
import appeng.api.implementations.ICraftingPatternItem;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.storage.data.IAEItemStack;
import appeng.core.AppEng;
import appeng.core.localization.GuiText;
import appeng.helpers.InvalidPatternHelper;
import appeng.helpers.PatternHelper;
import appeng.items.AEBaseItem;
import appeng.util.Platform;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
public class ItemEncodedPattern extends AEBaseItem implements ICraftingPatternItem
{
// rather simple client side caching.
private static final Map<ItemStack, ItemStack> SIMPLE_CACHE = new WeakHashMap<>();
public class ItemEncodedPattern extends AEBaseItem implements ICraftingPatternItem {
// rather simple client side caching.
private static final Map<ItemStack, ItemStack> SIMPLE_CACHE = new WeakHashMap<>();
public ItemEncodedPattern()
{
this.setMaxStackSize( 64 );
}
public ItemEncodedPattern() {
this.setMaxStackSize(64);
}
@Override
public ActionResult<ItemStack> onItemRightClick( final World w, final EntityPlayer player, final EnumHand hand )
{
this.clearPattern( player.getHeldItem( hand ), player );
@Override
public ActionResult<ItemStack> onItemRightClick(final World w, final EntityPlayer player, final EnumHand hand) {
this.clearPattern(player.getHeldItem(hand), player);
return new ActionResult<>( EnumActionResult.SUCCESS, player.getHeldItem( hand ) );
}
return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
}
@Override
public EnumActionResult onItemUseFirst( final EntityPlayer player, final World world, final BlockPos pos, final EnumFacing side, final float hitX, final float hitY, final float hitZ, final EnumHand hand )
{
return this.clearPattern( player.getHeldItem( hand ), player ) ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
}
@Override
public EnumActionResult onItemUseFirst(final EntityPlayer player, final World world, final BlockPos pos, final EnumFacing side, final float hitX, final float hitY, final float hitZ, final EnumHand hand) {
return this.clearPattern(player.getHeldItem(hand), player) ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
}
private boolean clearPattern( final ItemStack stack, final EntityPlayer player )
{
if( player.isSneaking() )
{
if( Platform.isClient() )
{
return false;
}
private boolean clearPattern(final ItemStack stack, final EntityPlayer player) {
if (player.isSneaking()) {
if (Platform.isClient()) {
return false;
}
final InventoryPlayer inv = player.inventory;
final InventoryPlayer inv = player.inventory;
ItemStack is = AEApi.instance().definitions().materials().blankPattern().maybeStack( stack.getCount() ).orElse( ItemStack.EMPTY );
if( !is.isEmpty() )
{
for( int s = 0; s < player.inventory.getSizeInventory(); s++ )
{
if( inv.getStackInSlot( s ) == stack )
{
inv.setInventorySlotContents( s, is );
return true;
}
}
}
}
ItemStack is = AEApi.instance().definitions().materials().blankPattern().maybeStack(stack.getCount()).orElse(ItemStack.EMPTY);
if (!is.isEmpty()) {
for (int s = 0; s < player.inventory.getSizeInventory(); s++) {
if (inv.getStackInSlot(s) == stack) {
inv.setInventorySlotContents(s, is);
return true;
}
}
}
}
return false;
}
return false;
}
@Override
@SideOnly( Side.CLIENT )
public void addCheckedInformation( final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips )
{
final ICraftingPatternDetails details = this.getPatternForItem( stack, world );
@Override
@SideOnly(Side.CLIENT)
public void addCheckedInformation(final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips) {
final ICraftingPatternDetails details = this.getPatternForItem(stack, world);
if( details == null )
{
if( !stack.hasTagCompound() )
{
return;
}
if (details == null) {
if (!stack.hasTagCompound()) {
return;
}
stack.setStackDisplayName( TextFormatting.RED + GuiText.InvalidPattern.getLocal() );
stack.setStackDisplayName(TextFormatting.RED + GuiText.InvalidPattern.getLocal());
InvalidPatternHelper invalid = new InvalidPatternHelper( stack );
InvalidPatternHelper invalid = new InvalidPatternHelper(stack);
final String label = ( invalid.isCraftable() ? GuiText.Crafts.getLocal() : GuiText.Creates.getLocal() ) + ": ";
final String and = ' ' + GuiText.And.getLocal() + ' ';
final String with = GuiText.With.getLocal() + ": ";
final String label = (invalid.isCraftable() ? GuiText.Crafts.getLocal() : GuiText.Creates.getLocal()) + ": ";
final String and = ' ' + GuiText.And.getLocal() + ' ';
final String with = GuiText.With.getLocal() + ": ";
boolean first = true;
for( final InvalidPatternHelper.PatternIngredient output : invalid.getOutputs() )
{
lines.add( ( first ? label : and ) + output.getFormattedToolTip() );
first = false;
}
boolean first = true;
for (final InvalidPatternHelper.PatternIngredient output : invalid.getOutputs()) {
lines.add((first ? label : and) + output.getFormattedToolTip());
first = false;
}
first = true;
for( final InvalidPatternHelper.PatternIngredient input : invalid.getInputs() )
{
lines.add( ( first ? with : and ) + input.getFormattedToolTip() );
first = false;
}
first = true;
for (final InvalidPatternHelper.PatternIngredient input : invalid.getInputs()) {
lines.add((first ? with : and) + input.getFormattedToolTip());
first = false;
}
if( invalid.isCraftable() )
{
final String substitutionLabel = GuiText.Substitute.getLocal() + " ";
final String canSubstitute = invalid.canSubstitute() ? GuiText.Yes.getLocal() : GuiText.No.getLocal();
if (invalid.isCraftable()) {
final String substitutionLabel = GuiText.Substitute.getLocal() + " ";
final String canSubstitute = invalid.canSubstitute() ? GuiText.Yes.getLocal() : GuiText.No.getLocal();
lines.add( substitutionLabel + canSubstitute );
}
lines.add(substitutionLabel + canSubstitute);
}
return;
}
return;
}
if( stack.hasDisplayName() )
{
stack.removeSubCompound( "display" );
}
if (stack.hasDisplayName()) {
stack.removeSubCompound("display");
}
final boolean isCrafting = details.isCraftable();
final boolean substitute = details.canSubstitute();
final boolean isCrafting = details.isCraftable();
final boolean substitute = details.canSubstitute();
final IAEItemStack[] in = details.getCondensedInputs();
final IAEItemStack[] out = details.getCondensedOutputs();
final IAEItemStack[] in = details.getCondensedInputs();
final IAEItemStack[] out = details.getCondensedOutputs();
final String label = ( isCrafting ? GuiText.Crafts.getLocal() : GuiText.Creates.getLocal() ) + ": ";
final String and = ' ' + GuiText.And.getLocal() + ' ';
final String with = GuiText.With.getLocal() + ": ";
final String label = (isCrafting ? GuiText.Crafts.getLocal() : GuiText.Creates.getLocal()) + ": ";
final String and = ' ' + GuiText.And.getLocal() + ' ';
final String with = GuiText.With.getLocal() + ": ";
boolean first = true;
for( final IAEItemStack anOut : out )
{
if( anOut == null )
{
continue;
}
boolean first = true;
for (final IAEItemStack anOut : out) {
if (anOut == null) {
continue;
}
lines.add( ( first ? label : and ) + anOut.getStackSize() + ' ' + Platform.getItemDisplayName( anOut ) );
first = false;
}
lines.add((first ? label : and) + anOut.getStackSize() + ' ' + Platform.getItemDisplayName(anOut));
first = false;
}
first = true;
for( final IAEItemStack anIn : in )
{
if( anIn == null )
{
continue;
}
first = true;
for (final IAEItemStack anIn : in) {
if (anIn == null) {
continue;
}
lines.add( ( first ? with : and ) + anIn.getStackSize() + ' ' + Platform.getItemDisplayName( anIn ) );
first = false;
}
lines.add((first ? with : and) + anIn.getStackSize() + ' ' + Platform.getItemDisplayName(anIn));
first = false;
}
if( isCrafting )
{
final String substitutionLabel = GuiText.Substitute.getLocal() + " ";
final String canSubstitute = substitute ? GuiText.Yes.getLocal() : GuiText.No.getLocal();
if (isCrafting) {
final String substitutionLabel = GuiText.Substitute.getLocal() + " ";
final String canSubstitute = substitute ? GuiText.Yes.getLocal() : GuiText.No.getLocal();
lines.add( substitutionLabel + canSubstitute );
}
}
lines.add(substitutionLabel + canSubstitute);
}
}
@Override
public ICraftingPatternDetails getPatternForItem( final ItemStack is, final World w )
{
try
{
return new PatternHelper( is, w );
}
catch( final Throwable t )
{
return null;
}
}
@Override
public ICraftingPatternDetails getPatternForItem(final ItemStack is, final World w) {
try {
return new PatternHelper(is, w);
} catch (final Throwable t) {
return null;
}
}
public ItemStack getOutput( final ItemStack item )
{
ItemStack out = SIMPLE_CACHE.get( item );
public ItemStack getOutput(final ItemStack item) {
ItemStack out = SIMPLE_CACHE.get(item);
if( out != null )
{
return out;
}
if (out != null) {
return out;
}
final World w = AppEng.proxy.getWorld();
if( w == null )
{
return ItemStack.EMPTY;
}
final World w = AppEng.proxy.getWorld();
if (w == null) {
return ItemStack.EMPTY;
}
final ICraftingPatternDetails details = this.getPatternForItem( item, w );
final ICraftingPatternDetails details = this.getPatternForItem(item, w);
out = details != null ? details.getOutputs()[0].createItemStack() : ItemStack.EMPTY;
out = details != null ? details.getOutputs()[0].createItemStack() : ItemStack.EMPTY;
SIMPLE_CACHE.put( item, out );
return out;
}
SIMPLE_CACHE.put(item, out);
return out;
}
}
@@ -19,76 +19,62 @@
package appeng.items.misc;
import appeng.api.util.AEColor;
import appeng.core.localization.GuiText;
import appeng.items.AEBaseItem;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import appeng.api.util.AEColor;
import appeng.core.localization.GuiText;
import appeng.items.AEBaseItem;
public class ItemPaintBall extends AEBaseItem {
public class ItemPaintBall extends AEBaseItem
{
private static final int DAMAGE_THRESHOLD = 20;
private static final int DAMAGE_THRESHOLD = 20;
public ItemPaintBall() {
this.setHasSubtypes(true);
}
public ItemPaintBall()
{
this.setHasSubtypes( true );
}
@Override
public String getItemStackDisplayName(final ItemStack is) {
return super.getItemStackDisplayName(is) + " - " + this.getExtraName(is);
}
@Override
public String getItemStackDisplayName( final ItemStack is )
{
return super.getItemStackDisplayName( is ) + " - " + this.getExtraName( is );
}
private String getExtraName(final ItemStack is) {
return (is.getItemDamage() >= DAMAGE_THRESHOLD ? GuiText.Lumen.getLocal() + ' ' : "") + this.getColor(is);
}
private String getExtraName( final ItemStack is )
{
return ( is.getItemDamage() >= DAMAGE_THRESHOLD ? GuiText.Lumen.getLocal() + ' ' : "" ) + this.getColor( is );
}
public AEColor getColor(final ItemStack is) {
int dmg = is.getItemDamage();
if (dmg >= DAMAGE_THRESHOLD) {
dmg -= DAMAGE_THRESHOLD;
}
public AEColor getColor( final ItemStack is )
{
int dmg = is.getItemDamage();
if( dmg >= DAMAGE_THRESHOLD )
{
dmg -= DAMAGE_THRESHOLD;
}
if (dmg >= AEColor.values().length) {
return AEColor.TRANSPARENT;
}
if( dmg >= AEColor.values().length )
{
return AEColor.TRANSPARENT;
}
return AEColor.values()[dmg];
}
return AEColor.values()[dmg];
}
@Override
protected void getCheckedSubItems(final CreativeTabs creativeTab, final NonNullList<ItemStack> itemStacks) {
for (final AEColor c : AEColor.values()) {
if (c != AEColor.TRANSPARENT) {
itemStacks.add(new ItemStack(this, 1, c.ordinal()));
}
}
@Override
protected void getCheckedSubItems( final CreativeTabs creativeTab, final NonNullList<ItemStack> itemStacks )
{
for( final AEColor c : AEColor.values() )
{
if( c != AEColor.TRANSPARENT )
{
itemStacks.add( new ItemStack( this, 1, c.ordinal() ) );
}
}
for (final AEColor c : AEColor.values()) {
if (c != AEColor.TRANSPARENT) {
itemStacks.add(new ItemStack(this, 1, DAMAGE_THRESHOLD + c.ordinal()));
}
}
}
for( final AEColor c : AEColor.values() )
{
if( c != AEColor.TRANSPARENT )
{
itemStacks.add( new ItemStack( this, 1, DAMAGE_THRESHOLD + c.ordinal() ) );
}
}
}
public static boolean isLumen( final ItemStack is )
{
final int dmg = is.getItemDamage();
return dmg >= DAMAGE_THRESHOLD;
}
public static boolean isLumen(final ItemStack is) {
final int dmg = is.getItemDamage();
return dmg >= DAMAGE_THRESHOLD;
}
}
@@ -19,46 +19,39 @@
package appeng.items.misc;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.ItemStack;
import appeng.api.util.AEColor;
import appeng.bootstrap.IItemRendering;
import appeng.bootstrap.ItemRenderingCustomizer;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.ItemStack;
public class ItemPaintBallRendering extends ItemRenderingCustomizer
{
public class ItemPaintBallRendering extends ItemRenderingCustomizer {
private static final ModelResourceLocation MODEL_NORMAL = new ModelResourceLocation( "appliedenergistics2:paint_ball" );
private static final ModelResourceLocation MODEL_SHIMMER = new ModelResourceLocation( "appliedenergistics2:paint_ball_shimmer" );
private static final ModelResourceLocation MODEL_NORMAL = new ModelResourceLocation("appliedenergistics2:paint_ball");
private static final ModelResourceLocation MODEL_SHIMMER = new ModelResourceLocation("appliedenergistics2:paint_ball_shimmer");
@Override
public void customize( IItemRendering rendering )
{
rendering.color( ItemPaintBallRendering::getColorFromItemstack );
rendering.variants( MODEL_NORMAL, MODEL_SHIMMER );
rendering.meshDefinition( is -> ItemPaintBall.isLumen( is ) ? MODEL_SHIMMER : MODEL_NORMAL );
}
@Override
public void customize(IItemRendering rendering) {
rendering.color(ItemPaintBallRendering::getColorFromItemstack);
rendering.variants(MODEL_NORMAL, MODEL_SHIMMER);
rendering.meshDefinition(is -> ItemPaintBall.isLumen(is) ? MODEL_SHIMMER : MODEL_NORMAL);
}
private static int getColorFromItemstack( ItemStack stack, int tintIndex )
{
final AEColor col = ( (ItemPaintBall) stack.getItem() ).getColor( stack );
private static int getColorFromItemstack(ItemStack stack, int tintIndex) {
final AEColor col = ((ItemPaintBall) stack.getItem()).getColor(stack);
final int colorValue = stack.getItemDamage() >= 20 ? col.mediumVariant : col.mediumVariant;
final int r = ( colorValue >> 16 ) & 0xff;
final int g = ( colorValue >> 8 ) & 0xff;
final int b = ( colorValue ) & 0xff;
final int colorValue = col.mediumVariant;
final int r = (colorValue >> 16) & 0xff;
final int g = (colorValue >> 8) & 0xff;
final int b = (colorValue) & 0xff;
if( stack.getItemDamage() >= 20 )
{
final float fail = 0.7f;
final int full = (int) ( 255 * 0.3 );
return (int) ( full + r * fail ) << 16 | (int) ( full + g * fail ) << 8 | (int) ( full + b * fail ) | 0xff << 24;
}
else
{
return r << 16 | g << 8 | b | 0xff << 24;
}
}
if (stack.getItemDamage() >= 20) {
final float fail = 0.7f;
final int full = (int) (255 * 0.3);
return (int) (full + r * fail) << 16 | (int) (full + g * fail) << 8 | (int) (full + b * fail) | 0xff << 24;
} else {
return r << 16 | g << 8 | b | 0xff << 24;
}
}
}
@@ -28,12 +28,10 @@ import appeng.client.render.FacadeItemModel;
* Handles rendering customization for facade items. Please note that this works very differently
* from actually rendering a Facade in a cable bus.
*/
public class FacadeRendering extends ItemRenderingCustomizer
{
@Override
public void customize( IItemRendering rendering )
{
// This actually just uses the path it will look for by default, no custom model redirection needed
rendering.builtInModel( "models/item/facade", new FacadeItemModel() );
}
public class FacadeRendering extends ItemRenderingCustomizer {
@Override
public void customize(IItemRendering rendering) {
// This actually just uses the path it will look for by default, no custom model redirection needed
rendering.builtInModel("models/item/facade", new FacadeItemModel());
}
}
+207 -265
View File
@@ -19,29 +19,6 @@
package appeng.items.parts;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
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.util.BlockRenderLayer;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.property.IExtendedBlockState;
import appeng.api.AEApi;
import appeng.api.exceptions.MissingDefinitionException;
import appeng.api.parts.IAlphaPassItem;
@@ -51,296 +28,261 @@ import appeng.core.FacadeConfig;
import appeng.facade.FacadePart;
import appeng.facade.IFacadeItem;
import appeng.items.AEBaseItem;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
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.util.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.property.IExtendedBlockState;
import java.util.ArrayList;
import java.util.List;
public class ItemFacade extends AEBaseItem implements IFacadeItem, IAlphaPassItem
{
public class ItemFacade extends AEBaseItem implements IFacadeItem, IAlphaPassItem {
private static final String TAG_ITEM_ID = "item";
private static final String TAG_DAMAGE = "damage";
private static final String TAG_ITEM_ID = "item";
private static final String TAG_DAMAGE = "damage";
private List<ItemStack> subTypes = null;
private List<ItemStack> subTypes = null;
public ItemFacade()
{
this.setHasSubtypes( true );
}
public ItemFacade() {
this.setHasSubtypes(true);
}
@Override
public EnumActionResult onItemUseFirst( final EntityPlayer player, final World world, final BlockPos pos, final EnumFacing side, final float hitX, final float hitY, final float hitZ, final EnumHand hand )
{
return AEApi.instance().partHelper().placeBus( player.getHeldItem( hand ), pos, side, player, hand, world );
}
@Override
public EnumActionResult onItemUseFirst(final EntityPlayer player, final World world, final BlockPos pos, final EnumFacing side, final float hitX, final float hitY, final float hitZ, final EnumHand hand) {
return AEApi.instance().partHelper().placeBus(player.getHeldItem(hand), pos, side, player, hand, world);
}
@Override
public String getItemStackDisplayName( final ItemStack is )
{
try
{
final ItemStack in = this.getTextureItem( is );
if( !in.isEmpty() )
{
return super.getItemStackDisplayName( is ) + " - " + in.getDisplayName();
}
}
catch( final Throwable ignored )
{
@Override
public String getItemStackDisplayName(final ItemStack is) {
try {
final ItemStack in = this.getTextureItem(is);
if (!in.isEmpty()) {
return super.getItemStackDisplayName(is) + " - " + in.getDisplayName();
}
} catch (final Throwable ignored) {
}
}
return super.getItemStackDisplayName( is );
}
return super.getItemStackDisplayName(is);
}
@Override
protected void getCheckedSubItems( final CreativeTabs creativeTab, final NonNullList<ItemStack> itemStacks )
{
this.calculateSubTypes();
itemStacks.addAll( this.subTypes );
}
@Override
protected void getCheckedSubItems(final CreativeTabs creativeTab, final NonNullList<ItemStack> itemStacks) {
this.calculateSubTypes();
itemStacks.addAll(this.subTypes);
}
private void calculateSubTypes()
{
if( this.subTypes == null )
{
this.subTypes = new ArrayList<>( 1000 );
for( final Object blk : Block.REGISTRY )
{
final Block b = (Block) blk;
try
{
final Item item = Item.getItemFromBlock( b );
if( item == Items.AIR )
{
continue;
}
private void calculateSubTypes() {
if (this.subTypes == null) {
this.subTypes = new ArrayList<>(1000);
for (final Object blk : Block.REGISTRY) {
final Block b = (Block) blk;
try {
final Item item = Item.getItemFromBlock(b);
if (item == Items.AIR) {
continue;
}
final NonNullList<ItemStack> tmpList = NonNullList.create();
b.getSubBlocks( b.getCreativeTabToDisplayOn(), tmpList );
for( final ItemStack l : tmpList )
{
final ItemStack facade = this.createFacadeForItem( l, false );
if( !facade.isEmpty() )
{
this.subTypes.add( facade );
}
}
}
catch( final Throwable t )
{
// just absorb..
}
}
}
}
final NonNullList<ItemStack> tmpList = NonNullList.create();
b.getSubBlocks(b.getCreativeTabToDisplayOn(), tmpList);
for (final ItemStack l : tmpList) {
final ItemStack facade = this.createFacadeForItem(l, false);
if (!facade.isEmpty()) {
this.subTypes.add(facade);
}
}
} catch (final Throwable t) {
// just absorb..
}
}
}
}
private static boolean hasSimpleModel( IBlockState blockState )
{
if( blockState.getRenderType() != EnumBlockRenderType.MODEL || blockState instanceof IExtendedBlockState )
{
return false;
}
private static boolean hasSimpleModel(IBlockState blockState) {
if (blockState.getRenderType() != EnumBlockRenderType.MODEL || blockState instanceof IExtendedBlockState) {
return false;
}
return blockState.isFullCube();
}
return blockState.isFullCube();
}
public ItemStack createFacadeForItem( final ItemStack itemStack, final boolean returnItem )
{
if( itemStack.isEmpty() )
{
return ItemStack.EMPTY;
}
public ItemStack createFacadeForItem(final ItemStack itemStack, final boolean returnItem) {
if (itemStack.isEmpty()) {
return ItemStack.EMPTY;
}
final Block block = Block.getBlockFromItem( itemStack.getItem() );
if( block == Blocks.AIR || itemStack.hasTagCompound() )
{
return ItemStack.EMPTY;
}
final Block block = Block.getBlockFromItem(itemStack.getItem());
if (block == Blocks.AIR || itemStack.hasTagCompound()) {
return ItemStack.EMPTY;
}
final int metadata = itemStack.getItem().getMetadata( itemStack.getItemDamage() );
final int metadata = itemStack.getItem().getMetadata(itemStack.getItemDamage());
// Try to get the block state based on the item stack's meta. If this fails, don't consider it for a facade
// This for example fails for Pistons because they hardcoded an invalid meta value in vanilla
IBlockState blockState;
try
{
blockState = block.getStateFromMeta( metadata );
}
catch( Exception e )
{
AELog.debug( e, "Cannot create a facade for " + block.getRegistryName() );
return ItemStack.EMPTY;
}
// Try to get the block state based on the item stack's meta. If this fails, don't consider it for a facade
// This for example fails for Pistons because they hardcoded an invalid meta value in vanilla
IBlockState blockState;
try {
blockState = block.getStateFromMeta(metadata);
} catch (Exception e) {
AELog.debug(e, "Cannot create a facade for " + block.getRegistryName());
return ItemStack.EMPTY;
}
final boolean areTileEntitiesEnabled = FacadeConfig.instance().allowTileEntityFacades();
final boolean isWhiteListed = FacadeConfig.instance().isWhiteListed( block, metadata );
final boolean isModel = blockState.getRenderType() == EnumBlockRenderType.MODEL;
final boolean areTileEntitiesEnabled = FacadeConfig.instance().allowTileEntityFacades();
final boolean isWhiteListed = FacadeConfig.instance().isWhiteListed(block, metadata);
final boolean isModel = blockState.getRenderType() == EnumBlockRenderType.MODEL;
final IBlockState defaultState = block.getDefaultState();
final boolean isTileEntity = block.hasTileEntity( defaultState );
final boolean isFullCube = block.isFullCube( defaultState );
final IBlockState defaultState = block.getDefaultState();
final boolean isTileEntity = block.hasTileEntity(defaultState);
final boolean isFullCube = block.isFullCube(defaultState);
final boolean isTileEntityAllowed = !isTileEntity || ( areTileEntitiesEnabled && isWhiteListed );
final boolean isBlockAllowed = isFullCube || isWhiteListed;
final boolean isTileEntityAllowed = !isTileEntity || (areTileEntitiesEnabled && isWhiteListed);
final boolean isBlockAllowed = isFullCube || isWhiteListed;
if( isModel && isTileEntityAllowed && isBlockAllowed )
{
if( returnItem )
{
return itemStack;
}
if (isModel && isTileEntityAllowed && isBlockAllowed) {
if (returnItem) {
return itemStack;
}
final ItemStack is = new ItemStack( this );
final NBTTagCompound data = new NBTTagCompound();
data.setString( TAG_ITEM_ID, itemStack.getItem().getRegistryName().toString() );
data.setInteger( TAG_DAMAGE, itemStack.getItemDamage() );
is.setTagCompound( data );
return is;
}
return ItemStack.EMPTY;
}
final ItemStack is = new ItemStack(this);
final NBTTagCompound data = new NBTTagCompound();
data.setString(TAG_ITEM_ID, itemStack.getItem().getRegistryName().toString());
data.setInteger(TAG_DAMAGE, itemStack.getItemDamage());
is.setTagCompound(data);
return is;
}
return ItemStack.EMPTY;
}
@Override
public FacadePart createPartFromItemStack( final ItemStack is, final AEPartLocation side )
{
final ItemStack in = this.getTextureItem( is );
if( !in.isEmpty() )
{
return new FacadePart( is, side );
}
return null;
}
@Override
public FacadePart createPartFromItemStack(final ItemStack is, final AEPartLocation side) {
final ItemStack in = this.getTextureItem(is);
if (!in.isEmpty()) {
return new FacadePart(is, side);
}
return null;
}
@Override
public ItemStack getTextureItem( ItemStack is )
{
@Override
public ItemStack getTextureItem(ItemStack is) {
NBTTagCompound nbt = is.getTagCompound();
NBTTagCompound nbt = is.getTagCompound();
if( nbt == null )
{
return ItemStack.EMPTY;
}
if (nbt == null) {
return ItemStack.EMPTY;
}
ResourceLocation itemId;
int itemDamage;
ResourceLocation itemId;
int itemDamage;
// Handle legacy facades
if( nbt.hasKey( "x" ) )
{
int[] data = nbt.getIntArray( "x" );
if( data.length != 2 )
{
return ItemStack.EMPTY;
}
// Handle legacy facades
if (nbt.hasKey("x")) {
int[] data = nbt.getIntArray("x");
if (data.length != 2) {
return ItemStack.EMPTY;
}
Item item = Item.REGISTRY.getObjectById( data[0] );
if( item == null )
{
return ItemStack.EMPTY;
}
Item item = Item.REGISTRY.getObjectById(data[0]);
if (item == null) {
return ItemStack.EMPTY;
}
itemId = item.getRegistryName();
itemDamage = data[1];
}
else
{
// First item is numeric item id, second is damage
itemId = new ResourceLocation( nbt.getString( TAG_ITEM_ID ) );
itemDamage = nbt.getInteger( TAG_DAMAGE );
}
itemId = item.getRegistryName();
itemDamage = data[1];
} else {
// First item is numeric item id, second is damage
itemId = new ResourceLocation(nbt.getString(TAG_ITEM_ID));
itemDamage = nbt.getInteger(TAG_DAMAGE);
}
Item baseItem = Item.REGISTRY.getObject( itemId );
Item baseItem = Item.REGISTRY.getObject(itemId);
if( baseItem == null )
{
return ItemStack.EMPTY;
}
if (baseItem == null) {
return ItemStack.EMPTY;
}
return new ItemStack( baseItem, 1, itemDamage );
}
return new ItemStack(baseItem, 1, itemDamage);
}
@Override
public IBlockState getTextureBlockState( ItemStack is )
{
@Override
public IBlockState getTextureBlockState(ItemStack is) {
ItemStack baseItemStack = this.getTextureItem( is );
ItemStack baseItemStack = this.getTextureItem(is);
if( baseItemStack.isEmpty() )
{
return Blocks.GLASS.getDefaultState();
}
if (baseItemStack.isEmpty()) {
return Blocks.GLASS.getDefaultState();
}
Block block = Block.getBlockFromItem( baseItemStack.getItem() );
Block block = Block.getBlockFromItem(baseItemStack.getItem());
if( block == Blocks.AIR )
{
return Blocks.GLASS.getDefaultState();
}
if (block == Blocks.AIR) {
return Blocks.GLASS.getDefaultState();
}
int metadata = baseItemStack.getItem().getMetadata( baseItemStack );
int metadata = baseItemStack.getItem().getMetadata(baseItemStack);
try
{
return block.getStateFromMeta( metadata );
}
catch( Exception e )
{
AELog.warn( "Block %s has broken getStateFromMeta method for meta %d", block.getRegistryName().toString(), baseItemStack.getItemDamage() );
return Blocks.GLASS.getDefaultState();
}
}
try {
return block.getStateFromMeta(metadata);
} catch (Exception e) {
AELog.warn("Block %s has broken getStateFromMeta method for meta %d", block.getRegistryName().toString(), baseItemStack.getItemDamage());
return Blocks.GLASS.getDefaultState();
}
}
public List<ItemStack> getFacades()
{
this.calculateSubTypes();
return this.subTypes;
}
public List<ItemStack> getFacades() {
this.calculateSubTypes();
return this.subTypes;
}
public ItemStack getCreativeTabIcon()
{
this.calculateSubTypes();
if( this.subTypes.isEmpty() )
{
return new ItemStack( Items.CAKE );
}
return this.subTypes.get( 0 );
}
public ItemStack getCreativeTabIcon() {
this.calculateSubTypes();
if (this.subTypes.isEmpty()) {
return new ItemStack(Items.CAKE);
}
return this.subTypes.get(0);
}
public ItemStack createFromIDs( final int[] ids )
{
ItemStack facadeStack = AEApi.instance()
.definitions()
.items()
.facade()
.maybeStack( 1 )
.orElseThrow( () -> new MissingDefinitionException( "Tried to create a facade, while facades are being deactivated." ) );
public ItemStack createFromIDs(final int[] ids) {
ItemStack facadeStack = AEApi.instance()
.definitions()
.items()
.facade()
.maybeStack(1)
.orElseThrow(() -> new MissingDefinitionException("Tried to create a facade, while facades are being deactivated."));
// Convert back to a registry name...
Item item = Item.REGISTRY.getObjectById( ids[0] );
if( item == null )
{
return ItemStack.EMPTY;
}
// Convert back to a registry name...
Item item = Item.REGISTRY.getObjectById(ids[0]);
if (item == null) {
return ItemStack.EMPTY;
}
final NBTTagCompound facadeTag = new NBTTagCompound();
facadeTag.setString( TAG_ITEM_ID, item.getRegistryName().toString() );
facadeTag.setInteger( TAG_DAMAGE, ids[1] );
facadeStack.setTagCompound( facadeTag );
final NBTTagCompound facadeTag = new NBTTagCompound();
facadeTag.setString(TAG_ITEM_ID, item.getRegistryName().toString());
facadeTag.setInteger(TAG_DAMAGE, ids[1]);
facadeStack.setTagCompound(facadeTag);
return facadeStack;
}
return facadeStack;
}
@Override
public boolean useAlphaPass( final ItemStack is )
{
IBlockState blockState = this.getTextureBlockState( is );
@Override
public boolean useAlphaPass(final ItemStack is) {
IBlockState blockState = this.getTextureBlockState(is);
if( blockState == null )
{
return false;
}
if (blockState == null) {
return false;
}
Block blk = blockState.getBlock();
return blk.canRenderInLayer( blockState, BlockRenderLayer.TRANSLUCENT );
}
Block blk = blockState.getBlock();
return blk.canRenderInLayer(blockState, BlockRenderLayer.TRANSLUCENT);
}
}
+239 -306
View File
@@ -19,22 +19,17 @@
package appeng.items.parts;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import appeng.api.AEApi;
import appeng.api.implementations.items.IItemGroup;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartItem;
import appeng.api.util.AEColor;
import appeng.core.features.ActivityState;
import appeng.core.features.ItemStackSrc;
import appeng.core.localization.GuiText;
import appeng.items.AEBaseItem;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@@ -46,352 +41,290 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
import appeng.api.AEApi;
import appeng.api.implementations.items.IItemGroup;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartItem;
import appeng.api.util.AEColor;
import appeng.core.features.ActivityState;
import appeng.core.features.ItemStackSrc;
import appeng.core.localization.GuiText;
import appeng.items.AEBaseItem;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.Map.Entry;
public final class ItemPart extends AEBaseItem implements IPartItem, IItemGroup
{
private static final int INITIAL_REGISTERED_CAPACITY = PartType.values().length;
private static final Comparator<Entry<Integer, PartTypeWithVariant>> REGISTERED_COMPARATOR = new RegisteredComparator();
public final class ItemPart extends AEBaseItem implements IPartItem, IItemGroup {
private static final int INITIAL_REGISTERED_CAPACITY = PartType.values().length;
private static final Comparator<Entry<Integer, PartTypeWithVariant>> REGISTERED_COMPARATOR = new RegisteredComparator();
public static ItemPart instance;
private final Map<Integer, PartTypeWithVariant> registered;
public static ItemPart instance;
private final Map<Integer, PartTypeWithVariant> registered;
public ItemPart()
{
this.registered = new HashMap<>( INITIAL_REGISTERED_CAPACITY );
public ItemPart() {
this.registered = new HashMap<>(INITIAL_REGISTERED_CAPACITY);
this.setHasSubtypes( true );
this.setHasSubtypes(true);
instance = this;
}
instance = this;
}
@Nonnull
public final ItemStackSrc createPart( final PartType mat )
{
Preconditions.checkNotNull( mat );
@Nonnull
public final ItemStackSrc createPart(final PartType mat) {
Preconditions.checkNotNull(mat);
return this.createPart( mat, 0 );
}
return this.createPart(mat, 0);
}
@Nonnull
public ItemStackSrc createPart( final PartType mat, final AEColor color )
{
Preconditions.checkNotNull( mat );
Preconditions.checkNotNull( color );
@Nonnull
public ItemStackSrc createPart(final PartType mat, final AEColor color) {
Preconditions.checkNotNull(mat);
Preconditions.checkNotNull(color);
final int varID = color.ordinal();
final int varID = color.ordinal();
return this.createPart( mat, varID );
}
return this.createPart(mat, varID);
}
@Nonnull
private ItemStackSrc createPart( final PartType mat, final int varID )
{
assert mat != null;
assert varID >= 0;
@Nonnull
private ItemStackSrc createPart(final PartType mat, final int varID) {
assert mat != null;
assert varID >= 0;
// verify
for( final PartTypeWithVariant p : this.registered.values() )
{
if( p.part == mat && p.variant == varID )
{
throw new IllegalStateException( "Cannot create the same material twice..." );
}
}
// verify
for (final PartTypeWithVariant p : this.registered.values()) {
if (p.part == mat && p.variant == varID) {
throw new IllegalStateException("Cannot create the same material twice...");
}
}
boolean enabled = mat.isEnabled();
boolean enabled = mat.isEnabled();
final int partDamage = mat.getBaseDamage() + varID;
final ActivityState state = ActivityState.from( enabled );
final ItemStackSrc output = new ItemStackSrc( this, partDamage, state );
final int partDamage = mat.getBaseDamage() + varID;
final ActivityState state = ActivityState.from(enabled);
final ItemStackSrc output = new ItemStackSrc(this, partDamage, state);
final PartTypeWithVariant pti = new PartTypeWithVariant( mat, varID );
final PartTypeWithVariant pti = new PartTypeWithVariant(mat, varID);
this.processMetaOverlap( enabled, partDamage, mat, pti );
this.processMetaOverlap(enabled, partDamage, mat, pti);
return output;
}
return output;
}
private void processMetaOverlap( final boolean enabled, final int partDamage, final PartType mat, final PartTypeWithVariant pti )
{
assert partDamage >= 0;
assert mat != null;
assert pti != null;
private void processMetaOverlap(final boolean enabled, final int partDamage, final PartType mat, final PartTypeWithVariant pti) {
assert partDamage >= 0;
assert mat != null;
assert pti != null;
final PartTypeWithVariant registeredPartType = this.registered.get( partDamage );
if( registeredPartType != null )
{
throw new IllegalStateException( "Meta Overlap detected with type " + mat + " and damage " + partDamage + ". Found " + registeredPartType + " there already." );
}
final PartTypeWithVariant registeredPartType = this.registered.get(partDamage);
if (registeredPartType != null) {
throw new IllegalStateException("Meta Overlap detected with type " + mat + " and damage " + partDamage + ". Found " + registeredPartType + " there already.");
}
if( enabled )
{
this.registered.put( partDamage, pti );
}
}
if (enabled) {
this.registered.put(partDamage, pti);
}
}
public int getDamageByType( final PartType t )
{
Preconditions.checkNotNull( t );
public int getDamageByType(final PartType t) {
Preconditions.checkNotNull(t);
for( final Entry<Integer, PartTypeWithVariant> pt : this.registered.entrySet() )
{
if( pt.getValue().part == t )
{
return pt.getKey();
}
}
return -1;
}
for (final Entry<Integer, PartTypeWithVariant> pt : this.registered.entrySet()) {
if (pt.getValue().part == t) {
return pt.getKey();
}
}
return -1;
}
@Override
public EnumActionResult onItemUse( final EntityPlayer player, final World w, final BlockPos pos, final EnumHand hand, final EnumFacing side, final float hitX, final float hitY, final float hitZ )
{
if( this.getTypeByStack( player.getHeldItem( hand ) ) == PartType.INVALID_TYPE )
{
return EnumActionResult.FAIL;
}
@Override
public EnumActionResult onItemUse(final EntityPlayer player, final World w, final BlockPos pos, final EnumHand hand, final EnumFacing side, final float hitX, final float hitY, final float hitZ) {
if (this.getTypeByStack(player.getHeldItem(hand)) == PartType.INVALID_TYPE) {
return EnumActionResult.FAIL;
}
return AEApi.instance().partHelper().placeBus( player.getHeldItem( hand ), pos, side, player, hand, w );
}
return AEApi.instance().partHelper().placeBus(player.getHeldItem(hand), pos, side, player, hand, w);
}
@Override
public String getUnlocalizedName( final ItemStack is )
{
Preconditions.checkNotNull( is );
return "item.appliedenergistics2.multi_part." + this.getTypeByStack( is ).getUnlocalizedName().toLowerCase();
}
@Override
public String getUnlocalizedName(final ItemStack is) {
Preconditions.checkNotNull(is);
return "item.appliedenergistics2.multi_part." + this.getTypeByStack(is).getUnlocalizedName().toLowerCase();
}
@Override
public String getItemStackDisplayName( final ItemStack is )
{
final PartType pt = this.getTypeByStack( is );
@Override
public String getItemStackDisplayName(final ItemStack is) {
final PartType pt = this.getTypeByStack(is);
if( pt.isCable() )
{
final AEColor[] variants = AEColor.values();
if (pt.isCable()) {
final AEColor[] variants = AEColor.values();
final int itemDamage = is.getItemDamage();
final PartTypeWithVariant registeredPartType = this.registered.get( itemDamage );
if( registeredPartType != null )
{
return super.getItemStackDisplayName( is ) + " - " + variants[registeredPartType.variant].toString();
}
}
final int itemDamage = is.getItemDamage();
final PartTypeWithVariant registeredPartType = this.registered.get(itemDamage);
if (registeredPartType != null) {
return super.getItemStackDisplayName(is) + " - " + variants[registeredPartType.variant].toString();
}
}
if( pt.getExtraName() != null )
{
return super.getItemStackDisplayName( is ) + " - " + pt.getExtraName().getLocal();
}
if (pt.getExtraName() != null) {
return super.getItemStackDisplayName(is) + " - " + pt.getExtraName().getLocal();
}
return super.getItemStackDisplayName( is );
}
return super.getItemStackDisplayName(is);
}
@Override
protected void getCheckedSubItems( final CreativeTabs creativeTab, final NonNullList<ItemStack> itemStacks )
{
final List<Entry<Integer, PartTypeWithVariant>> types = new ArrayList<>( this.registered.entrySet() );
Collections.sort( types, REGISTERED_COMPARATOR );
@Override
protected void getCheckedSubItems(final CreativeTabs creativeTab, final NonNullList<ItemStack> itemStacks) {
final List<Entry<Integer, PartTypeWithVariant>> types = new ArrayList<>(this.registered.entrySet());
Collections.sort(types, REGISTERED_COMPARATOR);
for( final Entry<Integer, PartTypeWithVariant> part : types )
{
itemStacks.add( new ItemStack( this, 1, part.getKey() ) );
}
}
for (final Entry<Integer, PartTypeWithVariant> part : types) {
itemStacks.add(new ItemStack(this, 1, part.getKey()));
}
}
@Nonnull
public PartType getTypeByStack( final ItemStack is )
{
Preconditions.checkNotNull( is );
@Nonnull
public PartType getTypeByStack(final ItemStack is) {
Preconditions.checkNotNull(is);
final PartTypeWithVariant pt = this.registered.get( is.getItemDamage() );
if( pt != null )
{
return pt.part;
}
final PartTypeWithVariant pt = this.registered.get(is.getItemDamage());
if (pt != null) {
return pt.part;
}
return PartType.INVALID_TYPE;
}
return PartType.INVALID_TYPE;
}
@Nullable
@Override
public IPart createPartFromItemStack( final ItemStack is )
{
final PartType type = this.getTypeByStack( is );
final Class<? extends IPart> part = type.getPart();
if( part == null )
{
return null;
}
@Nullable
@Override
public IPart createPartFromItemStack(final ItemStack is) {
final PartType type = this.getTypeByStack(is);
final Class<? extends IPart> part = type.getPart();
if (part == null) {
return null;
}
try
{
if( type.getConstructor() == null )
{
type.setConstructor( part.getConstructor( ItemStack.class ) );
}
try {
if (type.getConstructor() == null) {
type.setConstructor(part.getConstructor(ItemStack.class));
}
return type.getConstructor().newInstance( is );
}
catch( final InstantiationException e )
{
throw new IllegalStateException( "Unable to construct IBusPart from IBusItem : " + part
.getName() + " ; Possibly didn't have correct constructor( ItemStack )", e );
}
catch( final IllegalAccessException e )
{
throw new IllegalStateException( "Unable to construct IBusPart from IBusItem : " + part
.getName() + " ; Possibly didn't have correct constructor( ItemStack )", e );
}
catch( final InvocationTargetException e )
{
throw new IllegalStateException( "Unable to construct IBusPart from IBusItem : " + part
.getName() + " ; Possibly didn't have correct constructor( ItemStack )", e );
}
catch( final NoSuchMethodException e )
{
throw new IllegalStateException( "Unable to construct IBusPart from IBusItem : " + part
.getName() + " ; Possibly didn't have correct constructor( ItemStack )", e );
}
}
return type.getConstructor().newInstance(is);
} catch (final InstantiationException e) {
throw new IllegalStateException("Unable to construct IBusPart from IBusItem : " + part
.getName() + " ; Possibly didn't have correct constructor( ItemStack )", e);
} catch (final IllegalAccessException e) {
throw new IllegalStateException("Unable to construct IBusPart from IBusItem : " + part
.getName() + " ; Possibly didn't have correct constructor( ItemStack )", e);
} catch (final InvocationTargetException e) {
throw new IllegalStateException("Unable to construct IBusPart from IBusItem : " + part
.getName() + " ; Possibly didn't have correct constructor( ItemStack )", e);
} catch (final NoSuchMethodException e) {
throw new IllegalStateException("Unable to construct IBusPart from IBusItem : " + part
.getName() + " ; Possibly didn't have correct constructor( ItemStack )", e);
}
}
public int variantOf( final int itemDamage )
{
final PartTypeWithVariant registeredPartType = this.registered.get( itemDamage );
if( registeredPartType != null )
{
return registeredPartType.variant;
}
public int variantOf(final int itemDamage) {
final PartTypeWithVariant registeredPartType = this.registered.get(itemDamage);
if (registeredPartType != null) {
return registeredPartType.variant;
}
return 0;
}
return 0;
}
@Nullable
@Override
public String getUnlocalizedGroupName( final Set<ItemStack> others, final ItemStack is )
{
boolean importBus = false;
boolean importBusFluids = false;
boolean exportBus = false;
boolean exportBusFluids = false;
boolean group = false;
@Nullable
@Override
public String getUnlocalizedGroupName(final Set<ItemStack> others, final ItemStack is) {
boolean importBus = false;
boolean importBusFluids = false;
boolean exportBus = false;
boolean exportBusFluids = false;
boolean group = false;
final PartType u = this.getTypeByStack( is );
final PartType u = this.getTypeByStack(is);
for( final ItemStack stack : others )
{
if( stack.getItem() == this )
{
final PartType pt = this.getTypeByStack( stack );
switch( pt )
{
case IMPORT_BUS:
importBus = true;
if( u == pt )
{
group = true;
}
break;
case FLUID_IMPORT_BUS:
importBusFluids = true;
if( u == pt )
{
group = true;
}
break;
case EXPORT_BUS:
exportBus = true;
if( u == pt )
{
group = true;
}
break;
case FLUID_EXPORT_BUS:
exportBusFluids = true;
if( u == pt )
{
group = true;
}
break;
default:
}
}
}
for (final ItemStack stack : others) {
if (stack.getItem() == this) {
final PartType pt = this.getTypeByStack(stack);
switch (pt) {
case IMPORT_BUS:
importBus = true;
if (u == pt) {
group = true;
}
break;
case FLUID_IMPORT_BUS:
importBusFluids = true;
if (u == pt) {
group = true;
}
break;
case EXPORT_BUS:
exportBus = true;
if (u == pt) {
group = true;
}
break;
case FLUID_EXPORT_BUS:
exportBusFluids = true;
if (u == pt) {
group = true;
}
break;
default:
}
}
}
if( group && importBus && exportBus && ( u == PartType.IMPORT_BUS || u == PartType.EXPORT_BUS ) )
{
return GuiText.IOBuses.getUnlocalized();
}
if( group && importBusFluids && exportBusFluids && ( u == PartType.FLUID_IMPORT_BUS || u == PartType.FLUID_EXPORT_BUS ) )
{
return GuiText.IOBusesFluids.getUnlocalized();
}
if (group && importBus && exportBus && (u == PartType.IMPORT_BUS || u == PartType.EXPORT_BUS)) {
return GuiText.IOBuses.getUnlocalized();
}
if (group && importBusFluids && exportBusFluids && (u == PartType.FLUID_IMPORT_BUS || u == PartType.FLUID_EXPORT_BUS)) {
return GuiText.IOBusesFluids.getUnlocalized();
}
return null;
}
return null;
}
private static final class PartTypeWithVariant
{
private final PartType part;
private final int variant;
private static final class PartTypeWithVariant {
private final PartType part;
private final int variant;
private PartTypeWithVariant( final PartType part, final int variant )
{
assert part != null;
assert variant >= 0;
private PartTypeWithVariant(final PartType part, final int variant) {
assert part != null;
assert variant >= 0;
this.part = part;
this.variant = variant;
}
this.part = part;
this.variant = variant;
}
@Override
public String toString()
{
return "PartTypeWithVariant{" + "part=" + this.part + ", variant=" + this.variant + '}';
}
}
@Override
public String toString() {
return "PartTypeWithVariant{" + "part=" + this.part + ", variant=" + this.variant + '}';
}
}
private static final class RegisteredComparator implements Comparator<Entry<Integer, PartTypeWithVariant>>
{
@Override
public int compare( final Entry<Integer, PartTypeWithVariant> o1, final Entry<Integer, PartTypeWithVariant> o2 )
{
final String string1 = o1.getValue().part.name();
final String string2 = o2.getValue().part.name();
final int comparedString = string1.compareTo( string2 );
private static final class RegisteredComparator implements Comparator<Entry<Integer, PartTypeWithVariant>> {
@Override
public int compare(final Entry<Integer, PartTypeWithVariant> o1, final Entry<Integer, PartTypeWithVariant> o2) {
final String string1 = o1.getValue().part.name();
final String string2 = o2.getValue().part.name();
final int comparedString = string1.compareTo(string2);
if( comparedString == 0 )
{
return Integer.compare( o1.getKey(), o2.getKey() );
}
if (comparedString == 0) {
return Integer.compare(o1.getKey(), o2.getKey());
}
return comparedString;
}
}
return comparedString;
}
}
public void registerOreDicts()
{
for( final PartTypeWithVariant mt : ImmutableSet.copyOf( this.registered.values() ) )
{
if( mt.part.getOreName() != null )
{
final String[] names = mt.part.getOreName().split( "," );
public void registerOreDicts() {
for (final PartTypeWithVariant mt : ImmutableSet.copyOf(this.registered.values())) {
if (mt.part.getOreName() != null) {
final String[] names = mt.part.getOreName().split(",");
for( final String name : names )
{
OreDictionary.registerOre( name, new ItemStack( this, 1, mt.part.getBaseDamage() + mt.variant ) );
}
}
}
}
for (final String name : names) {
OreDictionary.registerOre(name, new ItemStack(this, 1, mt.part.getBaseDamage() + mt.variant));
}
}
}
}
}
@@ -19,17 +19,6 @@
package appeng.items.parts;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.util.AEColor;
import appeng.bootstrap.IItemRendering;
import appeng.bootstrap.ItemRenderingCustomizer;
@@ -39,109 +28,114 @@ import appeng.core.AppEng;
import appeng.core.features.registries.PartModels;
import appeng.parts.automation.PlaneConnections;
import appeng.parts.automation.PlaneModel;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class ItemPartRendering extends ItemRenderingCustomizer
{
public class ItemPartRendering extends ItemRenderingCustomizer {
private final PartModels partModels;
private final PartModels partModels;
private final ItemPart item;
private final ItemPart item;
public ItemPartRendering( PartModels partModels, ItemPart item )
{
this.partModels = partModels;
this.item = item;
}
public ItemPartRendering(PartModels partModels, ItemPart item) {
this.partModels = partModels;
this.item = item;
}
@Override
@SideOnly( Side.CLIENT )
public void customize( IItemRendering rendering )
{
@Override
@SideOnly(Side.CLIENT)
public void customize(IItemRendering rendering) {
rendering.meshDefinition( this::getItemMeshDefinition );
rendering.meshDefinition(this::getItemMeshDefinition);
rendering.color( new StaticItemColor( AEColor.TRANSPARENT ) );
rendering.color(new StaticItemColor(AEColor.TRANSPARENT));
// Register all item models as variants so they get loaded
rendering.variants( Arrays.stream( PartType.values() )
.filter( f -> f != PartType.INVALID_TYPE )
.flatMap( part -> part.getItemModels().stream() )
.collect( Collectors.toList() ) );
// Register all item models as variants so they get loaded
rendering.variants(Arrays.stream(PartType.values())
.filter(f -> f != PartType.INVALID_TYPE)
.flatMap(part -> part.getItemModels().stream())
.collect(Collectors.toList()));
// Register the built-in models for annihilation planes
ResourceLocation annihilationPlaneTexture = new ResourceLocation( AppEng.MOD_ID, "items/part/annihilation_plane" );
ResourceLocation annihilationPlaneOnTexture = new ResourceLocation( AppEng.MOD_ID, "parts/annihilation_plane_on" );
ResourceLocation fluidAnnihilationPlaneTexture = new ResourceLocation( AppEng.MOD_ID, "items/part/fluid_annihilation_plane" );
ResourceLocation fluidAnnihilationPlaneOnTexture = new ResourceLocation( AppEng.MOD_ID, "parts/fluid_annihilation_plane_on" );
ResourceLocation identityAnnihilationPlaneTexture = new ResourceLocation( AppEng.MOD_ID, "items/part/identity_annihilation_plane" );
ResourceLocation identityAnnihilationPlaneOnTexture = new ResourceLocation( AppEng.MOD_ID, "parts/identity_annihilation_plane_on" );
ResourceLocation formationPlaneTexture = new ResourceLocation( AppEng.MOD_ID, "items/part/formation_plane" );
ResourceLocation formationPlaneOnTexture = new ResourceLocation( AppEng.MOD_ID, "parts/formation_plane_on" );
ResourceLocation fluidFormationPlaneTexture = new ResourceLocation( AppEng.MOD_ID, "items/part/fluid_formation_plane" );
ResourceLocation fluidFormationPlaneOnTexture = new ResourceLocation( AppEng.MOD_ID, "parts/fluid_formation_plane_on" );
ResourceLocation sidesTexture = new ResourceLocation( AppEng.MOD_ID, "parts/plane_sides" );
ResourceLocation backTexture = new ResourceLocation( AppEng.MOD_ID, "parts/transition_plane_back" );
// Register the built-in models for annihilation planes
ResourceLocation annihilationPlaneTexture = new ResourceLocation(AppEng.MOD_ID, "items/part/annihilation_plane");
ResourceLocation annihilationPlaneOnTexture = new ResourceLocation(AppEng.MOD_ID, "parts/annihilation_plane_on");
ResourceLocation fluidAnnihilationPlaneTexture = new ResourceLocation(AppEng.MOD_ID, "items/part/fluid_annihilation_plane");
ResourceLocation fluidAnnihilationPlaneOnTexture = new ResourceLocation(AppEng.MOD_ID, "parts/fluid_annihilation_plane_on");
ResourceLocation identityAnnihilationPlaneTexture = new ResourceLocation(AppEng.MOD_ID, "items/part/identity_annihilation_plane");
ResourceLocation identityAnnihilationPlaneOnTexture = new ResourceLocation(AppEng.MOD_ID, "parts/identity_annihilation_plane_on");
ResourceLocation formationPlaneTexture = new ResourceLocation(AppEng.MOD_ID, "items/part/formation_plane");
ResourceLocation formationPlaneOnTexture = new ResourceLocation(AppEng.MOD_ID, "parts/formation_plane_on");
ResourceLocation fluidFormationPlaneTexture = new ResourceLocation(AppEng.MOD_ID, "items/part/fluid_formation_plane");
ResourceLocation fluidFormationPlaneOnTexture = new ResourceLocation(AppEng.MOD_ID, "parts/fluid_formation_plane_on");
ResourceLocation sidesTexture = new ResourceLocation(AppEng.MOD_ID, "parts/plane_sides");
ResourceLocation backTexture = new ResourceLocation(AppEng.MOD_ID, "parts/transition_plane_back");
List<String> modelNames = new ArrayList<>();
List<String> modelNames = new ArrayList<>();
for( PlaneConnections connection : PlaneConnections.PERMUTATIONS )
{
PlaneModel model = new PlaneModel( annihilationPlaneTexture, sidesTexture, backTexture, connection );
rendering.builtInModel( "models/part/annihilation_plane_" + connection.getFilenameSuffix(), model );
modelNames.add( "part/annihilation_plane_" + connection.getFilenameSuffix() );
for (PlaneConnections connection : PlaneConnections.PERMUTATIONS) {
PlaneModel model = new PlaneModel(annihilationPlaneTexture, sidesTexture, backTexture, connection);
rendering.builtInModel("models/part/annihilation_plane_" + connection.getFilenameSuffix(), model);
modelNames.add("part/annihilation_plane_" + connection.getFilenameSuffix());
model = new PlaneModel( annihilationPlaneOnTexture, sidesTexture, backTexture, connection );
rendering.builtInModel( "models/part/annihilation_plane_on_" + connection.getFilenameSuffix(), model );
modelNames.add( "part/annihilation_plane_on_" + connection.getFilenameSuffix() );
model = new PlaneModel(annihilationPlaneOnTexture, sidesTexture, backTexture, connection);
rendering.builtInModel("models/part/annihilation_plane_on_" + connection.getFilenameSuffix(), model);
modelNames.add("part/annihilation_plane_on_" + connection.getFilenameSuffix());
model = new PlaneModel( fluidAnnihilationPlaneTexture, sidesTexture, backTexture, connection );
rendering.builtInModel( "models/part/fluid_annihilation_plane_" + connection.getFilenameSuffix(), model );
modelNames.add( "part/fluid_annihilation_plane_" + connection.getFilenameSuffix() );
model = new PlaneModel(fluidAnnihilationPlaneTexture, sidesTexture, backTexture, connection);
rendering.builtInModel("models/part/fluid_annihilation_plane_" + connection.getFilenameSuffix(), model);
modelNames.add("part/fluid_annihilation_plane_" + connection.getFilenameSuffix());
model = new PlaneModel( fluidAnnihilationPlaneOnTexture, sidesTexture, backTexture, connection );
rendering.builtInModel( "models/part/fluid_annihilation_plane_on_" + connection.getFilenameSuffix(), model );
modelNames.add( "part/fluid_annihilation_plane_on_" + connection.getFilenameSuffix() );
model = new PlaneModel(fluidAnnihilationPlaneOnTexture, sidesTexture, backTexture, connection);
rendering.builtInModel("models/part/fluid_annihilation_plane_on_" + connection.getFilenameSuffix(), model);
modelNames.add("part/fluid_annihilation_plane_on_" + connection.getFilenameSuffix());
model = new PlaneModel( identityAnnihilationPlaneTexture, sidesTexture, backTexture, connection );
rendering.builtInModel( "models/part/identity_annihilation_plane_" + connection.getFilenameSuffix(), model );
modelNames.add( "part/identity_annihilation_plane_" + connection.getFilenameSuffix() );
model = new PlaneModel(identityAnnihilationPlaneTexture, sidesTexture, backTexture, connection);
rendering.builtInModel("models/part/identity_annihilation_plane_" + connection.getFilenameSuffix(), model);
modelNames.add("part/identity_annihilation_plane_" + connection.getFilenameSuffix());
model = new PlaneModel( identityAnnihilationPlaneOnTexture, sidesTexture, backTexture, connection );
rendering.builtInModel( "models/part/identity_annihilation_plane_on_" + connection.getFilenameSuffix(), model );
modelNames.add( "part/identity_annihilation_plane_on_" + connection.getFilenameSuffix() );
model = new PlaneModel(identityAnnihilationPlaneOnTexture, sidesTexture, backTexture, connection);
rendering.builtInModel("models/part/identity_annihilation_plane_on_" + connection.getFilenameSuffix(), model);
modelNames.add("part/identity_annihilation_plane_on_" + connection.getFilenameSuffix());
model = new PlaneModel( formationPlaneTexture, sidesTexture, backTexture, connection );
rendering.builtInModel( "models/part/formation_plane_" + connection.getFilenameSuffix(), model );
modelNames.add( "part/formation_plane_" + connection.getFilenameSuffix() );
model = new PlaneModel(formationPlaneTexture, sidesTexture, backTexture, connection);
rendering.builtInModel("models/part/formation_plane_" + connection.getFilenameSuffix(), model);
modelNames.add("part/formation_plane_" + connection.getFilenameSuffix());
model = new PlaneModel( formationPlaneOnTexture, sidesTexture, backTexture, connection );
rendering.builtInModel( "models/part/formation_plane_on_" + connection.getFilenameSuffix(), model );
modelNames.add( "part/formation_plane_on_" + connection.getFilenameSuffix() );
model = new PlaneModel(formationPlaneOnTexture, sidesTexture, backTexture, connection);
rendering.builtInModel("models/part/formation_plane_on_" + connection.getFilenameSuffix(), model);
modelNames.add("part/formation_plane_on_" + connection.getFilenameSuffix());
model = new PlaneModel( fluidFormationPlaneTexture, sidesTexture, backTexture, connection );
rendering.builtInModel( "models/part/fluid_formation_plane_" + connection.getFilenameSuffix(), model );
modelNames.add( "part/fluid_formation_plane_" + connection.getFilenameSuffix() );
model = new PlaneModel(fluidFormationPlaneTexture, sidesTexture, backTexture, connection);
rendering.builtInModel("models/part/fluid_formation_plane_" + connection.getFilenameSuffix(), model);
modelNames.add("part/fluid_formation_plane_" + connection.getFilenameSuffix());
model = new PlaneModel( fluidFormationPlaneOnTexture, sidesTexture, backTexture, connection );
rendering.builtInModel( "models/part/fluid_formation_plane_on_" + connection.getFilenameSuffix(), model );
modelNames.add( "part/fluid_formation_plane_on_" + connection.getFilenameSuffix() );
model = new PlaneModel(fluidFormationPlaneOnTexture, sidesTexture, backTexture, connection);
rendering.builtInModel("models/part/fluid_formation_plane_on_" + connection.getFilenameSuffix(), model);
modelNames.add("part/fluid_formation_plane_on_" + connection.getFilenameSuffix());
}
}
// base p2p model with frequency
rendering.builtInModel( "models/part/builtin/p2p_tunnel_frequency", new P2PTunnelFrequencyModel() );
// base p2p model with frequency
rendering.builtInModel("models/part/builtin/p2p_tunnel_frequency", new P2PTunnelFrequencyModel());
List<ResourceLocation> partResourceLocs = modelNames.stream()
.map( name -> new ResourceLocation( AppEng.MOD_ID, name ) )
.collect( Collectors.toList() );
this.partModels.registerModels( partResourceLocs );
}
List<ResourceLocation> partResourceLocs = modelNames.stream()
.map(name -> new ResourceLocation(AppEng.MOD_ID, name))
.collect(Collectors.toList());
this.partModels.registerModels(partResourceLocs);
}
private ModelResourceLocation getItemMeshDefinition( ItemStack is )
{
PartType partType = this.item.getTypeByStack( is );
int variant = this.item.variantOf( is.getItemDamage() );
return partType.getItemModels().get( variant );
}
private ModelResourceLocation getItemMeshDefinition(ItemStack is) {
PartType partType = this.item.getTypeByStack(is);
int variant = this.item.variantOf(is.getItemDamage());
return partType.getItemModels().get(variant);
}
}
@@ -29,10 +29,10 @@ import java.lang.annotation.Target;
* This annotation is used to mark static fields or static methods that return/contain models used
* for a part. They are automatically registered as part of the part item registration.
*/
@Retention( RetentionPolicy.RUNTIME )
@Target( {
ElementType.FIELD,
ElementType.METHOD
} )
public @interface PartModels
{}
@Retention(RetentionPolicy.RUNTIME)
@Target({
ElementType.FIELD,
ElementType.METHOD
})
public @interface PartModels {
}
@@ -1,7 +1,10 @@
package appeng.items.parts;
import appeng.api.parts.IPartModel;
import appeng.core.AELog;
import net.minecraft.util.ResourceLocation;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -10,135 +13,104 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import net.minecraft.util.ResourceLocation;
import appeng.api.parts.IPartModel;
import appeng.core.AELog;
/**
* Helps with the reflection magic needed to gather all models for AE2 cable bus parts.
*/
class PartModelsHelper
{
class PartModelsHelper {
static List<ResourceLocation> createModels( Class<?> clazz )
{
List<ResourceLocation> locations = new ArrayList<>();
static List<ResourceLocation> createModels(Class<?> clazz) {
List<ResourceLocation> locations = new ArrayList<>();
// Check all static fields for used models
Field[] fields = clazz.getDeclaredFields();
for( Field field : fields )
{
if( field.getAnnotation( PartModels.class ) == null )
{
continue;
}
// Check all static fields for used models
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
if (field.getAnnotation(PartModels.class) == null) {
continue;
}
if( !Modifier.isStatic( field.getModifiers() ) )
{
AELog.error( "The @PartModels annotation can only be used on static fields or methods. Was seen on: " + field );
continue;
}
if (!Modifier.isStatic(field.getModifiers())) {
AELog.error("The @PartModels annotation can only be used on static fields or methods. Was seen on: " + field);
continue;
}
Object value;
try
{
field.setAccessible( true );
value = field.get( null );
}
catch( IllegalAccessException e )
{
AELog.error( e, "Cannot access field annotated with @PartModels: " + field );
continue;
}
Object value;
try {
field.setAccessible(true);
value = field.get(null);
} catch (IllegalAccessException e) {
AELog.error(e, "Cannot access field annotated with @PartModels: " + field);
continue;
}
convertAndAddLocation( field, value, locations );
}
convertAndAddLocation(field, value, locations);
}
// Check all static methods for the annotation
for( Method method : clazz.getDeclaredMethods() )
{
if( method.getAnnotation( PartModels.class ) == null )
{
continue;
}
// Check all static methods for the annotation
for (Method method : clazz.getDeclaredMethods()) {
if (method.getAnnotation(PartModels.class) == null) {
continue;
}
if( !Modifier.isStatic( method.getModifiers() ) )
{
AELog.error( "The @PartModels annotation can only be used on static fields or methods. Was seen on: " + method );
continue;
}
if (!Modifier.isStatic(method.getModifiers())) {
AELog.error("The @PartModels annotation can only be used on static fields or methods. Was seen on: " + method);
continue;
}
// Check for parameter count
if( method.getParameters().length != 0 )
{
AELog.error( "The @PartModels annotation can only be used on static methods without parameters. Was seen on: " + method );
continue;
}
// Check for parameter count
if (method.getParameters().length != 0) {
AELog.error("The @PartModels annotation can only be used on static methods without parameters. Was seen on: " + method);
continue;
}
// Make sure we can handle the return type
Class<?> returnType = method.getReturnType();
if( !ResourceLocation.class.isAssignableFrom( returnType ) && !Collection.class.isAssignableFrom( returnType ) )
{
AELog.error(
"The @PartModels annotation can only be used on static methods that return a ResourceLocation or Collection of " + "ResourceLocations. Was seen on: " + method );
continue;
}
// Make sure we can handle the return type
Class<?> returnType = method.getReturnType();
if (!ResourceLocation.class.isAssignableFrom(returnType) && !Collection.class.isAssignableFrom(returnType)) {
AELog.error(
"The @PartModels annotation can only be used on static methods that return a ResourceLocation or Collection of " + "ResourceLocations. Was seen on: " + method);
continue;
}
Object value = null;
try
{
method.setAccessible( true );
value = method.invoke( null );
}
catch( IllegalAccessException | InvocationTargetException e )
{
AELog.error( e, "Failed to invoke the @PartModels annotated method " + method );
continue;
}
Object value = null;
try {
method.setAccessible(true);
value = method.invoke(null);
} catch (IllegalAccessException | InvocationTargetException e) {
AELog.error(e, "Failed to invoke the @PartModels annotated method " + method);
continue;
}
convertAndAddLocation( method, value, locations );
}
convertAndAddLocation(method, value, locations);
}
if( clazz.getSuperclass() != null )
{
locations.addAll( createModels( clazz.getSuperclass() ) );
}
if (clazz.getSuperclass() != null) {
locations.addAll(createModels(clazz.getSuperclass()));
}
return locations;
}
return locations;
}
private static void convertAndAddLocation( Object source, Object value, List<ResourceLocation> locations )
{
if( value == null )
{
return;
}
private static void convertAndAddLocation(Object source, Object value, List<ResourceLocation> locations) {
if (value == null) {
return;
}
if( value instanceof ResourceLocation )
{
locations.add( (ResourceLocation) value );
}
else if( value instanceof IPartModel )
{
locations.addAll( ( (IPartModel) value ).getModels() );
}
else if( value instanceof Collection )
{
// Check that each object is an IPartModel
Collection values = (Collection) value;
for( Object candidate : values )
{
if( !( candidate instanceof IPartModel ) )
{
AELog.error( "List of locations obtained from {} contains a non resource location: {}", source, candidate );
continue;
}
if (value instanceof ResourceLocation) {
locations.add((ResourceLocation) value);
} else if (value instanceof IPartModel) {
locations.addAll(((IPartModel) value).getModels());
} else if (value instanceof Collection) {
// Check that each object is an IPartModel
Collection values = (Collection) value;
for (Object candidate : values) {
if (!(candidate instanceof IPartModel)) {
AELog.error("List of locations obtained from {} contains a non resource location: {}", source, candidate);
continue;
}
locations.addAll( ( (IPartModel) candidate ).getModels() );
}
}
}
locations.addAll(((IPartModel) candidate).getModels());
}
}
}
}
+312 -395
View File
@@ -19,416 +19,333 @@
package appeng.items.parts;
import java.lang.reflect.Constructor;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import appeng.parts.misc.*;
import appeng.parts.p2p.*;
import appeng.parts.reporting.*;
import com.google.common.collect.ImmutableList;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.parts.IPart;
import appeng.api.util.AEColor;
import appeng.core.AEConfig;
import appeng.core.AppEng;
import appeng.core.features.AEFeature;
import appeng.core.localization.GuiText;
import appeng.fluids.parts.PartFluidAnnihilationPlane;
import appeng.fluids.parts.PartFluidExportBus;
import appeng.fluids.parts.PartFluidFormationPlane;
import appeng.fluids.parts.PartFluidImportBus;
import appeng.fluids.parts.PartFluidInterface;
import appeng.fluids.parts.PartFluidLevelEmitter;
import appeng.fluids.parts.PartFluidStorageBus;
import appeng.fluids.parts.PartFluidTerminal;
import appeng.fluids.parts.*;
import appeng.integration.IntegrationRegistry;
import appeng.integration.IntegrationType;
import appeng.parts.automation.PartAnnihilationPlane;
import appeng.parts.automation.PartExportBus;
import appeng.parts.automation.PartFormationPlane;
import appeng.parts.automation.PartIdentityAnnihilationPlane;
import appeng.parts.automation.PartImportBus;
import appeng.parts.automation.PartLevelEmitter;
import appeng.parts.networking.PartCableCovered;
import appeng.parts.networking.PartCableGlass;
import appeng.parts.networking.PartCableSmart;
import appeng.parts.networking.PartDenseCableCovered;
import appeng.parts.networking.PartDenseCableSmart;
import appeng.parts.networking.PartQuartzFiber;
import appeng.parts.automation.*;
import appeng.parts.misc.*;
import appeng.parts.networking.*;
import appeng.parts.p2p.*;
import appeng.parts.reporting.*;
import appeng.util.Platform;
import com.google.common.collect.ImmutableList;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.lang.reflect.Constructor;
import java.util.*;
import java.util.stream.Collectors;
public enum PartType
{
INVALID_TYPE( -1, "invalid", EnumSet.of( AEFeature.CORE ), EnumSet.noneOf( IntegrationType.class ), null ),
CABLE_GLASS( 0, "cable_glass", EnumSet.of( AEFeature.GLASS_CABLES ), EnumSet.noneOf( IntegrationType.class ), PartCableGlass.class )
{
@Override
public boolean isCable()
{
return true;
}
@Override
@SideOnly( Side.CLIENT )
protected List<ModelResourceLocation> createItemModels( String baseName )
{
return Arrays.stream( AEColor.values() ).map( color -> modelFromBaseName( baseName + "_" + color.name().toLowerCase() ) ).collect( Collectors.toList() );
}
},
CABLE_COVERED( 20, "cable_covered", EnumSet.of( AEFeature.COVERED_CABLES ), EnumSet.noneOf( IntegrationType.class ), PartCableCovered.class )
{
@Override
public boolean isCable()
{
return true;
}
@Override
@SideOnly( Side.CLIENT )
protected List<ModelResourceLocation> createItemModels( String baseName )
{
return Arrays.stream( AEColor.values() ).map( color -> modelFromBaseName( baseName + "_" + color.name().toLowerCase() ) ).collect( Collectors.toList() );
}
},
public enum PartType {
INVALID_TYPE(-1, "invalid", EnumSet.of(AEFeature.CORE), EnumSet.noneOf(IntegrationType.class), null),
CABLE_SMART( 40, "cable_smart", EnumSet.of( AEFeature.SMART_CABLES ), EnumSet.noneOf( IntegrationType.class ), PartCableSmart.class )
{
@Override
public boolean isCable()
{
return true;
}
CABLE_GLASS(0, "cable_glass", EnumSet.of(AEFeature.GLASS_CABLES), EnumSet.noneOf(IntegrationType.class), PartCableGlass.class) {
@Override
public boolean isCable() {
return true;
}
@Override
@SideOnly( Side.CLIENT )
protected List<ModelResourceLocation> createItemModels( String baseName )
{
return Arrays.stream( AEColor.values() ).map( color -> modelFromBaseName( baseName + "_" + color.name().toLowerCase() ) ).collect( Collectors.toList() );
}
},
@Override
@SideOnly(Side.CLIENT)
protected List<ModelResourceLocation> createItemModels(String baseName) {
return Arrays.stream(AEColor.values()).map(color -> modelFromBaseName(baseName + "_" + color.name().toLowerCase())).collect(Collectors.toList());
}
},
CABLE_DENSE_SMART( 60, "cable_dense_smart", EnumSet.of( AEFeature.DENSE_CABLES ), EnumSet.noneOf( IntegrationType.class ), PartDenseCableSmart.class )
{
@Override
public boolean isCable()
{
return true;
}
CABLE_COVERED(20, "cable_covered", EnumSet.of(AEFeature.COVERED_CABLES), EnumSet.noneOf(IntegrationType.class), PartCableCovered.class) {
@Override
public boolean isCable() {
return true;
}
@Override
@SideOnly( Side.CLIENT )
protected List<ModelResourceLocation> createItemModels( String baseName )
{
return Arrays.stream( AEColor.values() ).map( color -> modelFromBaseName( baseName + "_" + color.name().toLowerCase() ) ).collect( Collectors.toList() );
}
},
CABLE_DENSE_COVERED( 500, "cable_dense_covered", EnumSet.of( AEFeature.DENSE_CABLES ), EnumSet.noneOf( IntegrationType.class ), PartDenseCableCovered.class )
{
@Override
public boolean isCable()
{
return true;
}
@Override
@SideOnly( Side.CLIENT )
protected List<ModelResourceLocation> createItemModels( String baseName )
{
return Arrays.stream( AEColor.values() ).map( color -> modelFromBaseName( baseName + "_" + color.name().toLowerCase() ) ).collect( Collectors.toList() );
}
},
TOGGLE_BUS( 80, "toggle_bus", EnumSet.of( AEFeature.TOGGLE_BUS ), EnumSet.noneOf( IntegrationType.class ), PartToggleBus.class ),
INVERTED_TOGGLE_BUS( 100, "inverted_toggle_bus", EnumSet.of( AEFeature.TOGGLE_BUS ), EnumSet.noneOf( IntegrationType.class ), PartInvertedToggleBus.class ),
CABLE_ANCHOR( 120, "cable_anchor", EnumSet.of( AEFeature.CABLE_ANCHOR ), EnumSet.noneOf( IntegrationType.class ), PartCableAnchor.class ),
QUARTZ_FIBER( 140, "quartz_fiber", EnumSet.of( AEFeature.QUARTZ_FIBER ), EnumSet.noneOf( IntegrationType.class ), PartQuartzFiber.class ),
MONITOR( 160, "monitor", EnumSet.of( AEFeature.PANELS ), EnumSet.noneOf( IntegrationType.class ), PartPanel.class, "itemIlluminatedPanel" ),
SEMI_DARK_MONITOR( 180, "semi_dark_monitor", EnumSet.of( AEFeature.PANELS ), EnumSet.noneOf( IntegrationType.class ), PartSemiDarkPanel.class, "itemIlluminatedPanel" ),
DARK_MONITOR( 200, "dark_monitor", EnumSet.of( AEFeature.PANELS ), EnumSet.noneOf( IntegrationType.class ), PartDarkPanel.class, "itemIlluminatedPanel" ),
STORAGE_BUS( 220, "storage_bus", EnumSet.of( AEFeature.STORAGE_BUS ), EnumSet.noneOf( IntegrationType.class ), PartStorageBus.class ),
FLUID_STORAGE_BUS( 221, "fluid_storage_bus", EnumSet.of( AEFeature.FLUID_STORAGE_BUS ), EnumSet.noneOf( IntegrationType.class ), PartFluidStorageBus.class ),
OREDICT_STORAGE_BUS( 222, "oredict_storage_bus", EnumSet.of( AEFeature.STORAGE_BUS ), EnumSet.noneOf( IntegrationType.class ), PartOreDicStorageBus.class ),
IMPORT_BUS( 240, "import_bus", EnumSet.of( AEFeature.IMPORT_BUS ), EnumSet.noneOf( IntegrationType.class ), PartImportBus.class ),
FLUID_IMPORT_BUS( 241, "fluid_import_bus", EnumSet.of( AEFeature.FLUID_IMPORT_BUS ), EnumSet.noneOf( IntegrationType.class ), PartFluidImportBus.class ),
EXPORT_BUS( 260, "export_bus", EnumSet.of( AEFeature.EXPORT_BUS ), EnumSet.noneOf( IntegrationType.class ), PartExportBus.class ),
FLUID_EXPORT_BUS( 261, "fluid_export_bus", EnumSet.of( AEFeature.FLUID_EXPORT_BUS ), EnumSet.noneOf( IntegrationType.class ), PartFluidExportBus.class ),
LEVEL_EMITTER( 280, "level_emitter", EnumSet.of( AEFeature.LEVEL_EMITTER ), EnumSet.noneOf( IntegrationType.class ), PartLevelEmitter.class ),
FLUID_LEVEL_EMITTER( 281, "fluid_level_emitter", EnumSet.of( AEFeature.FLUID_LEVEL_EMITTER ), EnumSet.noneOf( IntegrationType.class ), PartFluidLevelEmitter.class ),
ANNIHILATION_PLANE( 300, "annihilation_plane", EnumSet.of( AEFeature.ANNIHILATION_PLANE ), EnumSet.noneOf( IntegrationType.class ), PartAnnihilationPlane.class ),
IDENTITY_ANNIHILATION_PLANE( 301, "identity_annihilation_plane", EnumSet.of( AEFeature.ANNIHILATION_PLANE, AEFeature.IDENTITY_ANNIHILATION_PLANE ), EnumSet.noneOf( IntegrationType.class ), PartIdentityAnnihilationPlane.class ),
FLUID_ANNIHILATION_PLANE( 302, "fluid_annihilation_plane", EnumSet.of( AEFeature.FLUID_ANNIHILATION_PLANE ), EnumSet.noneOf( IntegrationType.class ), PartFluidAnnihilationPlane.class ),
FORMATION_PLANE( 320, "formation_plane", EnumSet.of( AEFeature.FORMATION_PLANE ), EnumSet.noneOf( IntegrationType.class ), PartFormationPlane.class ),
FLUID_FORMATION_PLANE( 321, "fluid_formation_plane", EnumSet.of( AEFeature.FLUID_FORMATION_PLANE ), EnumSet.noneOf( IntegrationType.class ), PartFluidFormationPlane.class ),
PATTERN_TERMINAL( 340, "pattern_terminal", EnumSet.of( AEFeature.PATTERNS ), EnumSet.noneOf( IntegrationType.class ), PartPatternTerminal.class ),
EXPANDED_PROCESSING_PATTERN_TERMINAL( 341, "expanded_processing_pattern_terminal", EnumSet.of( AEFeature.PATTERNS ), EnumSet.noneOf( IntegrationType.class ), PartExpandedProcessingPatternTerminal.class ),
CRAFTING_TERMINAL( 360, "crafting_terminal", EnumSet.of( AEFeature.CRAFTING_TERMINAL ), EnumSet.noneOf( IntegrationType.class ), PartCraftingTerminal.class ),
TERMINAL( 380, "terminal", EnumSet.of( AEFeature.TERMINAL ), EnumSet.noneOf( IntegrationType.class ), PartTerminal.class ),
STORAGE_MONITOR( 400, "storage_monitor", EnumSet.of( AEFeature.STORAGE_MONITOR ), EnumSet.noneOf( IntegrationType.class ), PartStorageMonitor.class ),
CONVERSION_MONITOR( 420, "conversion_monitor", EnumSet.of( AEFeature.PART_CONVERSION_MONITOR ), EnumSet.noneOf( IntegrationType.class ), PartConversionMonitor.class ),
INTERFACE( 440, "interface", EnumSet.of( AEFeature.INTERFACE ), EnumSet.noneOf( IntegrationType.class ), PartInterface.class ),
FLUID_INTERFACE( 441, "fluid_interface", EnumSet.of( AEFeature.FLUID_INTERFACE ), EnumSet.noneOf( IntegrationType.class ), PartFluidInterface.class ),
P2P_TUNNEL_ME( 460, "p2p_tunnel_me", EnumSet.of( AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_ME ), EnumSet.noneOf( IntegrationType.class ), PartP2PTunnelME.class, GuiText.METunnel )
{
@Override
String getUnlocalizedName()
{
return "p2p_tunnel";
}
},
P2P_TUNNEL_REDSTONE( 461, "p2p_tunnel_redstone", EnumSet.of( AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_REDSTONE ), EnumSet.noneOf( IntegrationType.class ), PartP2PRedstone.class, GuiText.RedstoneTunnel )
{
@Override
String getUnlocalizedName()
{
return "p2p_tunnel";
}
},
P2P_TUNNEL_ITEMS( 462, "p2p_tunnel_items", EnumSet.of( AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_ITEMS ), EnumSet.noneOf( IntegrationType.class ), PartP2PItems.class, GuiText.ItemTunnel )
{
@Override
String getUnlocalizedName()
{
return "p2p_tunnel";
}
},
P2P_TUNNEL_FLUIDS( 463, "p2p_tunnel_fluids", EnumSet.of( AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_FLUIDS ), EnumSet.noneOf( IntegrationType.class ), PartP2PFluids.class, GuiText.FluidTunnel )
{
@Override
String getUnlocalizedName()
{
return "p2p_tunnel";
}
},
P2P_TUNNEL_IC2( 465, "p2p_tunnel_ic2", EnumSet.of( AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_EU ), EnumSet.of( IntegrationType.IC2 ), PartP2PIC2Power.class, GuiText.EUTunnel )
{
@Override
String getUnlocalizedName()
{
return "p2p_tunnel";
}
},
P2P_TUNNEL_LIGHT( 467, "p2p_tunnel_light", EnumSet.of( AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_LIGHT ), EnumSet.noneOf( IntegrationType.class ), PartP2PLight.class, GuiText.LightTunnel )
{
@Override
String getUnlocalizedName()
{
return "p2p_tunnel";
}
},
P2P_TUNNEL_FE( 469, "p2p_tunnel_fe", EnumSet.of( AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_FE ), EnumSet.noneOf( IntegrationType.class ), PartP2PFEPower.class, GuiText.FETunnel )
{
@Override
String getUnlocalizedName()
{
return "p2p_tunnel";
}
},
P2P_TUNNEL_GTEU( 470, "p2p_tunnel_gteu", EnumSet.of( AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_GTEU ), EnumSet.of( IntegrationType.GTCE ), PartP2PGTCEPower.class, GuiText.GTEUTunnel )
{
@Override
String getUnlocalizedName()
{
return "p2p_tunnel";
}
},
// P2PTunnelOpenComputers( 468, EnumSet.of( AEFeature.P2PTunnel, AEFeature.P2PTunnelOpenComputers ), EnumSet.of(
// IntegrationType.OpenComputers ), PartP2POpenComputers.class, GuiText.OCTunnel ),
INTERFACE_TERMINAL( 480, "interface_terminal", EnumSet.of( AEFeature.INTERFACE_TERMINAL ), EnumSet.noneOf( IntegrationType.class ), PartInterfaceTerminal.class ),
FLUID_TERMINAL( 520, "fluid_terminal", EnumSet.of( AEFeature.FLUID_TERMINAL ), EnumSet.noneOf( IntegrationType.class ), PartFluidTerminal.class ),
INTERFACE_CONFIGURATION_TERMINAL( 521, "interface_configuration_terminal", EnumSet.of( AEFeature.INTERFACE_TERMINAL ), EnumSet.noneOf( IntegrationType.class ), PartInterfaceConfigurationTerminal.class );
private final int baseDamage;
private final Set<AEFeature> features;
private final Set<IntegrationType> integrations;
private final Class<? extends IPart> myPart;
private final GuiText extraName;
@SideOnly( Side.CLIENT )
private List<ModelResourceLocation> itemModels;
private final Set<ResourceLocation> models;
private final boolean enabled;
private Constructor<? extends IPart> constructor;
private final String oreName;
PartType( final int baseMetaValue, final String itemModel, final Set<AEFeature> features, final Set<IntegrationType> integrations, final Class<? extends IPart> c )
{
this( baseMetaValue, itemModel, features, integrations, c, null, null );
}
PartType( final int baseMetaValue, final String itemModel, final Set<AEFeature> features, final Set<IntegrationType> integrations, final Class<? extends IPart> c, final String oreDict )
{
this( baseMetaValue, itemModel, features, integrations, c, null, oreDict );
}
PartType( final int baseMetaValue, final String itemModel, final Set<AEFeature> features, final Set<IntegrationType> integrations, final Class<? extends IPart> c, final GuiText en )
{
this( baseMetaValue, itemModel, features, integrations, c, en, null );
}
PartType( final int baseMetaValue, final String itemModel, final Set<AEFeature> features, final Set<IntegrationType> integrations, final Class<? extends IPart> c, final GuiText en, final String oreDict )
{
this.baseDamage = baseMetaValue;
this.features = Collections.unmodifiableSet( features );
this.integrations = Collections.unmodifiableSet( integrations );
this.myPart = c;
this.extraName = en;
this.oreName = oreDict;
// The part is enabled if all features + integrations it needs are enabled
this.enabled = features.stream().allMatch( AEConfig.instance()::isFeatureEnabled ) && integrations.stream().allMatch( IntegrationRegistry.INSTANCE::isEnabled );
if( this.enabled )
{
// Only load models if the part is enabled, otherwise we also run into class-loading issues while
// scanning for annotations
if( Platform.isClientInstall() )
{
this.itemModels = this.createItemModels( itemModel );
}
if( c != null )
{
this.models = new HashSet<>( PartModelsHelper.createModels( c ) );
}
else
{
this.models = Collections.emptySet();
}
}
else
{
if( Platform.isClientInstall() )
{
this.itemModels = Collections.emptyList();
}
this.models = Collections.emptySet();
}
}
@SideOnly( Side.CLIENT )
protected List<ModelResourceLocation> createItemModels( String baseName )
{
return ImmutableList.of( modelFromBaseName( baseName ) );
}
@SideOnly( Side.CLIENT )
private static ModelResourceLocation modelFromBaseName( String baseName )
{
return new ModelResourceLocation( new ResourceLocation( AppEng.MOD_ID, "part/" + baseName ), "inventory" );
}
public boolean isEnabled()
{
return this.enabled;
}
int getBaseDamage()
{
return this.baseDamage;
}
public boolean isCable()
{
return false;
}
Set<AEFeature> getFeature()
{
return this.features;
}
Set<IntegrationType> getIntegrations()
{
return this.integrations;
}
Class<? extends IPart> getPart()
{
return this.myPart;
}
String getUnlocalizedName()
{
return this.name().toLowerCase();
}
GuiText getExtraName()
{
return this.extraName;
}
Constructor<? extends IPart> getConstructor()
{
return this.constructor;
}
void setConstructor( final Constructor<? extends IPart> constructor )
{
this.constructor = constructor;
}
public String getOreName()
{
return this.oreName;
}
@SideOnly( Side.CLIENT )
public List<ModelResourceLocation> getItemModels()
{
return this.itemModels;
}
public Set<ResourceLocation> getModels()
{
return this.models;
}
@Override
@SideOnly(Side.CLIENT)
protected List<ModelResourceLocation> createItemModels(String baseName) {
return Arrays.stream(AEColor.values()).map(color -> modelFromBaseName(baseName + "_" + color.name().toLowerCase())).collect(Collectors.toList());
}
},
CABLE_SMART(40, "cable_smart", EnumSet.of(AEFeature.SMART_CABLES), EnumSet.noneOf(IntegrationType.class), PartCableSmart.class) {
@Override
public boolean isCable() {
return true;
}
@Override
@SideOnly(Side.CLIENT)
protected List<ModelResourceLocation> createItemModels(String baseName) {
return Arrays.stream(AEColor.values()).map(color -> modelFromBaseName(baseName + "_" + color.name().toLowerCase())).collect(Collectors.toList());
}
},
CABLE_DENSE_SMART(60, "cable_dense_smart", EnumSet.of(AEFeature.DENSE_CABLES), EnumSet.noneOf(IntegrationType.class), PartDenseCableSmart.class) {
@Override
public boolean isCable() {
return true;
}
@Override
@SideOnly(Side.CLIENT)
protected List<ModelResourceLocation> createItemModels(String baseName) {
return Arrays.stream(AEColor.values()).map(color -> modelFromBaseName(baseName + "_" + color.name().toLowerCase())).collect(Collectors.toList());
}
},
CABLE_DENSE_COVERED(500, "cable_dense_covered", EnumSet.of(AEFeature.DENSE_CABLES), EnumSet.noneOf(IntegrationType.class), PartDenseCableCovered.class) {
@Override
public boolean isCable() {
return true;
}
@Override
@SideOnly(Side.CLIENT)
protected List<ModelResourceLocation> createItemModels(String baseName) {
return Arrays.stream(AEColor.values()).map(color -> modelFromBaseName(baseName + "_" + color.name().toLowerCase())).collect(Collectors.toList());
}
},
TOGGLE_BUS(80, "toggle_bus", EnumSet.of(AEFeature.TOGGLE_BUS), EnumSet.noneOf(IntegrationType.class), PartToggleBus.class),
INVERTED_TOGGLE_BUS(100, "inverted_toggle_bus", EnumSet.of(AEFeature.TOGGLE_BUS), EnumSet.noneOf(IntegrationType.class), PartInvertedToggleBus.class),
CABLE_ANCHOR(120, "cable_anchor", EnumSet.of(AEFeature.CABLE_ANCHOR), EnumSet.noneOf(IntegrationType.class), PartCableAnchor.class),
QUARTZ_FIBER(140, "quartz_fiber", EnumSet.of(AEFeature.QUARTZ_FIBER), EnumSet.noneOf(IntegrationType.class), PartQuartzFiber.class),
MONITOR(160, "monitor", EnumSet.of(AEFeature.PANELS), EnumSet.noneOf(IntegrationType.class), PartPanel.class, "itemIlluminatedPanel"),
SEMI_DARK_MONITOR(180, "semi_dark_monitor", EnumSet.of(AEFeature.PANELS), EnumSet.noneOf(IntegrationType.class), PartSemiDarkPanel.class, "itemIlluminatedPanel"),
DARK_MONITOR(200, "dark_monitor", EnumSet.of(AEFeature.PANELS), EnumSet.noneOf(IntegrationType.class), PartDarkPanel.class, "itemIlluminatedPanel"),
STORAGE_BUS(220, "storage_bus", EnumSet.of(AEFeature.STORAGE_BUS), EnumSet.noneOf(IntegrationType.class), PartStorageBus.class),
FLUID_STORAGE_BUS(221, "fluid_storage_bus", EnumSet.of(AEFeature.FLUID_STORAGE_BUS), EnumSet.noneOf(IntegrationType.class), PartFluidStorageBus.class),
OREDICT_STORAGE_BUS(222, "oredict_storage_bus", EnumSet.of(AEFeature.STORAGE_BUS), EnumSet.noneOf(IntegrationType.class), PartOreDicStorageBus.class),
IMPORT_BUS(240, "import_bus", EnumSet.of(AEFeature.IMPORT_BUS), EnumSet.noneOf(IntegrationType.class), PartImportBus.class),
FLUID_IMPORT_BUS(241, "fluid_import_bus", EnumSet.of(AEFeature.FLUID_IMPORT_BUS), EnumSet.noneOf(IntegrationType.class), PartFluidImportBus.class),
EXPORT_BUS(260, "export_bus", EnumSet.of(AEFeature.EXPORT_BUS), EnumSet.noneOf(IntegrationType.class), PartExportBus.class),
FLUID_EXPORT_BUS(261, "fluid_export_bus", EnumSet.of(AEFeature.FLUID_EXPORT_BUS), EnumSet.noneOf(IntegrationType.class), PartFluidExportBus.class),
LEVEL_EMITTER(280, "level_emitter", EnumSet.of(AEFeature.LEVEL_EMITTER), EnumSet.noneOf(IntegrationType.class), PartLevelEmitter.class),
FLUID_LEVEL_EMITTER(281, "fluid_level_emitter", EnumSet.of(AEFeature.FLUID_LEVEL_EMITTER), EnumSet.noneOf(IntegrationType.class), PartFluidLevelEmitter.class),
ANNIHILATION_PLANE(300, "annihilation_plane", EnumSet.of(AEFeature.ANNIHILATION_PLANE), EnumSet.noneOf(IntegrationType.class), PartAnnihilationPlane.class),
IDENTITY_ANNIHILATION_PLANE(301, "identity_annihilation_plane", EnumSet.of(AEFeature.ANNIHILATION_PLANE, AEFeature.IDENTITY_ANNIHILATION_PLANE), EnumSet.noneOf(IntegrationType.class), PartIdentityAnnihilationPlane.class),
FLUID_ANNIHILATION_PLANE(302, "fluid_annihilation_plane", EnumSet.of(AEFeature.FLUID_ANNIHILATION_PLANE), EnumSet.noneOf(IntegrationType.class), PartFluidAnnihilationPlane.class),
FORMATION_PLANE(320, "formation_plane", EnumSet.of(AEFeature.FORMATION_PLANE), EnumSet.noneOf(IntegrationType.class), PartFormationPlane.class),
FLUID_FORMATION_PLANE(321, "fluid_formation_plane", EnumSet.of(AEFeature.FLUID_FORMATION_PLANE), EnumSet.noneOf(IntegrationType.class), PartFluidFormationPlane.class),
PATTERN_TERMINAL(340, "pattern_terminal", EnumSet.of(AEFeature.PATTERNS), EnumSet.noneOf(IntegrationType.class), PartPatternTerminal.class),
EXPANDED_PROCESSING_PATTERN_TERMINAL(341, "expanded_processing_pattern_terminal", EnumSet.of(AEFeature.PATTERNS), EnumSet.noneOf(IntegrationType.class), PartExpandedProcessingPatternTerminal.class),
CRAFTING_TERMINAL(360, "crafting_terminal", EnumSet.of(AEFeature.CRAFTING_TERMINAL), EnumSet.noneOf(IntegrationType.class), PartCraftingTerminal.class),
TERMINAL(380, "terminal", EnumSet.of(AEFeature.TERMINAL), EnumSet.noneOf(IntegrationType.class), PartTerminal.class),
STORAGE_MONITOR(400, "storage_monitor", EnumSet.of(AEFeature.STORAGE_MONITOR), EnumSet.noneOf(IntegrationType.class), PartStorageMonitor.class),
CONVERSION_MONITOR(420, "conversion_monitor", EnumSet.of(AEFeature.PART_CONVERSION_MONITOR), EnumSet.noneOf(IntegrationType.class), PartConversionMonitor.class),
INTERFACE(440, "interface", EnumSet.of(AEFeature.INTERFACE), EnumSet.noneOf(IntegrationType.class), PartInterface.class),
FLUID_INTERFACE(441, "fluid_interface", EnumSet.of(AEFeature.FLUID_INTERFACE), EnumSet.noneOf(IntegrationType.class), PartFluidInterface.class),
P2P_TUNNEL_ME(460, "p2p_tunnel_me", EnumSet.of(AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_ME), EnumSet.noneOf(IntegrationType.class), PartP2PTunnelME.class, GuiText.METunnel) {
@Override
String getUnlocalizedName() {
return "p2p_tunnel";
}
},
P2P_TUNNEL_REDSTONE(461, "p2p_tunnel_redstone", EnumSet.of(AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_REDSTONE), EnumSet.noneOf(IntegrationType.class), PartP2PRedstone.class, GuiText.RedstoneTunnel) {
@Override
String getUnlocalizedName() {
return "p2p_tunnel";
}
},
P2P_TUNNEL_ITEMS(462, "p2p_tunnel_items", EnumSet.of(AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_ITEMS), EnumSet.noneOf(IntegrationType.class), PartP2PItems.class, GuiText.ItemTunnel) {
@Override
String getUnlocalizedName() {
return "p2p_tunnel";
}
},
P2P_TUNNEL_FLUIDS(463, "p2p_tunnel_fluids", EnumSet.of(AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_FLUIDS), EnumSet.noneOf(IntegrationType.class), PartP2PFluids.class, GuiText.FluidTunnel) {
@Override
String getUnlocalizedName() {
return "p2p_tunnel";
}
},
P2P_TUNNEL_IC2(465, "p2p_tunnel_ic2", EnumSet.of(AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_EU), EnumSet.of(IntegrationType.IC2), PartP2PIC2Power.class, GuiText.EUTunnel) {
@Override
String getUnlocalizedName() {
return "p2p_tunnel";
}
},
P2P_TUNNEL_LIGHT(467, "p2p_tunnel_light", EnumSet.of(AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_LIGHT), EnumSet.noneOf(IntegrationType.class), PartP2PLight.class, GuiText.LightTunnel) {
@Override
String getUnlocalizedName() {
return "p2p_tunnel";
}
},
P2P_TUNNEL_FE(469, "p2p_tunnel_fe", EnumSet.of(AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_FE), EnumSet.noneOf(IntegrationType.class), PartP2PFEPower.class, GuiText.FETunnel) {
@Override
String getUnlocalizedName() {
return "p2p_tunnel";
}
},
P2P_TUNNEL_GTEU(470, "p2p_tunnel_gteu", EnumSet.of(AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_GTEU), EnumSet.of(IntegrationType.GTCE), PartP2PGTCEPower.class, GuiText.GTEUTunnel) {
@Override
String getUnlocalizedName() {
return "p2p_tunnel";
}
},
// P2PTunnelOpenComputers( 468, EnumSet.of( AEFeature.P2PTunnel, AEFeature.P2PTunnelOpenComputers ), EnumSet.of(
// IntegrationType.OpenComputers ), PartP2POpenComputers.class, GuiText.OCTunnel ),
INTERFACE_TERMINAL(480, "interface_terminal", EnumSet.of(AEFeature.INTERFACE_TERMINAL), EnumSet.noneOf(IntegrationType.class), PartInterfaceTerminal.class),
FLUID_TERMINAL(520, "fluid_terminal", EnumSet.of(AEFeature.FLUID_TERMINAL), EnumSet.noneOf(IntegrationType.class), PartFluidTerminal.class),
INTERFACE_CONFIGURATION_TERMINAL(521, "interface_configuration_terminal", EnumSet.of(AEFeature.INTERFACE_TERMINAL), EnumSet.noneOf(IntegrationType.class), PartInterfaceConfigurationTerminal.class);
private final int baseDamage;
private final Set<AEFeature> features;
private final Set<IntegrationType> integrations;
private final Class<? extends IPart> myPart;
private final GuiText extraName;
@SideOnly(Side.CLIENT)
private List<ModelResourceLocation> itemModels;
private final Set<ResourceLocation> models;
private final boolean enabled;
private Constructor<? extends IPart> constructor;
private final String oreName;
PartType(final int baseMetaValue, final String itemModel, final Set<AEFeature> features, final Set<IntegrationType> integrations, final Class<? extends IPart> c) {
this(baseMetaValue, itemModel, features, integrations, c, null, null);
}
PartType(final int baseMetaValue, final String itemModel, final Set<AEFeature> features, final Set<IntegrationType> integrations, final Class<? extends IPart> c, final String oreDict) {
this(baseMetaValue, itemModel, features, integrations, c, null, oreDict);
}
PartType(final int baseMetaValue, final String itemModel, final Set<AEFeature> features, final Set<IntegrationType> integrations, final Class<? extends IPart> c, final GuiText en) {
this(baseMetaValue, itemModel, features, integrations, c, en, null);
}
PartType(final int baseMetaValue, final String itemModel, final Set<AEFeature> features, final Set<IntegrationType> integrations, final Class<? extends IPart> c, final GuiText en, final String oreDict) {
this.baseDamage = baseMetaValue;
this.features = Collections.unmodifiableSet(features);
this.integrations = Collections.unmodifiableSet(integrations);
this.myPart = c;
this.extraName = en;
this.oreName = oreDict;
// The part is enabled if all features + integrations it needs are enabled
this.enabled = features.stream().allMatch(AEConfig.instance()::isFeatureEnabled) && integrations.stream().allMatch(IntegrationRegistry.INSTANCE::isEnabled);
if (this.enabled) {
// Only load models if the part is enabled, otherwise we also run into class-loading issues while
// scanning for annotations
if (Platform.isClientInstall()) {
this.itemModels = this.createItemModels(itemModel);
}
if (c != null) {
this.models = new HashSet<>(PartModelsHelper.createModels(c));
} else {
this.models = Collections.emptySet();
}
} else {
if (Platform.isClientInstall()) {
this.itemModels = Collections.emptyList();
}
this.models = Collections.emptySet();
}
}
@SideOnly(Side.CLIENT)
protected List<ModelResourceLocation> createItemModels(String baseName) {
return ImmutableList.of(modelFromBaseName(baseName));
}
@SideOnly(Side.CLIENT)
private static ModelResourceLocation modelFromBaseName(String baseName) {
return new ModelResourceLocation(new ResourceLocation(AppEng.MOD_ID, "part/" + baseName), "inventory");
}
public boolean isEnabled() {
return this.enabled;
}
int getBaseDamage() {
return this.baseDamage;
}
public boolean isCable() {
return false;
}
Set<AEFeature> getFeature() {
return this.features;
}
Set<IntegrationType> getIntegrations() {
return this.integrations;
}
Class<? extends IPart> getPart() {
return this.myPart;
}
String getUnlocalizedName() {
return this.name().toLowerCase();
}
GuiText getExtraName() {
return this.extraName;
}
Constructor<? extends IPart> getConstructor() {
return this.constructor;
}
void setConstructor(final Constructor<? extends IPart> constructor) {
this.constructor = constructor;
}
public String getOreName() {
return this.oreName;
}
@SideOnly(Side.CLIENT)
public List<ModelResourceLocation> getItemModels() {
return this.itemModels;
}
public Set<ResourceLocation> getModels() {
return this.models;
}
}
@@ -19,23 +19,6 @@
package appeng.items.storage;
import java.util.List;
import java.util.Set;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.FuzzyMode;
import appeng.api.exceptions.MissingDefinitionException;
@@ -55,6 +38,22 @@ import appeng.items.contents.CellUpgrades;
import appeng.items.materials.MaterialType;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import java.util.List;
import java.util.Set;
/**
@@ -62,183 +61,153 @@ import appeng.util.Platform;
* @version rv6 - 2018-01-17
* @since rv6 2018-01-17
*/
public abstract class AbstractStorageCell<T extends IAEStack<T>> extends AEBaseItem implements IStorageCell<T>, IItemGroup
{
protected final MaterialType component;
protected final int totalBytes;
public abstract class AbstractStorageCell<T extends IAEStack<T>> extends AEBaseItem implements IStorageCell<T>, IItemGroup {
protected final MaterialType component;
protected final int totalBytes;
public AbstractStorageCell( final MaterialType whichCell, final int kilobytes )
{
this.setMaxStackSize( 1 );
this.totalBytes = kilobytes * 1024;
this.component = whichCell;
}
public AbstractStorageCell(final MaterialType whichCell, final int kilobytes) {
this.setMaxStackSize(1);
this.totalBytes = kilobytes * 1024;
this.component = whichCell;
}
@SideOnly( Side.CLIENT )
@Override
public void addCheckedInformation( final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips )
{
AEApi.instance()
.client()
.addCellInformation( AEApi.instance().registries().cell().getCellInventory( stack, null, this.getChannel() ), lines );
}
@SideOnly(Side.CLIENT)
@Override
public void addCheckedInformation(final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips) {
AEApi.instance()
.client()
.addCellInformation(AEApi.instance().registries().cell().getCellInventory(stack, null, this.getChannel()), lines);
}
@Override
public int getBytes( final ItemStack cellItem )
{
return this.totalBytes;
}
@Override
public int getBytes(final ItemStack cellItem) {
return this.totalBytes;
}
@Override
public int getTotalTypes( final ItemStack cellItem )
{
return 63;
}
@Override
public int getTotalTypes(final ItemStack cellItem) {
return 63;
}
@Override
public boolean isBlackListed( final ItemStack cellItem, final T requestedAddition )
{
return false;
}
@Override
public boolean isBlackListed(final ItemStack cellItem, final T requestedAddition) {
return false;
}
@Override
public boolean storableInStorageCell()
{
return false;
}
@Override
public boolean storableInStorageCell() {
return false;
}
@Override
public boolean isStorageCell( final ItemStack i )
{
return true;
}
@Override
public boolean isStorageCell(final ItemStack i) {
return true;
}
@Override
public String getUnlocalizedGroupName( final Set<ItemStack> others, final ItemStack is )
{
return GuiText.StorageCells.getUnlocalized();
}
@Override
public String getUnlocalizedGroupName(final Set<ItemStack> others, final ItemStack is) {
return GuiText.StorageCells.getUnlocalized();
}
@Override
public boolean isEditable( final ItemStack is )
{
return true;
}
@Override
public boolean isEditable(final ItemStack is) {
return true;
}
@Override
public IItemHandler getUpgradesInventory( final ItemStack is )
{
return new CellUpgrades( is, 2 );
}
@Override
public IItemHandler getUpgradesInventory(final ItemStack is) {
return new CellUpgrades(is, 2);
}
@Override
public IItemHandler getConfigInventory( final ItemStack is )
{
return new CellConfig( is );
}
@Override
public IItemHandler getConfigInventory(final ItemStack is) {
return new CellConfig(is);
}
@Override
public FuzzyMode getFuzzyMode( final ItemStack is )
{
final String fz = Platform.openNbtData( is ).getString( "FuzzyMode" );
try
{
return FuzzyMode.valueOf( fz );
}
catch( final Throwable t )
{
return FuzzyMode.IGNORE_ALL;
}
}
@Override
public FuzzyMode getFuzzyMode(final ItemStack is) {
final String fz = Platform.openNbtData(is).getString("FuzzyMode");
try {
return FuzzyMode.valueOf(fz);
} catch (final Throwable t) {
return FuzzyMode.IGNORE_ALL;
}
}
@Override
public void setFuzzyMode( final ItemStack is, final FuzzyMode fzMode )
{
Platform.openNbtData( is ).setString( "FuzzyMode", fzMode.name() );
}
@Override
public void setFuzzyMode(final ItemStack is, final FuzzyMode fzMode) {
Platform.openNbtData(is).setString("FuzzyMode", fzMode.name());
}
@Override
public ActionResult<ItemStack> onItemRightClick( final World world, final EntityPlayer player, final EnumHand hand )
{
this.disassembleDrive( player.getHeldItem( hand ), world, player );
return new ActionResult<>( EnumActionResult.SUCCESS, player.getHeldItem( hand ) );
}
@Override
public ActionResult<ItemStack> onItemRightClick(final World world, final EntityPlayer player, final EnumHand hand) {
this.disassembleDrive(player.getHeldItem(hand), world, player);
return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
}
private boolean disassembleDrive( final ItemStack stack, final World world, final EntityPlayer player )
{
if( player.isSneaking() )
{
if( Platform.isClient() )
{
return false;
}
private boolean disassembleDrive(final ItemStack stack, final World world, final EntityPlayer player) {
if (player.isSneaking()) {
if (Platform.isClient()) {
return false;
}
final InventoryPlayer playerInventory = player.inventory;
final IMEInventoryHandler inv = AEApi.instance().registries().cell().getCellInventory( stack, null, this.getChannel() );
if( inv != null && playerInventory.getCurrentItem() == stack )
{
final InventoryAdaptor ia = InventoryAdaptor.getAdaptor( player );
final IItemList<IAEItemStack> list = inv.getAvailableItems( this.getChannel().createList() );
if( list.isEmpty() && ia != null )
{
playerInventory.setInventorySlotContents( playerInventory.currentItem, ItemStack.EMPTY );
final InventoryPlayer playerInventory = player.inventory;
final IMEInventoryHandler inv = AEApi.instance().registries().cell().getCellInventory(stack, null, this.getChannel());
if (inv != null && playerInventory.getCurrentItem() == stack) {
final InventoryAdaptor ia = InventoryAdaptor.getAdaptor(player);
final IItemList<IAEItemStack> list = inv.getAvailableItems(this.getChannel().createList());
if (list.isEmpty() && ia != null) {
playerInventory.setInventorySlotContents(playerInventory.currentItem, ItemStack.EMPTY);
// drop core
final ItemStack extraB = ia.addItems( this.component.stack( 1 ) );
if( !extraB.isEmpty() )
{
player.dropItem( extraB, false );
}
// drop core
final ItemStack extraB = ia.addItems(this.component.stack(1));
if (!extraB.isEmpty()) {
player.dropItem(extraB, false);
}
// drop upgrades
final IItemHandler upgradesInventory = this.getUpgradesInventory( stack );
for( int upgradeIndex = 0; upgradeIndex < upgradesInventory.getSlots(); upgradeIndex++ )
{
final ItemStack upgradeStack = upgradesInventory.getStackInSlot( upgradeIndex );
final ItemStack leftStack = ia.addItems( upgradeStack );
if( !leftStack.isEmpty() && upgradeStack.getItem() instanceof IUpgradeModule )
{
player.dropItem( upgradeStack, false );
}
}
// drop upgrades
final IItemHandler upgradesInventory = this.getUpgradesInventory(stack);
for (int upgradeIndex = 0; upgradeIndex < upgradesInventory.getSlots(); upgradeIndex++) {
final ItemStack upgradeStack = upgradesInventory.getStackInSlot(upgradeIndex);
final ItemStack leftStack = ia.addItems(upgradeStack);
if (!leftStack.isEmpty() && upgradeStack.getItem() instanceof IUpgradeModule) {
player.dropItem(upgradeStack, false);
}
}
// drop empty storage cell case
this.dropEmptyStorageCellCase( ia, player );
// drop empty storage cell case
this.dropEmptyStorageCellCase(ia, player);
if( player.inventoryContainer != null )
{
player.inventoryContainer.detectAndSendChanges();
}
if (player.inventoryContainer != null) {
player.inventoryContainer.detectAndSendChanges();
}
return true;
}
}
}
return false;
}
return true;
}
}
}
return false;
}
protected abstract void dropEmptyStorageCellCase( final InventoryAdaptor ia, final EntityPlayer player );
protected abstract void dropEmptyStorageCellCase(final InventoryAdaptor ia, final EntityPlayer player);
@Override
public EnumActionResult onItemUseFirst( final EntityPlayer player, final World world, final BlockPos pos, final EnumFacing side, final float hitX, final float hitY, final float hitZ, final EnumHand hand )
{
return this.disassembleDrive( player.getHeldItem( hand ), world, player ) ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
}
@Override
public EnumActionResult onItemUseFirst(final EntityPlayer player, final World world, final BlockPos pos, final EnumFacing side, final float hitX, final float hitY, final float hitZ, final EnumHand hand) {
return this.disassembleDrive(player.getHeldItem(hand), world, player) ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
}
@Override
public ItemStack getContainerItem( final ItemStack itemStack )
{
return AEApi.instance()
.definitions()
.materials()
.emptyStorageCell()
.maybeStack( 1 )
.orElseThrow( () -> new MissingDefinitionException( "Tried to use empty storage cells while basic storage cells are defined." ) );
}
@Override
public ItemStack getContainerItem(final ItemStack itemStack) {
return AEApi.instance()
.definitions()
.materials()
.emptyStorageCell()
.maybeStack(1)
.orElseThrow(() -> new MissingDefinitionException("Tried to use empty storage cells while basic storage cells are defined."));
}
@Override
public boolean hasContainerItem( final ItemStack stack )
{
return AEConfig.instance().isFeatureEnabled( AEFeature.ENABLE_DISASSEMBLY_CRAFTING );
}
@Override
public boolean hasContainerItem(final ItemStack stack) {
return AEConfig.instance().isFeatureEnabled(AEFeature.ENABLE_DISASSEMBLY_CRAFTING);
}
}
@@ -19,79 +19,70 @@
package appeng.items.storage;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import appeng.api.AEApi;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.items.materials.MaterialType;
import appeng.util.InventoryAdaptor;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
public final class BasicItemStorageCell extends AbstractStorageCell<IAEItemStack>
{
public final class BasicItemStorageCell extends AbstractStorageCell<IAEItemStack> {
protected final int perType;
protected final double idleDrain;
protected final int perType;
protected final double idleDrain;
public BasicItemStorageCell( final MaterialType whichCell, final int kilobytes )
{
super( whichCell, kilobytes );
switch( whichCell )
{
case CELL1K_PART:
this.idleDrain = 0.5;
this.perType = 8;
break;
case CELL4K_PART:
this.idleDrain = 1.0;
this.perType = 32;
break;
case CELL16K_PART:
this.idleDrain = 1.5;
this.perType = 128;
break;
case CELL64K_PART:
this.idleDrain = 2.0;
this.perType = 512;
break;
default:
this.idleDrain = 0.0;
this.perType = 8;
}
public BasicItemStorageCell(final MaterialType whichCell, final int kilobytes) {
super(whichCell, kilobytes);
switch (whichCell) {
case CELL1K_PART:
this.idleDrain = 0.5;
this.perType = 8;
break;
case CELL4K_PART:
this.idleDrain = 1.0;
this.perType = 32;
break;
case CELL16K_PART:
this.idleDrain = 1.5;
this.perType = 128;
break;
case CELL64K_PART:
this.idleDrain = 2.0;
this.perType = 512;
break;
default:
this.idleDrain = 0.0;
this.perType = 8;
}
}
}
@Override
public int getBytesPerType( ItemStack cellItem )
{
return this.perType;
}
@Override
public int getBytesPerType(ItemStack cellItem) {
return this.perType;
}
@Override
public double getIdleDrain()
{
return this.idleDrain;
}
@Override
public double getIdleDrain() {
return this.idleDrain;
}
@Override
public IStorageChannel<IAEItemStack> getChannel()
{
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
}
@Override
public IStorageChannel<IAEItemStack> getChannel() {
return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class);
}
@Override
protected void dropEmptyStorageCellCase( final InventoryAdaptor ia, final EntityPlayer player )
{
AEApi.instance().definitions().materials().emptyStorageCell().maybeStack( 1 ).ifPresent( is ->
{
final ItemStack extraA = ia.addItems( is );
if( !extraA.isEmpty() )
{
player.dropItem( extraA, false );
}
} );
}
@Override
protected void dropEmptyStorageCellCase(final InventoryAdaptor ia, final EntityPlayer player) {
AEApi.instance().definitions().materials().emptyStorageCell().maybeStack(1).ifPresent(is ->
{
final ItemStack extraA = ia.addItems(is);
if (!extraA.isEmpty()) {
player.dropItem(extraA, false);
}
});
}
}
@@ -19,15 +19,6 @@
package appeng.items.storage;
import java.util.List;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.ICellInventoryHandler;
@@ -36,67 +27,64 @@ import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.items.AEBaseItem;
import appeng.items.contents.CellConfig;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import java.util.List;
public class ItemCreativeStorageCell extends AEBaseItem implements ICellWorkbenchItem
{
public class ItemCreativeStorageCell extends AEBaseItem implements ICellWorkbenchItem {
public ItemCreativeStorageCell()
{
this.setMaxStackSize( 1 );
}
public ItemCreativeStorageCell() {
this.setMaxStackSize(1);
}
@Override
public boolean isEditable( final ItemStack is )
{
return true;
}
@Override
public boolean isEditable(final ItemStack is) {
return true;
}
@Override
public IItemHandler getUpgradesInventory( final ItemStack is )
{
return null;
}
@Override
public IItemHandler getUpgradesInventory(final ItemStack is) {
return null;
}
@Override
public IItemHandler getConfigInventory( final ItemStack is )
{
return new CellConfig( is );
}
@Override
public IItemHandler getConfigInventory(final ItemStack is) {
return new CellConfig(is);
}
@Override
public FuzzyMode getFuzzyMode( final ItemStack is )
{
return FuzzyMode.IGNORE_ALL;
}
@Override
public FuzzyMode getFuzzyMode(final ItemStack is) {
return FuzzyMode.IGNORE_ALL;
}
@Override
public void setFuzzyMode( final ItemStack is, final FuzzyMode fzMode )
{
@Override
public void setFuzzyMode(final ItemStack is, final FuzzyMode fzMode) {
}
}
@SideOnly( Side.CLIENT )
@Override
public void addCheckedInformation( final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips )
{
final IMEInventoryHandler<?> inventory = AEApi.instance()
.registries()
.cell()
.getCellInventory( stack, null,
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
@SideOnly(Side.CLIENT)
@Override
public void addCheckedInformation(final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips) {
final IMEInventoryHandler<?> inventory = AEApi.instance()
.registries()
.cell()
.getCellInventory(stack, null,
AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
if( inventory instanceof ICellInventoryHandler )
{
final CellConfig cc = new CellConfig( stack );
if (inventory instanceof ICellInventoryHandler) {
final CellConfig cc = new CellConfig(stack);
for( final ItemStack is : cc )
{
if( !is.isEmpty() )
{
lines.add( is.getDisplayName() );
}
}
}
}
for (final ItemStack is : cc) {
if (!is.isEmpty()) {
lines.add(is.getDisplayName());
}
}
}
}
}
@@ -19,17 +19,6 @@
package appeng.items.storage;
import java.util.List;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.implementations.TransitionResult;
import appeng.api.implementations.items.ISpatialStorageCell;
import appeng.api.storage.ISpatialDimension;
@@ -40,151 +29,137 @@ import appeng.core.localization.GuiText;
import appeng.items.AEBaseItem;
import appeng.spatial.StorageHelper;
import appeng.util.Platform;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.List;
public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorageCell
{
private static final String NBT_CELL_ID_KEY = "StorageCellID";
private static final String NBT_SIZE_X_KEY = "sizeX";
private static final String NBT_SIZE_Y_KEY = "sizeY";
private static final String NBT_SIZE_Z_KEY = "sizeZ";
public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorageCell {
private static final String NBT_CELL_ID_KEY = "StorageCellID";
private static final String NBT_SIZE_X_KEY = "sizeX";
private static final String NBT_SIZE_Y_KEY = "sizeY";
private static final String NBT_SIZE_Z_KEY = "sizeZ";
private final int maxRegion;
private final int maxRegion;
public ItemSpatialStorageCell( final int spatialScale )
{
this.setMaxStackSize( 1 );
this.maxRegion = spatialScale;
}
public ItemSpatialStorageCell(final int spatialScale) {
this.setMaxStackSize(1);
this.maxRegion = spatialScale;
}
@SideOnly( Side.CLIENT )
@Override
public void addCheckedInformation( final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips )
{
final int id = this.getStoredDimensionID( stack );
if( id >= 0 )
{
lines.add( GuiText.CellId.getLocal() + ": " + id );
}
@SideOnly(Side.CLIENT)
@Override
public void addCheckedInformation(final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips) {
final int id = this.getStoredDimensionID(stack);
if (id >= 0) {
lines.add(GuiText.CellId.getLocal() + ": " + id);
}
final WorldCoord wc = this.getStoredSize( stack );
if( wc.x > 0 )
{
lines.add( GuiText.StoredSize.getLocal() + ": " + wc.x + " x " + wc.y + " x " + wc.z );
}
}
final WorldCoord wc = this.getStoredSize(stack);
if (wc.x > 0) {
lines.add(GuiText.StoredSize.getLocal() + ": " + wc.x + " x " + wc.y + " x " + wc.z);
}
}
@Override
public boolean isSpatialStorage( final ItemStack is )
{
return true;
}
@Override
public boolean isSpatialStorage(final ItemStack is) {
return true;
}
@Override
public int getMaxStoredDim( final ItemStack is )
{
return this.maxRegion;
}
@Override
public int getMaxStoredDim(final ItemStack is) {
return this.maxRegion;
}
@Override
public ISpatialDimension getSpatialDimension()
{
final int id = AppEng.instance().getStorageDimensionID();
World w = DimensionManager.getWorld( id );
if( w == null )
{
DimensionManager.initDimension( id );
w = DimensionManager.getWorld( id );
}
@Override
public ISpatialDimension getSpatialDimension() {
final int id = AppEng.instance().getStorageDimensionID();
World w = DimensionManager.getWorld(id);
if (w == null) {
DimensionManager.initDimension(id);
w = DimensionManager.getWorld(id);
}
if( w != null && w.hasCapability( Capabilities.SPATIAL_DIMENSION, null ) )
{
return w.getCapability( Capabilities.SPATIAL_DIMENSION, null );
}
return null;
}
if (w != null && w.hasCapability(Capabilities.SPATIAL_DIMENSION, null)) {
return w.getCapability(Capabilities.SPATIAL_DIMENSION, null);
}
return null;
}
@Override
public WorldCoord getStoredSize( final ItemStack is )
{
if( is.hasTagCompound() )
{
final NBTTagCompound c = is.getTagCompound();
return new WorldCoord( c.getInteger( NBT_SIZE_X_KEY ), c.getInteger( NBT_SIZE_Y_KEY ), c.getInteger( NBT_SIZE_Z_KEY ) );
}
return new WorldCoord( 0, 0, 0 );
}
@Override
public WorldCoord getStoredSize(final ItemStack is) {
if (is.hasTagCompound()) {
final NBTTagCompound c = is.getTagCompound();
return new WorldCoord(c.getInteger(NBT_SIZE_X_KEY), c.getInteger(NBT_SIZE_Y_KEY), c.getInteger(NBT_SIZE_Z_KEY));
}
return new WorldCoord(0, 0, 0);
}
@Override
public int getStoredDimensionID( final ItemStack is )
{
if( is.hasTagCompound() )
{
final NBTTagCompound c = is.getTagCompound();
return c.getInteger( NBT_CELL_ID_KEY );
}
return -1;
}
@Override
public int getStoredDimensionID(final ItemStack is) {
if (is.hasTagCompound()) {
final NBTTagCompound c = is.getTagCompound();
return c.getInteger(NBT_CELL_ID_KEY);
}
return -1;
}
@Override
public TransitionResult doSpatialTransition( final ItemStack is, final World w, final WorldCoord min, final WorldCoord max, int playerId )
{
final int targetX = max.x - min.x - 1;
final int targetY = max.y - min.y - 1;
final int targetZ = max.z - min.z - 1;
final int maxSize = this.getMaxStoredDim( is );
@Override
public TransitionResult doSpatialTransition(final ItemStack is, final World w, final WorldCoord min, final WorldCoord max, int playerId) {
final int targetX = max.x - min.x - 1;
final int targetY = max.y - min.y - 1;
final int targetZ = max.z - min.z - 1;
final int maxSize = this.getMaxStoredDim(is);
final BlockPos targetSize = new BlockPos( targetX, targetY, targetZ );
final BlockPos targetSize = new BlockPos(targetX, targetY, targetZ);
ISpatialDimension manager = this.getSpatialDimension();
ISpatialDimension manager = this.getSpatialDimension();
int cellid = this.getStoredDimensionID( is );
if( cellid < 0 )
{
cellid = manager.createNewCellDimension( targetSize, playerId );
}
int cellid = this.getStoredDimensionID(is);
if (cellid < 0) {
cellid = manager.createNewCellDimension(targetSize, playerId);
}
try
{
if( manager.isCellDimension( cellid ) )
{
BlockPos scale = manager.getCellContentSize( cellid );
try {
if (manager.isCellDimension(cellid)) {
BlockPos scale = manager.getCellContentSize(cellid);
if( scale.equals( targetSize ) )
{
if( targetX <= maxSize && targetY <= maxSize && targetZ <= maxSize )
{
BlockPos offset = manager.getCellDimensionOrigin( cellid );
if (scale.equals(targetSize)) {
if (targetX <= maxSize && targetY <= maxSize && targetZ <= maxSize) {
BlockPos offset = manager.getCellDimensionOrigin(cellid);
this.setStorageCell( is, cellid, targetSize );
StorageHelper.getInstance()
.swapRegions( w, min.x + 1, min.y + 1, min.z + 1, manager.getWorld(), offset.getX(), offset.getY(),
offset.getZ(), targetX - 1, targetY - 1,
targetZ - 1 );
this.setStorageCell(is, cellid, targetSize);
StorageHelper.getInstance()
.swapRegions(w, min.x + 1, min.y + 1, min.z + 1, manager.getWorld(), offset.getX(), offset.getY(),
offset.getZ(), targetX - 1, targetY - 1,
targetZ - 1);
return new TransitionResult( true, 0 );
}
}
}
return new TransitionResult( false, 0 );
}
finally
{
// clean up newly created dimensions that failed transfer
if( manager.isCellDimension( cellid ) && this.getStoredDimensionID( is ) < 0 )
{
manager.deleteCellDimension( cellid );
}
}
}
return new TransitionResult(true, 0);
}
}
}
return new TransitionResult(false, 0);
} finally {
// clean up newly created dimensions that failed transfer
if (manager.isCellDimension(cellid) && this.getStoredDimensionID(is) < 0) {
manager.deleteCellDimension(cellid);
}
}
}
private void setStorageCell( final ItemStack is, int id, BlockPos size )
{
final NBTTagCompound c = Platform.openNbtData( is );
private void setStorageCell(final ItemStack is, int id, BlockPos size) {
final NBTTagCompound c = Platform.openNbtData(is);
c.setInteger( NBT_CELL_ID_KEY, id );
c.setInteger( NBT_SIZE_X_KEY, size.getX() );
c.setInteger( NBT_SIZE_Y_KEY, size.getY() );
c.setInteger( NBT_SIZE_Z_KEY, size.getZ() );
}
c.setInteger(NBT_CELL_ID_KEY, id);
c.setInteger(NBT_SIZE_X_KEY, size.getX());
c.setInteger(NBT_SIZE_Y_KEY, size.getY());
c.setInteger(NBT_SIZE_Z_KEY, size.getZ());
}
}
@@ -19,9 +19,6 @@
package appeng.items.storage;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.FuzzyMode;
import appeng.api.config.Upgrades;
@@ -39,125 +36,103 @@ import appeng.util.prioritylist.FuzzyPriorityList;
import appeng.util.prioritylist.IPartitionList;
import appeng.util.prioritylist.MergedPriorityList;
import appeng.util.prioritylist.PrecisePriorityList;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
public class ItemViewCell extends AEBaseItem implements ICellWorkbenchItem
{
public ItemViewCell()
{
this.setMaxStackSize( 1 );
}
public class ItemViewCell extends AEBaseItem implements ICellWorkbenchItem {
public ItemViewCell() {
this.setMaxStackSize(1);
}
public static IPartitionList<IAEItemStack> createFilter( final ItemStack[] list )
{
IPartitionList<IAEItemStack> myPartitionList = null;
public static IPartitionList<IAEItemStack> createFilter(final ItemStack[] list) {
IPartitionList<IAEItemStack> myPartitionList = null;
final MergedPriorityList<IAEItemStack> myMergedList = new MergedPriorityList<>();
final MergedPriorityList<IAEItemStack> myMergedList = new MergedPriorityList<>();
for( final ItemStack currentViewCell : list )
{
if( currentViewCell == null )
{
continue;
}
for (final ItemStack currentViewCell : list) {
if (currentViewCell == null) {
continue;
}
if( ( currentViewCell.getItem() instanceof ItemViewCell ) )
{
final IItemList<IAEItemStack> priorityList = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
if ((currentViewCell.getItem() instanceof ItemViewCell)) {
final IItemList<IAEItemStack> priorityList = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
final ICellWorkbenchItem vc = (ICellWorkbenchItem) currentViewCell.getItem();
final IItemHandler upgrades = vc.getUpgradesInventory( currentViewCell );
final IItemHandler config = vc.getConfigInventory( currentViewCell );
final FuzzyMode fzMode = vc.getFuzzyMode( currentViewCell );
final ICellWorkbenchItem vc = (ICellWorkbenchItem) currentViewCell.getItem();
final IItemHandler upgrades = vc.getUpgradesInventory(currentViewCell);
final IItemHandler config = vc.getConfigInventory(currentViewCell);
final FuzzyMode fzMode = vc.getFuzzyMode(currentViewCell);
boolean hasInverter = false;
boolean hasFuzzy = false;
boolean hasInverter = false;
boolean hasFuzzy = false;
for( int x = 0; x < upgrades.getSlots(); x++ )
{
final ItemStack is = upgrades.getStackInSlot( x );
if( !is.isEmpty() && is.getItem() instanceof IUpgradeModule )
{
final 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 < upgrades.getSlots(); x++) {
final ItemStack is = upgrades.getStackInSlot(x);
if (!is.isEmpty() && is.getItem() instanceof IUpgradeModule) {
final 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.getSlots(); x++ )
{
final ItemStack is = config.getStackInSlot( x );
if( !is.isEmpty() )
{
priorityList.add( AEItemStack.fromItemStack( is ) );
}
}
for (int x = 0; x < config.getSlots(); x++) {
final ItemStack is = config.getStackInSlot(x);
if (!is.isEmpty()) {
priorityList.add(AEItemStack.fromItemStack(is));
}
}
if( !priorityList.isEmpty() )
{
if( hasFuzzy )
{
myMergedList.addNewList( new FuzzyPriorityList<>( priorityList, fzMode ), !hasInverter );
}
else
{
myMergedList.addNewList( new PrecisePriorityList<>( priorityList ), !hasInverter );
}
if (!priorityList.isEmpty()) {
if (hasFuzzy) {
myMergedList.addNewList(new FuzzyPriorityList<>(priorityList, fzMode), !hasInverter);
} else {
myMergedList.addNewList(new PrecisePriorityList<>(priorityList), !hasInverter);
}
myPartitionList = myMergedList;
}
}
}
myPartitionList = myMergedList;
}
}
}
return myPartitionList;
}
return myPartitionList;
}
@Override
public boolean isEditable( final ItemStack is )
{
return true;
}
@Override
public boolean isEditable(final ItemStack is) {
return true;
}
@Override
public IItemHandler getUpgradesInventory( final ItemStack is )
{
return new CellUpgrades( is, 2 );
}
@Override
public IItemHandler getUpgradesInventory(final ItemStack is) {
return new CellUpgrades(is, 2);
}
@Override
public IItemHandler getConfigInventory( final ItemStack is )
{
return new CellConfig( is );
}
@Override
public IItemHandler getConfigInventory(final ItemStack is) {
return new CellConfig(is);
}
@Override
public FuzzyMode getFuzzyMode( final ItemStack is )
{
final String fz = Platform.openNbtData( is ).getString( "FuzzyMode" );
try
{
return FuzzyMode.valueOf( fz );
}
catch( final Throwable t )
{
return FuzzyMode.IGNORE_ALL;
}
}
@Override
public FuzzyMode getFuzzyMode(final ItemStack is) {
final String fz = Platform.openNbtData(is).getString("FuzzyMode");
try {
return FuzzyMode.valueOf(fz);
} catch (final Throwable t) {
return FuzzyMode.IGNORE_ALL;
}
}
@Override
public void setFuzzyMode( final ItemStack is, final FuzzyMode fzMode )
{
Platform.openNbtData( is ).setString( "FuzzyMode", fzMode.name() );
}
@Override
public void setFuzzyMode(final ItemStack is, final FuzzyMode fzMode) {
Platform.openNbtData(is).setString("FuzzyMode", fzMode.name());
}
}
@@ -19,11 +19,14 @@
package appeng.items.tools;
import java.util.EnumSet;
import java.util.List;
import appeng.api.config.SecurityPermissions;
import appeng.api.features.IPlayerRegistry;
import appeng.api.implementations.items.IBiometricCard;
import appeng.api.networking.security.ISecurityRegistry;
import appeng.core.localization.GuiText;
import appeng.items.AEBaseItem;
import appeng.util.Platform;
import com.mojang.authlib.GameProfile;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
@@ -37,172 +40,133 @@ import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.config.SecurityPermissions;
import appeng.api.features.IPlayerRegistry;
import appeng.api.implementations.items.IBiometricCard;
import appeng.api.networking.security.ISecurityRegistry;
import appeng.core.localization.GuiText;
import appeng.items.AEBaseItem;
import appeng.util.Platform;
import java.util.EnumSet;
import java.util.List;
public class ToolBiometricCard extends AEBaseItem implements IBiometricCard
{
public ToolBiometricCard()
{
this.setMaxStackSize( 1 );
}
public class ToolBiometricCard extends AEBaseItem implements IBiometricCard {
public ToolBiometricCard() {
this.setMaxStackSize(1);
}
@Override
public ActionResult<ItemStack> onItemRightClick( final World w, final EntityPlayer p, final EnumHand hand )
{
if( p.isSneaking() )
{
this.encode( p.getHeldItem( hand ), p );
p.swingArm( hand );
return new ActionResult<>( EnumActionResult.SUCCESS, p.getHeldItem( hand ) );
}
@Override
public ActionResult<ItemStack> onItemRightClick(final World w, final EntityPlayer p, final EnumHand hand) {
if (p.isSneaking()) {
this.encode(p.getHeldItem(hand), p);
p.swingArm(hand);
return new ActionResult<>(EnumActionResult.SUCCESS, p.getHeldItem(hand));
}
return new ActionResult<>( EnumActionResult.PASS, p.getHeldItem( hand ) );
}
return new ActionResult<>(EnumActionResult.PASS, p.getHeldItem(hand));
}
@Override
public boolean itemInteractionForEntity( ItemStack is, final EntityPlayer player, final EntityLivingBase target, final EnumHand hand )
{
if( target instanceof EntityPlayer && !player.isSneaking() )
{
if( player.capabilities.isCreativeMode )
{
is = player.getHeldItem( hand );
}
this.encode( is, (EntityPlayer) target );
player.swingArm( hand );
return true;
}
return false;
}
@Override
public boolean itemInteractionForEntity(ItemStack is, final EntityPlayer player, final EntityLivingBase target, final EnumHand hand) {
if (target instanceof EntityPlayer && !player.isSneaking()) {
if (player.capabilities.isCreativeMode) {
is = player.getHeldItem(hand);
}
this.encode(is, (EntityPlayer) target);
player.swingArm(hand);
return true;
}
return false;
}
@Override
public String getItemStackDisplayName( final ItemStack is )
{
final GameProfile username = this.getProfile( is );
return username != null ? super.getItemStackDisplayName( is ) + " - " + username.getName() : super.getItemStackDisplayName( is );
}
@Override
public String getItemStackDisplayName(final ItemStack is) {
final GameProfile username = this.getProfile(is);
return username != null ? super.getItemStackDisplayName(is) + " - " + username.getName() : super.getItemStackDisplayName(is);
}
private void encode( final ItemStack is, final EntityPlayer p )
{
final GameProfile username = this.getProfile( is );
private void encode(final ItemStack is, final EntityPlayer p) {
final GameProfile username = this.getProfile(is);
if( username != null && username.equals( p.getGameProfile() ) )
{
this.setProfile( is, null );
}
else
{
this.setProfile( is, p.getGameProfile() );
}
}
if (username != null && username.equals(p.getGameProfile())) {
this.setProfile(is, null);
} else {
this.setProfile(is, p.getGameProfile());
}
}
@Override
public void setProfile( final ItemStack itemStack, final GameProfile profile )
{
final NBTTagCompound tag = Platform.openNbtData( itemStack );
@Override
public void setProfile(final ItemStack itemStack, final GameProfile profile) {
final NBTTagCompound tag = Platform.openNbtData(itemStack);
if( profile != null )
{
final NBTTagCompound pNBT = new NBTTagCompound();
NBTUtil.writeGameProfile( pNBT, profile );
tag.setTag( "profile", pNBT );
}
else
{
tag.removeTag( "profile" );
}
}
if (profile != null) {
final NBTTagCompound pNBT = new NBTTagCompound();
NBTUtil.writeGameProfile(pNBT, profile);
tag.setTag("profile", pNBT);
} else {
tag.removeTag("profile");
}
}
@Override
public GameProfile getProfile( final ItemStack is )
{
final NBTTagCompound tag = Platform.openNbtData( is );
if( tag.hasKey( "profile" ) )
{
return NBTUtil.readGameProfileFromNBT( tag.getCompoundTag( "profile" ) );
}
return null;
}
@Override
public GameProfile getProfile(final ItemStack is) {
final NBTTagCompound tag = Platform.openNbtData(is);
if (tag.hasKey("profile")) {
return NBTUtil.readGameProfileFromNBT(tag.getCompoundTag("profile"));
}
return null;
}
@Override
public EnumSet<SecurityPermissions> getPermissions( final ItemStack is )
{
final NBTTagCompound tag = Platform.openNbtData( is );
final EnumSet<SecurityPermissions> result = EnumSet.noneOf( SecurityPermissions.class );
@Override
public EnumSet<SecurityPermissions> getPermissions(final ItemStack is) {
final NBTTagCompound tag = Platform.openNbtData(is);
final EnumSet<SecurityPermissions> result = EnumSet.noneOf(SecurityPermissions.class);
for( final SecurityPermissions sp : SecurityPermissions.values() )
{
if( tag.getBoolean( sp.name() ) )
{
result.add( sp );
}
}
for (final SecurityPermissions sp : SecurityPermissions.values()) {
if (tag.getBoolean(sp.name())) {
result.add(sp);
}
}
return result;
}
return result;
}
@Override
public boolean hasPermission( final ItemStack is, final SecurityPermissions permission )
{
final NBTTagCompound tag = Platform.openNbtData( is );
return tag.getBoolean( permission.name() );
}
@Override
public boolean hasPermission(final ItemStack is, final SecurityPermissions permission) {
final NBTTagCompound tag = Platform.openNbtData(is);
return tag.getBoolean(permission.name());
}
@Override
public void removePermission( final ItemStack itemStack, final SecurityPermissions permission )
{
final NBTTagCompound tag = Platform.openNbtData( itemStack );
if( tag.hasKey( permission.name() ) )
{
tag.removeTag( permission.name() );
}
}
@Override
public void removePermission(final ItemStack itemStack, final SecurityPermissions permission) {
final NBTTagCompound tag = Platform.openNbtData(itemStack);
if (tag.hasKey(permission.name())) {
tag.removeTag(permission.name());
}
}
@Override
public void addPermission( final ItemStack itemStack, final SecurityPermissions permission )
{
final NBTTagCompound tag = Platform.openNbtData( itemStack );
tag.setBoolean( permission.name(), true );
}
@Override
public void addPermission(final ItemStack itemStack, final SecurityPermissions permission) {
final NBTTagCompound tag = Platform.openNbtData(itemStack);
tag.setBoolean(permission.name(), true);
}
@Override
public void registerPermissions( final ISecurityRegistry register, final IPlayerRegistry pr, final ItemStack is )
{
register.addPlayer( pr.getID( this.getProfile( is ) ), this.getPermissions( is ) );
}
@Override
public void registerPermissions(final ISecurityRegistry register, final IPlayerRegistry pr, final ItemStack is) {
register.addPlayer(pr.getID(this.getProfile(is)), this.getPermissions(is));
}
@Override
@SideOnly( Side.CLIENT )
public void addCheckedInformation( final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips )
{
final EnumSet<SecurityPermissions> perms = this.getPermissions( stack );
if( perms.isEmpty() )
{
lines.add( GuiText.NoPermissions.getLocal() );
}
else
{
String msg = null;
@Override
@SideOnly(Side.CLIENT)
public void addCheckedInformation(final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips) {
final EnumSet<SecurityPermissions> perms = this.getPermissions(stack);
if (perms.isEmpty()) {
lines.add(GuiText.NoPermissions.getLocal());
} else {
String msg = null;
for( final SecurityPermissions sp : perms )
{
if( msg == null )
{
msg = Platform.gui_localize( sp.getUnlocalizedName() );
}
else
{
msg = msg + ", " + Platform.gui_localize( sp.getUnlocalizedName() );
}
}
lines.add( msg );
}
}
for (final SecurityPermissions sp : perms) {
if (msg == null) {
msg = Platform.gui_localize(sp.getUnlocalizedName());
} else {
msg = msg + ", " + Platform.gui_localize(sp.getUnlocalizedName());
}
}
lines.add(msg);
}
}
}
@@ -1,28 +1,24 @@
package appeng.items.tools;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.bootstrap.IItemRendering;
import appeng.bootstrap.ItemRenderingCustomizer;
import appeng.client.render.model.BiometricCardModel;
import appeng.core.AppEng;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ToolBiometricCardRendering extends ItemRenderingCustomizer
{
public class ToolBiometricCardRendering extends ItemRenderingCustomizer {
private static final ResourceLocation MODEL = new ResourceLocation( AppEng.MOD_ID, "builtin/biometric_card" );
private static final ResourceLocation MODEL = new ResourceLocation(AppEng.MOD_ID, "builtin/biometric_card");
@Override
@SideOnly( Side.CLIENT )
public void customize( IItemRendering rendering )
{
rendering.builtInModel( "models/item/builtin/biometric_card", new BiometricCardModel() );
rendering.model( new ModelResourceLocation( MODEL, "inventory" ) ).variants( MODEL );
}
@Override
@SideOnly(Side.CLIENT)
public void customize(IItemRendering rendering) {
rendering.builtInModel("models/item/builtin/biometric_card", new BiometricCardModel());
rendering.model(new ModelResourceLocation(MODEL, "inventory")).variants(MODEL);
}
}
@@ -19,8 +19,13 @@
package appeng.items.tools;
import java.util.List;
import appeng.api.implementations.items.IMemoryCard;
import appeng.api.implementations.items.MemoryCardMessages;
import appeng.api.util.AEColor;
import appeng.core.localization.GuiText;
import appeng.core.localization.PlayerMessages;
import appeng.items.AEBaseItem;
import appeng.util.Platform;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@@ -37,193 +42,158 @@ import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.implementations.items.IMemoryCard;
import appeng.api.implementations.items.MemoryCardMessages;
import appeng.api.util.AEColor;
import appeng.core.localization.GuiText;
import appeng.core.localization.PlayerMessages;
import appeng.items.AEBaseItem;
import appeng.util.Platform;
import java.util.List;
public class ToolMemoryCard extends AEBaseItem implements IMemoryCard
{
public class ToolMemoryCard extends AEBaseItem implements IMemoryCard {
private static final AEColor[] DEFAULT_COLOR_CODE = new AEColor[] {
AEColor.TRANSPARENT, AEColor.TRANSPARENT, AEColor.TRANSPARENT, AEColor.TRANSPARENT,
AEColor.TRANSPARENT, AEColor.TRANSPARENT, AEColor.TRANSPARENT, AEColor.TRANSPARENT,
};
private static final AEColor[] DEFAULT_COLOR_CODE = new AEColor[]{
AEColor.TRANSPARENT, AEColor.TRANSPARENT, AEColor.TRANSPARENT, AEColor.TRANSPARENT,
AEColor.TRANSPARENT, AEColor.TRANSPARENT, AEColor.TRANSPARENT, AEColor.TRANSPARENT,
};
public ToolMemoryCard()
{
this.setMaxStackSize( 1 );
}
public ToolMemoryCard() {
this.setMaxStackSize(1);
}
@Override
@SideOnly( Side.CLIENT )
public void addCheckedInformation( final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips )
{
lines.add( this.getLocalizedName( this.getSettingsName( stack ) + ".name", this.getSettingsName( stack ) ) );
@Override
@SideOnly(Side.CLIENT)
public void addCheckedInformation(final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips) {
lines.add(this.getLocalizedName(this.getSettingsName(stack) + ".name", this.getSettingsName(stack)));
final NBTTagCompound data = this.getData( stack );
if( data.hasKey( "tooltip" ) )
{
lines.add( I18n.translateToLocal( this.getLocalizedName( data.getString( "tooltip" ) + ".name", data.getString( "tooltip" ) ) ) );
}
final NBTTagCompound data = this.getData(stack);
if (data.hasKey("tooltip")) {
lines.add(I18n.translateToLocal(this.getLocalizedName(data.getString("tooltip") + ".name", data.getString("tooltip"))));
}
if( data.hasKey( "freq" ) )
{
final short freq = data.getShort( "freq" );
final String freqTooltip = TextFormatting.BOLD + Platform.p2p().toHexString( freq );
if (data.hasKey("freq")) {
final short freq = data.getShort("freq");
final String freqTooltip = TextFormatting.BOLD + Platform.p2p().toHexString(freq);
lines.add( I18n.translateToLocalFormatted( "gui.tooltips.appliedenergistics2.P2PFrequency", freqTooltip ) );
}
}
lines.add(I18n.translateToLocalFormatted("gui.tooltips.appliedenergistics2.P2PFrequency", freqTooltip));
}
}
/**
* Find the localized string...
*
* @param name possible names for the localized string
*
* @return localized name
*/
private String getLocalizedName( final String... name )
{
for( final String n : name )
{
final String l = I18n.translateToLocal( n );
if( !l.equals( n ) )
{
return l;
}
}
/**
* Find the localized string...
*
* @param name possible names for the localized string
* @return localized name
*/
private String getLocalizedName(final String... name) {
for (final String n : name) {
final String l = I18n.translateToLocal(n);
if (!l.equals(n)) {
return l;
}
}
for( final String n : name )
{
return n;
}
for (final String n : name) {
return n;
}
return "";
}
return "";
}
@Override
public void setMemoryCardContents( final ItemStack is, final String settingsName, final NBTTagCompound data )
{
final NBTTagCompound c = Platform.openNbtData( is );
c.setString( "Config", settingsName );
c.setTag( "Data", data );
}
@Override
public void setMemoryCardContents(final ItemStack is, final String settingsName, final NBTTagCompound data) {
final NBTTagCompound c = Platform.openNbtData(is);
c.setString("Config", settingsName);
c.setTag("Data", data);
}
@Override
public String getSettingsName( final ItemStack is )
{
final NBTTagCompound c = Platform.openNbtData( is );
final String name = c.getString( "Config" );
return name == null || name.isEmpty() ? GuiText.Blank.getUnlocalized() : name;
}
@Override
public String getSettingsName(final ItemStack is) {
final NBTTagCompound c = Platform.openNbtData(is);
final String name = c.getString("Config");
return name == null || name.isEmpty() ? GuiText.Blank.getUnlocalized() : name;
}
@Override
public NBTTagCompound getData( final ItemStack is )
{
final NBTTagCompound c = Platform.openNbtData( is );
NBTTagCompound o = c.getCompoundTag( "Data" );
if( o == null )
{
o = new NBTTagCompound();
}
return o.copy();
}
@Override
public NBTTagCompound getData(final ItemStack is) {
final NBTTagCompound c = Platform.openNbtData(is);
NBTTagCompound o = c.getCompoundTag("Data");
if (o == null) {
o = new NBTTagCompound();
}
return o.copy();
}
@Override
public AEColor[] getColorCode( ItemStack is )
{
final NBTTagCompound tag = this.getData( is );
@Override
public AEColor[] getColorCode(ItemStack is) {
final NBTTagCompound tag = this.getData(is);
if( tag.hasKey( "colorCode" ) )
{
final int[] frequency = tag.getIntArray( "colorCode" );
final AEColor[] colorArray = AEColor.values();
if (tag.hasKey("colorCode")) {
final int[] frequency = tag.getIntArray("colorCode");
final AEColor[] colorArray = AEColor.values();
return new AEColor[] {
colorArray[frequency[0]], colorArray[frequency[1]], colorArray[frequency[2]], colorArray[frequency[3]],
colorArray[frequency[4]], colorArray[frequency[5]], colorArray[frequency[6]], colorArray[frequency[7]],
};
}
return new AEColor[]{
colorArray[frequency[0]], colorArray[frequency[1]], colorArray[frequency[2]], colorArray[frequency[3]],
colorArray[frequency[4]], colorArray[frequency[5]], colorArray[frequency[6]], colorArray[frequency[7]],
};
}
return DEFAULT_COLOR_CODE;
}
return DEFAULT_COLOR_CODE;
}
@Override
public void notifyUser( final EntityPlayer player, final MemoryCardMessages msg )
{
if( Platform.isClient() )
{
return;
}
@Override
public void notifyUser(final EntityPlayer player, final MemoryCardMessages msg) {
if (Platform.isClient()) {
return;
}
switch( msg )
{
case SETTINGS_CLEARED:
player.sendMessage( PlayerMessages.SettingCleared.get() );
break;
case INVALID_MACHINE:
player.sendMessage( PlayerMessages.InvalidMachine.get() );
break;
case SETTINGS_LOADED:
player.sendMessage( PlayerMessages.LoadedSettings.get() );
break;
case SETTINGS_SAVED:
player.sendMessage( PlayerMessages.SavedSettings.get() );
break;
case SETTINGS_RESET:
player.sendMessage( PlayerMessages.ResetSettings.get() );
break;
default:
}
}
switch (msg) {
case SETTINGS_CLEARED:
player.sendMessage(PlayerMessages.SettingCleared.get());
break;
case INVALID_MACHINE:
player.sendMessage(PlayerMessages.InvalidMachine.get());
break;
case SETTINGS_LOADED:
player.sendMessage(PlayerMessages.LoadedSettings.get());
break;
case SETTINGS_SAVED:
player.sendMessage(PlayerMessages.SavedSettings.get());
break;
case SETTINGS_RESET:
player.sendMessage(PlayerMessages.ResetSettings.get());
break;
default:
}
}
@Override
public EnumActionResult onItemUse( final EntityPlayer player, final World w, final BlockPos pos, final EnumHand hand, final EnumFacing side, final float hx, final float hy, final float hz )
{
if( player.isSneaking() )
{
if( !w.isRemote )
{
this.clearCard( player, w, hand );
}
return EnumActionResult.SUCCESS;
}
else
{
return super.onItemUse( player, w, pos, hand, side, hx, hy, hz );
}
}
@Override
public EnumActionResult onItemUse(final EntityPlayer player, final World w, final BlockPos pos, final EnumHand hand, final EnumFacing side, final float hx, final float hy, final float hz) {
if (player.isSneaking()) {
if (!w.isRemote) {
this.clearCard(player, w, hand);
}
return EnumActionResult.SUCCESS;
} else {
return super.onItemUse(player, w, pos, hand, side, hx, hy, hz);
}
}
@Override
public ActionResult<ItemStack> onItemRightClick( World w, EntityPlayer player, EnumHand hand )
{
if( player.isSneaking() )
{
if( !w.isRemote )
{
this.clearCard( player, w, hand );
}
}
@Override
public ActionResult<ItemStack> onItemRightClick(World w, EntityPlayer player, EnumHand hand) {
if (player.isSneaking()) {
if (!w.isRemote) {
this.clearCard(player, w, hand);
}
}
return super.onItemRightClick( w, player, hand );
return super.onItemRightClick(w, player, hand);
}
}
@Override
public boolean doesSneakBypassUse( final ItemStack itemstack, final IBlockAccess world, final BlockPos pos, final EntityPlayer player )
{
return true;
}
@Override
public boolean doesSneakBypassUse(final ItemStack itemstack, final IBlockAccess world, final BlockPos pos, final EntityPlayer player) {
return true;
}
private void clearCard( final EntityPlayer player, final World w, final EnumHand hand )
{
final IMemoryCard mem = (IMemoryCard) player.getHeldItem( hand ).getItem();
mem.notifyUser( player, MemoryCardMessages.SETTINGS_CLEARED );
player.getHeldItem( hand ).setTagCompound( null );
}
private void clearCard(final EntityPlayer player, final World w, final EnumHand hand) {
final IMemoryCard mem = (IMemoryCard) player.getHeldItem(hand).getItem();
mem.notifyUser(player, MemoryCardMessages.SETTINGS_CLEARED);
player.getHeldItem(hand).setTagCompound(null);
}
}
@@ -1,28 +1,24 @@
package appeng.items.tools;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.bootstrap.IItemRendering;
import appeng.bootstrap.ItemRenderingCustomizer;
import appeng.client.render.model.MemoryCardModel;
import appeng.core.AppEng;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ToolMemoryCardRendering extends ItemRenderingCustomizer
{
public class ToolMemoryCardRendering extends ItemRenderingCustomizer {
private static final ResourceLocation MODEL = new ResourceLocation( AppEng.MOD_ID, "builtin/memory_card" );
private static final ResourceLocation MODEL = new ResourceLocation(AppEng.MOD_ID, "builtin/memory_card");
@Override
@SideOnly( Side.CLIENT )
public void customize( IItemRendering rendering )
{
rendering.builtInModel( "models/item/builtin/memory_card", new MemoryCardModel() );
rendering.model( new ModelResourceLocation( MODEL, "inventory" ) ).variants( MODEL );
}
@Override
@SideOnly(Side.CLIENT)
public void customize(IItemRendering rendering) {
rendering.builtInModel("models/item/builtin/memory_card", new MemoryCardModel());
rendering.model(new ModelResourceLocation(MODEL, "inventory")).variants(MODEL);
}
}
@@ -19,25 +19,6 @@
package appeng.items.tools;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.Optional.Interface;
import cofh.api.item.IToolHammer;
import appeng.api.implementations.guiobjects.IGuiItem;
import appeng.api.implementations.guiobjects.IGuiItemObject;
import appeng.api.implementations.items.IAEWrench;
@@ -55,171 +36,152 @@ import appeng.core.sync.packets.PacketClick;
import appeng.items.AEBaseItem;
import appeng.items.contents.NetworkToolViewer;
import appeng.util.Platform;
import cofh.api.item.IToolHammer;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.Optional.Interface;
// TODO BC Integration
//@Interface( iface = "buildcraft.api.tools.IToolWrench", iname = IntegrationType.BuildCraftCore )
@Interface( iface = "cofh.api.item.IToolHammer", modid = "cofhcore" )
public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench, IToolHammer /* , IToolWrench */
{
@Interface(iface = "cofh.api.item.IToolHammer", modid = "cofhcore")
public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench, IToolHammer /* , IToolWrench */ {
public ToolNetworkTool()
{
this.setMaxStackSize( 1 );
this.setHarvestLevel( "wrench", 0 );
}
public ToolNetworkTool() {
this.setMaxStackSize(1);
this.setHarvestLevel("wrench", 0);
}
@Override
public IGuiItemObject getGuiObject( final ItemStack is, final World world, final BlockPos pos )
{
final TileEntity te = world.getTileEntity( pos );
return new NetworkToolViewer( is, (IGridHost) ( te instanceof IGridHost ? te : null ) );
}
@Override
public IGuiItemObject getGuiObject(final ItemStack is, final World world, final BlockPos pos) {
final TileEntity te = world.getTileEntity(pos);
return new NetworkToolViewer(is, (IGridHost) (te instanceof IGridHost ? te : null));
}
@Override
public ActionResult<ItemStack> onItemRightClick( final World w, final EntityPlayer p, final EnumHand hand )
{
if( Platform.isClient() )
{
final RayTraceResult mop = AppEng.proxy.getRTR();
@Override
public ActionResult<ItemStack> onItemRightClick(final World w, final EntityPlayer p, final EnumHand hand) {
if (Platform.isClient()) {
final RayTraceResult mop = AppEng.proxy.getRTR();
if( mop == null || mop.typeOfHit == RayTraceResult.Type.MISS )
{
NetworkHandler.instance().sendToServer( new PacketClick( BlockPos.ORIGIN, null, 0, 0, 0, hand ) );
}
}
if (mop == null || mop.typeOfHit == RayTraceResult.Type.MISS) {
NetworkHandler.instance().sendToServer(new PacketClick(BlockPos.ORIGIN, null, 0, 0, 0, hand));
}
}
return new ActionResult<>( EnumActionResult.SUCCESS, p.getHeldItem( hand ) );
}
return new ActionResult<>(EnumActionResult.SUCCESS, p.getHeldItem(hand));
}
@Override
public EnumActionResult onItemUseFirst( final EntityPlayer player, final World world, final BlockPos pos, final EnumFacing side, final float hitX, final float hitY, final float hitZ, final EnumHand hand )
{
final RayTraceResult mop = new RayTraceResult( new Vec3d( hitX, hitY, hitZ ), side, pos );
final TileEntity te = world.getTileEntity( pos );
@Override
public EnumActionResult onItemUseFirst(final EntityPlayer player, final World world, final BlockPos pos, final EnumFacing side, final float hitX, final float hitY, final float hitZ, final EnumHand hand) {
final RayTraceResult mop = new RayTraceResult(new Vec3d(hitX, hitY, hitZ), side, pos);
final TileEntity te = world.getTileEntity(pos);
if( te instanceof IPartHost )
{
final SelectedPart part = ( (IPartHost) te ).selectPart( mop.hitVec );
if (te instanceof IPartHost) {
final SelectedPart part = ((IPartHost) te).selectPart(mop.hitVec);
if( part.part != null || part.facade != null )
{
if( part.part instanceof INetworkToolAgent && !( (INetworkToolAgent) part.part ).showNetworkInfo( mop ) )
{
return EnumActionResult.FAIL;
}
else if( player.isSneaking() )
{
return EnumActionResult.PASS;
}
}
}
else if( te instanceof INetworkToolAgent && !( (INetworkToolAgent) te ).showNetworkInfo( mop ) )
{
return EnumActionResult.FAIL;
}
if (part.part != null || part.facade != null) {
if (part.part instanceof INetworkToolAgent && !((INetworkToolAgent) part.part).showNetworkInfo(mop)) {
return EnumActionResult.FAIL;
} else if (player.isSneaking()) {
return EnumActionResult.PASS;
}
}
} else if (te instanceof INetworkToolAgent && !((INetworkToolAgent) te).showNetworkInfo(mop)) {
return EnumActionResult.FAIL;
}
if( Platform.isClient() )
{
NetworkHandler.instance().sendToServer( new PacketClick( pos, side, hitX, hitY, hitZ, hand ) );
}
if (Platform.isClient()) {
NetworkHandler.instance().sendToServer(new PacketClick(pos, side, hitX, hitY, hitZ, hand));
}
return EnumActionResult.SUCCESS;
}
return EnumActionResult.SUCCESS;
}
@Override
public boolean doesSneakBypassUse( final ItemStack itemstack, final IBlockAccess world, final BlockPos pos, final EntityPlayer player )
{
return true;
}
@Override
public boolean doesSneakBypassUse(final ItemStack itemstack, final IBlockAccess world, final BlockPos pos, final EntityPlayer player) {
return true;
}
public boolean serverSideToolLogic( final ItemStack is, final EntityPlayer p, final EnumHand hand, final World w, final BlockPos pos, final EnumFacing side, final float hitX, final float hitY, final float hitZ )
{
if( side != null )
{
if( !Platform.hasPermissions( new DimensionalCoord( w, pos ), p ) )
{
return false;
}
public boolean serverSideToolLogic(final ItemStack is, final EntityPlayer p, final EnumHand hand, final World w, final BlockPos pos, final EnumFacing side, final float hitX, final float hitY, final float hitZ) {
if (side != null) {
if (!Platform.hasPermissions(new DimensionalCoord(w, pos), p)) {
return false;
}
final Block b = w.getBlockState( pos ).getBlock();
if( !p.isSneaking() )
{
final TileEntity te = w.getTileEntity( pos );
if( !( te instanceof IGridHost ) )
{
if( b.rotateBlock( w, pos, side ) )
{
b.neighborChanged( Platform.AIR_BLOCK.getDefaultState(), w, pos, Platform.AIR_BLOCK, null );
p.swingArm( hand );
return !w.isRemote;
}
}
}
final Block b = w.getBlockState(pos).getBlock();
if (!p.isSneaking()) {
final TileEntity te = w.getTileEntity(pos);
if (!(te instanceof IGridHost)) {
if (b.rotateBlock(w, pos, side)) {
b.neighborChanged(Platform.AIR_BLOCK.getDefaultState(), w, pos, Platform.AIR_BLOCK, null);
p.swingArm(hand);
return !w.isRemote;
}
}
}
if( !p.isSneaking() )
{
if( p.openContainer instanceof AEBaseContainer )
{
return true;
}
if (!p.isSneaking()) {
if (p.openContainer instanceof AEBaseContainer) {
return true;
}
final TileEntity te = w.getTileEntity( pos );
final TileEntity te = w.getTileEntity(pos);
if( te instanceof IGridHost )
{
Platform.openGUI( p, te, AEPartLocation.fromFacing( side ), GuiBridge.GUI_NETWORK_STATUS );
}
else
{
Platform.openGUI( p, null, AEPartLocation.INTERNAL, GuiBridge.GUI_NETWORK_TOOL );
}
if (te instanceof IGridHost) {
Platform.openGUI(p, te, AEPartLocation.fromFacing(side), GuiBridge.GUI_NETWORK_STATUS);
} else {
Platform.openGUI(p, null, AEPartLocation.INTERNAL, GuiBridge.GUI_NETWORK_TOOL);
}
return true;
}
else
{
b.onBlockActivated( w, pos, w.getBlockState( pos ), p, hand, side, hitX, hitY, hitZ );
}
}
else
{
Platform.openGUI( p, null, AEPartLocation.INTERNAL, GuiBridge.GUI_NETWORK_TOOL );
}
return true;
} else {
b.onBlockActivated(w, pos, w.getBlockState(pos), p, hand, side, hitX, hitY, hitZ);
}
} else {
Platform.openGUI(p, null, AEPartLocation.INTERNAL, GuiBridge.GUI_NETWORK_TOOL);
}
return false;
}
return false;
}
@Override
public boolean canWrench( final ItemStack wrench, final EntityPlayer player, final BlockPos pos )
{
return true;
}
@Override
public boolean canWrench(final ItemStack wrench, final EntityPlayer player, final BlockPos pos) {
return true;
}
// IToolHammer - start
@Override
public boolean isUsable( ItemStack item, EntityLivingBase user, BlockPos pos )
{
return true;
}
// IToolHammer - start
@Override
public boolean isUsable(ItemStack item, EntityLivingBase user, BlockPos pos) {
return true;
}
@Override
public boolean isUsable( ItemStack item, EntityLivingBase user, Entity entity )
{
return true;
}
@Override
public boolean isUsable(ItemStack item, EntityLivingBase user, Entity entity) {
return true;
}
@Override
public void toolUsed( ItemStack item, EntityLivingBase user, BlockPos pos )
{
}
@Override
public void toolUsed(ItemStack item, EntityLivingBase user, BlockPos pos) {
}
@Override
public void toolUsed( ItemStack item, EntityLivingBase user, Entity entity )
{
}
// IToolHammer - end
@Override
public void toolUsed(ItemStack item, EntityLivingBase user, Entity entity) {
}
// IToolHammer - end
// TODO: BC WRENCH INTEGRATION
// TODO: BC WRENCH INTEGRATION
}
@@ -19,48 +19,41 @@
package appeng.items.tools.powered;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.AxisAlignedBB;
import appeng.api.config.Actionable;
import appeng.core.AEConfig;
import appeng.core.AppEng;
import appeng.core.sync.packets.PacketLightning;
import appeng.items.tools.powered.powersink.AEBasePoweredItem;
import appeng.util.Platform;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.AxisAlignedBB;
public class ToolChargedStaff extends AEBasePoweredItem
{
public class ToolChargedStaff extends AEBasePoweredItem {
public ToolChargedStaff()
{
super( AEConfig.instance().getChargedStaffBattery() );
}
public ToolChargedStaff() {
super(AEConfig.instance().getChargedStaffBattery());
}
@Override
public boolean hitEntity( final ItemStack item, final EntityLivingBase target, final EntityLivingBase hitter )
{
if( this.getAECurrentPower( item ) > 300 )
{
this.extractAEPower( item, 300, Actionable.MODULATE );
if( Platform.isServer() )
{
for( int x = 0; x < 2; x++ )
{
final AxisAlignedBB entityBoundingBox = target.getEntityBoundingBox();
final float dx = (float) ( Platform.getRandomFloat() * target.width + entityBoundingBox.minX );
final float dy = (float) ( Platform.getRandomFloat() * target.height + entityBoundingBox.minY );
final float dz = (float) ( Platform.getRandomFloat() * target.width + entityBoundingBox.minZ );
AppEng.proxy.sendToAllNearExcept( null, dx, dy, dz, 32.0, target.world, new PacketLightning( dx, dy, dz ) );
}
}
target.attackEntityFrom( DamageSource.MAGIC, 6 );
return true;
}
@Override
public boolean hitEntity(final ItemStack item, final EntityLivingBase target, final EntityLivingBase hitter) {
if (this.getAECurrentPower(item) > 300) {
this.extractAEPower(item, 300, Actionable.MODULATE);
if (Platform.isServer()) {
for (int x = 0; x < 2; x++) {
final AxisAlignedBB entityBoundingBox = target.getEntityBoundingBox();
final float dx = (float) (Platform.getRandomFloat() * target.width + entityBoundingBox.minX);
final float dy = (float) (Platform.getRandomFloat() * target.height + entityBoundingBox.minY);
final float dz = (float) (Platform.getRandomFloat() * target.width + entityBoundingBox.minZ);
AppEng.proxy.sendToAllNearExcept(null, dx, dy, dz, 32.0, target.world, new PacketLightning(dx, dy, dz));
}
}
target.attackEntityFrom(DamageSource.MAGIC, 6);
return true;
}
return false;
}
return false;
}
}
@@ -19,38 +19,6 @@
package appeng.items.tools.powered;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang3.text.WordUtils;
import net.minecraft.block.Block;
import net.minecraft.block.BlockColored;
import net.minecraft.block.BlockStainedGlass;
import net.minecraft.block.BlockStainedGlassPane;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemSnowball;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.oredict.OreDictionary;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode;
@@ -79,477 +47,413 @@ import appeng.me.helpers.BaseActionSource;
import appeng.tile.misc.TilePaint;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCell<IAEItemStack>, IItemGroup, IBlockTool, IMouseWheelItem
{
private static final Map<Integer, AEColor> ORE_TO_COLOR = new HashMap<>();
static
{
for( final AEColor color : AEColor.VALID_COLORS )
{
final String dyeName = color.dye.getUnlocalizedName();
final String oreDictName = "dye" + WordUtils.capitalize( dyeName );
final int oreDictId = OreDictionary.getOreID( oreDictName );
ORE_TO_COLOR.put( oreDictId, color );
}
}
public ToolColorApplicator()
{
super( AEConfig.instance().getColorApplicatorBattery() );
}
@Override
public EnumActionResult onItemUse( EntityPlayer p, World w, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ )
{
return this.onItemUse( p.getHeldItem( hand ), p, w, pos, hand, side, hitX, hitY, hitZ );
}
@Override
public EnumActionResult onItemUse( ItemStack is, EntityPlayer p, World w, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ )
{
final Block blk = w.getBlockState( pos ).getBlock();
ItemStack paintBall = this.getColor( is );
final IMEInventory<IAEItemStack> inv = AEApi.instance()
.registries()
.cell()
.getCellInventory( is, null,
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
if( inv != null )
{
final IAEItemStack option = inv.extractItems( AEItemStack.fromItemStack( paintBall ), Actionable.SIMULATE, new BaseActionSource() );
if( option != null )
{
paintBall = option.createItemStack();
paintBall.setCount( 1 );
}
else
{
paintBall = ItemStack.EMPTY;
}
if( !Platform.hasPermissions( new DimensionalCoord( w, pos ), p ) )
{
return EnumActionResult.FAIL;
}
final double powerPerUse = 100;
if( !paintBall.isEmpty() && paintBall.getItem() instanceof ItemSnowball )
{
final TileEntity te = w.getTileEntity( pos );
// clean cables.
if( te instanceof IColorableTile )
{
if( this.getAECurrentPower( is ) > powerPerUse && ( (IColorableTile) te ).getColor() != AEColor.TRANSPARENT )
{
if( ( (IColorableTile) te ).recolourBlock( side, AEColor.TRANSPARENT, p ) )
{
inv.extractItems( AEItemStack.fromItemStack( paintBall ), Actionable.MODULATE, new BaseActionSource() );
this.extractAEPower( is, powerPerUse, Actionable.MODULATE );
return EnumActionResult.SUCCESS;
}
}
}
// clean paint balls..
final Block testBlk = w.getBlockState( pos.offset( side ) ).getBlock();
final TileEntity painted = w.getTileEntity( pos.offset( side ) );
if( this.getAECurrentPower( is ) > powerPerUse && testBlk instanceof BlockPaint && painted instanceof TilePaint )
{
inv.extractItems( AEItemStack.fromItemStack( paintBall ), Actionable.MODULATE, new BaseActionSource() );
this.extractAEPower( is, powerPerUse, Actionable.MODULATE );
( (TilePaint) painted ).cleanSide( side.getOpposite() );
return EnumActionResult.SUCCESS;
}
}
else if( !paintBall.isEmpty() )
{
final AEColor color = this.getColorFromItem( paintBall );
if( color != null && this.getAECurrentPower( is ) > powerPerUse )
{
if( color != AEColor.TRANSPARENT && this.recolourBlock( blk, side, w, pos, side, color, p ) )
{
inv.extractItems( AEItemStack.fromItemStack( paintBall ), Actionable.MODULATE, new BaseActionSource() );
this.extractAEPower( is, powerPerUse, Actionable.MODULATE );
return EnumActionResult.SUCCESS;
}
}
}
}
if( p.isSneaking() )
{
this.cycleColors( is, paintBall, 1 );
}
return EnumActionResult.FAIL;
}
@Override
public String getItemStackDisplayName( final ItemStack par1ItemStack )
{
String extra = GuiText.Empty.getLocal();
final AEColor selected = this.getActiveColor( par1ItemStack );
if( selected != null && Platform.isClient() )
{
extra = Platform.gui_localize( selected.unlocalizedName );
}
return super.getItemStackDisplayName( par1ItemStack ) + " - " + extra;
}
public AEColor getActiveColor( final ItemStack tol )
{
return this.getColorFromItem( this.getColor( tol ) );
}
private AEColor getColorFromItem( final ItemStack paintBall )
{
if( paintBall.isEmpty() )
{
return null;
}
if( paintBall.getItem() instanceof ItemSnowball )
{
return AEColor.TRANSPARENT;
}
if( paintBall.getItem() instanceof ItemPaintBall )
{
final ItemPaintBall ipb = (ItemPaintBall) paintBall.getItem();
return ipb.getColor( paintBall );
}
else
{
final int[] id = OreDictionary.getOreIDs( paintBall );
for( final int oreID : id )
{
if( ORE_TO_COLOR.containsKey( oreID ) )
{
return ORE_TO_COLOR.get( oreID );
}
}
}
return null;
}
public ItemStack getColor( final ItemStack is )
{
final NBTTagCompound c = is.getTagCompound();
if( c != null && c.hasKey( "color" ) )
{
final NBTTagCompound color = c.getCompoundTag( "color" );
final ItemStack oldColor = new ItemStack( color );
if( !oldColor.isEmpty() )
{
return oldColor;
}
}
return this.findNextColor( is, ItemStack.EMPTY, 0 );
}
private ItemStack findNextColor( final ItemStack is, final ItemStack anchor, final int scrollOffset )
{
ItemStack newColor = ItemStack.EMPTY;
final IMEInventory<IAEItemStack> inv = AEApi.instance()
.registries()
.cell()
.getCellInventory( is, null,
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
if( inv != null )
{
final IItemList<IAEItemStack> itemList = inv
.getAvailableItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList() );
if( anchor.isEmpty() )
{
final IAEItemStack firstItem = itemList.getFirstItem();
if( firstItem != null )
{
newColor = firstItem.asItemStackRepresentation();
}
}
else
{
final LinkedList<IAEItemStack> list = new LinkedList<>();
for( final IAEItemStack i : itemList )
{
list.add( i );
}
Collections.sort( list, ( a, b ) -> Integer.compare( a.getItemDamage(), b.getItemDamage() ) );
if( list.size() <= 0 )
{
return ItemStack.EMPTY;
}
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 ).asItemStackRepresentation();
}
}
if( !newColor.isEmpty() )
{
this.setColor( is, newColor );
}
return newColor;
}
private void setColor( final ItemStack is, final ItemStack newColor )
{
final NBTTagCompound data = Platform.openNbtData( is );
if( newColor.isEmpty() )
{
data.removeTag( "color" );
}
else
{
final NBTTagCompound color = new NBTTagCompound();
newColor.writeToNBT( color );
data.setTag( "color", color );
}
}
private boolean recolourBlock( final Block blk, final EnumFacing side, final World w, final BlockPos pos, final EnumFacing orientation, final AEColor newColor, final EntityPlayer p )
{
final IBlockState state = w.getBlockState( pos );
if( blk instanceof BlockColored )
{
final EnumDyeColor color = state.getValue( BlockColored.COLOR );
if( newColor.dye == color )
{
return false;
}
return w.setBlockState( pos, state.withProperty( BlockColored.COLOR, newColor.dye ) );
}
if( blk == Blocks.GLASS )
{
return w.setBlockState( pos, Blocks.STAINED_GLASS.getDefaultState().withProperty( BlockStainedGlass.COLOR, newColor.dye ) );
}
if( blk == Blocks.STAINED_GLASS )
{
final EnumDyeColor color = state.getValue( BlockStainedGlass.COLOR );
if( newColor.dye == color )
{
return false;
}
return w.setBlockState( pos, state.withProperty( BlockStainedGlass.COLOR, newColor.dye ) );
}
if( blk == Blocks.GLASS_PANE )
{
return w.setBlockState( pos, Blocks.STAINED_GLASS_PANE.getDefaultState().withProperty( BlockStainedGlassPane.COLOR, newColor.dye ) );
}
if( blk == Blocks.STAINED_GLASS_PANE )
{
final EnumDyeColor color = state.getValue( BlockStainedGlassPane.COLOR );
if( newColor.dye == color )
{
return false;
}
return w.setBlockState( pos, state.withProperty( BlockStainedGlassPane.COLOR, newColor.dye ) );
}
if( blk == Blocks.HARDENED_CLAY )
{
return w.setBlockState( pos, Blocks.STAINED_HARDENED_CLAY.getDefaultState().withProperty( BlockColored.COLOR, newColor.dye ) );
}
if( blk instanceof BlockCableBus )
{
return ( (BlockCableBus) blk ).recolorBlock( w, pos, side, newColor.dye, p );
}
return blk.recolorBlock( w, pos, side, newColor.dye );
}
public void cycleColors( final ItemStack is, final ItemStack paintBall, final int i )
{
if( paintBall.isEmpty() )
{
this.setColor( is, this.getColor( is ) );
}
else
{
this.setColor( is, this.findNextColor( is, paintBall, i ) );
}
}
@Override
@SideOnly( Side.CLIENT )
public void addCheckedInformation( final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips )
{
super.addCheckedInformation( stack, world, lines, advancedTooltips );
final ICellInventoryHandler<IAEItemStack> cdi = AEApi.instance()
.registries()
.cell()
.getCellInventory( stack, null,
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
AEApi.instance().client().addCellInformation( cdi, lines );
}
@Override
public int getBytes( final ItemStack cellItem )
{
return 512;
}
@Override
public int getBytesPerType( final ItemStack cellItem )
{
return 8;
}
@Override
public int getTotalTypes( final ItemStack cellItem )
{
return 27;
}
@Override
public boolean isBlackListed( final ItemStack cellItem, final IAEItemStack requestedAddition )
{
if( requestedAddition != null )
{
final int[] id = OreDictionary.getOreIDs( requestedAddition.getDefinition() );
for( final int x : id )
{
if( ORE_TO_COLOR.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( final ItemStack i )
{
return true;
}
@Override
public double getIdleDrain()
{
return 0.5;
}
@Override
public IStorageChannel<IAEItemStack> getChannel()
{
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
}
@Override
public String getUnlocalizedGroupName( final Set<ItemStack> others, final ItemStack is )
{
return GuiText.StorageCells.getUnlocalized();
}
@Override
public boolean isEditable( final ItemStack is )
{
return true;
}
@Override
public IItemHandler getUpgradesInventory( final ItemStack is )
{
return new CellUpgrades( is, 2 );
}
@Override
public IItemHandler getConfigInventory( final ItemStack is )
{
return new CellConfig( is );
}
@Override
public FuzzyMode getFuzzyMode( final ItemStack is )
{
final String fz = Platform.openNbtData( is ).getString( "FuzzyMode" );
try
{
return FuzzyMode.valueOf( fz );
}
catch( final Throwable t )
{
return FuzzyMode.IGNORE_ALL;
}
}
@Override
public void setFuzzyMode( final ItemStack is, final FuzzyMode fzMode )
{
Platform.openNbtData( is ).setString( "FuzzyMode", fzMode.name() );
}
@Override
public void onWheel( final ItemStack is, final boolean up )
{
this.cycleColors( is, this.getColor( is ), up ? 1 : -1 );
}
import net.minecraft.block.Block;
import net.minecraft.block.BlockColored;
import net.minecraft.block.BlockStainedGlass;
import net.minecraft.block.BlockStainedGlassPane;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemSnowball;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.oredict.OreDictionary;
import org.apache.commons.lang3.text.WordUtils;
import java.util.*;
public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCell<IAEItemStack>, IItemGroup, IBlockTool, IMouseWheelItem {
private static final Map<Integer, AEColor> ORE_TO_COLOR = new HashMap<>();
static {
for (final AEColor color : AEColor.VALID_COLORS) {
final String dyeName = color.dye.getUnlocalizedName();
final String oreDictName = "dye" + WordUtils.capitalize(dyeName);
final int oreDictId = OreDictionary.getOreID(oreDictName);
ORE_TO_COLOR.put(oreDictId, color);
}
}
public ToolColorApplicator() {
super(AEConfig.instance().getColorApplicatorBattery());
}
@Override
public EnumActionResult onItemUse(EntityPlayer p, World w, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
return this.onItemUse(p.getHeldItem(hand), p, w, pos, hand, side, hitX, hitY, hitZ);
}
@Override
public EnumActionResult onItemUse(ItemStack is, EntityPlayer p, World w, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
final Block blk = w.getBlockState(pos).getBlock();
ItemStack paintBall = this.getColor(is);
final IMEInventory<IAEItemStack> inv = AEApi.instance()
.registries()
.cell()
.getCellInventory(is, null,
AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
if (inv != null) {
final IAEItemStack option = inv.extractItems(AEItemStack.fromItemStack(paintBall), Actionable.SIMULATE, new BaseActionSource());
if (option != null) {
paintBall = option.createItemStack();
paintBall.setCount(1);
} else {
paintBall = ItemStack.EMPTY;
}
if (!Platform.hasPermissions(new DimensionalCoord(w, pos), p)) {
return EnumActionResult.FAIL;
}
final double powerPerUse = 100;
if (!paintBall.isEmpty() && paintBall.getItem() instanceof ItemSnowball) {
final TileEntity te = w.getTileEntity(pos);
// clean cables.
if (te instanceof IColorableTile) {
if (this.getAECurrentPower(is) > powerPerUse && ((IColorableTile) te).getColor() != AEColor.TRANSPARENT) {
if (((IColorableTile) te).recolourBlock(side, AEColor.TRANSPARENT, p)) {
inv.extractItems(AEItemStack.fromItemStack(paintBall), Actionable.MODULATE, new BaseActionSource());
this.extractAEPower(is, powerPerUse, Actionable.MODULATE);
return EnumActionResult.SUCCESS;
}
}
}
// clean paint balls..
final Block testBlk = w.getBlockState(pos.offset(side)).getBlock();
final TileEntity painted = w.getTileEntity(pos.offset(side));
if (this.getAECurrentPower(is) > powerPerUse && testBlk instanceof BlockPaint && painted instanceof TilePaint) {
inv.extractItems(AEItemStack.fromItemStack(paintBall), Actionable.MODULATE, new BaseActionSource());
this.extractAEPower(is, powerPerUse, Actionable.MODULATE);
((TilePaint) painted).cleanSide(side.getOpposite());
return EnumActionResult.SUCCESS;
}
} else if (!paintBall.isEmpty()) {
final AEColor color = this.getColorFromItem(paintBall);
if (color != null && this.getAECurrentPower(is) > powerPerUse) {
if (color != AEColor.TRANSPARENT && this.recolourBlock(blk, side, w, pos, side, color, p)) {
inv.extractItems(AEItemStack.fromItemStack(paintBall), Actionable.MODULATE, new BaseActionSource());
this.extractAEPower(is, powerPerUse, Actionable.MODULATE);
return EnumActionResult.SUCCESS;
}
}
}
}
if (p.isSneaking()) {
this.cycleColors(is, paintBall, 1);
}
return EnumActionResult.FAIL;
}
@Override
public String getItemStackDisplayName(final ItemStack par1ItemStack) {
String extra = GuiText.Empty.getLocal();
final AEColor selected = this.getActiveColor(par1ItemStack);
if (selected != null && Platform.isClient()) {
extra = Platform.gui_localize(selected.unlocalizedName);
}
return super.getItemStackDisplayName(par1ItemStack) + " - " + extra;
}
public AEColor getActiveColor(final ItemStack tol) {
return this.getColorFromItem(this.getColor(tol));
}
private AEColor getColorFromItem(final ItemStack paintBall) {
if (paintBall.isEmpty()) {
return null;
}
if (paintBall.getItem() instanceof ItemSnowball) {
return AEColor.TRANSPARENT;
}
if (paintBall.getItem() instanceof ItemPaintBall) {
final ItemPaintBall ipb = (ItemPaintBall) paintBall.getItem();
return ipb.getColor(paintBall);
} else {
final int[] id = OreDictionary.getOreIDs(paintBall);
for (final int oreID : id) {
if (ORE_TO_COLOR.containsKey(oreID)) {
return ORE_TO_COLOR.get(oreID);
}
}
}
return null;
}
public ItemStack getColor(final ItemStack is) {
final NBTTagCompound c = is.getTagCompound();
if (c != null && c.hasKey("color")) {
final NBTTagCompound color = c.getCompoundTag("color");
final ItemStack oldColor = new ItemStack(color);
if (!oldColor.isEmpty()) {
return oldColor;
}
}
return this.findNextColor(is, ItemStack.EMPTY, 0);
}
private ItemStack findNextColor(final ItemStack is, final ItemStack anchor, final int scrollOffset) {
ItemStack newColor = ItemStack.EMPTY;
final IMEInventory<IAEItemStack> inv = AEApi.instance()
.registries()
.cell()
.getCellInventory(is, null,
AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
if (inv != null) {
final IItemList<IAEItemStack> itemList = inv
.getAvailableItems(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList());
if (anchor.isEmpty()) {
final IAEItemStack firstItem = itemList.getFirstItem();
if (firstItem != null) {
newColor = firstItem.asItemStackRepresentation();
}
} else {
final LinkedList<IAEItemStack> list = new LinkedList<>();
for (final IAEItemStack i : itemList) {
list.add(i);
}
Collections.sort(list, (a, b) -> Integer.compare(a.getItemDamage(), b.getItemDamage()));
if (list.size() <= 0) {
return ItemStack.EMPTY;
}
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).asItemStackRepresentation();
}
}
if (!newColor.isEmpty()) {
this.setColor(is, newColor);
}
return newColor;
}
private void setColor(final ItemStack is, final ItemStack newColor) {
final NBTTagCompound data = Platform.openNbtData(is);
if (newColor.isEmpty()) {
data.removeTag("color");
} else {
final NBTTagCompound color = new NBTTagCompound();
newColor.writeToNBT(color);
data.setTag("color", color);
}
}
private boolean recolourBlock(final Block blk, final EnumFacing side, final World w, final BlockPos pos, final EnumFacing orientation, final AEColor newColor, final EntityPlayer p) {
final IBlockState state = w.getBlockState(pos);
if (blk instanceof BlockColored) {
final EnumDyeColor color = state.getValue(BlockColored.COLOR);
if (newColor.dye == color) {
return false;
}
return w.setBlockState(pos, state.withProperty(BlockColored.COLOR, newColor.dye));
}
if (blk == Blocks.GLASS) {
return w.setBlockState(pos, Blocks.STAINED_GLASS.getDefaultState().withProperty(BlockStainedGlass.COLOR, newColor.dye));
}
if (blk == Blocks.STAINED_GLASS) {
final EnumDyeColor color = state.getValue(BlockStainedGlass.COLOR);
if (newColor.dye == color) {
return false;
}
return w.setBlockState(pos, state.withProperty(BlockStainedGlass.COLOR, newColor.dye));
}
if (blk == Blocks.GLASS_PANE) {
return w.setBlockState(pos, Blocks.STAINED_GLASS_PANE.getDefaultState().withProperty(BlockStainedGlassPane.COLOR, newColor.dye));
}
if (blk == Blocks.STAINED_GLASS_PANE) {
final EnumDyeColor color = state.getValue(BlockStainedGlassPane.COLOR);
if (newColor.dye == color) {
return false;
}
return w.setBlockState(pos, state.withProperty(BlockStainedGlassPane.COLOR, newColor.dye));
}
if (blk == Blocks.HARDENED_CLAY) {
return w.setBlockState(pos, Blocks.STAINED_HARDENED_CLAY.getDefaultState().withProperty(BlockColored.COLOR, newColor.dye));
}
if (blk instanceof BlockCableBus) {
return ((BlockCableBus) blk).recolorBlock(w, pos, side, newColor.dye, p);
}
return blk.recolorBlock(w, pos, side, newColor.dye);
}
public void cycleColors(final ItemStack is, final ItemStack paintBall, final int i) {
if (paintBall.isEmpty()) {
this.setColor(is, this.getColor(is));
} else {
this.setColor(is, this.findNextColor(is, paintBall, i));
}
}
@Override
@SideOnly(Side.CLIENT)
public void addCheckedInformation(final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips) {
super.addCheckedInformation(stack, world, lines, advancedTooltips);
final ICellInventoryHandler<IAEItemStack> cdi = AEApi.instance()
.registries()
.cell()
.getCellInventory(stack, null,
AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
AEApi.instance().client().addCellInformation(cdi, lines);
}
@Override
public int getBytes(final ItemStack cellItem) {
return 512;
}
@Override
public int getBytesPerType(final ItemStack cellItem) {
return 8;
}
@Override
public int getTotalTypes(final ItemStack cellItem) {
return 27;
}
@Override
public boolean isBlackListed(final ItemStack cellItem, final IAEItemStack requestedAddition) {
if (requestedAddition != null) {
final int[] id = OreDictionary.getOreIDs(requestedAddition.getDefinition());
for (final int x : id) {
if (ORE_TO_COLOR.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(final ItemStack i) {
return true;
}
@Override
public double getIdleDrain() {
return 0.5;
}
@Override
public IStorageChannel<IAEItemStack> getChannel() {
return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class);
}
@Override
public String getUnlocalizedGroupName(final Set<ItemStack> others, final ItemStack is) {
return GuiText.StorageCells.getUnlocalized();
}
@Override
public boolean isEditable(final ItemStack is) {
return true;
}
@Override
public IItemHandler getUpgradesInventory(final ItemStack is) {
return new CellUpgrades(is, 2);
}
@Override
public IItemHandler getConfigInventory(final ItemStack is) {
return new CellConfig(is);
}
@Override
public FuzzyMode getFuzzyMode(final ItemStack is) {
final String fz = Platform.openNbtData(is).getString("FuzzyMode");
try {
return FuzzyMode.valueOf(fz);
} catch (final Throwable t) {
return FuzzyMode.IGNORE_ALL;
}
}
@Override
public void setFuzzyMode(final ItemStack is, final FuzzyMode fzMode) {
Platform.openNbtData(is).setString("FuzzyMode", fzMode.name());
}
@Override
public void onWheel(final ItemStack is, final boolean up) {
this.cycleColors(is, this.getColor(is), up ? 1 : -1);
}
}
@@ -1,69 +1,60 @@
package appeng.items.tools.powered;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.util.AEColor;
import appeng.bootstrap.IItemRendering;
import appeng.bootstrap.ItemRenderingCustomizer;
import appeng.client.render.model.ColorApplicatorModel;
import appeng.core.AppEng;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ToolColorApplicatorRendering extends ItemRenderingCustomizer
{
public class ToolColorApplicatorRendering extends ItemRenderingCustomizer {
private static final ModelResourceLocation MODEL_COLORED = new ModelResourceLocation( new ResourceLocation( AppEng.MOD_ID, "builtin/color_applicator_colored" ), "inventory" );
private static final ModelResourceLocation MODEL_UNCOLORED = new ModelResourceLocation( new ResourceLocation( AppEng.MOD_ID, "color_applicator_uncolored" ), "inventory" );
private static final ModelResourceLocation MODEL_COLORED = new ModelResourceLocation(new ResourceLocation(AppEng.MOD_ID, "builtin/color_applicator_colored"), "inventory");
private static final ModelResourceLocation MODEL_UNCOLORED = new ModelResourceLocation(new ResourceLocation(AppEng.MOD_ID, "color_applicator_uncolored"), "inventory");
@Override
@SideOnly( Side.CLIENT )
public void customize( IItemRendering rendering )
{
rendering.builtInModel( "models/item/builtin/color_applicator_colored", new ColorApplicatorModel() );
rendering.variants( MODEL_COLORED, MODEL_UNCOLORED );
rendering.color( this::getColor );
rendering.meshDefinition( this::getMesh );
}
@Override
@SideOnly(Side.CLIENT)
public void customize(IItemRendering rendering) {
rendering.builtInModel("models/item/builtin/color_applicator_colored", new ColorApplicatorModel());
rendering.variants(MODEL_COLORED, MODEL_UNCOLORED);
rendering.color(this::getColor);
rendering.meshDefinition(this::getMesh);
}
private ModelResourceLocation getMesh( ItemStack itemStack )
{
// If the stack has no color, don't use the colored model since the impact of calling getColor for every quad is
// extremely high,
// if the stack tries to re-search its inventory for a new paintball everytime
AEColor col = ( (ToolColorApplicator) itemStack.getItem() ).getActiveColor( itemStack );
return ( col != null ) ? MODEL_COLORED : MODEL_UNCOLORED;
}
private ModelResourceLocation getMesh(ItemStack itemStack) {
// If the stack has no color, don't use the colored model since the impact of calling getColor for every quad is
// extremely high,
// if the stack tries to re-search its inventory for a new paintball everytime
AEColor col = ((ToolColorApplicator) itemStack.getItem()).getActiveColor(itemStack);
return (col != null) ? MODEL_COLORED : MODEL_UNCOLORED;
}
private int getColor( ItemStack itemStack, int idx )
{
if( idx == 0 )
{
return -1;
}
private int getColor(ItemStack itemStack, int idx) {
if (idx == 0) {
return -1;
}
final AEColor col = ( (ToolColorApplicator) itemStack.getItem() ).getActiveColor( itemStack );
final AEColor col = ((ToolColorApplicator) itemStack.getItem()).getActiveColor(itemStack);
if( col == null )
{
return -1;
}
if (col == null) {
return -1;
}
switch( idx )
{
case 1:
return col.blackVariant;
case 2:
return col.mediumVariant;
case 3:
return col.whiteVariant;
default:
return -1;
}
}
switch (idx) {
case 1:
return col.blackVariant;
case 2:
return col.mediumVariant;
case 3:
return col.whiteVariant;
default:
return -1;
}
}
}
@@ -19,11 +19,14 @@
package appeng.items.tools.powered;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import appeng.api.config.Actionable;
import appeng.api.util.DimensionalCoord;
import appeng.block.misc.BlockTinyTNT;
import appeng.core.AEConfig;
import appeng.hooks.IBlockTool;
import appeng.items.tools.powered.powersink.AEBasePoweredItem;
import appeng.util.InWorldToolOperationResult;
import appeng.util.Platform;
import net.minecraft.block.Block;
import net.minecraft.block.BlockTNT;
import net.minecraft.block.material.Material;
@@ -36,333 +39,265 @@ import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import appeng.api.config.Actionable;
import appeng.api.util.DimensionalCoord;
import appeng.block.misc.BlockTinyTNT;
import appeng.core.AEConfig;
import appeng.hooks.IBlockTool;
import appeng.items.tools.powered.powersink.AEBasePoweredItem;
import appeng.util.InWorldToolOperationResult;
import appeng.util.Platform;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockTool
{
private final Map<InWorldToolOperationIngredient, InWorldToolOperationResult> heatUp;
private final Map<InWorldToolOperationIngredient, InWorldToolOperationResult> coolDown;
public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockTool {
private final Map<InWorldToolOperationIngredient, InWorldToolOperationResult> heatUp;
private final Map<InWorldToolOperationIngredient, InWorldToolOperationResult> coolDown;
public ToolEntropyManipulator()
{
super( AEConfig.instance().getEntropyManipulatorBattery() );
public ToolEntropyManipulator() {
super(AEConfig.instance().getEntropyManipulatorBattery());
this.heatUp = new HashMap<>();
this.coolDown = new HashMap<>();
this.heatUp = new HashMap<>();
this.coolDown = new HashMap<>();
this.coolDown.put( new InWorldToolOperationIngredient( Blocks.STONE.getDefaultState() ),
new InWorldToolOperationResult( Blocks.COBBLESTONE.getDefaultState() ) );
this.coolDown.put( new InWorldToolOperationIngredient( Blocks.STONEBRICK.getDefaultState() ),
new InWorldToolOperationResult( Blocks.STONEBRICK.getStateFromMeta( 2 ) ) );
this.coolDown.put( new InWorldToolOperationIngredient( Blocks.LAVA, true ), new InWorldToolOperationResult( Blocks.OBSIDIAN.getDefaultState() ) );
this.coolDown.put( new InWorldToolOperationIngredient( Blocks.FLOWING_LAVA, true ),
new InWorldToolOperationResult( Blocks.OBSIDIAN.getDefaultState() ) );
this.coolDown.put( new InWorldToolOperationIngredient( Blocks.GRASS, true ), new InWorldToolOperationResult( Blocks.DIRT.getDefaultState() ) );
this.coolDown.put(new InWorldToolOperationIngredient(Blocks.STONE.getDefaultState()),
new InWorldToolOperationResult(Blocks.COBBLESTONE.getDefaultState()));
this.coolDown.put(new InWorldToolOperationIngredient(Blocks.STONEBRICK.getDefaultState()),
new InWorldToolOperationResult(Blocks.STONEBRICK.getStateFromMeta(2)));
this.coolDown.put(new InWorldToolOperationIngredient(Blocks.LAVA, true), new InWorldToolOperationResult(Blocks.OBSIDIAN.getDefaultState()));
this.coolDown.put(new InWorldToolOperationIngredient(Blocks.FLOWING_LAVA, true),
new InWorldToolOperationResult(Blocks.OBSIDIAN.getDefaultState()));
this.coolDown.put(new InWorldToolOperationIngredient(Blocks.GRASS, true), new InWorldToolOperationResult(Blocks.DIRT.getDefaultState()));
final List<ItemStack> snowBalls = new ArrayList<>();
snowBalls.add( new ItemStack( Items.SNOWBALL ) );
this.coolDown.put( new InWorldToolOperationIngredient( Blocks.FLOWING_WATER, true ), new InWorldToolOperationResult( null, snowBalls ) );
this.coolDown.put( new InWorldToolOperationIngredient( Blocks.WATER, true ), new InWorldToolOperationResult( Blocks.ICE.getDefaultState() ) );
final List<ItemStack> snowBalls = new ArrayList<>();
snowBalls.add(new ItemStack(Items.SNOWBALL));
this.coolDown.put(new InWorldToolOperationIngredient(Blocks.FLOWING_WATER, true), new InWorldToolOperationResult(null, snowBalls));
this.coolDown.put(new InWorldToolOperationIngredient(Blocks.WATER, true), new InWorldToolOperationResult(Blocks.ICE.getDefaultState()));
this.heatUp.put( new InWorldToolOperationIngredient( Blocks.ICE.getDefaultState() ), new InWorldToolOperationResult( Blocks.WATER.getDefaultState() ) );
this.heatUp.put( new InWorldToolOperationIngredient( Blocks.FLOWING_WATER, true ), new InWorldToolOperationResult() );
this.heatUp.put( new InWorldToolOperationIngredient( Blocks.WATER, true ), new InWorldToolOperationResult() );
this.heatUp.put( new InWorldToolOperationIngredient( Blocks.SNOW, true ),
new InWorldToolOperationResult( Blocks.FLOWING_WATER.getStateFromMeta( 7 ) ) );
}
this.heatUp.put(new InWorldToolOperationIngredient(Blocks.ICE.getDefaultState()), new InWorldToolOperationResult(Blocks.WATER.getDefaultState()));
this.heatUp.put(new InWorldToolOperationIngredient(Blocks.FLOWING_WATER, true), new InWorldToolOperationResult());
this.heatUp.put(new InWorldToolOperationIngredient(Blocks.WATER, true), new InWorldToolOperationResult());
this.heatUp.put(new InWorldToolOperationIngredient(Blocks.SNOW, true),
new InWorldToolOperationResult(Blocks.FLOWING_WATER.getStateFromMeta(7)));
}
private static class InWorldToolOperationIngredient
{
private final IBlockState state;
private final boolean blockOnly;
private static class InWorldToolOperationIngredient {
private final IBlockState state;
private final boolean blockOnly;
public InWorldToolOperationIngredient( final IBlockState state )
{
this.state = state;
this.blockOnly = false;
}
public InWorldToolOperationIngredient(final IBlockState state) {
this.state = state;
this.blockOnly = false;
}
public InWorldToolOperationIngredient( final Block blk, final boolean b )
{
this.state = blk.getDefaultState();
this.blockOnly = b;
}
public InWorldToolOperationIngredient(final Block blk, final boolean b) {
this.state = blk.getDefaultState();
this.blockOnly = b;
}
@Override
public int hashCode()
{
return this.state.getBlock().hashCode();
}
@Override
public int hashCode() {
return this.state.getBlock().hashCode();
}
@Override
public boolean equals( final Object obj )
{
if( obj == null )
{
return false;
}
if( this.getClass() != obj.getClass() )
{
return false;
}
final InWorldToolOperationIngredient other = (InWorldToolOperationIngredient) obj;
return this.state == other.state && ( this.blockOnly && this.state.getBlock() == other.state.getBlock() );
}
}
@Override
public boolean equals(final Object obj) {
if (obj == null) {
return false;
}
if (this.getClass() != obj.getClass()) {
return false;
}
final InWorldToolOperationIngredient other = (InWorldToolOperationIngredient) obj;
return this.state == other.state && (this.blockOnly && this.state.getBlock() == other.state.getBlock());
}
}
private void heat( final IBlockState state, final World w, final BlockPos pos )
{
InWorldToolOperationResult r = this.heatUp.get( new InWorldToolOperationIngredient( state ) );
private void heat(final IBlockState state, final World w, final BlockPos pos) {
InWorldToolOperationResult r = this.heatUp.get(new InWorldToolOperationIngredient(state));
if( r == null )
{
r = this.heatUp.get( new InWorldToolOperationIngredient( state.getBlock(), true ) );
}
if (r == null) {
r = this.heatUp.get(new InWorldToolOperationIngredient(state.getBlock(), true));
}
if( r.getBlockState() != null )
{
w.setBlockState( pos, r.getBlockState(), 3 );
}
else
{
w.setBlockToAir( pos );
}
if (r.getBlockState() != null) {
w.setBlockState(pos, r.getBlockState(), 3);
} else {
w.setBlockToAir(pos);
}
if( r.getDrops() != null )
{
Platform.spawnDrops( w, pos, r.getDrops() );
}
}
if (r.getDrops() != null) {
Platform.spawnDrops(w, pos, r.getDrops());
}
}
private boolean canHeat( final IBlockState state )
{
InWorldToolOperationResult r = this.heatUp.get( new InWorldToolOperationIngredient( state ) );
private boolean canHeat(final IBlockState state) {
InWorldToolOperationResult r = this.heatUp.get(new InWorldToolOperationIngredient(state));
if( r == null )
{
r = this.heatUp.get( new InWorldToolOperationIngredient( state.getBlock(), true ) );
}
if (r == null) {
r = this.heatUp.get(new InWorldToolOperationIngredient(state.getBlock(), true));
}
return r != null;
}
return r != null;
}
private void cool( final IBlockState state, final World w, final BlockPos pos )
{
InWorldToolOperationResult r = this.coolDown.get( new InWorldToolOperationIngredient( state ) );
private void cool(final IBlockState state, final World w, final BlockPos pos) {
InWorldToolOperationResult r = this.coolDown.get(new InWorldToolOperationIngredient(state));
if( r == null )
{
r = this.coolDown.get( new InWorldToolOperationIngredient( state.getBlock(), true ) );
}
if (r == null) {
r = this.coolDown.get(new InWorldToolOperationIngredient(state.getBlock(), true));
}
if( r.getBlockState() != null )
{
w.setBlockState( pos, r.getBlockState(), 3 );
}
else
{
w.setBlockToAir( pos );
}
if (r.getBlockState() != null) {
w.setBlockState(pos, r.getBlockState(), 3);
} else {
w.setBlockToAir(pos);
}
if( r.getDrops() != null )
{
Platform.spawnDrops( w, pos, r.getDrops() );
}
}
if (r.getDrops() != null) {
Platform.spawnDrops(w, pos, r.getDrops());
}
}
private boolean canCool( final IBlockState state )
{
InWorldToolOperationResult r = this.coolDown.get( new InWorldToolOperationIngredient( state ) );
private boolean canCool(final IBlockState state) {
InWorldToolOperationResult r = this.coolDown.get(new InWorldToolOperationIngredient(state));
if( r == null )
{
r = this.coolDown.get( new InWorldToolOperationIngredient( state.getBlock(), true ) );
}
if (r == null) {
r = this.coolDown.get(new InWorldToolOperationIngredient(state.getBlock(), true));
}
return r != null;
}
return r != null;
}
@Override
public boolean hitEntity( final ItemStack item, final EntityLivingBase target, final EntityLivingBase hitter )
{
if( this.getAECurrentPower( item ) > 1600 )
{
this.extractAEPower( item, 1600, Actionable.MODULATE );
target.setFire( 8 );
}
@Override
public boolean hitEntity(final ItemStack item, final EntityLivingBase target, final EntityLivingBase hitter) {
if (this.getAECurrentPower(item) > 1600) {
this.extractAEPower(item, 1600, Actionable.MODULATE);
target.setFire(8);
}
return false;
}
return false;
}
@Override
public ActionResult<ItemStack> onItemRightClick( final World w, final EntityPlayer p, final EnumHand hand )
{
final RayTraceResult target = this.rayTrace( w, p, true );
@Override
public ActionResult<ItemStack> onItemRightClick(final World w, final EntityPlayer p, final EnumHand hand) {
final RayTraceResult target = this.rayTrace(w, p, true);
if( target == null )
{
return new ActionResult<>( EnumActionResult.FAIL, p.getHeldItem( hand ) );
}
else
{
if( target.typeOfHit == RayTraceResult.Type.BLOCK )
{
final IBlockState state = w.getBlockState( target.getBlockPos() );
if( state.getMaterial() == Material.LAVA || state.getMaterial() == Material.WATER )
{
if( Platform.hasPermissions( new DimensionalCoord( w, target.getBlockPos() ), p ) )
{
this.onItemUse( p, w, target.getBlockPos(), hand, EnumFacing.UP, 0.0F, 0.0F, 0.0F );
}
}
}
}
if (target == null) {
return new ActionResult<>(EnumActionResult.FAIL, p.getHeldItem(hand));
} else {
if (target.typeOfHit == RayTraceResult.Type.BLOCK) {
final IBlockState state = w.getBlockState(target.getBlockPos());
if (state.getMaterial() == Material.LAVA || state.getMaterial() == Material.WATER) {
if (Platform.hasPermissions(new DimensionalCoord(w, target.getBlockPos()), p)) {
this.onItemUse(p, w, target.getBlockPos(), hand, EnumFacing.UP, 0.0F, 0.0F, 0.0F);
}
}
}
}
return new ActionResult<>( EnumActionResult.SUCCESS, p.getHeldItem( hand ) );
}
return new ActionResult<>(EnumActionResult.SUCCESS, p.getHeldItem(hand));
}
@Override
public EnumActionResult onItemUse( EntityPlayer p, World w, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ )
{
return this.onItemUse( p.getHeldItem( hand ), p, w, pos, hand, side, hitX, hitY, hitZ );
}
@Override
public EnumActionResult onItemUse(EntityPlayer p, World w, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
return this.onItemUse(p.getHeldItem(hand), p, w, pos, hand, side, hitX, hitY, hitZ);
}
@Override
public EnumActionResult onItemUse( ItemStack item, EntityPlayer p, World w, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ )
{
if( this.getAECurrentPower( item ) > 1600 )
{
if( !p.canPlayerEdit( pos, side, item ) )
{
return EnumActionResult.FAIL;
}
@Override
public EnumActionResult onItemUse(ItemStack item, EntityPlayer p, World w, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (this.getAECurrentPower(item) > 1600) {
if (!p.canPlayerEdit(pos, side, item)) {
return EnumActionResult.FAIL;
}
final IBlockState state = w.getBlockState( pos );
final Block blockID = state.getBlock();
final IBlockState state = w.getBlockState(pos);
final Block blockID = state.getBlock();
if( p.isSneaking() )
{
if( this.canCool( state ) )
{
this.extractAEPower( item, 1600, Actionable.MODULATE );
this.cool( state, w, pos );
return EnumActionResult.SUCCESS;
}
}
else
{
if( blockID instanceof BlockTNT )
{
w.setBlockToAir( pos );
( (BlockTNT) blockID ).explode( w, pos, state, p );
return EnumActionResult.SUCCESS;
}
if (p.isSneaking()) {
if (this.canCool(state)) {
this.extractAEPower(item, 1600, Actionable.MODULATE);
this.cool(state, w, pos);
return EnumActionResult.SUCCESS;
}
} else {
if (blockID instanceof BlockTNT) {
w.setBlockToAir(pos);
((BlockTNT) blockID).explode(w, pos, state, p);
return EnumActionResult.SUCCESS;
}
if( blockID instanceof BlockTinyTNT )
{
w.setBlockToAir( pos );
( (BlockTinyTNT) blockID ).startFuse( w, pos, p );
return EnumActionResult.SUCCESS;
}
if (blockID instanceof BlockTinyTNT) {
w.setBlockToAir(pos);
((BlockTinyTNT) blockID).startFuse(w, pos, p);
return EnumActionResult.SUCCESS;
}
if( this.canHeat( state ) )
{
this.extractAEPower( item, 1600, Actionable.MODULATE );
this.heat( state, w, pos );
return EnumActionResult.SUCCESS;
}
if (this.canHeat(state)) {
this.extractAEPower(item, 1600, Actionable.MODULATE);
this.heat(state, w, pos);
return EnumActionResult.SUCCESS;
}
final ItemStack[] stack = Platform.getBlockDrops( w, pos );
final List<ItemStack> out = new ArrayList<>();
boolean hasFurnaceable = false;
boolean canFurnaceable = true;
final ItemStack[] stack = Platform.getBlockDrops(w, pos);
final List<ItemStack> out = new ArrayList<>();
boolean hasFurnaceable = false;
boolean canFurnaceable = true;
for( final ItemStack i : stack )
{
final ItemStack result = FurnaceRecipes.instance().getSmeltingResult( i );
for (final ItemStack i : stack) {
final ItemStack result = FurnaceRecipes.instance().getSmeltingResult(i);
if( !result.isEmpty() )
{
if( result.getItem() instanceof ItemBlock )
{
if( Block.getBlockFromItem( result.getItem() ) == blockID && result.getItem().getDamage( result ) == blockID
.getMetaFromState( state ) )
{
canFurnaceable = false;
}
}
hasFurnaceable = true;
out.add( result );
}
else
{
canFurnaceable = false;
out.add( i );
}
}
if (!result.isEmpty()) {
if (result.getItem() instanceof ItemBlock) {
if (Block.getBlockFromItem(result.getItem()) == blockID && result.getItem().getDamage(result) == blockID
.getMetaFromState(state)) {
canFurnaceable = false;
}
}
hasFurnaceable = true;
out.add(result);
} else {
canFurnaceable = false;
out.add(i);
}
}
if( hasFurnaceable && canFurnaceable )
{
this.extractAEPower( item, 1600, Actionable.MODULATE );
final InWorldToolOperationResult or = InWorldToolOperationResult.getBlockOperationResult( out.toArray( new ItemStack[out.size()] ) );
w.playSound( p, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, SoundEvents.ITEM_FLINTANDSTEEL_USE, SoundCategory.PLAYERS, 1.0F,
itemRand.nextFloat() * 0.4F + 0.8F );
if (hasFurnaceable && canFurnaceable) {
this.extractAEPower(item, 1600, Actionable.MODULATE);
final InWorldToolOperationResult or = InWorldToolOperationResult.getBlockOperationResult(out.toArray(new ItemStack[out.size()]));
w.playSound(p, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, SoundEvents.ITEM_FLINTANDSTEEL_USE, SoundCategory.PLAYERS, 1.0F,
itemRand.nextFloat() * 0.4F + 0.8F);
if( or.getBlockState() == null )
{
w.setBlockState( pos, Platform.AIR_BLOCK.getDefaultState(), 3 );
}
else
{
w.setBlockState( pos, or.getBlockState(), 3 );
}
if (or.getBlockState() == null) {
w.setBlockState(pos, Platform.AIR_BLOCK.getDefaultState(), 3);
} else {
w.setBlockState(pos, or.getBlockState(), 3);
}
if( or.getDrops() != null )
{
Platform.spawnDrops( w, pos, or.getDrops() );
}
if (or.getDrops() != null) {
Platform.spawnDrops(w, pos, or.getDrops());
}
return EnumActionResult.SUCCESS;
}
else
{
final BlockPos offsetPos = pos.offset( side );
return EnumActionResult.SUCCESS;
} else {
final BlockPos offsetPos = pos.offset(side);
if( !p.canPlayerEdit( offsetPos, side, item ) )
{
return EnumActionResult.FAIL;
}
if (!p.canPlayerEdit(offsetPos, side, item)) {
return EnumActionResult.FAIL;
}
if( w.isAirBlock( offsetPos ) )
{
this.extractAEPower( item, 1600, Actionable.MODULATE );
w.playSound( p, offsetPos.getX() + 0.5D, offsetPos.getY() + 0.5D, offsetPos.getZ() + 0.5D, SoundEvents.ITEM_FLINTANDSTEEL_USE,
SoundCategory.PLAYERS, 1.0F, itemRand.nextFloat() * 0.4F + 0.8F );
w.setBlockState( offsetPos, Blocks.FIRE.getDefaultState() );
}
if (w.isAirBlock(offsetPos)) {
this.extractAEPower(item, 1600, Actionable.MODULATE);
w.playSound(p, offsetPos.getX() + 0.5D, offsetPos.getY() + 0.5D, offsetPos.getZ() + 0.5D, SoundEvents.ITEM_FLINTANDSTEEL_USE,
SoundCategory.PLAYERS, 1.0F, itemRand.nextFloat() * 0.4F + 0.8F);
w.setBlockState(offsetPos, Blocks.FIRE.getDefaultState());
}
return EnumActionResult.SUCCESS;
}
}
}
return EnumActionResult.SUCCESS;
}
}
}
return EnumActionResult.PASS;
}
return EnumActionResult.PASS;
}
}
@@ -19,34 +19,6 @@
package appeng.items.tools.powered;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.util.ITooltipFlag;
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.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode;
@@ -76,459 +48,390 @@ import appeng.me.helpers.PlayerSource;
import appeng.tile.misc.TilePaint;
import appeng.util.LookDirection;
import appeng.util.Platform;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.util.ITooltipFlag;
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.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.*;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import javax.annotation.Nullable;
import java.util.List;
public class ToolMatterCannon extends AEBasePoweredItem implements IStorageCell<IAEItemStack>
{
public class ToolMatterCannon extends AEBasePoweredItem implements IStorageCell<IAEItemStack> {
public ToolMatterCannon()
{
super( AEConfig.instance().getMatterCannonBattery() );
}
public ToolMatterCannon() {
super(AEConfig.instance().getMatterCannonBattery());
}
@SideOnly( Side.CLIENT )
@Override
public void addCheckedInformation( final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips )
{
super.addCheckedInformation( stack, world, lines, advancedTooltips );
@SideOnly(Side.CLIENT)
@Override
public void addCheckedInformation(final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips) {
super.addCheckedInformation(stack, world, lines, advancedTooltips);
final ICellInventoryHandler<IAEItemStack> cdi = AEApi.instance()
.registries()
.cell()
.getCellInventory( stack, null,
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
final ICellInventoryHandler<IAEItemStack> cdi = AEApi.instance()
.registries()
.cell()
.getCellInventory(stack, null,
AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
AEApi.instance().client().addCellInformation( cdi, lines );
}
AEApi.instance().client().addCellInformation(cdi, lines);
}
@Override
public ActionResult<ItemStack> onItemRightClick( final World w, final EntityPlayer p, final @Nullable EnumHand hand )
{
if( this.getAECurrentPower( p.getHeldItem( hand ) ) > 1600 )
{
int shots = 1;
@Override
public ActionResult<ItemStack> onItemRightClick(final World w, final EntityPlayer p, final @Nullable EnumHand hand) {
if (this.getAECurrentPower(p.getHeldItem(hand)) > 1600) {
int shots = 1;
final CellUpgrades cu = (CellUpgrades) this.getUpgradesInventory( p.getHeldItem( hand ) );
if( cu != null )
{
shots += cu.getInstalledUpgrades( Upgrades.SPEED );
}
final CellUpgrades cu = (CellUpgrades) this.getUpgradesInventory(p.getHeldItem(hand));
if (cu != null) {
shots += cu.getInstalledUpgrades(Upgrades.SPEED);
}
final ICellInventoryHandler<IAEItemStack> inv = AEApi.instance()
.registries()
.cell()
.getCellInventory( p.getHeldItem( hand ), null,
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
if( inv != null )
{
final IItemList<IAEItemStack> itemList = inv
.getAvailableItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList() );
IAEItemStack req = itemList.getFirstItem();
if( req instanceof IAEItemStack )
{
shots = Math.min( shots, (int) req.getStackSize() );
for( int sh = 0; sh < shots; sh++ )
{
IAEItemStack aeAmmo = req.copy();
this.extractAEPower( p.getHeldItem( hand ), 1600, Actionable.MODULATE );
final ICellInventoryHandler<IAEItemStack> inv = AEApi.instance()
.registries()
.cell()
.getCellInventory(p.getHeldItem(hand), null,
AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
if (inv != null) {
final IItemList<IAEItemStack> itemList = inv
.getAvailableItems(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList());
IAEItemStack req = itemList.getFirstItem();
if (req instanceof IAEItemStack) {
shots = Math.min(shots, (int) req.getStackSize());
for (int sh = 0; sh < shots; sh++) {
IAEItemStack aeAmmo = req.copy();
this.extractAEPower(p.getHeldItem(hand), 1600, Actionable.MODULATE);
if( Platform.isClient() )
{
return new ActionResult<>( EnumActionResult.SUCCESS, p.getHeldItem( hand ) );
}
if (Platform.isClient()) {
return new ActionResult<>(EnumActionResult.SUCCESS, p.getHeldItem(hand));
}
aeAmmo.setStackSize( 1 );
final ItemStack ammo = aeAmmo.createItemStack();
if( ammo == null )
{
return new ActionResult<>( EnumActionResult.SUCCESS, p.getHeldItem( hand ) );
}
aeAmmo.setStackSize(1);
final ItemStack ammo = aeAmmo.createItemStack();
if (ammo == null) {
return new ActionResult<>(EnumActionResult.SUCCESS, p.getHeldItem(hand));
}
aeAmmo = inv.extractItems( aeAmmo, Actionable.MODULATE, new PlayerSource( p, null ) );
if( aeAmmo == null )
{
return new ActionResult<>( EnumActionResult.SUCCESS, p.getHeldItem( hand ) );
}
aeAmmo = inv.extractItems(aeAmmo, Actionable.MODULATE, new PlayerSource(p, null));
if (aeAmmo == null) {
return new ActionResult<>(EnumActionResult.SUCCESS, p.getHeldItem(hand));
}
final LookDirection dir = Platform.getPlayerRay( p, p.getEyeHeight() );
final LookDirection dir = Platform.getPlayerRay(p, p.getEyeHeight());
final Vec3d Vec3d = dir.getA();
final Vec3d Vec3d1 = dir.getB();
final Vec3d direction = Vec3d1.subtract( Vec3d );
direction.normalize();
final Vec3d Vec3d = dir.getA();
final Vec3d Vec3d1 = dir.getB();
final Vec3d direction = Vec3d1.subtract(Vec3d);
direction.normalize();
final double d0 = Vec3d.x;
final double d1 = Vec3d.y;
final double d2 = Vec3d.z;
final double d0 = Vec3d.x;
final double d1 = Vec3d.y;
final double d2 = Vec3d.z;
final float penetration = AEApi.instance().registries().matterCannon().getPenetration( ammo ); // 196.96655f;
if( penetration <= 0 )
{
final ItemStack type = aeAmmo.asItemStackRepresentation();
if( type.getItem() instanceof ItemPaintBall )
{
this.shootPaintBalls( type, w, p, Vec3d, Vec3d1, direction, d0, d1, d2 );
}
return new ActionResult<>( EnumActionResult.SUCCESS, p.getHeldItem( hand ) );
}
else
{
this.standardAmmo( penetration, w, p, Vec3d, Vec3d1, direction, d0, d1, d2 );
}
}
}
else
{
if( Platform.isServer() )
{
p.sendMessage( PlayerMessages.AmmoDepleted.get() );
}
return new ActionResult<>( EnumActionResult.SUCCESS, p.getHeldItem( hand ) );
}
}
}
return new ActionResult<>( EnumActionResult.FAIL, p.getHeldItem( hand ) );
}
final float penetration = AEApi.instance().registries().matterCannon().getPenetration(ammo); // 196.96655f;
if (penetration <= 0) {
final ItemStack type = aeAmmo.asItemStackRepresentation();
if (type.getItem() instanceof ItemPaintBall) {
this.shootPaintBalls(type, w, p, Vec3d, Vec3d1, direction, d0, d1, d2);
}
return new ActionResult<>(EnumActionResult.SUCCESS, p.getHeldItem(hand));
} else {
this.standardAmmo(penetration, w, p, Vec3d, Vec3d1, direction, d0, d1, d2);
}
}
} else {
if (Platform.isServer()) {
p.sendMessage(PlayerMessages.AmmoDepleted.get());
}
return new ActionResult<>(EnumActionResult.SUCCESS, p.getHeldItem(hand));
}
}
}
return new ActionResult<>(EnumActionResult.FAIL, p.getHeldItem(hand));
}
private void shootPaintBalls( final ItemStack type, final World w, final EntityPlayer p, final Vec3d Vec3d, final Vec3d Vec3d1, final Vec3d direction, final double d0, final double d1, final double d2 )
{
final AxisAlignedBB bb = new AxisAlignedBB( Math.min( Vec3d.x, Vec3d1.x ), Math.min( Vec3d.y, Vec3d1.y ), Math.min( Vec3d.z, Vec3d1.z ), Math
.max( Vec3d.x, Vec3d1.x ), Math.max( Vec3d.y, Vec3d1.y ), Math.max( Vec3d.z, Vec3d1.z ) ).grow( 16, 16, 16 );
private void shootPaintBalls(final ItemStack type, final World w, final EntityPlayer p, final Vec3d Vec3d, final Vec3d Vec3d1, final Vec3d direction, final double d0, final double d1, final double d2) {
final AxisAlignedBB bb = new AxisAlignedBB(Math.min(Vec3d.x, Vec3d1.x), Math.min(Vec3d.y, Vec3d1.y), Math.min(Vec3d.z, Vec3d1.z), Math
.max(Vec3d.x, Vec3d1.x), Math.max(Vec3d.y, Vec3d1.y), Math.max(Vec3d.z, Vec3d1.z)).grow(16, 16, 16);
Entity entity = null;
final List list = w.getEntitiesWithinAABBExcludingEntity( p, bb );
double closest = 9999999.0D;
Entity entity = null;
final List list = w.getEntitiesWithinAABBExcludingEntity(p, bb);
double closest = 9999999.0D;
for( int l = 0; l < list.size(); ++l )
{
final Entity entity1 = (Entity) list.get( l );
for (int l = 0; l < list.size(); ++l) {
final Entity entity1 = (Entity) list.get(l);
if( !entity1.isDead && entity1 != p && !( entity1 instanceof EntityItem ) )
{
if( entity1.isEntityAlive() )
{
// prevent killing / flying of mounts.
if( entity1.isRidingOrBeingRiddenBy( p ) )
{
continue;
}
if (!entity1.isDead && entity1 != p && !(entity1 instanceof EntityItem)) {
if (entity1.isEntityAlive()) {
// prevent killing / flying of mounts.
if (entity1.isRidingOrBeingRiddenBy(p)) {
continue;
}
final float f1 = 0.3F;
final float f1 = 0.3F;
final AxisAlignedBB boundingBox = entity1.getEntityBoundingBox().grow( f1, f1, f1 );
final RayTraceResult RayTraceResult = boundingBox.calculateIntercept( Vec3d, Vec3d1 );
final AxisAlignedBB boundingBox = entity1.getEntityBoundingBox().grow(f1, f1, f1);
final RayTraceResult RayTraceResult = boundingBox.calculateIntercept(Vec3d, Vec3d1);
if( RayTraceResult != null )
{
final double nd = Vec3d.squareDistanceTo( RayTraceResult.hitVec );
if (RayTraceResult != null) {
final double nd = Vec3d.squareDistanceTo(RayTraceResult.hitVec);
if( nd < closest )
{
entity = entity1;
closest = nd;
}
}
}
}
}
if (nd < closest) {
entity = entity1;
closest = nd;
}
}
}
}
}
RayTraceResult pos = w.rayTraceBlocks( Vec3d, Vec3d1, false );
RayTraceResult pos = w.rayTraceBlocks(Vec3d, Vec3d1, false);
final Vec3d vec = new Vec3d( d0, d1, d2 );
if( entity != null && pos != null && pos.hitVec.squareDistanceTo( vec ) > closest )
{
pos = new RayTraceResult( entity );
}
else if( entity != null && pos == null )
{
pos = new RayTraceResult( entity );
}
final Vec3d vec = new Vec3d(d0, d1, d2);
if (entity != null && pos != null && pos.hitVec.squareDistanceTo(vec) > closest) {
pos = new RayTraceResult(entity);
} else if (entity != null && pos == null) {
pos = new RayTraceResult(entity);
}
try
{
AppEng.proxy.sendToAllNearExcept( null, d0, d1, d2, 128, w,
new PacketMatterCannon( d0, d1, d2, (float) direction.x, (float) direction.y, (float) direction.z, (byte) ( pos == null ? 32 : pos.hitVec
.squareDistanceTo( vec ) + 1 ) ) );
}
catch( final Exception err )
{
AELog.debug( err );
}
try {
AppEng.proxy.sendToAllNearExcept(null, d0, d1, d2, 128, w,
new PacketMatterCannon(d0, d1, d2, (float) direction.x, (float) direction.y, (float) direction.z, (byte) (pos == null ? 32 : pos.hitVec
.squareDistanceTo(vec) + 1)));
} catch (final Exception err) {
AELog.debug(err);
}
if( pos != null && type != null && type.getItem() instanceof ItemPaintBall )
{
final ItemPaintBall ipb = (ItemPaintBall) type.getItem();
if (pos != null && type != null && type.getItem() instanceof ItemPaintBall) {
final ItemPaintBall ipb = (ItemPaintBall) type.getItem();
final AEColor col = ipb.getColor( type );
// boolean lit = ipb.isLumen( type );
final AEColor col = ipb.getColor(type);
// boolean lit = ipb.isLumen( type );
if( pos.typeOfHit == RayTraceResult.Type.ENTITY )
{
final int id = pos.entityHit.getEntityId();
final PlayerColor marker = new PlayerColor( id, col, 20 * 30 );
TickHandler.INSTANCE.getPlayerColors().put( id, marker );
if (pos.typeOfHit == RayTraceResult.Type.ENTITY) {
final int id = pos.entityHit.getEntityId();
final PlayerColor marker = new PlayerColor(id, col, 20 * 30);
TickHandler.INSTANCE.getPlayerColors().put(id, marker);
if( pos.entityHit instanceof EntitySheep )
{
final EntitySheep sh = (EntitySheep) pos.entityHit;
sh.setFleeceColor( col.dye );
}
if (pos.entityHit instanceof EntitySheep) {
final EntitySheep sh = (EntitySheep) pos.entityHit;
sh.setFleeceColor(col.dye);
}
pos.entityHit.attackEntityFrom( DamageSource.causePlayerDamage( p ), 0 );
NetworkHandler.instance().sendToAll( marker.getPacket() );
}
else if( pos.typeOfHit == RayTraceResult.Type.BLOCK )
{
final EnumFacing side = pos.sideHit;
final BlockPos hitPos = pos.getBlockPos().offset( side );
pos.entityHit.attackEntityFrom(DamageSource.causePlayerDamage(p), 0);
NetworkHandler.instance().sendToAll(marker.getPacket());
} else if (pos.typeOfHit == RayTraceResult.Type.BLOCK) {
final EnumFacing side = pos.sideHit;
final BlockPos hitPos = pos.getBlockPos().offset(side);
if( !Platform.hasPermissions( new DimensionalCoord( w, hitPos ), p ) )
{
return;
}
if (!Platform.hasPermissions(new DimensionalCoord(w, hitPos), p)) {
return;
}
final Block whatsThere = w.getBlockState( hitPos ).getBlock();
if( whatsThere.isReplaceable( w, hitPos ) && w.isAirBlock( hitPos ) )
{
AEApi.instance().definitions().blocks().paint().maybeBlock().ifPresent( paintBlock ->
{
w.setBlockState( hitPos, paintBlock.getDefaultState(), 3 );
} );
}
final Block whatsThere = w.getBlockState(hitPos).getBlock();
if (whatsThere.isReplaceable(w, hitPos) && w.isAirBlock(hitPos)) {
AEApi.instance().definitions().blocks().paint().maybeBlock().ifPresent(paintBlock ->
{
w.setBlockState(hitPos, paintBlock.getDefaultState(), 3);
});
}
final TileEntity te = w.getTileEntity( hitPos );
if( te instanceof TilePaint )
{
final Vec3d hp = pos.hitVec.subtract( hitPos.getX(), hitPos.getY(), hitPos.getZ() );
( (TilePaint) te ).addBlot( type, side.getOpposite(), hp );
}
}
}
}
final TileEntity te = w.getTileEntity(hitPos);
if (te instanceof TilePaint) {
final Vec3d hp = pos.hitVec.subtract(hitPos.getX(), hitPos.getY(), hitPos.getZ());
((TilePaint) te).addBlot(type, side.getOpposite(), hp);
}
}
}
}
private void standardAmmo( float penetration, final World w, final EntityPlayer p, final Vec3d Vec3d, final Vec3d Vec3d1, final Vec3d direction, final double d0, final double d1, final double d2 )
{
boolean hasDestroyed = true;
while( penetration > 0 && hasDestroyed )
{
hasDestroyed = false;
private void standardAmmo(float penetration, final World w, final EntityPlayer p, final Vec3d Vec3d, final Vec3d Vec3d1, final Vec3d direction, final double d0, final double d1, final double d2) {
boolean hasDestroyed = true;
while (penetration > 0 && hasDestroyed) {
hasDestroyed = false;
final AxisAlignedBB bb = new AxisAlignedBB( Math.min( Vec3d.x, Vec3d1.x ), Math.min( Vec3d.y, Vec3d1.y ), Math.min( Vec3d.z, Vec3d1.z ), Math
.max( Vec3d.x, Vec3d1.x ), Math.max( Vec3d.y, Vec3d1.y ), Math.max( Vec3d.z, Vec3d1.z ) ).grow( 16, 16, 16 );
final AxisAlignedBB bb = new AxisAlignedBB(Math.min(Vec3d.x, Vec3d1.x), Math.min(Vec3d.y, Vec3d1.y), Math.min(Vec3d.z, Vec3d1.z), Math
.max(Vec3d.x, Vec3d1.x), Math.max(Vec3d.y, Vec3d1.y), Math.max(Vec3d.z, Vec3d1.z)).grow(16, 16, 16);
Entity entity = null;
final List list = w.getEntitiesWithinAABBExcludingEntity( p, bb );
double closest = 9999999.0D;
Entity entity = null;
final List list = w.getEntitiesWithinAABBExcludingEntity(p, bb);
double closest = 9999999.0D;
for( int l = 0; l < list.size(); ++l )
{
final Entity entity1 = (Entity) list.get( l );
for (int l = 0; l < list.size(); ++l) {
final Entity entity1 = (Entity) list.get(l);
if( !entity1.isDead && entity1 != p && !( entity1 instanceof EntityItem ) )
{
if( entity1.isEntityAlive() )
{
// prevent killing / flying of mounts.
if( entity1.isRidingOrBeingRiddenBy( p ) )
{
continue;
}
if (!entity1.isDead && entity1 != p && !(entity1 instanceof EntityItem)) {
if (entity1.isEntityAlive()) {
// prevent killing / flying of mounts.
if (entity1.isRidingOrBeingRiddenBy(p)) {
continue;
}
final float f1 = 0.3F;
final float f1 = 0.3F;
final AxisAlignedBB boundingBox = entity1.getEntityBoundingBox().grow( f1, f1, f1 );
final RayTraceResult RayTraceResult = boundingBox.calculateIntercept( Vec3d, Vec3d1 );
final AxisAlignedBB boundingBox = entity1.getEntityBoundingBox().grow(f1, f1, f1);
final RayTraceResult RayTraceResult = boundingBox.calculateIntercept(Vec3d, Vec3d1);
if( RayTraceResult != null )
{
final double nd = Vec3d.squareDistanceTo( RayTraceResult.hitVec );
if (RayTraceResult != null) {
final double nd = Vec3d.squareDistanceTo(RayTraceResult.hitVec);
if( nd < closest )
{
entity = entity1;
closest = nd;
}
}
}
}
}
if (nd < closest) {
entity = entity1;
closest = nd;
}
}
}
}
}
final Vec3d vec = new Vec3d( d0, d1, d2 );
RayTraceResult pos = w.rayTraceBlocks( Vec3d, Vec3d1, true );
if( entity != null && pos != null && pos.hitVec.squareDistanceTo( vec ) > closest )
{
pos = new RayTraceResult( entity );
}
else if( entity != null && pos == null )
{
pos = new RayTraceResult( entity );
}
final Vec3d vec = new Vec3d(d0, d1, d2);
RayTraceResult pos = w.rayTraceBlocks(Vec3d, Vec3d1, true);
if (entity != null && pos != null && pos.hitVec.squareDistanceTo(vec) > closest) {
pos = new RayTraceResult(entity);
} else if (entity != null && pos == null) {
pos = new RayTraceResult(entity);
}
try
{
AppEng.proxy.sendToAllNearExcept( null, d0, d1, d2, 128, w,
new PacketMatterCannon( d0, d1, d2, (float) direction.x, (float) direction.y, (float) direction.z, (byte) ( pos == null ? 32 : pos.hitVec
.squareDistanceTo( vec ) + 1 ) ) );
}
catch( final Exception err )
{
AELog.debug( err );
}
try {
AppEng.proxy.sendToAllNearExcept(null, d0, d1, d2, 128, w,
new PacketMatterCannon(d0, d1, d2, (float) direction.x, (float) direction.y, (float) direction.z, (byte) (pos == null ? 32 : pos.hitVec
.squareDistanceTo(vec) + 1)));
} catch (final Exception err) {
AELog.debug(err);
}
if( pos != null )
{
final DamageSource dmgSrc = DamageSource.causePlayerDamage( p );
dmgSrc.damageType = "matter_cannon";
if (pos != null) {
final DamageSource dmgSrc = DamageSource.causePlayerDamage(p);
dmgSrc.damageType = "matter_cannon";
if( pos.typeOfHit == RayTraceResult.Type.ENTITY )
{
final int dmg = (int) Math.ceil( penetration / 20.0f );
if( pos.entityHit instanceof EntityLivingBase )
{
final EntityLivingBase el = (EntityLivingBase) pos.entityHit;
penetration -= dmg;
el.knockBack( p, 0, -direction.x, -direction.z );
// el.knockBack( p, 0, Vec3d.x,
// Vec3d.z );
el.attackEntityFrom( dmgSrc, dmg );
if( !el.isEntityAlive() )
{
hasDestroyed = true;
}
}
else if( pos.entityHit instanceof EntityItem )
{
hasDestroyed = true;
pos.entityHit.setDead();
}
else if( pos.entityHit.attackEntityFrom( dmgSrc, dmg ) )
{
hasDestroyed = pos.entityHit.isEntityAlive();
}
}
else if( pos.typeOfHit == RayTraceResult.Type.BLOCK )
{
if( !AEConfig.instance().isFeatureEnabled( AEFeature.MASS_CANNON_BLOCK_DAMAGE ) )
{
penetration = 0;
}
else
{
final IBlockState bs = w.getBlockState( pos.getBlockPos() );
// int meta = w.getBlockMetadata(
// pos.blockX, pos.blockY, pos.blockZ );
if (pos.typeOfHit == RayTraceResult.Type.ENTITY) {
final int dmg = (int) Math.ceil(penetration / 20.0f);
if (pos.entityHit instanceof EntityLivingBase) {
final EntityLivingBase el = (EntityLivingBase) pos.entityHit;
penetration -= dmg;
el.knockBack(p, 0, -direction.x, -direction.z);
// el.knockBack( p, 0, Vec3d.x,
// Vec3d.z );
el.attackEntityFrom(dmgSrc, dmg);
if (!el.isEntityAlive()) {
hasDestroyed = true;
}
} else if (pos.entityHit instanceof EntityItem) {
hasDestroyed = true;
pos.entityHit.setDead();
} else if (pos.entityHit.attackEntityFrom(dmgSrc, dmg)) {
hasDestroyed = pos.entityHit.isEntityAlive();
}
} else if (pos.typeOfHit == RayTraceResult.Type.BLOCK) {
if (!AEConfig.instance().isFeatureEnabled(AEFeature.MASS_CANNON_BLOCK_DAMAGE)) {
penetration = 0;
} else {
final IBlockState bs = w.getBlockState(pos.getBlockPos());
// int meta = w.getBlockMetadata(
// pos.blockX, pos.blockY, pos.blockZ );
final float hardness = bs.getBlockHardness( w, pos.getBlockPos() ) * 9.0f;
if( hardness >= 0.0 )
{
if( penetration > hardness && Platform.hasPermissions( new DimensionalCoord( w, pos.getBlockPos() ), p ) )
{
hasDestroyed = true;
penetration -= hardness;
penetration *= 0.60;
w.destroyBlock( pos.getBlockPos(), true );
}
}
}
}
}
}
}
final float hardness = bs.getBlockHardness(w, pos.getBlockPos()) * 9.0f;
if (hardness >= 0.0) {
if (penetration > hardness && Platform.hasPermissions(new DimensionalCoord(w, pos.getBlockPos()), p)) {
hasDestroyed = true;
penetration -= hardness;
penetration *= 0.60;
w.destroyBlock(pos.getBlockPos(), true);
}
}
}
}
}
}
}
@Override
public boolean isEditable( final ItemStack is )
{
return true;
}
@Override
public boolean isEditable(final ItemStack is) {
return true;
}
@Override
public IItemHandler getUpgradesInventory( final ItemStack is )
{
return new CellUpgrades( is, 4 );
}
@Override
public IItemHandler getUpgradesInventory(final ItemStack is) {
return new CellUpgrades(is, 4);
}
@Override
public IItemHandler getConfigInventory( final ItemStack is )
{
return new CellConfig( is );
}
@Override
public IItemHandler getConfigInventory(final ItemStack is) {
return new CellConfig(is);
}
@Override
public FuzzyMode getFuzzyMode( final ItemStack is )
{
final String fz = Platform.openNbtData( is ).getString( "FuzzyMode" );
try
{
return FuzzyMode.valueOf( fz );
}
catch( final Throwable t )
{
return FuzzyMode.IGNORE_ALL;
}
}
@Override
public FuzzyMode getFuzzyMode(final ItemStack is) {
final String fz = Platform.openNbtData(is).getString("FuzzyMode");
try {
return FuzzyMode.valueOf(fz);
} catch (final Throwable t) {
return FuzzyMode.IGNORE_ALL;
}
}
@Override
public void setFuzzyMode( final ItemStack is, final FuzzyMode fzMode )
{
Platform.openNbtData( is ).setString( "FuzzyMode", fzMode.name() );
}
@Override
public void setFuzzyMode(final ItemStack is, final FuzzyMode fzMode) {
Platform.openNbtData(is).setString("FuzzyMode", fzMode.name());
}
@Override
public int getBytes( final ItemStack cellItem )
{
return 512;
}
@Override
public int getBytes(final ItemStack cellItem) {
return 512;
}
@Override
public int getBytesPerType( final ItemStack cellItem )
{
return 8;
}
@Override
public int getBytesPerType(final ItemStack cellItem) {
return 8;
}
@Override
public int getTotalTypes( final ItemStack cellItem )
{
return 1;
}
@Override
public int getTotalTypes(final ItemStack cellItem) {
return 1;
}
@Override
public boolean isBlackListed( final ItemStack cellItem, final IAEItemStack requestedAddition )
{
final float pen = AEApi.instance().registries().matterCannon().getPenetration( requestedAddition.createItemStack() );
if( pen > 0 )
{
return false;
}
@Override
public boolean isBlackListed(final ItemStack cellItem, final IAEItemStack requestedAddition) {
final float pen = AEApi.instance().registries().matterCannon().getPenetration(requestedAddition.createItemStack());
if (pen > 0) {
return false;
}
if( requestedAddition.getItem() instanceof ItemPaintBall )
{
return false;
}
return !(requestedAddition.getItem() instanceof ItemPaintBall);
}
return true;
}
@Override
public boolean storableInStorageCell() {
return true;
}
@Override
public boolean storableInStorageCell()
{
return true;
}
@Override
public boolean isStorageCell(final ItemStack i) {
return true;
}
@Override
public boolean isStorageCell( final ItemStack i )
{
return true;
}
@Override
public double getIdleDrain() {
return 0.5;
}
@Override
public double getIdleDrain()
{
return 0.5;
}
@Override
public IStorageChannel<IAEItemStack> getChannel()
{
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
}
@Override
public IStorageChannel<IAEItemStack> getChannel() {
return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class);
}
}
@@ -19,21 +19,6 @@
package appeng.items.tools.powered;
import java.util.List;
import java.util.Set;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.FuzzyMode;
import appeng.api.implementations.guiobjects.IGuiItem;
@@ -53,145 +38,135 @@ import appeng.items.contents.CellUpgrades;
import appeng.items.contents.PortableCellViewer;
import appeng.items.tools.powered.powersink.AEBasePoweredItem;
import appeng.util.Platform;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import java.util.List;
import java.util.Set;
public class ToolPortableCell extends AEBasePoweredItem implements IStorageCell<IAEItemStack>, IGuiItem, IItemGroup
{
public ToolPortableCell()
{
super( AEConfig.instance().getPortableCellBattery() );
}
public class ToolPortableCell extends AEBasePoweredItem implements IStorageCell<IAEItemStack>, IGuiItem, IItemGroup {
public ToolPortableCell() {
super(AEConfig.instance().getPortableCellBattery());
}
@Override
public ActionResult<ItemStack> onItemRightClick( final World w, final EntityPlayer player, final EnumHand hand )
{
Platform.openGUI( player, null, AEPartLocation.INTERNAL, GuiBridge.GUI_PORTABLE_CELL );
return new ActionResult<>( EnumActionResult.SUCCESS, player.getHeldItem( hand ) );
}
@Override
public ActionResult<ItemStack> onItemRightClick(final World w, final EntityPlayer player, final EnumHand hand) {
Platform.openGUI(player, null, AEPartLocation.INTERNAL, GuiBridge.GUI_PORTABLE_CELL);
return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
}
@SideOnly( Side.CLIENT )
@Override
public boolean isFull3D()
{
return false;
}
@SideOnly(Side.CLIENT)
@Override
public boolean isFull3D() {
return false;
}
@Override
@SideOnly( Side.CLIENT )
public void addCheckedInformation( final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips )
{
super.addCheckedInformation( stack, world, lines, advancedTooltips );
@Override
@SideOnly(Side.CLIENT)
public void addCheckedInformation(final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips) {
super.addCheckedInformation(stack, world, lines, advancedTooltips);
final ICellInventoryHandler<IAEItemStack> cdi = AEApi.instance()
.registries()
.cell()
.getCellInventory( stack, null,
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
final ICellInventoryHandler<IAEItemStack> cdi = AEApi.instance()
.registries()
.cell()
.getCellInventory(stack, null,
AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
AEApi.instance().client().addCellInformation( cdi, lines );
}
AEApi.instance().client().addCellInformation(cdi, lines);
}
@Override
public int getBytes( final ItemStack cellItem )
{
return 512;
}
@Override
public int getBytes(final ItemStack cellItem) {
return 512;
}
@Override
public int getBytesPerType( final ItemStack cellItem )
{
return 8;
}
@Override
public int getBytesPerType(final ItemStack cellItem) {
return 8;
}
@Override
public int getTotalTypes( final ItemStack cellItem )
{
return 27;
}
@Override
public int getTotalTypes(final ItemStack cellItem) {
return 27;
}
@Override
public boolean isBlackListed( final ItemStack cellItem, final IAEItemStack requestedAddition )
{
return false;
}
@Override
public boolean isBlackListed(final ItemStack cellItem, final IAEItemStack requestedAddition) {
return false;
}
@Override
public boolean storableInStorageCell()
{
return false;
}
@Override
public boolean storableInStorageCell() {
return false;
}
@Override
public boolean isStorageCell( final ItemStack i )
{
return true;
}
@Override
public boolean isStorageCell(final ItemStack i) {
return true;
}
@Override
public double getIdleDrain()
{
return 0.5;
}
@Override
public double getIdleDrain() {
return 0.5;
}
@Override
public IStorageChannel<IAEItemStack> getChannel()
{
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
}
@Override
public IStorageChannel<IAEItemStack> getChannel() {
return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class);
}
@Override
public String getUnlocalizedGroupName( final Set<ItemStack> others, final ItemStack is )
{
return GuiText.StorageCells.getUnlocalized();
}
@Override
public String getUnlocalizedGroupName(final Set<ItemStack> others, final ItemStack is) {
return GuiText.StorageCells.getUnlocalized();
}
@Override
public boolean isEditable( final ItemStack is )
{
return true;
}
@Override
public boolean isEditable(final ItemStack is) {
return true;
}
@Override
public IItemHandler getUpgradesInventory( final ItemStack is )
{
return new CellUpgrades( is, 2 );
}
@Override
public IItemHandler getUpgradesInventory(final ItemStack is) {
return new CellUpgrades(is, 2);
}
@Override
public IItemHandler getConfigInventory( final ItemStack is )
{
return new CellConfig( is );
}
@Override
public IItemHandler getConfigInventory(final ItemStack is) {
return new CellConfig(is);
}
@Override
public FuzzyMode getFuzzyMode( final ItemStack is )
{
final String fz = Platform.openNbtData( is ).getString( "FuzzyMode" );
try
{
return FuzzyMode.valueOf( fz );
}
catch( final Throwable t )
{
return FuzzyMode.IGNORE_ALL;
}
}
@Override
public FuzzyMode getFuzzyMode(final ItemStack is) {
final String fz = Platform.openNbtData(is).getString("FuzzyMode");
try {
return FuzzyMode.valueOf(fz);
} catch (final Throwable t) {
return FuzzyMode.IGNORE_ALL;
}
}
@Override
public void setFuzzyMode( final ItemStack is, final FuzzyMode fzMode )
{
Platform.openNbtData( is ).setString( "FuzzyMode", fzMode.name() );
}
@Override
public void setFuzzyMode(final ItemStack is, final FuzzyMode fzMode) {
Platform.openNbtData(is).setString("FuzzyMode", fzMode.name());
}
@Override
public IGuiItemObject getGuiObject( final ItemStack is, final World w, final BlockPos pos )
{
return new PortableCellViewer( is, pos.getX() );
}
@Override
public IGuiItemObject getGuiObject(final ItemStack is, final World w, final BlockPos pos) {
return new PortableCellViewer(is, pos.getX());
}
@Override
public boolean shouldCauseReequipAnimation( ItemStack oldStack, ItemStack newStack, boolean slotChanged )
{
return slotChanged;
}
@Override
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) {
return slotChanged;
}
}
@@ -19,8 +19,15 @@
package appeng.items.tools.powered;
import java.util.List;
import appeng.api.AEApi;
import appeng.api.config.*;
import appeng.api.features.IWirelessTermHandler;
import appeng.api.util.IConfigManager;
import appeng.core.AEConfig;
import appeng.core.localization.GuiText;
import appeng.items.tools.powered.powersink.AEBasePoweredItem;
import appeng.util.ConfigManager;
import appeng.util.Platform;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@@ -33,125 +40,94 @@ import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
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.localization.GuiText;
import appeng.items.tools.powered.powersink.AEBasePoweredItem;
import appeng.util.ConfigManager;
import appeng.util.Platform;
import java.util.List;
public class ToolWirelessTerminal extends AEBasePoweredItem implements IWirelessTermHandler
{
public class ToolWirelessTerminal extends AEBasePoweredItem implements IWirelessTermHandler {
public ToolWirelessTerminal()
{
super( AEConfig.instance().getWirelessTerminalBattery() );
}
public ToolWirelessTerminal() {
super(AEConfig.instance().getWirelessTerminalBattery());
}
@Override
public ActionResult<ItemStack> onItemRightClick( final World w, final EntityPlayer player, final EnumHand hand )
{
AEApi.instance().registries().wireless().openWirelessTerminalGui( player.getHeldItem( hand ), w, player );
return new ActionResult<>( EnumActionResult.SUCCESS, player.getHeldItem( hand ) );
}
@Override
public ActionResult<ItemStack> onItemRightClick(final World w, final EntityPlayer player, final EnumHand hand) {
AEApi.instance().registries().wireless().openWirelessTerminalGui(player.getHeldItem(hand), w, player);
return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
}
@SideOnly( Side.CLIENT )
@Override
public boolean isFull3D()
{
return false;
}
@SideOnly(Side.CLIENT)
@Override
public boolean isFull3D() {
return false;
}
@Override
@SideOnly( Side.CLIENT )
public void addCheckedInformation( final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips )
{
super.addCheckedInformation( stack, world, lines, advancedTooltips );
@Override
@SideOnly(Side.CLIENT)
public void addCheckedInformation(final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips) {
super.addCheckedInformation(stack, world, lines, advancedTooltips);
if( stack.hasTagCompound() )
{
final NBTTagCompound tag = Platform.openNbtData( stack );
if( tag != null )
{
final String encKey = tag.getString( "encryptionKey" );
if (stack.hasTagCompound()) {
final NBTTagCompound tag = Platform.openNbtData(stack);
if (tag != null) {
final String encKey = tag.getString("encryptionKey");
if( encKey == null || encKey.isEmpty() )
{
lines.add( GuiText.Unlinked.getLocal() );
}
else
{
lines.add( GuiText.Linked.getLocal() );
}
}
}
else
{
lines.add( I18n.translateToLocal( "AppEng.GuiITooltip.Unlinked" ) );
}
}
if (encKey == null || encKey.isEmpty()) {
lines.add(GuiText.Unlinked.getLocal());
} else {
lines.add(GuiText.Linked.getLocal());
}
}
} else {
lines.add(I18n.translateToLocal("AppEng.GuiITooltip.Unlinked"));
}
}
@Override
public boolean canHandle( final ItemStack is )
{
return AEApi.instance().definitions().items().wirelessTerminal().isSameAs( is );
}
@Override
public boolean canHandle(final ItemStack is) {
return AEApi.instance().definitions().items().wirelessTerminal().isSameAs(is);
}
@Override
public boolean usePower( final EntityPlayer player, final double amount, final ItemStack is )
{
return this.extractAEPower( is, amount, Actionable.MODULATE ) >= amount - 0.5;
}
@Override
public boolean usePower(final EntityPlayer player, final double amount, final ItemStack is) {
return this.extractAEPower(is, amount, Actionable.MODULATE) >= amount - 0.5;
}
@Override
public boolean hasPower( final EntityPlayer player, final double amt, final ItemStack is )
{
return this.getAECurrentPower( is ) >= amt;
}
@Override
public boolean hasPower(final EntityPlayer player, final double amt, final ItemStack is) {
return this.getAECurrentPower(is) >= amt;
}
@Override
public IConfigManager getConfigManager( final ItemStack target )
{
final ConfigManager out = new ConfigManager( ( manager, settingName, newValue ) ->
{
final NBTTagCompound data = Platform.openNbtData( target );
manager.writeToNBT( data );
} );
@Override
public IConfigManager getConfigManager(final ItemStack target) {
final ConfigManager out = new ConfigManager((manager, settingName, newValue) ->
{
final 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.registerSetting(Settings.SORT_BY, SortOrder.NAME);
out.registerSetting(Settings.VIEW_MODE, ViewItems.ALL);
out.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING);
out.readFromNBT( Platform.openNbtData( target ).copy() );
return out;
}
out.readFromNBT(Platform.openNbtData(target).copy());
return out;
}
@Override
public String getEncryptionKey( final ItemStack item )
{
final NBTTagCompound tag = Platform.openNbtData( item );
return tag.getString( "encryptionKey" );
}
@Override
public String getEncryptionKey(final ItemStack item) {
final NBTTagCompound tag = Platform.openNbtData(item);
return tag.getString("encryptionKey");
}
@Override
public void setEncryptionKey( final ItemStack item, final String encKey, final String name )
{
final NBTTagCompound tag = Platform.openNbtData( item );
tag.setString( "encryptionKey", encKey );
tag.setString( "name", name );
}
@Override
public void setEncryptionKey(final ItemStack item, final String encKey, final String name) {
final NBTTagCompound tag = Platform.openNbtData(item);
tag.setString("encryptionKey", encKey);
tag.setString("name", name);
}
@Override
public boolean shouldCauseReequipAnimation( ItemStack oldStack, ItemStack newStack, boolean slotChanged )
{
return slotChanged;
}
@Override
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) {
return slotChanged;
}
}
@@ -19,9 +19,13 @@
package appeng.items.tools.powered.powersink;
import java.text.MessageFormat;
import java.util.List;
import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
import appeng.api.config.PowerUnits;
import appeng.api.implementations.items.IAEItemPowerStorage;
import appeng.core.localization.GuiText;
import appeng.items.AEBaseItem;
import appeng.util.Platform;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
@@ -32,151 +36,128 @@ import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
import appeng.api.config.PowerUnits;
import appeng.api.implementations.items.IAEItemPowerStorage;
import appeng.core.localization.GuiText;
import appeng.items.AEBaseItem;
import appeng.util.Platform;
import java.text.MessageFormat;
import java.util.List;
public abstract class AEBasePoweredItem extends AEBaseItem implements IAEItemPowerStorage
{
private static final String CURRENT_POWER_NBT_KEY = "internalCurrentPower";
private static final String MAX_POWER_NBT_KEY = "internalMaxPower";
private final double powerCapacity;
public abstract class AEBasePoweredItem extends AEBaseItem implements IAEItemPowerStorage {
private static final String CURRENT_POWER_NBT_KEY = "internalCurrentPower";
private static final String MAX_POWER_NBT_KEY = "internalMaxPower";
private final double powerCapacity;
public AEBasePoweredItem( final double powerCapacity )
{
this.setMaxStackSize( 1 );
this.setMaxDamage( 32 );
this.hasSubtypes = false;
this.setFull3D();
public AEBasePoweredItem(final double powerCapacity) {
this.setMaxStackSize(1);
this.setMaxDamage(32);
this.hasSubtypes = false;
this.setFull3D();
this.powerCapacity = powerCapacity;
}
this.powerCapacity = powerCapacity;
}
@SideOnly( Side.CLIENT )
@Override
public void addCheckedInformation( final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips )
{
final NBTTagCompound tag = stack.getTagCompound();
double internalCurrentPower = 0;
final double internalMaxPower = this.getAEMaxPower( stack );
@SideOnly(Side.CLIENT)
@Override
public void addCheckedInformation(final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips) {
final NBTTagCompound tag = stack.getTagCompound();
double internalCurrentPower = 0;
final double internalMaxPower = this.getAEMaxPower(stack);
if( tag != null )
{
internalCurrentPower = tag.getDouble( CURRENT_POWER_NBT_KEY );
}
if (tag != null) {
internalCurrentPower = tag.getDouble(CURRENT_POWER_NBT_KEY);
}
final double percent = internalCurrentPower / internalMaxPower;
final 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 ) );
}
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 isDamageable() {
return true;
}
@Override
protected void getCheckedSubItems( final CreativeTabs creativeTab, final NonNullList<ItemStack> itemStacks )
{
super.getCheckedSubItems( creativeTab, itemStacks );
@Override
protected void getCheckedSubItems(final CreativeTabs creativeTab, final NonNullList<ItemStack> itemStacks) {
super.getCheckedSubItems(creativeTab, itemStacks);
final ItemStack charged = new ItemStack( this, 1 );
final NBTTagCompound tag = Platform.openNbtData( charged );
tag.setDouble( CURRENT_POWER_NBT_KEY, this.getAEMaxPower( charged ) );
tag.setDouble( MAX_POWER_NBT_KEY, this.getAEMaxPower( charged ) );
final ItemStack charged = new ItemStack(this, 1);
final NBTTagCompound tag = Platform.openNbtData(charged);
tag.setDouble(CURRENT_POWER_NBT_KEY, this.getAEMaxPower(charged));
tag.setDouble(MAX_POWER_NBT_KEY, this.getAEMaxPower(charged));
itemStacks.add( charged );
}
itemStacks.add(charged);
}
@Override
public boolean isRepairable()
{
return false;
}
@Override
public boolean isRepairable() {
return false;
}
@Override
public double getDurabilityForDisplay( final ItemStack is )
{
return 1 - this.getAECurrentPower( is ) / this.getAEMaxPower( is );
}
@Override
public double getDurabilityForDisplay(final ItemStack is) {
return 1 - this.getAECurrentPower(is) / this.getAEMaxPower(is);
}
@Override
public boolean isDamaged( final ItemStack stack )
{
return true;
}
@Override
public boolean isDamaged(final ItemStack stack) {
return true;
}
@Override
public void setDamage( final ItemStack stack, final int damage )
{
@Override
public void setDamage(final ItemStack stack, final int damage) {
}
}
@Override
public double injectAEPower( final ItemStack is, final double amount, Actionable mode )
{
final double maxStorage = this.getAEMaxPower( is );
final double currentStorage = this.getAECurrentPower( is );
final double required = maxStorage - currentStorage;
final double overflow = amount - required;
@Override
public double injectAEPower(final ItemStack is, final double amount, Actionable mode) {
final double maxStorage = this.getAEMaxPower(is);
final double currentStorage = this.getAECurrentPower(is);
final double required = maxStorage - currentStorage;
final double overflow = amount - required;
if( mode == Actionable.MODULATE )
{
final NBTTagCompound data = Platform.openNbtData( is );
final double toAdd = Math.min( amount, required );
if (mode == Actionable.MODULATE) {
final NBTTagCompound data = Platform.openNbtData(is);
final double toAdd = Math.min(amount, required);
data.setDouble( CURRENT_POWER_NBT_KEY, currentStorage + toAdd );
}
data.setDouble(CURRENT_POWER_NBT_KEY, currentStorage + toAdd);
}
return Math.max( 0, overflow );
}
return Math.max(0, overflow);
}
@Override
public double extractAEPower( final ItemStack is, final double amount, Actionable mode )
{
final double currentStorage = this.getAECurrentPower( is );
final double fulfillable = Math.min( amount, currentStorage );
@Override
public double extractAEPower(final ItemStack is, final double amount, Actionable mode) {
final double currentStorage = this.getAECurrentPower(is);
final double fulfillable = Math.min(amount, currentStorage);
if( mode == Actionable.MODULATE )
{
final NBTTagCompound data = Platform.openNbtData( is );
if (mode == Actionable.MODULATE) {
final NBTTagCompound data = Platform.openNbtData(is);
data.setDouble( CURRENT_POWER_NBT_KEY, currentStorage - fulfillable );
}
data.setDouble(CURRENT_POWER_NBT_KEY, currentStorage - fulfillable);
}
return fulfillable;
}
return fulfillable;
}
@Override
public double getAEMaxPower( final ItemStack is )
{
return this.powerCapacity;
}
@Override
public double getAEMaxPower(final ItemStack is) {
return this.powerCapacity;
}
@Override
public double getAECurrentPower( final ItemStack is )
{
final NBTTagCompound data = Platform.openNbtData( is );
@Override
public double getAECurrentPower(final ItemStack is) {
final NBTTagCompound data = Platform.openNbtData(is);
return data.getDouble( CURRENT_POWER_NBT_KEY );
}
return data.getDouble(CURRENT_POWER_NBT_KEY);
}
@Override
public AccessRestriction getPowerFlow( final ItemStack is )
{
return AccessRestriction.WRITE;
}
@Override
public AccessRestriction getPowerFlow(final ItemStack is) {
return AccessRestriction.WRITE;
}
@Override
public ICapabilityProvider initCapabilities( ItemStack stack, NBTTagCompound nbt )
{
return new PoweredItemCapabilities( stack, this );
}
@Override
public ICapabilityProvider initCapabilities(ItemStack stack, NBTTagCompound nbt) {
return new PoweredItemCapabilities(stack, this);
}
}
@@ -19,8 +19,10 @@
package appeng.items.tools.powered.powersink;
import javax.annotation.Nullable;
import appeng.api.config.Actionable;
import appeng.api.config.PowerUnits;
import appeng.api.implementations.items.IAEItemPowerStorage;
import appeng.capabilities.Capabilities;
import net.darkhax.tesla.api.ITeslaConsumer;
import net.darkhax.tesla.api.ITeslaHolder;
import net.minecraft.item.ItemStack;
@@ -29,117 +31,94 @@ import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.energy.IEnergyStorage;
import appeng.api.config.Actionable;
import appeng.api.config.PowerUnits;
import appeng.api.implementations.items.IAEItemPowerStorage;
import appeng.capabilities.Capabilities;
import javax.annotation.Nullable;
/**
* The capability provider to expose chargable items to other mods.
*/
class PoweredItemCapabilities implements ICapabilityProvider, IEnergyStorage
{
class PoweredItemCapabilities implements ICapabilityProvider, IEnergyStorage {
private final ItemStack is;
private final ItemStack is;
private final IAEItemPowerStorage item;
private final IAEItemPowerStorage item;
private final Object teslaAdapter;
private final Object teslaAdapter;
PoweredItemCapabilities( ItemStack is, IAEItemPowerStorage item )
{
this.is = is;
this.item = item;
if( Capabilities.TESLA_CONSUMER != null || Capabilities.TESLA_HOLDER != null )
{
this.teslaAdapter = new TeslaAdapter();
}
else
{
this.teslaAdapter = null;
}
}
PoweredItemCapabilities(ItemStack is, IAEItemPowerStorage item) {
this.is = is;
this.item = item;
if (Capabilities.TESLA_CONSUMER != null || Capabilities.TESLA_HOLDER != null) {
this.teslaAdapter = new TeslaAdapter();
} else {
this.teslaAdapter = null;
}
}
@Override
public boolean hasCapability( Capability<?> capability, @Nullable EnumFacing facing )
{
return capability == Capabilities.FORGE_ENERGY || capability == Capabilities.TESLA_CONSUMER || capability == Capabilities.TESLA_HOLDER;
}
@Override
public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) {
return capability == Capabilities.FORGE_ENERGY || capability == Capabilities.TESLA_CONSUMER || capability == Capabilities.TESLA_HOLDER;
}
@SuppressWarnings( "unchecked" )
@Override
public <T> T getCapability( Capability<T> capability, @Nullable EnumFacing facing )
{
if( capability == Capabilities.FORGE_ENERGY )
{
return (T) this;
}
else if( capability == Capabilities.TESLA_CONSUMER || capability == Capabilities.TESLA_HOLDER )
{
return (T) this.teslaAdapter;
}
return null;
}
@SuppressWarnings("unchecked")
@Override
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) {
if (capability == Capabilities.FORGE_ENERGY) {
return (T) this;
} else if (capability == Capabilities.TESLA_CONSUMER || capability == Capabilities.TESLA_HOLDER) {
return (T) this.teslaAdapter;
}
return null;
}
@Override
public int receiveEnergy( int maxReceive, boolean simulate )
{
final double convertedOffer = PowerUnits.RF.convertTo( PowerUnits.AE, maxReceive );
final double overflow = this.item.injectAEPower( this.is, convertedOffer, simulate ? Actionable.SIMULATE : Actionable.MODULATE );
@Override
public int receiveEnergy(int maxReceive, boolean simulate) {
final double convertedOffer = PowerUnits.RF.convertTo(PowerUnits.AE, maxReceive);
final double overflow = this.item.injectAEPower(this.is, convertedOffer, simulate ? Actionable.SIMULATE : Actionable.MODULATE);
return maxReceive - (int) PowerUnits.AE.convertTo( PowerUnits.RF, overflow );
}
return maxReceive - (int) PowerUnits.AE.convertTo(PowerUnits.RF, overflow);
}
@Override
public int extractEnergy( int maxExtract, boolean simulate )
{
return 0;
}
@Override
public int extractEnergy(int maxExtract, boolean simulate) {
return 0;
}
@Override
public int getEnergyStored()
{
return (int) PowerUnits.AE.convertTo( PowerUnits.RF, this.item.getAECurrentPower( this.is ) );
}
@Override
public int getEnergyStored() {
return (int) PowerUnits.AE.convertTo(PowerUnits.RF, this.item.getAECurrentPower(this.is));
}
@Override
public int getMaxEnergyStored()
{
return (int) PowerUnits.AE.convertTo( PowerUnits.RF, this.item.getAEMaxPower( this.is ) );
}
@Override
public int getMaxEnergyStored() {
return (int) PowerUnits.AE.convertTo(PowerUnits.RF, this.item.getAEMaxPower(this.is));
}
@Override
public boolean canExtract()
{
return false;
}
@Override
public boolean canExtract() {
return false;
}
@Override
public boolean canReceive()
{
return true;
}
@Override
public boolean canReceive() {
return true;
}
private class TeslaAdapter implements ITeslaConsumer, ITeslaHolder
{
private class TeslaAdapter implements ITeslaConsumer, ITeslaHolder {
@Override
public long givePower( long power, boolean simulated )
{
return PoweredItemCapabilities.this.receiveEnergy( (int) power, simulated );
}
@Override
public long givePower(long power, boolean simulated) {
return PoweredItemCapabilities.this.receiveEnergy((int) power, simulated);
}
@Override
public long getStoredPower()
{
return PoweredItemCapabilities.this.getEnergyStored();
}
@Override
public long getStoredPower() {
return PoweredItemCapabilities.this.getEnergyStored();
}
@Override
public long getCapacity()
{
return PoweredItemCapabilities.this.getMaxEnergyStored();
}
}
@Override
public long getCapacity() {
return PoweredItemCapabilities.this.getMaxEnergyStored();
}
}
}
@@ -19,26 +19,22 @@
package appeng.items.tools.quartz;
import appeng.core.features.AEFeature;
import appeng.util.Platform;
import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemStack;
import appeng.core.features.AEFeature;
import appeng.util.Platform;
public class ToolQuartzAxe extends ItemAxe {
private final AEFeature type;
public class ToolQuartzAxe extends ItemAxe
{
private final AEFeature type;
public ToolQuartzAxe(final AEFeature type) {
super(ToolMaterial.IRON);
this.type = type;
}
public ToolQuartzAxe( final AEFeature type )
{
super( ToolMaterial.IRON );
this.type = type;
}
@Override
public boolean getIsRepairable( final ItemStack a, final ItemStack b )
{
return Platform.canRepair( this.type, a, b );
}
@Override
public boolean getIsRepairable(final ItemStack a, final ItemStack b) {
return Platform.canRepair(this.type, a, b);
}
}
@@ -19,6 +19,14 @@
package appeng.items.tools.quartz;
import appeng.api.implementations.guiobjects.IGuiItem;
import appeng.api.implementations.guiobjects.IGuiItemObject;
import appeng.api.util.AEPartLocation;
import appeng.core.features.AEFeature;
import appeng.core.sync.GuiBridge;
import appeng.items.AEBaseItem;
import appeng.items.contents.QuartzKnifeObj;
import appeng.util.Platform;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
@@ -28,78 +36,58 @@ import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import appeng.api.implementations.guiobjects.IGuiItem;
import appeng.api.implementations.guiobjects.IGuiItemObject;
import appeng.api.util.AEPartLocation;
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 {
private final AEFeature type;
public class ToolQuartzCuttingKnife extends AEBaseItem implements IGuiItem
{
private final AEFeature type;
public ToolQuartzCuttingKnife(final AEFeature type) {
this.type = type;
this.setMaxDamage(50);
this.setMaxStackSize(1);
}
public ToolQuartzCuttingKnife( final AEFeature type )
{
this.type = type;
this.setMaxDamage( 50 );
this.setMaxStackSize( 1 );
}
@Override
public EnumActionResult onItemUse(final EntityPlayer p, final World worldIn, final BlockPos pos, final EnumHand hand, final EnumFacing side, final float hitX, final float hitY, final float hitZ) {
if (Platform.isServer()) {
Platform.openGUI(p, null, AEPartLocation.INTERNAL, GuiBridge.GUI_QUARTZ_KNIFE);
}
return EnumActionResult.SUCCESS;
}
@Override
public EnumActionResult onItemUse( final EntityPlayer p, final World worldIn, final BlockPos pos, final EnumHand hand, final EnumFacing side, final float hitX, final float hitY, final float hitZ )
{
if( Platform.isServer() )
{
Platform.openGUI( p, null, AEPartLocation.INTERNAL, GuiBridge.GUI_QUARTZ_KNIFE );
}
return EnumActionResult.SUCCESS;
}
@Override
public ActionResult<ItemStack> onItemRightClick(final World w, final EntityPlayer p, final EnumHand hand) {
if (Platform.isServer()) {
Platform.openGUI(p, null, AEPartLocation.INTERNAL, GuiBridge.GUI_QUARTZ_KNIFE);
}
p.swingArm(hand);
return new ActionResult<>(EnumActionResult.SUCCESS, p.getHeldItem(hand));
}
@Override
public ActionResult<ItemStack> onItemRightClick( final World w, final EntityPlayer p, final EnumHand hand )
{
if( Platform.isServer() )
{
Platform.openGUI( p, null, AEPartLocation.INTERNAL, GuiBridge.GUI_QUARTZ_KNIFE );
}
p.swingArm( hand );
return new ActionResult<>( EnumActionResult.SUCCESS, p.getHeldItem( hand ) );
}
@Override
public boolean getIsRepairable(final ItemStack a, final ItemStack b) {
return Platform.canRepair(this.type, a, b);
}
@Override
public boolean getIsRepairable( final ItemStack a, final ItemStack b )
{
return Platform.canRepair( this.type, a, b );
}
@Override
public boolean isRepairable() {
return false;
}
@Override
public boolean isRepairable()
{
return false;
}
@Override
public ItemStack getContainerItem(final ItemStack itemStack) {
ItemStack copy = itemStack.copy();
copy.setItemDamage(itemStack.getItemDamage() + 1);
@Override
public ItemStack getContainerItem( final ItemStack itemStack )
{
ItemStack copy = itemStack.copy();
copy.setItemDamage( itemStack.getItemDamage() + 1 );
return copy;
}
return copy;
}
@Override
public boolean hasContainerItem(final ItemStack stack) {
return true;
}
@Override
public boolean hasContainerItem( final ItemStack stack )
{
return true;
}
@Override
public IGuiItemObject getGuiObject( final ItemStack is, final World world, final BlockPos pos )
{
return new QuartzKnifeObj( is );
}
@Override
public IGuiItemObject getGuiObject(final ItemStack is, final World world, final BlockPos pos) {
return new QuartzKnifeObj(is);
}
}
@@ -19,27 +19,23 @@
package appeng.items.tools.quartz;
import appeng.core.features.AEFeature;
import appeng.util.Platform;
import net.minecraft.item.ItemHoe;
import net.minecraft.item.ItemStack;
import appeng.core.features.AEFeature;
import appeng.util.Platform;
public class ToolQuartzHoe extends ItemHoe {
private final AEFeature type;
public class ToolQuartzHoe extends ItemHoe
{
private final AEFeature type;
public ToolQuartzHoe(final AEFeature type) {
super(ToolMaterial.IRON);
this.type = type;
}
public ToolQuartzHoe( final AEFeature type )
{
super( ToolMaterial.IRON );
this.type = type;
}
@Override
public boolean getIsRepairable( final ItemStack a, final ItemStack b )
{
return Platform.canRepair( this.type, a, b );
}
@Override
public boolean getIsRepairable(final ItemStack a, final ItemStack b) {
return Platform.canRepair(this.type, a, b);
}
}
@@ -19,26 +19,22 @@
package appeng.items.tools.quartz;
import appeng.core.features.AEFeature;
import appeng.util.Platform;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemStack;
import appeng.core.features.AEFeature;
import appeng.util.Platform;
public class ToolQuartzPickaxe extends ItemPickaxe {
private final AEFeature type;
public class ToolQuartzPickaxe extends ItemPickaxe
{
private final AEFeature type;
public ToolQuartzPickaxe(final AEFeature type) {
super(ToolMaterial.IRON);
this.type = type;
}
public ToolQuartzPickaxe( final AEFeature type )
{
super( ToolMaterial.IRON );
this.type = type;
}
@Override
public boolean getIsRepairable( final ItemStack a, final ItemStack b )
{
return Platform.canRepair( this.type, a, b );
}
@Override
public boolean getIsRepairable(final ItemStack a, final ItemStack b) {
return Platform.canRepair(this.type, a, b);
}
}
@@ -19,26 +19,22 @@
package appeng.items.tools.quartz;
import appeng.core.features.AEFeature;
import appeng.util.Platform;
import net.minecraft.item.ItemSpade;
import net.minecraft.item.ItemStack;
import appeng.core.features.AEFeature;
import appeng.util.Platform;
public class ToolQuartzSpade extends ItemSpade {
private final AEFeature type;
public class ToolQuartzSpade extends ItemSpade
{
private final AEFeature type;
public ToolQuartzSpade(final AEFeature type) {
super(ToolMaterial.IRON);
this.type = type;
}
public ToolQuartzSpade( final AEFeature type )
{
super( ToolMaterial.IRON );
this.type = type;
}
@Override
public boolean getIsRepairable( final ItemStack a, final ItemStack b )
{
return Platform.canRepair( this.type, a, b );
}
@Override
public boolean getIsRepairable(final ItemStack a, final ItemStack b) {
return Platform.canRepair(this.type, a, b);
}
}
@@ -19,26 +19,22 @@
package appeng.items.tools.quartz;
import appeng.core.features.AEFeature;
import appeng.util.Platform;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import appeng.core.features.AEFeature;
import appeng.util.Platform;
public class ToolQuartzSword extends ItemSword {
private final AEFeature type;
public class ToolQuartzSword extends ItemSword
{
private final AEFeature type;
public ToolQuartzSword(AEFeature type) {
super(ToolMaterial.IRON);
this.type = type;
}
public ToolQuartzSword( AEFeature type )
{
super( ToolMaterial.IRON );
this.type = type;
}
@Override
public boolean getIsRepairable( final ItemStack a, final ItemStack b )
{
return Platform.canRepair( this.type, a, b );
}
@Override
public boolean getIsRepairable(final ItemStack a, final ItemStack b) {
return Platform.canRepair(this.type, a, b);
}
}
@@ -19,6 +19,11 @@
package appeng.items.tools.quartz;
import appeng.api.implementations.items.IAEWrench;
import appeng.api.util.DimensionalCoord;
import appeng.items.AEBaseItem;
import appeng.util.Platform;
import cofh.api.item.IToolHammer;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
@@ -32,96 +37,77 @@ import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.Optional.Interface;
import cofh.api.item.IToolHammer;
import appeng.api.implementations.items.IAEWrench;
import appeng.api.util.DimensionalCoord;
import appeng.items.AEBaseItem;
import appeng.util.Platform;
// TODO BC Integration
//@Interface( iface = "buildcraft.api.tools.IToolWrench", iname = IntegrationType.BuildCraftCore )
@Interface( iface = "cofh.api.item.IToolHammer", modid = "cofhcore" )
public class ToolQuartzWrench extends AEBaseItem implements IAEWrench, IToolHammer /* , IToolWrench */
{
@Interface(iface = "cofh.api.item.IToolHammer", modid = "cofhcore")
public class ToolQuartzWrench extends AEBaseItem implements IAEWrench, IToolHammer /* , IToolWrench */ {
public ToolQuartzWrench()
{
this.setMaxStackSize( 1 );
this.setHarvestLevel( "wrench", 0 );
}
public ToolQuartzWrench() {
this.setMaxStackSize(1);
this.setHarvestLevel("wrench", 0);
}
@Override
public EnumActionResult onItemUseFirst( final EntityPlayer player, final World world, final BlockPos pos, final EnumFacing side, final float hitX, final float hitY, final float hitZ, final EnumHand hand )
{
final Block b = world.getBlockState( pos ).getBlock();
if( b != null && !player.isSneaking() && Platform.hasPermissions( new DimensionalCoord( world, pos ), player ) )
{
if( Platform.isClient() )
{
// TODO 1.10-R - if we return FAIL on client, action will not be sent to server. Fix that in all
// Block#onItemUseFirst overrides.
return !world.isRemote ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
}
@Override
public EnumActionResult onItemUseFirst(final EntityPlayer player, final World world, final BlockPos pos, final EnumFacing side, final float hitX, final float hitY, final float hitZ, final EnumHand hand) {
final Block b = world.getBlockState(pos).getBlock();
if (b != null && !player.isSneaking() && Platform.hasPermissions(new DimensionalCoord(world, pos), player)) {
if (Platform.isClient()) {
// TODO 1.10-R - if we return FAIL on client, action will not be sent to server. Fix that in all
// Block#onItemUseFirst overrides.
return !world.isRemote ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
}
if( b.rotateBlock( world, pos, side ) )
{
player.swingArm( hand );
return !world.isRemote ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
}
}
return EnumActionResult.PASS;
}
if (b.rotateBlock(world, pos, side)) {
player.swingArm(hand);
return !world.isRemote ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
}
}
return EnumActionResult.PASS;
}
@Override
public boolean doesSneakBypassUse( final ItemStack itemstack, final IBlockAccess world, final BlockPos pos, final EntityPlayer player )
{
return true;
}
@Override
public boolean doesSneakBypassUse(final ItemStack itemstack, final IBlockAccess world, final BlockPos pos, final EntityPlayer player) {
return true;
}
@Override
public boolean canWrench( final ItemStack wrench, final EntityPlayer player, final BlockPos pos )
{
return true;
}
@Override
public boolean canWrench(final ItemStack wrench, final EntityPlayer player, final BlockPos pos) {
return true;
}
// IToolHammer - start
@Override
public boolean isUsable( ItemStack item, EntityLivingBase user, BlockPos pos )
{
return true;
}
// IToolHammer - start
@Override
public boolean isUsable(ItemStack item, EntityLivingBase user, BlockPos pos) {
return true;
}
@Override
public boolean isUsable( ItemStack item, EntityLivingBase user, Entity entity )
{
return true;
}
@Override
public boolean isUsable(ItemStack item, EntityLivingBase user, Entity entity) {
return true;
}
@Override
public void toolUsed( ItemStack item, EntityLivingBase user, BlockPos pos )
{
}
@Override
public void toolUsed(ItemStack item, EntityLivingBase user, BlockPos pos) {
}
@Override
public void toolUsed( ItemStack item, EntityLivingBase user, Entity entity )
{
}
@Override
public void toolUsed(ItemStack item, EntityLivingBase user, Entity entity) {
}
// IToolHammer - end
// IToolHammer - end
// TODO: BC Wrench Integration
/*
* @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();
* }
*/
// TODO: BC Wrench Integration
/*
* @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();
* }
*/
}