From bbe80bc5de5f5918ca48380f7f0d4a653956e974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sun, 20 Apr 2014 20:53:48 +0200 Subject: [PATCH] Fixed Abstract Bus Card in servers (broke in recent cleanup). Updated SGT2 API. --- .../java/stargatetech2/api/IStackManager.java | 34 +++++++++++++++++ .../stargatetech2/api/IStargateTechAPI.java | 5 +++ .../api/shields/IShieldController.java | 37 +++++++++++++++++++ .../api/shields/IShieldable.java | 10 ++--- .../api/shields/ShieldPermissions.java | 24 ++++++------ .../cil/oc/common/asm/ClassTransformer.scala | 11 +++--- .../server/driver/item/AbstractBusCard.scala | 4 +- 7 files changed, 101 insertions(+), 24 deletions(-) create mode 100644 src/api/java/stargatetech2/api/IStackManager.java create mode 100644 src/api/java/stargatetech2/api/shields/IShieldController.java diff --git a/src/api/java/stargatetech2/api/IStackManager.java b/src/api/java/stargatetech2/api/IStackManager.java new file mode 100644 index 000000000..a1493c727 --- /dev/null +++ b/src/api/java/stargatetech2/api/IStackManager.java @@ -0,0 +1,34 @@ +package stargatetech2.api; + +import java.util.Collection; + +import net.minecraft.item.ItemStack; + +/** + * The way to get ItemStacks added to the game by StargateTech 2 + * + * @author LordFokas + */ +public interface IStackManager { + /** + * Used to fetch an ItemStack by it's name, with a default size of 1. + * + * @param stack The stack we want to fetch. + * @return The stack, or null if none was found. + */ + public ItemStack get(String stack); + + /** + * Used to fetch an ItemStack by it's name with a given size. + * + * @param stack The stack we want to fetch. + * @param size The size the stack comes with. Must be in the range 1 - 64. + * @return The stack, or null if none was found. + */ + public ItemStack get(String stack, int size); + + /** + * @return A list with the names of all the existing stacks. + */ + public Collection getAllStacks(); +} \ No newline at end of file diff --git a/src/api/java/stargatetech2/api/IStargateTechAPI.java b/src/api/java/stargatetech2/api/IStargateTechAPI.java index ab00336e3..04e0ad6ed 100644 --- a/src/api/java/stargatetech2/api/IStargateTechAPI.java +++ b/src/api/java/stargatetech2/api/IStargateTechAPI.java @@ -24,4 +24,9 @@ public interface IStargateTechAPI { * @return The current IFactory instance. */ public IFactory getFactory(); + + /** + * @return The current IStackManager instance. + */ + public IStackManager getStackManager(); } \ No newline at end of file diff --git a/src/api/java/stargatetech2/api/shields/IShieldController.java b/src/api/java/stargatetech2/api/shields/IShieldController.java new file mode 100644 index 000000000..4f3fa4763 --- /dev/null +++ b/src/api/java/stargatetech2/api/shields/IShieldController.java @@ -0,0 +1,37 @@ +package stargatetech2.api.shields; + +/** + * Implemented by the Shield Controller TileEntities. + * + * @author LordFokas + */ +public interface IShieldController { + /** + * Given the way shield emitters work together, you cannot + * directly access their ShieldPermissions object. + * This means you cannot use this method to change + * permissions on a shield. + * + * @return A deep clone of the ShieldPermissions object that + * defines this controller's shield behavior. + */ + public ShieldPermissions getPermissions(); + + /** + * @return True if the shield is activated, false otherwise. + */ + public boolean isShieldOn(); + + /** + * @return The name of the player who owns this Shield Controller. + */ + public String getOwner(); + + /** + * Checks if a player can access this device. + * + * @param player The player's name. + * @return Whether or not this player can access this device. + */ + public boolean hasAccess(String player); +} \ No newline at end of file diff --git a/src/api/java/stargatetech2/api/shields/IShieldable.java b/src/api/java/stargatetech2/api/shields/IShieldable.java index b185defe8..50003e0e3 100644 --- a/src/api/java/stargatetech2/api/shields/IShieldable.java +++ b/src/api/java/stargatetech2/api/shields/IShieldable.java @@ -10,16 +10,16 @@ import net.minecraft.world.World; public interface IShieldable { /** * Called by shield emitters to make blocks raise their shields. - * The block on {px, py, pz} contains an ITileShieldEmitter from which - * you can get the current ShieldPermissions object. + * The block on {px, py, pz} contains an IShieldController from + * which you can get the current ShieldPermissions object. * * @param world The world this IShieldable is on. * @param x This IShieldable's X Coordinate. * @param y This IShieldable's Y Coordinate. * @param z This IShieldable's Z Coordinate. - * @param px The X Coordinate of the shield emitter raising a shield on this block. - * @param py The Y Coordinate of the shield emitter raising a shield on this block. - * @param pz The Z Coordinate of the shield emitter raising a shield on this block. + * @param px The X Coordinate of the shield controller in charge of the shield on this block. + * @param py The Y Coordinate of the shield controller in charge of the shield on this block. + * @param pz The Z Coordinate of the shield controller in charge of the shield on this block. */ public void onShield(World world, int x, int y, int z, int px, int py, int pz); diff --git a/src/api/java/stargatetech2/api/shields/ShieldPermissions.java b/src/api/java/stargatetech2/api/shields/ShieldPermissions.java index c0cf3920c..da06013bd 100644 --- a/src/api/java/stargatetech2/api/shields/ShieldPermissions.java +++ b/src/api/java/stargatetech2/api/shields/ShieldPermissions.java @@ -1,6 +1,7 @@ package stargatetech2.api.shields; -import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityMinecart; @@ -13,21 +14,22 @@ import net.minecraft.nbt.NBTTagCompound; public class ShieldPermissions { // Permission Flags - public static final int PERM_PLAYER = 0x01; - public static final int PERM_VILLAGER = 0x02; - public static final int PERM_ANIMAL = 0x04; - public static final int PERM_MONSTER = 0x08; - public static final int PERM_MINECART = 0x10; + public static final int PERM_FRIEND = 0x01; + public static final int PERM_PLAYER = 0x02; + public static final int PERM_VILLAGER = 0x04; + public static final int PERM_ANIMAL = 0x08; + public static final int PERM_MONSTER = 0x10; + public static final int PERM_VESSEL = 0x20; private int permValue = 0; - private ArrayList playerExceptions = new ArrayList(); + private LinkedList playerExceptions = new LinkedList(); /** * @return A default ShieldPermissions object. */ public static ShieldPermissions getDefault(){ ShieldPermissions perm = new ShieldPermissions(); - perm.allow(PERM_PLAYER); + perm.allow(PERM_FRIEND | PERM_PLAYER); return perm; } @@ -68,7 +70,7 @@ public class ShieldPermissions { * @return A list of strings containing the names of all the players * who currently are exceptions to the player permission setting. */ - public ArrayList getExceptionList(){ + public List getExceptionList(){ return playerExceptions; } @@ -96,7 +98,7 @@ public class ShieldPermissions { }else if(entity instanceof EntityMob){ allow = hasBit(PERM_MONSTER); }else if(entity instanceof EntityMinecart){ - allow = hasBit(PERM_MINECART); + allow = hasBit(PERM_VESSEL); } if(allow && entity.riddenByEntity != null && doDismount && entity.worldObj.isRemote == false){ if(!isEntityAllowed(entity.riddenByEntity, true)){ @@ -141,7 +143,7 @@ public class ShieldPermissions { if(nbt != null){ int exceptions = nbt.getInteger("exceptions"); permissions.permValue = nbt.getInteger("permValue"); - permissions.playerExceptions = new ArrayList(exceptions); + permissions.playerExceptions = new LinkedList(); for(int i = 0; i < exceptions; i++){ permissions.setPlayerException(nbt.getString("pex" + i)); } diff --git a/src/main/scala/li/cil/oc/common/asm/ClassTransformer.scala b/src/main/scala/li/cil/oc/common/asm/ClassTransformer.scala index f43ae4a63..e121bac7e 100644 --- a/src/main/scala/li/cil/oc/common/asm/ClassTransformer.scala +++ b/src/main/scala/li/cil/oc/common/asm/ClassTransformer.scala @@ -86,13 +86,12 @@ class ClassTransformer extends IClassTransformer { def ensureStargateTechCompatibility(basicClass: Array[Byte]): Array[Byte] = { if (!Mods.StargateTech2.isAvailable) { - return basicClass + // No SGT2 or version is too old, abstract bus API doesn't exist. + val classNode = newClassNode(basicClass) + classNode.interfaces.remove("stargatetech2/api/bus/IBusDevice") + writeClass(classNode) } - - // Version of SGT2 is too old, abstract bus API doesn't exist. - val classNode = newClassNode(basicClass) - classNode.interfaces.remove("stargatetech2/api/bus/IBusDevice") - writeClass(classNode) + else basicClass } def injectEnvironmentImplementation(classNode: ClassNode, basicClass: Array[Byte]): Array[Byte] = { diff --git a/src/main/scala/li/cil/oc/server/driver/item/AbstractBusCard.scala b/src/main/scala/li/cil/oc/server/driver/item/AbstractBusCard.scala index a7bf25d28..717a5aa94 100644 --- a/src/main/scala/li/cil/oc/server/driver/item/AbstractBusCard.scala +++ b/src/main/scala/li/cil/oc/server/driver/item/AbstractBusCard.scala @@ -5,13 +5,13 @@ import li.cil.oc.api.driver.Slot import li.cil.oc.server.component import li.cil.oc.util.mods.Mods import net.minecraft.item.ItemStack -import net.minecraft.tileentity.{TileEntity => MCTileEntity} +import net.minecraft.tileentity.TileEntity import stargatetech2.api.bus.IBusDevice object AbstractBusCard extends Item { override def worksWith(stack: ItemStack) = isOneOf(stack, Items.abstractBus) - override def createEnvironment(stack: ItemStack, container: MCTileEntity) = if (Mods.StargateTech2.isAvailable) container match { + override def createEnvironment(stack: ItemStack, container: TileEntity) = if (Mods.StargateTech2.isAvailable) container match { case device: IBusDevice => new component.AbstractBus(device) case _ => null }