Added AppliedEnergistics rotation support
Implemented mod specific jump lock
This commit is contained in:
parent
67a9eba9b2
commit
7fadad8f76
16 changed files with 235 additions and 29 deletions
|
@ -11,8 +11,7 @@ public interface IBlockTransformer {
|
|||
|
||||
// Called when preparing to save a ship structure.
|
||||
// Use this to prevent jump during critical events/animations.
|
||||
@Deprecated
|
||||
boolean isJumpReady(final TileEntity tileEntity);
|
||||
boolean isJumpReady(final Block block, final int metadata, final TileEntity tileEntity, StringBuilder reason);
|
||||
|
||||
// Called when saving a ship structure.
|
||||
// Use this to save external data in the ship schematic.
|
||||
|
|
|
@ -0,0 +1,190 @@
|
|||
package cr0s.warpdrive.compat;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import cr0s.warpdrive.api.IBlockTransformer;
|
||||
import cr0s.warpdrive.api.ITransformation;
|
||||
import cr0s.warpdrive.config.WarpDriveConfig;
|
||||
|
||||
public class CompatAppliedEnergistics2 implements IBlockTransformer {
|
||||
|
||||
private static Class<?> classAEBaseBlock;
|
||||
private static Class<?> classBlockQuartzTorch;
|
||||
private static Class<?> classBlockCableBus;
|
||||
private static Class<?> classBlockQuantumLinkChamber;
|
||||
private static Class<?> classTileQuantumBridge;
|
||||
private static Method methodTileQuantumBridge_getQEFrequency;
|
||||
|
||||
public static void register() {
|
||||
try {
|
||||
classAEBaseBlock = Class.forName("appeng.block.AEBaseBlock");
|
||||
classBlockQuartzTorch = Class.forName("appeng.block.misc.BlockQuartzTorch");
|
||||
classBlockCableBus = Class.forName("appeng.block.networking.BlockCableBus");
|
||||
classBlockQuantumLinkChamber = Class.forName("appeng.block.qnb.BlockQuantumLinkChamber");
|
||||
classTileQuantumBridge = Class.forName("appeng.tile.qnb.TileQuantumBridge");
|
||||
methodTileQuantumBridge_getQEFrequency = classTileQuantumBridge.getMethod("getQEFrequency");
|
||||
WarpDriveConfig.registerBlockTransformer("appliedenergistics2", new CompatAppliedEnergistics2());
|
||||
} catch(ClassNotFoundException | NoSuchMethodException | SecurityException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(final Block block, final int metadata, final TileEntity tileEntity) {
|
||||
return classAEBaseBlock.isInstance(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJumpReady(final Block block, final int metadata, final TileEntity tileEntity, StringBuilder reason) {
|
||||
if (classBlockQuantumLinkChamber.isInstance(block)) {
|
||||
if (classTileQuantumBridge.isInstance(tileEntity)) {
|
||||
try {
|
||||
Object object = methodTileQuantumBridge_getQEFrequency.invoke(tileEntity);
|
||||
if (((Long)object) != 0L) {
|
||||
reason.append("Quantum field interference detected!");
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase saveExternals(final TileEntity tileEntity) {
|
||||
// nothing to do
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(TileEntity tileEntity) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
private static final byte[] mrotQuartzTorch = { 0, 1, 5, 4, 2, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
|
||||
private static final Map<String, String> rotSideNames;
|
||||
private static final Map<String, String> rotTagSuffix;
|
||||
static {
|
||||
Map<String, String> map = new HashMap();
|
||||
map.put("EAST", "SOUTH");
|
||||
map.put("SOUTH", "WEST");
|
||||
map.put("WEST", "NORTH");
|
||||
map.put("NORTH", "EAST");
|
||||
rotSideNames = Collections.unmodifiableMap(map);
|
||||
map = new HashMap();
|
||||
map.put("2", "5");
|
||||
map.put("5", "3");
|
||||
map.put("3", "4");
|
||||
map.put("4", "2");
|
||||
rotTagSuffix = Collections.unmodifiableMap(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int rotate(final Block block, final int metadata, NBTTagCompound nbtTileEntity, final ITransformation transformation) {
|
||||
byte rotationSteps = transformation.getRotationSteps();
|
||||
if (rotationSteps == 0) {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
if (classBlockQuartzTorch.isInstance(block)) {
|
||||
switch (rotationSteps) {
|
||||
case 1:
|
||||
return mrotQuartzTorch[metadata];
|
||||
case 2:
|
||||
return mrotQuartzTorch[mrotQuartzTorch[metadata]];
|
||||
case 3:
|
||||
return mrotQuartzTorch[mrotQuartzTorch[mrotQuartzTorch[metadata]]];
|
||||
default:
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
|
||||
if (nbtTileEntity.hasKey("orientation_up") && nbtTileEntity.hasKey("orientation_forward")) {
|
||||
String orientation_forward = nbtTileEntity.getString("orientation_forward");
|
||||
String orientation_up = nbtTileEntity.getString("orientation_up");
|
||||
if (orientation_forward.equals("UP") || orientation_forward.equals("DOWN")) {
|
||||
switch (rotationSteps) {
|
||||
case 1:
|
||||
nbtTileEntity.setString("orientation_up", rotSideNames.get(orientation_up));
|
||||
break;
|
||||
case 2:
|
||||
nbtTileEntity.setString("orientation_up", rotSideNames.get(rotSideNames.get(orientation_up)));
|
||||
break;
|
||||
case 3:
|
||||
nbtTileEntity.setString("orientation_up", rotSideNames.get(rotSideNames.get(rotSideNames.get(orientation_up))));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (rotationSteps) {
|
||||
case 1:
|
||||
nbtTileEntity.setString("orientation_forward", rotSideNames.get(orientation_forward));
|
||||
break;
|
||||
case 2:
|
||||
nbtTileEntity.setString("orientation_forward", rotSideNames.get(rotSideNames.get(orientation_forward)));
|
||||
break;
|
||||
case 3:
|
||||
nbtTileEntity.setString("orientation_forward", rotSideNames.get(rotSideNames.get(rotSideNames.get(orientation_forward))));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (classBlockCableBus.isInstance(block)) {
|
||||
HashMap<String, NBTTagCompound> tagRotateds = new HashMap(7);
|
||||
ArrayList<String> keys = new ArrayList();
|
||||
keys.addAll(nbtTileEntity.func_150296_c());
|
||||
for (String key : keys) {
|
||||
if ( (key.startsWith("def:") && !key.equals("def:6"))
|
||||
|| (key.startsWith("extra:") && !key.equals("extra:6"))) {
|
||||
NBTTagCompound compound = (NBTTagCompound) nbtTileEntity.getCompoundTag(key).copy();
|
||||
String[] parts = key.split(":");
|
||||
if (parts.length != 2 || !rotTagSuffix.containsKey(parts[1])) {
|
||||
// skip
|
||||
} else {
|
||||
switch (rotationSteps) {
|
||||
case 1:
|
||||
tagRotateds.put(parts[0] + ":" + rotTagSuffix.get(parts[1]), compound);
|
||||
break;
|
||||
case 2:
|
||||
tagRotateds.put(parts[0] + ":" + rotTagSuffix.get(rotTagSuffix.get(parts[1])), compound);
|
||||
break;
|
||||
case 3:
|
||||
tagRotateds.put(parts[0] + ":" + rotTagSuffix.get(rotTagSuffix.get(rotTagSuffix.get(parts[1]))), compound);
|
||||
break;
|
||||
default:
|
||||
tagRotateds.put(key, compound);
|
||||
break;
|
||||
}
|
||||
nbtTileEntity.removeTag(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Entry<String, NBTTagCompound> entry : tagRotateds.entrySet()) {
|
||||
nbtTileEntity.setTag(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
return metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restoreExternals(TileEntity tileEntity, ITransformation transformation, NBTBase nbtBase) {
|
||||
// nothing to do
|
||||
}
|
||||
}
|
|
@ -49,7 +49,7 @@ public class CompatArsMagica2 implements IBlockTransformer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isJumpReady(final TileEntity tileEntity) {
|
||||
public boolean isJumpReady(final Block block, final int metadata, final TileEntity tileEntity, StringBuilder reason) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ public class CompatBiblioCraft implements IBlockTransformer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isJumpReady(TileEntity tileEntity) {
|
||||
public boolean isJumpReady(final Block block, final int metadata, final TileEntity tileEntity, StringBuilder reason) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.api.IBlockTransformer;
|
||||
import cr0s.warpdrive.api.ITransformation;
|
||||
|
@ -37,7 +36,7 @@ public class CompatComputerCraft implements IBlockTransformer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isJumpReady(TileEntity tileEntity) {
|
||||
public boolean isJumpReady(final Block block, final int metadata, final TileEntity tileEntity, StringBuilder reason) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ public class CompatEnderIO implements IBlockTransformer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isJumpReady(TileEntity tileEntity) {
|
||||
public boolean isJumpReady(final Block block, final int metadata, final TileEntity tileEntity, StringBuilder reason) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ public class CompatImmersiveEngineering implements IBlockTransformer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isJumpReady(TileEntity tileEntity) {
|
||||
public boolean isJumpReady(final Block block, final int metadata, final TileEntity tileEntity, StringBuilder reason) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import cr0s.warpdrive.api.IBlockTransformer;
|
||||
import cr0s.warpdrive.api.ITransformation;
|
||||
import cr0s.warpdrive.config.WarpDriveConfig;
|
||||
|
@ -28,7 +27,7 @@ public class CompatIndustrialCraft2 implements IBlockTransformer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isJumpReady(TileEntity tileEntity) {
|
||||
public boolean isJumpReady(final Block block, final int metadata, final TileEntity tileEntity, StringBuilder reason) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ public class CompatJABBA implements IBlockTransformer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isJumpReady(TileEntity tileEntity) {
|
||||
public boolean isJumpReady(final Block block, final int metadata, final TileEntity tileEntity, StringBuilder reason) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ public class CompatMetallurgy implements IBlockTransformer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isJumpReady(TileEntity tileEntity) {
|
||||
public boolean isJumpReady(final Block block, final int metadata, final TileEntity tileEntity, StringBuilder reason) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ public class CompatNatura implements IBlockTransformer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isJumpReady(TileEntity tileEntity) {
|
||||
public boolean isJumpReady(final Block block, final int metadata, final TileEntity tileEntity, StringBuilder reason) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import cr0s.warpdrive.api.IBlockTransformer;
|
||||
import cr0s.warpdrive.api.ITransformation;
|
||||
import cr0s.warpdrive.config.WarpDriveConfig;
|
||||
|
@ -28,7 +27,7 @@ public class CompatOpenComputers implements IBlockTransformer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isJumpReady(TileEntity tileEntity) {
|
||||
public boolean isJumpReady(final Block block, final int metadata, final TileEntity tileEntity, StringBuilder reason) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ public class CompatStargateTech2 implements IBlockTransformer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isJumpReady(TileEntity tileEntity) {
|
||||
public boolean isJumpReady(final Block block, final int metadata, final TileEntity tileEntity, StringBuilder reason) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public class CompatTConstruct implements IBlockTransformer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isJumpReady(TileEntity tileEntity) {
|
||||
public boolean isJumpReady(final Block block, final int metadata, final TileEntity tileEntity, StringBuilder reason) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ import cpw.mods.fml.common.Loader;
|
|||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.api.IBlockTransformer;
|
||||
import cr0s.warpdrive.compat.CompatAppliedEnergistics2;
|
||||
import cr0s.warpdrive.compat.CompatArsMagica2;
|
||||
import cr0s.warpdrive.compat.CompatBiblioCraft;
|
||||
import cr0s.warpdrive.compat.CompatComputerCraft;
|
||||
|
@ -758,6 +759,9 @@ public class WarpDriveConfig {
|
|||
isCoFHCoreLoaded = Loader.isModLoaded("CoFHCore");
|
||||
isThermalExpansionLoaded = Loader.isModLoaded("ThermalExpansion");
|
||||
isAppliedEnergistics2Loaded = Loader.isModLoaded("appliedenergistics2");
|
||||
if (isAppliedEnergistics2Loaded) {
|
||||
CompatAppliedEnergistics2.register();
|
||||
}
|
||||
isOpenComputersLoaded = Loader.isModLoaded("OpenComputers");
|
||||
if (isOpenComputersLoaded) {
|
||||
CompatOpenComputers.register();
|
||||
|
|
|
@ -60,7 +60,7 @@ public class JumpSequencer extends AbstractSequencer {
|
|||
private ArrayList<Vector3> collisionAtTarget;
|
||||
private float collisionStrength = 0;
|
||||
|
||||
public boolean on = false;
|
||||
public boolean isEnabled = false;
|
||||
private final static int STATE_IDLE = 0;
|
||||
private final static int STATE_BLOCKS = 1;
|
||||
private final static int STATE_EXTERNALS = 2;
|
||||
|
@ -115,16 +115,16 @@ public class JumpSequencer extends AbstractSequencer {
|
|||
}
|
||||
|
||||
public void enable() {
|
||||
on = true;
|
||||
isEnabled = true;
|
||||
register();
|
||||
}
|
||||
|
||||
private void disable(String reason) {
|
||||
if (!on) {
|
||||
if (!isEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
on = false;
|
||||
isEnabled = false;
|
||||
|
||||
if (WarpDriveConfig.LOGGING_JUMP) {
|
||||
if (reason == null || reason.isEmpty()) {
|
||||
|
@ -146,7 +146,7 @@ public class JumpSequencer extends AbstractSequencer {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!on) {
|
||||
if (!isEnabled) {
|
||||
if (WarpDriveConfig.LOGGING_JUMP) {
|
||||
WarpDrive.logger.info(this + " Removing from onUpdate...");
|
||||
}
|
||||
|
@ -163,7 +163,8 @@ public class JumpSequencer extends AbstractSequencer {
|
|||
ticks++;
|
||||
if (state == STATE_IDLE) {
|
||||
prepareToJump();
|
||||
if (on) {
|
||||
if (isEnabled) {
|
||||
currentIndexInShip = 0;
|
||||
state = STATE_BLOCKS;
|
||||
}
|
||||
} else if (state == STATE_BLOCKS) {
|
||||
|
@ -339,8 +340,8 @@ public class JumpSequencer extends AbstractSequencer {
|
|||
Boolean planetValid = false;
|
||||
int closestPlanetDistance = Integer.MAX_VALUE;
|
||||
Planet closestPlanet = null;
|
||||
for (int iPlane = 0; (!planetValid) && iPlane < WarpDriveConfig.PLANETS.length; iPlane++) {
|
||||
Planet planet = WarpDriveConfig.PLANETS[iPlane];
|
||||
for (int indexPlanet = 0; (!planetValid) && indexPlanet < WarpDriveConfig.PLANETS.length; indexPlanet++) {
|
||||
Planet planet = WarpDriveConfig.PLANETS[indexPlanet];
|
||||
if (sourceWorld.provider.dimensionId == planet.dimensionId) {
|
||||
planetFound = true;
|
||||
int planetDistance = planet.isValidToSpace(new VectorI(ship.coreX, ship.coreY, ship.coreZ));
|
||||
|
@ -364,7 +365,7 @@ public class JumpSequencer extends AbstractSequencer {
|
|||
}
|
||||
if (!planetFound) {
|
||||
LocalProfiler.stop();
|
||||
String msg = "Unable to reach space!\nThere's not planet defined for current dimension " + sourceWorld.provider.getDimensionName() + " ("
|
||||
String msg = "Unable to reach space!\nThere's no planet defined for current dimension " + sourceWorld.provider.getDimensionName() + " ("
|
||||
+ sourceWorld.provider.dimensionId + ")";
|
||||
ship.messageToAllPlayersOnShip(this, msg);
|
||||
disable(msg);
|
||||
|
@ -387,8 +388,8 @@ public class JumpSequencer extends AbstractSequencer {
|
|||
Boolean planetFound = false;
|
||||
int closestPlaneDistance = Integer.MAX_VALUE;
|
||||
Planet closestTransitionPlane = null;
|
||||
for (int iPlanet = 0; (!planetFound) && iPlanet < WarpDriveConfig.PLANETS.length; iPlanet++) {
|
||||
Planet planet = WarpDriveConfig.PLANETS[iPlanet];
|
||||
for (int indexPlanet = 0; (!planetFound) && indexPlanet < WarpDriveConfig.PLANETS.length; indexPlanet++) {
|
||||
Planet planet = WarpDriveConfig.PLANETS[indexPlanet];
|
||||
int planeDistance = planet.isValidFromSpace(new VectorI(ship.coreX, ship.coreY, ship.coreZ));
|
||||
if (planeDistance == 0) {
|
||||
planetFound = true;
|
||||
|
@ -537,7 +538,6 @@ public class JumpSequencer extends AbstractSequencer {
|
|||
}
|
||||
|
||||
saveShip(shipVolume);
|
||||
this.currentIndexInShip = 0;
|
||||
msCounter = System.currentTimeMillis();
|
||||
LocalProfiler.stop();
|
||||
if (WarpDriveConfig.LOGGING_JUMP) {
|
||||
|
@ -583,6 +583,22 @@ public class JumpSequencer extends AbstractSequencer {
|
|||
TileEntity tileEntity = sourceWorld.getTileEntity(x, y, z);
|
||||
JumpBlock jumpBlock = new JumpBlock(block, blockMeta, tileEntity, x, y, z);
|
||||
|
||||
if (jumpBlock.blockTileEntity != null && jumpBlock.externals != null) {
|
||||
for (Entry<String, NBTBase> external : jumpBlock.externals.entrySet()) {
|
||||
IBlockTransformer blockTransformer = WarpDriveConfig.blockTransformers.get(external.getKey());
|
||||
if (blockTransformer != null) {
|
||||
StringBuilder reason = new StringBuilder();
|
||||
if (!blockTransformer.isJumpReady(jumpBlock.block, jumpBlock.blockMeta, jumpBlock.blockTileEntity, reason)) {
|
||||
String msg = reason.toString() + " " + jumpBlock.block + "@" + jumpBlock.blockMeta + " at " + jumpBlock.x + " " + jumpBlock.y + " " + jumpBlock.z;
|
||||
disable(msg);
|
||||
ship.messageToAllPlayersOnShip(this, msg);
|
||||
LocalProfiler.stop();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// default priority is 2 for block, 3 for tile entities
|
||||
Integer placeTime = Dictionary.BLOCKS_PLACE.get(block);
|
||||
if (placeTime == null) {
|
||||
|
|
Loading…
Reference in a new issue