mirror of
https://github.com/GTNewHorizons/WirelessCraftingTerminal.git
synced 2026-11-21 12:32:44 +00:00
1 parent
2b5b5f3d81
commit
7f684de9c6
33 files changed
+1127
-1066
No files matched your search
@@ -1,5 +1,8 @@
|
||||
package cofh.api.energy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
@@ -49,4 +52,6 @@ public interface IEnergyContainerItem {
|
||||
*/
|
||||
int getMaxEnergyStored(ItemStack container);
|
||||
|
||||
void addInformation(ItemStack is, EntityPlayer player, List<String> list, boolean displayMore);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package ic2.api.item;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Provides the ability to store energy on the implementing item.
|
||||
*
|
||||
* The item should have a maximum damage of 13.
|
||||
*/
|
||||
public interface IElectricItem {
|
||||
/**
|
||||
* Determine if the item can be used in a machine or as an armor part to supply energy.
|
||||
*
|
||||
* @return Whether the item can supply energy
|
||||
*/
|
||||
boolean canProvideEnergy(ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Get the item ID to use for a charge energy greater than 0.
|
||||
*
|
||||
* @return Item ID to use
|
||||
*/
|
||||
Item getChargedItem(ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Get the item ID to use for a charge energy of 0.
|
||||
*
|
||||
* @return Item ID to use
|
||||
*/
|
||||
Item getEmptyItem(ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Get the item's maximum charge energy in EU.
|
||||
*
|
||||
* @return Maximum charge energy
|
||||
*/
|
||||
double getMaxCharge(ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Get the item's tier, lower tiers can't send energy to higher ones.
|
||||
*
|
||||
* Batteries are Tier 1, Advanced Batteries are Tier 2, Energy Crystals are Tier 3, Lapotron
|
||||
* Crystals are Tier 4.
|
||||
*
|
||||
* @return Item's tier
|
||||
*/
|
||||
int getTier(ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Get the item's transfer limit in EU per transfer operation.
|
||||
*
|
||||
* @return Transfer limit
|
||||
*/
|
||||
double getTransferLimit(ItemStack itemStack);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
package ic2.api.item;
|
||||
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* This interface specifies a manager to handle the various tasks for electric items.
|
||||
*
|
||||
* The default implementation does the following:
|
||||
* - store and retrieve the charge
|
||||
* - handle charging, taking amount, tier, transfer limit, canProvideEnergy and simulate into account
|
||||
* - replace item IDs if appropriate (getChargedItemId() and getEmptyItemId())
|
||||
* - update and manage the damage value for the visual charge indicator
|
||||
*
|
||||
* @note If you're implementing your own variant (ISpecialElectricItem), you can delegate to the
|
||||
* default implementations through ElectricItem.rawManager. The default implementation is designed
|
||||
* to minimize its dependency on its own constraints/structure and delegates most work back to the
|
||||
* more atomic features in the gateway manager.
|
||||
*/
|
||||
public interface IElectricItemManager {
|
||||
/**
|
||||
* Charge an item with a specified amount of energy.
|
||||
*
|
||||
* @param itemStack electric item's stack
|
||||
* @param amount amount of energy to charge in EU
|
||||
* @param tier tier of the charging device, has to be at least as high as the item to charge
|
||||
* @param ignoreTransferLimit ignore the transfer limit specified by getTransferLimit()
|
||||
* @param simulate don't actually change the item, just determine the return value
|
||||
* @return Energy transferred into the electric item
|
||||
*/
|
||||
double charge(ItemStack stack, double amount, int tier, boolean ignoreTransferLimit, boolean simulate);
|
||||
|
||||
/**
|
||||
* Discharge an item by a specified amount of energy
|
||||
*
|
||||
* @param itemStack electric item's stack
|
||||
* @param amount amount of energy to discharge in EU
|
||||
* @param tier tier of the discharging device, has to be at least as high as the item to discharge
|
||||
* @param ignoreTransferLimit ignore the transfer limit specified by getTransferLimit()
|
||||
* @param externally use the supplied item externally, i.e. to power something else as if it was a battery
|
||||
* @param simulate don't actually discharge the item, just determine the return value
|
||||
* @return Energy retrieved from the electric item
|
||||
*/
|
||||
double discharge(ItemStack stack, double amount, int tier, boolean ignoreTransferLimit, boolean externally, boolean simulate);
|
||||
|
||||
/**
|
||||
* Determine the charge level for the specified item.
|
||||
*
|
||||
* @param itemStack ItemStack containing the electric item
|
||||
* @return charge level in EU
|
||||
*/
|
||||
double getCharge(ItemStack stack);
|
||||
|
||||
/**
|
||||
* Determine if the specified electric item has at least a specific amount of EU.
|
||||
* This is supposed to be used in the item code during operation, for example if you want to implement your own electric item.
|
||||
* BatPacks are not taken into account.
|
||||
*
|
||||
* @param itemStack electric item's stack
|
||||
* @param amount minimum amount of energy required
|
||||
* @return true if there's enough energy
|
||||
*/
|
||||
boolean canUse(ItemStack stack, double amount);
|
||||
|
||||
/**
|
||||
* Try to retrieve a specific amount of energy from an Item, and if applicable, a BatPack.
|
||||
* This is supposed to be used in the item code during operation, for example if you want to implement your own electric item.
|
||||
*
|
||||
* @param itemStack electric item's stack
|
||||
* @param amount amount of energy to discharge in EU
|
||||
* @param entity entity holding the item
|
||||
* @return true if the operation succeeded
|
||||
*/
|
||||
boolean use(ItemStack stack, double amount, EntityLivingBase entity);
|
||||
|
||||
/**
|
||||
* Charge an item from the BatPack a player is wearing.
|
||||
* This is supposed to be used in the item code during operation, for example if you want to implement your own electric item.
|
||||
* use() already contains this functionality.
|
||||
*
|
||||
* @param itemStack electric item's stack
|
||||
* @param entity entity holding the item
|
||||
*/
|
||||
void chargeFromArmor(ItemStack stack, EntityLivingBase entity);
|
||||
|
||||
/**
|
||||
* Get the tool tip to display for electric items.
|
||||
*
|
||||
* @param itemStack ItemStack to determine the tooltip for
|
||||
* @return tool tip string or null for none
|
||||
*/
|
||||
String getToolTip(ItemStack stack);
|
||||
|
||||
// TODO: add tier getter
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package ic2.api.item;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface ISpecialElectricItem extends IElectricItem {
|
||||
/**
|
||||
* Supply a custom IElectricItemManager.
|
||||
*
|
||||
* @param itemStack ItemStack to get the manager for
|
||||
* @return IElectricItemManager instance
|
||||
*/
|
||||
IElectricItemManager getManager(ItemStack itemStack);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
@API(apiVersion="1.0", owner="IC2", provides="IC2API")
|
||||
package ic2.api.item;
|
||||
import cpw.mods.fml.common.API;
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
@API( apiVersion = "1.7.10-rv3-1.6b", owner = "ae2wct", provides = "ae2wct|API" ) package net.p455w0rd.wirelesscraftingterminal.api;
|
||||
import cpw.mods.fml.common.API;
|
||||
+2
-1
@@ -38,6 +38,7 @@ import appeng.core.localization.GuiText;
|
||||
import appeng.helpers.InventoryAction;
|
||||
import appeng.util.IConfigManagerHost;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ObfuscationReflectionHelper;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
@@ -299,7 +300,7 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo
|
||||
Keyboard.enableRepeatEvents(true);
|
||||
this.maxRows = this.getMaxRows();
|
||||
this.perRow = AEConfig.instance.getConfigManager().getSetting( Settings.TERMINAL_STYLE ) != TerminalStyle.FULL ? 9 : 9 + ( ( this.width - this.standardSize ) / 18 );
|
||||
this.isNEIEnabled = IntegrationRegistry.INSTANCE.isEnabled(IntegrationType.NEI);
|
||||
this.isNEIEnabled = Loader.isModLoaded("NotEnoughItems");
|
||||
int top = isNEIEnabled ? 22 : 0;
|
||||
final int magicNumber = 114 + 1;
|
||||
final int extraSpace = this.height - magicNumber - 0 - top - this.reservedSpace;
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -11,7 +11,6 @@ import java.io.File;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.features.IWirelessTermHandler;
|
||||
import net.p455w0rd.wirelesscraftingterminal.common.utils.WCTLog;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.crash.IntegrationCrashEnhancement;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler;
|
||||
import net.p455w0rd.wirelesscraftingterminal.creativetab.CreativeTabWCT;
|
||||
import net.p455w0rd.wirelesscraftingterminal.handlers.AchievementHandler;
|
||||
@@ -22,7 +21,8 @@ import net.p455w0rd.wirelesscraftingterminal.proxy.CommonProxy;
|
||||
import net.p455w0rd.wirelesscraftingterminal.reference.Reference;
|
||||
import net.p455w0rd.wirelesscraftingterminal.items.ItemEnum;
|
||||
|
||||
@Mod(modid = Reference.MODID, acceptedMinecraftVersions = "[1.7.10]", name = Reference.NAME, version = Reference.VERSION, guiFactory = Reference.GUI_FACTORY, dependencies = "required-after:Forge@["
|
||||
@Mod(modid = Reference.MODID, acceptedMinecraftVersions = "[1.7.10]", name = Reference.NAME, version = Reference.VERSION, guiFactory = Reference.GUI_FACTORY, dependencies = ""
|
||||
+ "required-after:Forge@["
|
||||
+ net.minecraftforge.common.ForgeVersion.majorVersion + '.' // majorVersion
|
||||
+ net.minecraftforge.common.ForgeVersion.minorVersion + '.' // minorVersion
|
||||
+ net.minecraftforge.common.ForgeVersion.revisionVersion + '.' // revisionVersion
|
||||
@@ -42,9 +42,6 @@ public class WirelessCraftingTerminal {
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
if (!Loader.isModLoaded("wct-core")) {
|
||||
WirelessCraftingTerminal.proxy.missingCoreMod();
|
||||
}
|
||||
long stopwatch = WCTLog.beginSection("PreInit");
|
||||
WirelessCraftingTerminal.WCTState = LoaderState.PREINITIALIZATION;
|
||||
WirelessCraftingTerminal.INSTANCE = this;
|
||||
@@ -59,9 +56,9 @@ public class WirelessCraftingTerminal {
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent event) {
|
||||
long stopwatch = WCTLog.beginSection("Init");
|
||||
IntegrationRegistry.INSTANCE.init();
|
||||
WirelessCraftingTerminal.WCTState = LoaderState.INITIALIZATION;
|
||||
RecipeHandler.addRecipes(true);
|
||||
IntegrationRegistry.INSTANCE.init();
|
||||
AchievementHandler.init();
|
||||
WCTLog.endSection("Init", stopwatch);
|
||||
}
|
||||
@@ -70,7 +67,6 @@ public class WirelessCraftingTerminal {
|
||||
public void postInit(final FMLPostInitializationEvent event) {
|
||||
long stopwatch = WCTLog.beginSection("PostInit");
|
||||
IntegrationRegistry.INSTANCE.postInit();
|
||||
FMLCommonHandler.instance().registerCrashCallable(new IntegrationCrashEnhancement());
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler(WirelessCraftingTerminal.INSTANCE, new WCTGuiHandler());
|
||||
NetworkHandler.instance = new NetworkHandler("WCT");
|
||||
WirelessCraftingTerminal.proxy.removeItemsFromNEI();
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package net.p455w0rd.wirelesscraftingterminal.core.crash;
|
||||
|
||||
import cpw.mods.fml.common.ICrashCallable;
|
||||
|
||||
|
||||
abstract class BaseCrashEnhancement implements ICrashCallable
|
||||
{
|
||||
private final String name;
|
||||
private final String value;
|
||||
|
||||
public BaseCrashEnhancement( final String name, final String value )
|
||||
{
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String call() throws Exception
|
||||
{
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getLabel()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
package net.p455w0rd.wirelesscraftingterminal.core.crash;
|
||||
|
||||
import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationRegistry;
|
||||
|
||||
public class IntegrationCrashEnhancement extends BaseCrashEnhancement
|
||||
{
|
||||
public IntegrationCrashEnhancement()
|
||||
{
|
||||
super( "AE2 Integration", IntegrationRegistry.INSTANCE.getStatus() );
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,12 @@ package net.p455w0rd.wirelesscraftingterminal.handlers;
|
||||
import java.io.File;
|
||||
|
||||
import cpw.mods.fml.client.event.ConfigChangedEvent;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
import net.p455w0rd.wirelesscraftingterminal.common.WirelessCraftingTerminal;
|
||||
import net.p455w0rd.wirelesscraftingterminal.common.utils.WCTLog;
|
||||
import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationRegistry;
|
||||
import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationType;
|
||||
import net.p455w0rd.wirelesscraftingterminal.items.ItemEnum;
|
||||
import net.p455w0rd.wirelesscraftingterminal.reference.Reference;
|
||||
|
||||
@@ -115,7 +114,7 @@ public class ConfigHandler {
|
||||
}
|
||||
|
||||
public static void removeBoosterIcon() {
|
||||
if (IntegrationRegistry.INSTANCE.isEnabled(IntegrationType.NEI)) {
|
||||
if (Loader.isModLoaded("NotEnoughItems")) {
|
||||
if (!codechicken.nei.api.ItemInfo.hiddenItems.contains(ItemEnum.BOOSTER_ICON.getStack())) {
|
||||
codechicken.nei.api.API.hideItem(ItemEnum.BOOSTER_ICON.getStack());
|
||||
}
|
||||
@@ -124,14 +123,14 @@ public class ConfigHandler {
|
||||
|
||||
public static void removeBooster() {
|
||||
if (Reference.WCT_BOOSTER_ENABLED) {
|
||||
if (IntegrationRegistry.INSTANCE.isEnabled(IntegrationType.NEI)) {
|
||||
if (Loader.isModLoaded("NotEnoughItems")) {
|
||||
if (codechicken.nei.api.ItemInfo.hiddenItems.contains(ItemEnum.BOOSTER_CARD.getStack())) {
|
||||
codechicken.nei.api.ItemInfo.hiddenItems.remove(ItemEnum.BOOSTER_CARD.getStack());
|
||||
}
|
||||
}
|
||||
ItemEnum.BOOSTER_CARD.getItem().setCreativeTab(WirelessCraftingTerminal.creativeTab);
|
||||
} else {
|
||||
if (IntegrationRegistry.INSTANCE.isEnabled(IntegrationType.NEI)) {
|
||||
if (Loader.isModLoaded("NotEnoughItems")) {
|
||||
codechicken.nei.api.API.hideItem(ItemEnum.BOOSTER_CARD.getStack());
|
||||
}
|
||||
ItemEnum.BOOSTER_CARD.getItem().setCreativeTab(null);
|
||||
|
||||
@@ -3,8 +3,8 @@ package net.p455w0rd.wirelesscraftingterminal.integration;
|
||||
public class IntegrationHelper
|
||||
{
|
||||
|
||||
public static void testClassExistence( final Object o, final Class<?> clz )
|
||||
public static void testClassExistence( final Object obj, final Class<?> clazz )
|
||||
{
|
||||
clz.isInstance( o );
|
||||
clazz.isInstance(obj);
|
||||
}
|
||||
}
|
||||
+31
-45
@@ -8,75 +8,64 @@ import javax.annotation.Nonnull;
|
||||
import cpw.mods.fml.relauncher.FMLLaunchHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
|
||||
public enum IntegrationRegistry
|
||||
{
|
||||
public enum IntegrationRegistry {
|
||||
INSTANCE;
|
||||
|
||||
private static final String PACKAGE_PREFIX = "net.p455w0rd.wirelesscraftingterminal.integration.modules.";
|
||||
|
||||
private final Collection<IntegrationNode> modules = new LinkedList<IntegrationNode>();
|
||||
|
||||
public void add( final IntegrationType type )
|
||||
{
|
||||
if( type.side == IntegrationSide.CLIENT && FMLLaunchHandler.side() == Side.SERVER )
|
||||
{
|
||||
public void add(final IntegrationType type) {
|
||||
if (type.side == IntegrationSide.CLIENT && FMLLaunchHandler.side() == Side.SERVER) {
|
||||
return;
|
||||
}
|
||||
|
||||
if( type.side == IntegrationSide.SERVER && FMLLaunchHandler.side() == Side.CLIENT )
|
||||
{
|
||||
if (type.side == IntegrationSide.SERVER && FMLLaunchHandler.side() == Side.CLIENT) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.modules.add( new IntegrationNode( type.dspName, type.modID, type, PACKAGE_PREFIX + type.name() ) );
|
||||
this.modules.add(new IntegrationNode(type.dspName, type.modID, type, PACKAGE_PREFIX + type.name()));
|
||||
}
|
||||
|
||||
public void init()
|
||||
{
|
||||
for( final IntegrationNode node : this.modules )
|
||||
public void init() {
|
||||
for (final IntegrationType type : IntegrationType.values())
|
||||
{
|
||||
node.call( IntegrationStage.PRE_INIT );
|
||||
IntegrationRegistry.INSTANCE.add(type);
|
||||
}
|
||||
|
||||
for (final IntegrationNode node : this.modules) {
|
||||
node.call(IntegrationStage.PRE_INIT);
|
||||
}
|
||||
|
||||
for( final IntegrationNode node : this.modules )
|
||||
{
|
||||
node.call( IntegrationStage.INIT );
|
||||
for (final IntegrationNode node : this.modules) {
|
||||
node.call(IntegrationStage.INIT);
|
||||
}
|
||||
}
|
||||
|
||||
public void postInit()
|
||||
{
|
||||
for( final IntegrationNode node : this.modules )
|
||||
{
|
||||
node.call( IntegrationStage.POST_INIT );
|
||||
public void postInit() {
|
||||
for (final IntegrationNode node : this.modules) {
|
||||
node.call(IntegrationStage.POST_INIT);
|
||||
}
|
||||
}
|
||||
|
||||
public String getStatus()
|
||||
{
|
||||
final StringBuilder builder = new StringBuilder( this.modules.size() * 3 );
|
||||
public String getStatus() {
|
||||
final StringBuilder builder = new StringBuilder(this.modules.size() * 3);
|
||||
|
||||
for( final IntegrationNode node : this.modules )
|
||||
{
|
||||
if( builder.length() != 0 )
|
||||
{
|
||||
builder.append( ", " );
|
||||
for (final IntegrationNode node : this.modules) {
|
||||
if (builder.length() != 0) {
|
||||
builder.append(", ");
|
||||
}
|
||||
|
||||
final String integrationState = node.getShortName() + ":" + ( node.getState() == IntegrationStage.FAILED ? "OFF" : "ON" );
|
||||
builder.append( integrationState );
|
||||
final String integrationState = node.getShortName() + ":" + (node.getState() == IntegrationStage.FAILED ? "OFF" : "ON");
|
||||
builder.append(integrationState);
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public boolean isEnabled( final IntegrationType name )
|
||||
{
|
||||
for( final IntegrationNode node : this.modules )
|
||||
{
|
||||
if( node.getShortName() == name )
|
||||
{
|
||||
public boolean isEnabled(final IntegrationType name) {
|
||||
for (final IntegrationNode node : this.modules) {
|
||||
if (node.getShortName() == name) {
|
||||
return node.isActive();
|
||||
}
|
||||
}
|
||||
@@ -84,17 +73,14 @@ public enum IntegrationRegistry
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Object getInstance( final IntegrationType name )
|
||||
{
|
||||
for( final IntegrationNode node : this.modules )
|
||||
{
|
||||
if( node.getShortName() == name && node.isActive() )
|
||||
{
|
||||
public Object getInstance(final IntegrationType name) {
|
||||
for (final IntegrationNode node : this.modules) {
|
||||
if (node.getShortName() == name && node.isActive()) {
|
||||
return node.getInstance();
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalStateException( "integration with " + name.name() + " is disabled." );
|
||||
throw new IllegalStateException("integration with " + name.name() + " is disabled.");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,7 +9,9 @@ public enum IntegrationType
|
||||
|
||||
//InvTweaks( IntegrationSide.CLIENT, "Inventory Tweaks", "inventorytweaks" ),
|
||||
|
||||
NEI( IntegrationSide.CLIENT, "Not Enough Items", "NotEnoughItems" );
|
||||
NEI( IntegrationSide.CLIENT, "Not Enough Items", "NotEnoughItems" ),
|
||||
|
||||
IC2( IntegrationSide.BOTH, "Industrial Craft 2", "IC2" );
|
||||
|
||||
public final IntegrationSide side;
|
||||
public final String dspName;
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package net.p455w0rd.wirelesscraftingterminal.integration.modules;
|
||||
|
||||
import net.p455w0rd.wirelesscraftingterminal.helpers.Reflected;
|
||||
import net.p455w0rd.wirelesscraftingterminal.integration.IIntegrationModule;
|
||||
import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationHelper;
|
||||
|
||||
public class IC2 implements IIntegrationModule
|
||||
{
|
||||
@Reflected
|
||||
public static IC2 instance;
|
||||
|
||||
@Reflected
|
||||
public IC2()
|
||||
{
|
||||
IntegrationHelper.testClassExistence( this, ic2.api.item.IElectricItem.class );
|
||||
IntegrationHelper.testClassExistence( this, ic2.api.item.ISpecialElectricItem.class );
|
||||
IntegrationHelper.testClassExistence( this, ic2.api.item.IElectricItemManager.class );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInit()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -197,7 +197,7 @@ public class ItemMagnet extends Item {
|
||||
return;
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
|
||||
List<ItemStack> filteredList = getFilteredItems(this.getItemStack());
|
||||
// items
|
||||
Iterator iterator = getEntitiesInRange(EntityItem.class, world, (int) player.posX, (int) player.posY, (int) player.posZ, this.distanceFromPlayer).iterator();
|
||||
@@ -367,6 +367,9 @@ public class ItemMagnet extends Item {
|
||||
}
|
||||
|
||||
private boolean hasNetworkAccess(final SecurityPermissions perm, final boolean requirePower, EntityPlayer player, ItemStack wirelessTerm) {
|
||||
if (player.capabilities.isCreativeMode) {
|
||||
return true;
|
||||
}
|
||||
final IGrid g = this.obj.getTargetGrid();
|
||||
if (g != null) {
|
||||
if (requirePower) {
|
||||
|
||||
+177
-35
@@ -13,8 +13,11 @@ import appeng.api.config.Settings;
|
||||
import appeng.api.config.SortDir;
|
||||
import appeng.api.config.SortOrder;
|
||||
import appeng.api.config.ViewItems;
|
||||
import appeng.api.implementations.items.IAEItemPowerStorage;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.items.tools.powered.powersink.AEBasePoweredItem;
|
||||
import appeng.core.features.IAEFeature;
|
||||
import appeng.core.features.IFeatureHandler;
|
||||
import appeng.items.tools.powered.powersink.AERootPoweredItem;
|
||||
import appeng.util.ConfigManager;
|
||||
import appeng.util.IConfigManagerHost;
|
||||
import appeng.util.Platform;
|
||||
@@ -22,8 +25,11 @@ import cofh.api.energy.IEnergyContainerItem;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import ic2.api.item.IElectricItemManager;
|
||||
import ic2.api.item.ISpecialElectricItem;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -37,20 +43,19 @@ import net.p455w0rd.wirelesscraftingterminal.api.WCTApi;
|
||||
import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils;
|
||||
import net.p455w0rd.wirelesscraftingterminal.handlers.LocaleHandler;
|
||||
import net.p455w0rd.wirelesscraftingterminal.reference.Reference;
|
||||
import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationType;
|
||||
import net.p455w0rd.wirelesscraftingterminal.transformer.annotations.Integration.Interface;
|
||||
|
||||
@Interface(iface = "cofh.api.energy.IEnergyContainerItem", iname = IntegrationType.RFItem)
|
||||
public class ItemWirelessCraftingTerminal extends AEBasePoweredItem implements IWirelessCraftingTermHandler, IEnergyContainerItem {
|
||||
public class ItemWirelessCraftingTerminal extends AERootPoweredItem implements IWirelessCraftingTermHandler, IAEItemPowerStorage, IAEFeature, IEnergyContainerItem, IElectricItemManager, ISpecialElectricItem
|
||||
{
|
||||
|
||||
private static final String LINK_KEY_STRING = "key";
|
||||
public static double GLOBAL_POWER_MULTIPLIER = PowerMultiplier.CONFIG.multiplier;
|
||||
private static final String POWER_NBT_KEY = "internalCurrentPower";
|
||||
private static final String BOOSTER_SLOT_NBT = "BoosterSlot";
|
||||
private static final String MAGNET_SLOT_NBT = "MagnetSlot";
|
||||
private EntityPlayer entityPlayer;
|
||||
|
||||
public ItemWirelessCraftingTerminal() {
|
||||
super(Reference.WCT_MAX_POWER, Optional.<String> absent());
|
||||
super(Reference.WCT_MAX_POWER, Optional.<String>absent());
|
||||
setUnlocalizedName("wirelessCraftingTerminal");
|
||||
setTextureName(Reference.MODID + ":wirelessCraftingTerminal");
|
||||
setMaxStackSize(1);
|
||||
@@ -100,6 +105,9 @@ public class ItemWirelessCraftingTerminal extends AEBasePoweredItem implements I
|
||||
return;
|
||||
}
|
||||
EntityPlayer p = (EntityPlayer) e;
|
||||
if (this.entityPlayer == null) {
|
||||
this.entityPlayer = p;
|
||||
}
|
||||
ItemStack wirelessTerminal = null;
|
||||
InventoryPlayer inv = p.inventory;
|
||||
wirelessTerminal = RandomUtils.getWirelessTerm(inv);
|
||||
@@ -199,9 +207,11 @@ public class ItemWirelessCraftingTerminal extends AEBasePoweredItem implements I
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addCheckedInformation(ItemStack is, EntityPlayer player, List<String> list, boolean displayMore) {
|
||||
@Override
|
||||
public void addCheckedInformation(ItemStack is, EntityPlayer player, List list, boolean displayMore) {
|
||||
String shift = LocaleHandler.PressShift.getLocal().replace("Shift", color("yellow") + "" + color("bold") + "" + color("italics") + "Shift" + color("gray"));
|
||||
final NBTTagCompound tag = ensureTagCompound(is);
|
||||
|
||||
@@ -311,7 +321,11 @@ public class ItemWirelessCraftingTerminal extends AEBasePoweredItem implements I
|
||||
|
||||
@Override
|
||||
public double extractAEPower(final ItemStack is, final double amt) {
|
||||
return getInternalBattery(is, batteryOperation.EXTRACT, amt);
|
||||
int finalAmt = 0;
|
||||
if (this.entityPlayer != null) {
|
||||
finalAmt = (int) (this.entityPlayer.capabilities.isCreativeMode ? 0 : amt);
|
||||
}
|
||||
return getInternalBattery(is, batteryOperation.EXTRACT, finalAmt);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -319,6 +333,42 @@ public class ItemWirelessCraftingTerminal extends AEBasePoweredItem implements I
|
||||
return Reference.WCT_MAX_POWER;
|
||||
}
|
||||
|
||||
private enum batteryOperation {
|
||||
STORAGE, INJECT, EXTRACT
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDamageable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDamaged(final ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRepairable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public boolean isFull3D() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxDamage() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDamage(ItemStack stack) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//RF Integration
|
||||
@Override
|
||||
public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) {
|
||||
if (container == null) {
|
||||
@@ -373,40 +423,132 @@ public class ItemWirelessCraftingTerminal extends AEBasePoweredItem implements I
|
||||
public int getMaxEnergyStored(ItemStack container) {
|
||||
return (int) PowerUnits.AE.convertTo(PowerUnits.RF, getAEMaxPower(container));
|
||||
}
|
||||
|
||||
//IC2 integration
|
||||
private double wctInjectExternalPower( final PowerUnits input, final ItemStack is, final double amount, final boolean simulate )
|
||||
{
|
||||
if( simulate )
|
||||
{
|
||||
final int requiredEU = (int) PowerUnits.AE.convertTo( PowerUnits.EU, this.getAEMaxPower( is ) - this.getAECurrentPower( is ) );
|
||||
if( amount < requiredEU )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return amount - requiredEU;
|
||||
}
|
||||
else
|
||||
{
|
||||
final double powerRemainder = this.injectAEPower( is, PowerUnits.EU.convertTo( PowerUnits.AE, amount ) );
|
||||
return PowerUnits.AE.convertTo( PowerUnits.EU, powerRemainder );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double charge( final ItemStack is, final double amount, final int tier, final boolean ignoreTransferLimit, final boolean simulate )
|
||||
{
|
||||
double addedAmt = amount;
|
||||
final double limit = this.getTransferLimit( is );
|
||||
|
||||
private enum batteryOperation {
|
||||
STORAGE, INJECT, EXTRACT
|
||||
if( !ignoreTransferLimit && amount > limit )
|
||||
{
|
||||
addedAmt = limit;
|
||||
}
|
||||
|
||||
return addedAmt - ( (int) this.wctInjectExternalPower( PowerUnits.EU, is, addedAmt, simulate ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDamageable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDamaged(final ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRepairable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public boolean isFull3D() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxDamage() {
|
||||
public double discharge( final ItemStack itemStack, final double amount, final int tier, final boolean ignoreTransferLimit, final boolean externally, final boolean simulate )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDamage(ItemStack stack) {
|
||||
return 0;
|
||||
public double getCharge( final ItemStack is )
|
||||
{
|
||||
return (int) PowerUnits.AE.convertTo( PowerUnits.EU, this.getAECurrentPower( is ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse( final ItemStack is, final double amount )
|
||||
{
|
||||
return this.getCharge( is ) > amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean use( final ItemStack is, final double amount, final EntityLivingBase entity )
|
||||
{
|
||||
if( this.canUse( is, amount ) )
|
||||
{
|
||||
// use the power..
|
||||
this.extractAEPower( is, PowerUnits.EU.convertTo( PowerUnits.AE, amount ) );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void chargeFromArmor( final ItemStack itemStack, final EntityLivingBase entity )
|
||||
{
|
||||
// wtf?
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getToolTip( final ItemStack itemStack )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy( final ItemStack itemStack )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getChargedItem( final ItemStack itemStack )
|
||||
{
|
||||
return itemStack.getItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getEmptyItem( final ItemStack itemStack )
|
||||
{
|
||||
return itemStack.getItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxCharge( final ItemStack itemStack )
|
||||
{
|
||||
return PowerUnits.AE.convertTo( PowerUnits.EU, this.getAEMaxPower( itemStack ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTier( final ItemStack itemStack )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTransferLimit( final ItemStack itemStack )
|
||||
{
|
||||
return Math.max( 32, this.getMaxCharge( itemStack ) / 200 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IElectricItemManager getManager( final ItemStack itemStack )
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFeatureHandler handler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInit() {
|
||||
// X)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +1,11 @@
|
||||
package net.p455w0rd.wirelesscraftingterminal.proxy;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.p455w0rd.wirelesscraftingterminal.handlers.KeybindHandler;
|
||||
import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationRegistry;
|
||||
import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationType;
|
||||
import net.p455w0rd.wirelesscraftingterminal.items.ItemEnum;
|
||||
import net.p455w0rd.wirelesscraftingterminal.transformer.MissingCoreMod;
|
||||
|
||||
public class ClientProxy extends CommonProxy {
|
||||
|
||||
@@ -19,7 +17,7 @@ public class ClientProxy extends CommonProxy {
|
||||
|
||||
@Override
|
||||
public void removeItemsFromNEI() {
|
||||
if (IntegrationRegistry.INSTANCE.isEnabled(IntegrationType.NEI)) {
|
||||
if (Loader.isModLoaded("NotEnoughItems")) {
|
||||
codechicken.nei.api.API.hideItem(new ItemStack(ItemEnum.WCT_BOOSTER_BG_ICON.getItem(), 1));
|
||||
return;
|
||||
}
|
||||
@@ -29,9 +27,4 @@ public class ClientProxy extends CommonProxy {
|
||||
// No renderers...yet =]
|
||||
}
|
||||
|
||||
@Override
|
||||
public void missingCoreMod() {
|
||||
throw new MissingCoreMod();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -59,10 +59,6 @@ public class CommonProxy {
|
||||
// =P
|
||||
}
|
||||
|
||||
public void missingCoreMod() {
|
||||
throw new IllegalStateException("Unable to Load WCT Core Mod, please verify that WCT is properly install in the mods folder, with a .jar extension.");
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void tickEvent(TickEvent.PlayerTickEvent e) {
|
||||
ItemStack wirelessTerm = null;
|
||||
|
||||
@@ -2,7 +2,7 @@ package net.p455w0rd.wirelesscraftingterminal.reference;
|
||||
|
||||
public class Reference {
|
||||
public static final String MODID = "ae2wct";
|
||||
public static final String VERSION = "1.7.10-rv3-1.6b";
|
||||
public static final String VERSION = "@version@";
|
||||
public static final String NAME = "AE2 Wireless Crafting Terminal";
|
||||
public static final String SERVER_PROXY_CLASS = "net.p455w0rd.wirelesscraftingterminal.proxy.CommonProxy";
|
||||
public static final String CLIENT_PROXY_CLASS = "net.p455w0rd.wirelesscraftingterminal.proxy.ClientProxy";
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
package net.p455w0rd.wirelesscraftingterminal.transformer;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationType;
|
||||
|
||||
public @interface Integration
|
||||
{
|
||||
@Retention( RetentionPolicy.RUNTIME )
|
||||
@Target( ElementType.TYPE )
|
||||
@interface InterfaceList
|
||||
{
|
||||
Interface[] value();
|
||||
}
|
||||
|
||||
@Retention( RetentionPolicy.RUNTIME )
|
||||
@Target( ElementType.TYPE )
|
||||
@interface Interface
|
||||
{
|
||||
String iface();
|
||||
|
||||
IntegrationType iname();
|
||||
}
|
||||
|
||||
@Retention( RetentionPolicy.RUNTIME )
|
||||
@Target( ElementType.METHOD )
|
||||
@interface Method
|
||||
{
|
||||
IntegrationType iname();
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
package net.p455w0rd.wirelesscraftingterminal.transformer;
|
||||
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiErrorScreen;
|
||||
|
||||
import cpw.mods.fml.client.CustomModLoadingErrorDisplayException;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
public final class MissingCoreMod extends CustomModLoadingErrorDisplayException
|
||||
{
|
||||
private static final int SHADOW_WHITE = 0xeeeeee;
|
||||
private static final int COLOR_WHITE = 0xffffff;
|
||||
private static final long serialVersionUID = -966774766922821652L;
|
||||
private static final int SCREEN_OFFSET = 15;
|
||||
|
||||
private boolean deobf = false;
|
||||
|
||||
@Override
|
||||
public void initGui( final GuiErrorScreen errorScreen, final FontRenderer fontRenderer )
|
||||
{
|
||||
final Class<?> clz = errorScreen.getClass();
|
||||
try
|
||||
{
|
||||
clz.getField( "mc" );
|
||||
this.deobf = true;
|
||||
}
|
||||
catch( final Throwable ignored )
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen( final GuiErrorScreen errorScreen, final FontRenderer fontRenderer, final int mouseRelX, final int mouseRelY, final float tickTime )
|
||||
{
|
||||
int offset = 10;
|
||||
this.drawCenteredString( fontRenderer, "Sorry, couldn't load WCT properly.", errorScreen.width / 2, offset, COLOR_WHITE );
|
||||
|
||||
offset += SCREEN_OFFSET;
|
||||
this.drawCenteredString( fontRenderer, "Please make sure that WCT is installed into your mods folder.", errorScreen.width / 2, offset, SHADOW_WHITE );
|
||||
|
||||
offset += 2 * SCREEN_OFFSET;
|
||||
|
||||
if( this.deobf )
|
||||
{
|
||||
offset += SCREEN_OFFSET;
|
||||
this.drawCenteredString( fontRenderer, "In a developer environment add the following too your args,", errorScreen.width / 2, offset, COLOR_WHITE );
|
||||
|
||||
offset += SCREEN_OFFSET;
|
||||
this.drawCenteredString( fontRenderer, "-Dfml.coreMods.load=net.p455w0rd.wirelesscraftingterminal.transformer.WCTCore", errorScreen.width / 2, offset, SHADOW_WHITE );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.drawCenteredString( fontRenderer, "You're launcher may refer to this by different names,", errorScreen.width / 2, offset, COLOR_WHITE );
|
||||
|
||||
offset += SCREEN_OFFSET + 5;
|
||||
|
||||
this.drawCenteredString( fontRenderer, "MultiMC calls this tab \"Loader Mods\"", errorScreen.width / 2, offset, SHADOW_WHITE );
|
||||
|
||||
offset += SCREEN_OFFSET;
|
||||
this.drawCenteredString( fontRenderer, "Magic Launcher calls this tab \"External Mods\"", errorScreen.width / 2, offset, SHADOW_WHITE );
|
||||
|
||||
offset += SCREEN_OFFSET;
|
||||
this.drawCenteredString( fontRenderer, "Most other launchers refer to this tab as just \"Mods\"", errorScreen.width / 2, offset, SHADOW_WHITE );
|
||||
|
||||
offset += 2 * SCREEN_OFFSET;
|
||||
this.drawCenteredString( fontRenderer, "Also make sure that the WCT file is a .jar, and not a .zip", errorScreen.width / 2, offset, COLOR_WHITE );
|
||||
}
|
||||
}
|
||||
|
||||
private void drawCenteredString( final FontRenderer fontRenderer, final String string, final int x, final int y, final int colour )
|
||||
{
|
||||
final String reEncoded = string.replaceAll( "\\P{InBasic_Latin}", "" );
|
||||
final int reEncodedWidth = fontRenderer.getStringWidth( reEncoded );
|
||||
final int centeredX = x - reEncodedWidth / 2;
|
||||
|
||||
fontRenderer.drawStringWithShadow( string, centeredX, y, colour );
|
||||
}
|
||||
}
|
||||
@@ -1,136 +0,0 @@
|
||||
package net.p455w0rd.wirelesscraftingterminal.transformer;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.eventbus.EventBus;
|
||||
|
||||
import cpw.mods.fml.common.DummyModContainer;
|
||||
import cpw.mods.fml.common.LoadController;
|
||||
import cpw.mods.fml.common.Mod.EventHandler;
|
||||
import cpw.mods.fml.common.ModMetadata;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.relauncher.FMLRelaunchLog;
|
||||
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
|
||||
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.MCVersion;
|
||||
import cpw.mods.fml.common.versioning.ArtifactVersion;
|
||||
import cpw.mods.fml.common.versioning.VersionParser;
|
||||
import net.p455w0rd.wirelesscraftingterminal.reference.Reference;
|
||||
|
||||
|
||||
|
||||
@MCVersion( "1.7.10" )
|
||||
public final class WCTCore extends DummyModContainer implements IFMLLoadingPlugin
|
||||
{
|
||||
private final ModMetadata metadata = new ModMetadata();
|
||||
|
||||
public WCTCore()
|
||||
{
|
||||
FMLRelaunchLog.info( "[WCT] Core Init" );
|
||||
this.metadata.autogenerated = false;
|
||||
this.metadata.authorList.add( "p455w0rd" );
|
||||
this.metadata.credits = "AlgorithmX2";
|
||||
this.metadata.modId = this.getModId();
|
||||
this.metadata.version = this.getVersion();
|
||||
this.metadata.name = this.getName();
|
||||
this.metadata.url = "http://p455w0rd.net/mc";
|
||||
this.metadata.description = "Embedded Coremod for Wireless Crafting Terminal";
|
||||
this.metadata.autogenerated = false;
|
||||
this.metadata.dependencies=this.getDependencies();
|
||||
this.metadata.requiredMods=this.getRequirements();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void load( final FMLInitializationEvent event )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ArtifactVersion> getDependencies()
|
||||
{
|
||||
List<ArtifactVersion> deps = Lists.newArrayList();
|
||||
deps.add(VersionParser.parseVersionReference("appliedenergistics2-core"));
|
||||
return deps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ArtifactVersion> getRequirements()
|
||||
{
|
||||
Set<ArtifactVersion> reqDeps = new HashSet<ArtifactVersion>();
|
||||
reqDeps.add(VersionParser.parseVersionReference("appliedenergistics2-core"));
|
||||
return reqDeps;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String[] getASMTransformerClass()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModContainerClass()
|
||||
{
|
||||
return "net.p455w0rd.wirelesscraftingterminal.transformer.WCTCore";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getSetupClass()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectData( final Map<String, Object> data )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAccessTransformerClass()
|
||||
{
|
||||
return "net.p455w0rd.wirelesscraftingterminal.transformer.asm.ASMIntegration";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModMetadata getMetadata()
|
||||
{
|
||||
return this.metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModId()
|
||||
{
|
||||
return "wct-core";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "Wireless Crafting Terminal Core";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion()
|
||||
{
|
||||
return Reference.VERSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean registerBus( final EventBus bus, final LoadController controller )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayVersion()
|
||||
{
|
||||
return this.getVersion();
|
||||
}
|
||||
}
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
package net.p455w0rd.wirelesscraftingterminal.transformer.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationType;
|
||||
|
||||
|
||||
public @interface Integration
|
||||
{
|
||||
@Retention( RetentionPolicy.RUNTIME )
|
||||
@Target( ElementType.TYPE )
|
||||
@interface InterfaceList
|
||||
{
|
||||
Interface[] value();
|
||||
}
|
||||
|
||||
@Retention( RetentionPolicy.RUNTIME )
|
||||
@Target( ElementType.TYPE )
|
||||
@interface Interface
|
||||
{
|
||||
String iface();
|
||||
|
||||
IntegrationType iname();
|
||||
}
|
||||
|
||||
@Retention( RetentionPolicy.RUNTIME )
|
||||
@Target( ElementType.METHOD )
|
||||
@interface Method
|
||||
{
|
||||
IntegrationType iname();
|
||||
}
|
||||
}
|
||||
@@ -1,182 +0,0 @@
|
||||
package net.p455w0rd.wirelesscraftingterminal.transformer.asm;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.AnnotationNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
import net.minecraft.launchwrapper.IClassTransformer;
|
||||
import net.p455w0rd.wirelesscraftingterminal.helpers.Reflected;
|
||||
import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationRegistry;
|
||||
import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationType;
|
||||
import net.p455w0rd.wirelesscraftingterminal.transformer.Integration;
|
||||
import cpw.mods.fml.relauncher.FMLRelaunchLog;
|
||||
|
||||
@Reflected
|
||||
public final class ASMIntegration implements IClassTransformer {
|
||||
@Reflected
|
||||
public ASMIntegration() {
|
||||
|
||||
/**
|
||||
* Side, Display Name, ModID ClassPostFix
|
||||
*/
|
||||
|
||||
for (final IntegrationType type : IntegrationType.values()) {
|
||||
IntegrationRegistry.INSTANCE.add(type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public byte[] transform(final String name, final String transformedName, final byte[] basicClass) {
|
||||
if (basicClass == null || transformedName.startsWith("net.p455w0rd.wirelesscraftingterminal.transformer")) {
|
||||
return basicClass;
|
||||
}
|
||||
|
||||
if (transformedName.startsWith("net.p455w0rd.wirelesscraftingterminal.")) {
|
||||
final ClassNode classNode = new ClassNode();
|
||||
final ClassReader classReader = new ClassReader(basicClass);
|
||||
classReader.accept(classNode, 0);
|
||||
|
||||
try {
|
||||
final boolean reWrite = this.removeOptionals(classNode);
|
||||
|
||||
if (reWrite) {
|
||||
final ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
|
||||
classNode.accept(writer);
|
||||
return writer.toByteArray();
|
||||
}
|
||||
} catch (final Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
return basicClass;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private boolean removeOptionals(final ClassNode classNode) {
|
||||
boolean changed = false;
|
||||
|
||||
if (classNode.visibleAnnotations != null) {
|
||||
for (final AnnotationNode an : classNode.visibleAnnotations) {
|
||||
if (this.hasAnnotation(an, Integration.Interface.class)) {
|
||||
if (this.stripInterface(classNode, Integration.Interface.class, an)) {
|
||||
changed = true;
|
||||
}
|
||||
} else if (this.hasAnnotation(an, Integration.InterfaceList.class)) {
|
||||
for (final Object o : ((Iterable) an.values.get(1))) {
|
||||
if (this.stripInterface(classNode, Integration.InterfaceList.class, (AnnotationNode) o)) {
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final Iterator<MethodNode> i = classNode.methods.iterator();
|
||||
while (i.hasNext()) {
|
||||
final MethodNode mn = i.next();
|
||||
|
||||
if (mn.visibleAnnotations != null) {
|
||||
for (final AnnotationNode an : mn.visibleAnnotations) {
|
||||
if (this.hasAnnotation(an, Integration.Method.class)) {
|
||||
if (this.stripMethod(classNode, mn, i, Integration.Method.class, an)) {
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
this.log("Updated " + classNode.name);
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
private boolean hasAnnotation(final AnnotationNode ann, final Class<?> annotation) {
|
||||
return ann.desc.equals(Type.getDescriptor(annotation));
|
||||
}
|
||||
|
||||
private boolean stripInterface(final ClassNode classNode, final Class<?> class1, final AnnotationNode an) {
|
||||
if (an.values.size() != 4) {
|
||||
throw new IllegalArgumentException("Unable to handle Interface annotation on " + classNode.name);
|
||||
}
|
||||
|
||||
String iFace = null;
|
||||
|
||||
if (an.values.get(0).equals("iface")) {
|
||||
iFace = (String) an.values.get(1);
|
||||
} else if (an.values.get(2).equals("iface")) {
|
||||
iFace = (String) an.values.get(3);
|
||||
}
|
||||
|
||||
String iName = null;
|
||||
if (an.values.get(0).equals("iname")) {
|
||||
iName = ((String[]) an.values.get(1))[1];
|
||||
} else if (an.values.get(2).equals("iname")) {
|
||||
iName = ((String[]) an.values.get(3))[1];
|
||||
}
|
||||
|
||||
if (iName != null && iFace != null) {
|
||||
final IntegrationType type = IntegrationType.valueOf(iName);
|
||||
if (!IntegrationRegistry.INSTANCE.isEnabled(type)) {
|
||||
this.log("Removing Interface " + iFace + " from " + classNode.name + " because " + iName
|
||||
+ " integration is disabled.");
|
||||
classNode.interfaces.remove(iFace.replace('.', '/'));
|
||||
return true;
|
||||
} else {
|
||||
this.log("Allowing Interface " + iFace + " from " + classNode.name + " because " + iName
|
||||
+ " integration is enabled.");
|
||||
}
|
||||
} else {
|
||||
throw new IllegalStateException("Unable to handle Method annotation on " + classNode.name);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private boolean stripMethod(final ClassNode classNode, final MethodNode mn, final Iterator<MethodNode> i,
|
||||
final Class class1, final AnnotationNode an) {
|
||||
if (an.values.size() != 2) {
|
||||
throw new IllegalArgumentException("Unable to handle Method annotation on " + classNode.name);
|
||||
}
|
||||
|
||||
String iName = null;
|
||||
|
||||
if (an.values.get(0).equals("iname")) {
|
||||
iName = ((String[]) an.values.get(1))[1];
|
||||
}
|
||||
|
||||
if (iName != null) {
|
||||
final IntegrationType type = IntegrationType.valueOf(iName);
|
||||
if (!IntegrationRegistry.INSTANCE.isEnabled(type)) {
|
||||
this.log("Removing Method " + mn.name + " from " + classNode.name + " because " + iName
|
||||
+ " integration is disabled.");
|
||||
i.remove();
|
||||
return true;
|
||||
} else {
|
||||
this.log("Allowing Method " + mn.name + " from " + classNode.name + " because " + iName
|
||||
+ " integration is enabled.");
|
||||
}
|
||||
} else {
|
||||
throw new IllegalStateException("Unable to handle Method annotation on " + classNode.name);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void log(final String string) {
|
||||
FMLRelaunchLog.log("WCT-CORE", Level.INFO, string);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user