Fixed Abstract Bus Card in servers (broke in recent cleanup).

Updated SGT2 API.
This commit is contained in:
Florian Nücke 2014-04-20 20:53:48 +02:00
parent 50ddf683d2
commit bbe80bc5de
7 changed files with 101 additions and 24 deletions

View File

@ -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<String> getAllStacks();
}

View File

@ -24,4 +24,9 @@ public interface IStargateTechAPI {
* @return The current IFactory instance.
*/
public IFactory getFactory();
/**
* @return The current IStackManager instance.
*/
public IStackManager getStackManager();
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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<String> playerExceptions = new ArrayList<String>();
private LinkedList<String> playerExceptions = new LinkedList<String>();
/**
* @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<String> getExceptionList(){
public List<String> 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<String>(exceptions);
permissions.playerExceptions = new LinkedList<String>();
for(int i = 0; i < exceptions; i++){
permissions.setPlayerException(nbt.getString("pex" + i));
}

View File

@ -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] = {

View File

@ -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
}