-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a7e869e
commit 71a9abd
Showing
9 changed files
with
279 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/scala/li/cil/oc/integration/cofh/item/EventHandlerCoFH.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package li.cil.oc.integration.cofh.item | ||
|
||
import cofh.api.item.IToolHammer | ||
import net.minecraft.entity.player.EntityPlayer | ||
import net.minecraft.item.ItemStack | ||
import net.minecraft.util.math.BlockPos | ||
|
||
object EventHandlerCoFH { | ||
def useWrench(player: EntityPlayer, pos: BlockPos, changeDurability: Boolean): Boolean = { | ||
player.getHeldItemMainhand.getItem match { | ||
case wrench: IToolHammer => | ||
if (changeDurability) { | ||
wrench.toolUsed(player.getHeldItemMainhand, player, pos) | ||
true | ||
} | ||
else wrench.isUsable(player.getHeldItemMainhand, player, pos) | ||
case _ => false | ||
} | ||
} | ||
|
||
def isWrench(stack: ItemStack): Boolean = stack.getItem.isInstanceOf[IToolHammer] | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/scala/li/cil/oc/integration/cofh/item/ModCoFHItem.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package li.cil.oc.integration.cofh.item | ||
|
||
import li.cil.oc.api | ||
import li.cil.oc.integration.ModProxy | ||
import li.cil.oc.integration.Mods | ||
|
||
object ModCoFHItem extends ModProxy { | ||
override def getMod = Mods.CoFHCore | ||
|
||
override def initialize(): Unit = { | ||
api.IMC.registerWrenchTool("li.cil.oc.integration.cofh.item.EventHandlerCoFH.useWrench") | ||
api.IMC.registerWrenchToolCheck("li.cil.oc.integration.cofh.item.EventHandlerCoFH.isWrench") | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/scala/li/cil/oc/integration/cofh/tileentity/DriverEnergyInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package li.cil.oc.integration.cofh.tileentity; | ||
|
||
import cofh.api.tileentity.IEnergyInfo; | ||
import li.cil.oc.api.machine.Arguments; | ||
import li.cil.oc.api.machine.Callback; | ||
import li.cil.oc.api.machine.Context; | ||
import li.cil.oc.api.network.ManagedEnvironment; | ||
import li.cil.oc.api.prefab.DriverSidedTileEntity; | ||
import li.cil.oc.integration.ManagedTileEntityEnvironment; | ||
import net.minecraft.util.EnumFacing; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
|
||
public final class DriverEnergyInfo extends DriverSidedTileEntity { | ||
@Override | ||
public Class<?> getTileEntityClass() { | ||
return IEnergyInfo.class; | ||
} | ||
|
||
@Override | ||
public ManagedEnvironment createEnvironment(final World world, final BlockPos pos, final EnumFacing side) { | ||
return new Environment((IEnergyInfo) world.getTileEntity(pos)); | ||
} | ||
|
||
public static final class Environment extends ManagedTileEntityEnvironment<IEnergyInfo> { | ||
public Environment(final IEnergyInfo tileEntity) { | ||
super(tileEntity, "energy_info"); | ||
} | ||
|
||
@Callback(doc = "function():number -- Returns the amount of stored energy.") | ||
public Object[] getEnergy(final Context context, final Arguments args) { | ||
return new Object[]{tileEntity.getInfoEnergyStored()}; | ||
} | ||
|
||
@Callback(doc = "function():number -- Returns the energy per tick.") | ||
public Object[] getEnergyPerTick(final Context context, final Arguments args) { | ||
return new Object[]{tileEntity.getInfoEnergyPerTick()}; | ||
} | ||
|
||
@Callback(doc = "function():number -- Returns the maximum energy per tick.") | ||
public Object[] getMaxEnergyPerTick(final Context context, final Arguments args) { | ||
return new Object[]{tileEntity.getInfoMaxEnergyPerTick()}; | ||
} | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/main/scala/li/cil/oc/integration/cofh/tileentity/DriverRedstoneControl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package li.cil.oc.integration.cofh.tileentity; | ||
|
||
import cofh.api.tileentity.IRedstoneControl; | ||
import li.cil.oc.api.machine.Arguments; | ||
import li.cil.oc.api.machine.Callback; | ||
import li.cil.oc.api.machine.Context; | ||
import li.cil.oc.api.network.ManagedEnvironment; | ||
import li.cil.oc.api.prefab.DriverSidedTileEntity; | ||
import li.cil.oc.integration.ManagedTileEntityEnvironment; | ||
import net.minecraft.util.EnumFacing; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
|
||
public final class DriverRedstoneControl extends DriverSidedTileEntity { | ||
@Override | ||
public Class<?> getTileEntityClass() { | ||
return IRedstoneControl.class; | ||
} | ||
|
||
@Override | ||
public ManagedEnvironment createEnvironment(final World world, final BlockPos pos, final EnumFacing side) { | ||
return new Environment((IRedstoneControl) world.getTileEntity(pos)); | ||
} | ||
|
||
public static final class Environment extends ManagedTileEntityEnvironment<IRedstoneControl> { | ||
public Environment(final IRedstoneControl tileEntity) { | ||
super(tileEntity, "redstone_control"); | ||
} | ||
|
||
@Callback(doc = "function():boolean -- Returns whether the control is disabled.") | ||
public Object[] getControlDisable(final Context context, final Arguments args) { | ||
return new Object[]{tileEntity.getControl() == IRedstoneControl.ControlMode.DISABLED}; | ||
} | ||
|
||
@Callback(doc = "function():int -- Returns the control status.") | ||
public Object[] getControlSetting(final Context context, final Arguments args) { | ||
return new Object[]{tileEntity.getControl().ordinal()}; | ||
|
||
} | ||
|
||
@Callback(doc = "function():string -- Returns the control status.") | ||
public Object[] getControlSettingName(final Context context, final Arguments args) { | ||
return new Object[]{tileEntity.getControl().name()}; | ||
|
||
} | ||
|
||
@Callback(doc = "function(int):string -- Returns the name of the given control") | ||
public Object[] getControlName(final Context context, final Arguments args) { | ||
IRedstoneControl.ControlMode m = IRedstoneControl.ControlMode.values()[args.checkInteger(0)]; | ||
return new Object[]{m.name()}; | ||
} | ||
|
||
@Callback(doc = "function():boolean -- Returns whether the component is powered.") | ||
public Object[] isPowered(final Context context, final Arguments args) { | ||
return new Object[]{tileEntity.isPowered()}; | ||
} | ||
|
||
@Callback(doc = "function():boolean -- Sets whether the control tp disabled.") | ||
public Object[] setControlDisable(final Context context, final Arguments args) { | ||
tileEntity.setControl(IRedstoneControl.ControlMode.DISABLED); | ||
return new Object[]{true}; | ||
} | ||
|
||
@Callback(doc = "function(state:int):boolean -- Sets the control status to the given value.") | ||
public Object[] setControlSetting(final Context context, final Arguments args) { | ||
if (args.isInteger(0)) { | ||
tileEntity.setControl(IRedstoneControl.ControlMode.values()[args.checkInteger(0)]); | ||
return new Object[]{true}; | ||
} else { | ||
tileEntity.setControl(IRedstoneControl.ControlMode.valueOf(args.checkString(0))); | ||
return new Object[]{true}; | ||
} | ||
|
||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/scala/li/cil/oc/integration/cofh/tileentity/DriverSecureTile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package li.cil.oc.integration.cofh.tileentity; | ||
|
||
import cofh.api.core.ISecurable; | ||
import com.mojang.authlib.GameProfile; | ||
import li.cil.oc.api.machine.Arguments; | ||
import li.cil.oc.api.machine.Callback; | ||
import li.cil.oc.api.machine.Context; | ||
import li.cil.oc.api.network.ManagedEnvironment; | ||
import li.cil.oc.api.prefab.DriverSidedTileEntity; | ||
import li.cil.oc.integration.ManagedTileEntityEnvironment; | ||
import net.minecraft.entity.player.EntityPlayerMP; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.util.EnumFacing; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
import net.minecraftforge.common.util.FakePlayer; | ||
import net.minecraftforge.common.util.FakePlayerFactory; | ||
import net.minecraftforge.fml.common.FMLCommonHandler; | ||
import org.apache.commons.lang3.text.WordUtils; | ||
|
||
public final class DriverSecureTile extends DriverSidedTileEntity { | ||
@Override | ||
public Class<?> getTileEntityClass() { | ||
return ISecurable.class; | ||
} | ||
|
||
@Override | ||
public ManagedEnvironment createEnvironment(final World world, final BlockPos pos, final EnumFacing side) { | ||
return new Environment((ISecurable) world.getTileEntity(pos)); | ||
} | ||
|
||
public static final class Environment extends ManagedTileEntityEnvironment<ISecurable> { | ||
public Environment(final ISecurable tileEntity) { | ||
super(tileEntity, "secure_tile"); | ||
} | ||
|
||
@Callback(doc = "function(name:string):boolean -- Returns whether the player with the given name can access the component") | ||
public Object[] canPlayerAccess(final Context context, final Arguments args) { | ||
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance(); | ||
EntityPlayerMP player = server.getPlayerList().getPlayerByUsername(args.checkString(0)); | ||
return new Object[]{player != null && tileEntity.canPlayerAccess(player)}; | ||
} | ||
|
||
@Callback(doc = "function():string -- Returns the type of the access.") | ||
public Object[] getAccess(final Context context, final Arguments args) { | ||
return new Object[]{WordUtils.capitalize(tileEntity.getAccess().name())}; | ||
} | ||
|
||
@Callback(doc = "function():string -- Returns the name of the owner.") | ||
public Object[] getOwnerName(final Context context, final Arguments args) { | ||
return new Object[]{tileEntity.getOwnerName()}; | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/scala/li/cil/oc/integration/cofh/tileentity/DriverSteamInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package li.cil.oc.integration.cofh.tileentity; | ||
|
||
import cofh.api.tileentity.IEnergyInfo; | ||
import cofh.api.tileentity.ISteamInfo; | ||
import li.cil.oc.api.machine.Arguments; | ||
import li.cil.oc.api.machine.Callback; | ||
import li.cil.oc.api.machine.Context; | ||
import li.cil.oc.api.network.ManagedEnvironment; | ||
import li.cil.oc.api.prefab.DriverSidedTileEntity; | ||
import li.cil.oc.integration.ManagedTileEntityEnvironment; | ||
import net.minecraft.util.EnumFacing; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
|
||
public final class DriverSteamInfo extends DriverSidedTileEntity { | ||
@Override | ||
public Class<?> getTileEntityClass() { | ||
return ISteamInfo.class; | ||
} | ||
|
||
@Override | ||
public ManagedEnvironment createEnvironment(final World world, final BlockPos pos, final EnumFacing side) { | ||
return new Environment((ISteamInfo) world.getTileEntity(pos)); | ||
} | ||
|
||
public static final class Environment extends ManagedTileEntityEnvironment<ISteamInfo> { | ||
public Environment(final ISteamInfo tileEntity) { | ||
super(tileEntity, "steam_info"); | ||
} | ||
|
||
@Callback(doc = "function():number -- Returns the steam per tick.") | ||
public Object[] getSteamPerTick(final Context context, final Arguments args) { | ||
return new Object[]{tileEntity.getInfoSteamPerTick()}; | ||
} | ||
|
||
@Callback(doc = "function():number -- Returns the maximum steam per tick.") | ||
public Object[] getMaxSteamPerTick(final Context context, final Arguments args) { | ||
return new Object[]{tileEntity.getInfoMaxSteamPerTick()}; | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/scala/li/cil/oc/integration/cofh/tileentity/ModCoFHTileEntity.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package li.cil.oc.integration.cofh.tileentity | ||
|
||
import li.cil.oc.api.Driver | ||
import li.cil.oc.integration.ModProxy | ||
import li.cil.oc.integration.Mods | ||
|
||
object ModCoFHTileEntity extends ModProxy { | ||
override def getMod = Mods.CoFHCore | ||
|
||
override def initialize() { | ||
Driver.add(new DriverEnergyInfo) | ||
Driver.add(new DriverRedstoneControl) | ||
Driver.add(new DriverSecureTile) | ||
Driver.add(new DriverSteamInfo) | ||
} | ||
} |