Fixed Enantiomorphic reactor laser rotation & synchronization
This commit is contained in:
parent
5923d4ef93
commit
cc11ebdffa
2 changed files with 67 additions and 37 deletions
|
@ -82,24 +82,17 @@ public class TileEntityEnanReactorLaser extends TileEntityAbstractLaser implemen
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReactorFace(@Nonnull final ReactorFace reactorFace, final TileEntityEnanReactorCore reactorCore) {
|
public void setReactorFace(@Nonnull final ReactorFace reactorFace, final TileEntityEnanReactorCore reactorCore) {
|
||||||
// skip if it's already set to another reactor
|
// skip if it's already set to another valid reactor core
|
||||||
if ( this.reactorFace != reactorFace
|
if ( this.reactorFace != reactorFace
|
||||||
&& this.reactorFace != ReactorFace.UNKNOWN ) {
|
&& this.reactorFace != ReactorFace.UNKNOWN ) {
|
||||||
|
if (getReactorCore() != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// always update cached signature name
|
// always update cached signature name
|
||||||
reactorSignatureName = reactorCore != null ? reactorCore.getSignatureName() : "";
|
reactorSignatureName = reactorCore != null ? reactorCore.getSignatureName() : "";
|
||||||
|
|
||||||
// skip if it's already set to save resources
|
|
||||||
if (this.reactorFace == reactorFace) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// update properties
|
|
||||||
this.reactorFace = reactorFace;
|
|
||||||
this.weakReactorCore = reactorCore != null && reactorFace != ReactorFace.UNKNOWN ? new WeakReference<>(reactorCore) : null;
|
|
||||||
|
|
||||||
// refresh blockstate
|
// refresh blockstate
|
||||||
final IBlockState blockState_old = world.getBlockState(pos);
|
final IBlockState blockState_old = world.getBlockState(pos);
|
||||||
final IBlockState blockState_new;
|
final IBlockState blockState_new;
|
||||||
|
@ -112,6 +105,15 @@ public class TileEntityEnanReactorLaser extends TileEntityAbstractLaser implemen
|
||||||
}
|
}
|
||||||
updateBlockState(blockState_old, blockState_new);
|
updateBlockState(blockState_old, blockState_new);
|
||||||
|
|
||||||
|
// skip if it's already set to save resources
|
||||||
|
if (this.reactorFace == reactorFace) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// update properties
|
||||||
|
this.reactorFace = reactorFace;
|
||||||
|
this.weakReactorCore = reactorCore != null && reactorFace != ReactorFace.UNKNOWN ? new WeakReference<>(reactorCore) : null;
|
||||||
|
|
||||||
// cache reactor coordinates
|
// cache reactor coordinates
|
||||||
if (reactorCore != null) {
|
if (reactorCore != null) {
|
||||||
vReactorCore = reactorCore.getCenter();
|
vReactorCore = reactorCore.getCenter();
|
||||||
|
@ -136,6 +138,7 @@ public class TileEntityEnanReactorLaser extends TileEntityAbstractLaser implemen
|
||||||
this,
|
this,
|
||||||
Commons.format(world, pos),
|
Commons.format(world, pos),
|
||||||
tileEntity));
|
tileEntity));
|
||||||
|
reactorFace = ReactorFace.UNKNOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return reactorCore;
|
return reactorCore;
|
||||||
|
|
|
@ -5,24 +5,26 @@ import cr0s.warpdrive.api.ITransformation;
|
||||||
import cr0s.warpdrive.api.WarpDriveText;
|
import cr0s.warpdrive.api.WarpDriveText;
|
||||||
import cr0s.warpdrive.block.BlockAbstractBase;
|
import cr0s.warpdrive.block.BlockAbstractBase;
|
||||||
import cr0s.warpdrive.block.BlockAbstractContainer;
|
import cr0s.warpdrive.block.BlockAbstractContainer;
|
||||||
|
import cr0s.warpdrive.block.BlockAbstractRotatingContainer;
|
||||||
import cr0s.warpdrive.block.breathing.BlockAirFlow;
|
import cr0s.warpdrive.block.breathing.BlockAirFlow;
|
||||||
import cr0s.warpdrive.block.breathing.BlockAirGeneratorTiered;
|
|
||||||
import cr0s.warpdrive.block.breathing.BlockAirSource;
|
import cr0s.warpdrive.block.breathing.BlockAirSource;
|
||||||
import cr0s.warpdrive.block.decoration.BlockAbstractLamp;
|
import cr0s.warpdrive.block.decoration.BlockAbstractLamp;
|
||||||
import cr0s.warpdrive.block.detection.BlockMonitor;
|
|
||||||
import cr0s.warpdrive.block.forcefield.BlockForceFieldProjector;
|
import cr0s.warpdrive.block.forcefield.BlockForceFieldProjector;
|
||||||
import cr0s.warpdrive.block.hull.BlockHullSlab;
|
import cr0s.warpdrive.block.hull.BlockHullSlab;
|
||||||
import cr0s.warpdrive.block.movement.BlockShipCore;
|
|
||||||
import cr0s.warpdrive.config.WarpDriveConfig;
|
import cr0s.warpdrive.config.WarpDriveConfig;
|
||||||
import cr0s.warpdrive.data.ChunkData;
|
import cr0s.warpdrive.data.ChunkData;
|
||||||
import cr0s.warpdrive.data.StateAir;
|
import cr0s.warpdrive.data.StateAir;
|
||||||
import cr0s.warpdrive.event.ChunkHandler;
|
import cr0s.warpdrive.event.ChunkHandler;
|
||||||
|
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.nbt.NBTBase;
|
import net.minecraft.nbt.NBTBase;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
@ -34,8 +36,7 @@ public class CompatWarpDrive implements IBlockTransformer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isApplicable(final Block block, final int metadata, final TileEntity tileEntity) {
|
public boolean isApplicable(final Block block, final int metadata, final TileEntity tileEntity) {
|
||||||
return block instanceof BlockHullSlab
|
return block instanceof BlockAbstractBase
|
||||||
|| block instanceof BlockAbstractBase
|
|
||||||
|| block instanceof BlockAbstractContainer;
|
|| block instanceof BlockAbstractContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,26 +120,56 @@ public class CompatWarpDrive implements IBlockTransformer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Monitor and lamps
|
if (nbtTileEntity != null) {
|
||||||
if ( block instanceof BlockAirSource
|
// subspace capacitor sides
|
||||||
|| block instanceof BlockMonitor
|
if (nbtTileEntity.hasKey("modeSide")) {
|
||||||
|| block instanceof BlockAbstractLamp ) {
|
nbtTileEntity.setByteArray("modeSide", rotate_byteArray(rotationSteps, nbtTileEntity.getByteArray("modeSide")));
|
||||||
|
}
|
||||||
|
|
||||||
|
// reactor stabilization laser
|
||||||
|
if ( nbtTileEntity.hasKey("reactorFace")
|
||||||
|
&& rotationSteps != 0 ) {
|
||||||
|
final String reactorFaceOriginal = nbtTileEntity.getString("reactorFace");
|
||||||
|
final Pattern patternFacing = Pattern.compile("(laser\\.[a-z]+\\.)([a-z]+)([+-]*)");
|
||||||
|
final Matcher matcher = patternFacing.matcher(reactorFaceOriginal);
|
||||||
|
if (!matcher.matches()) {
|
||||||
|
throw new RuntimeException(String.format("Failed to parse reactor facing %s: unrecognized format",
|
||||||
|
reactorFaceOriginal));
|
||||||
|
}
|
||||||
|
|
||||||
|
final String prefix = matcher.group(1);
|
||||||
|
final String nameFacing = matcher.group(2);
|
||||||
|
final String suffix = matcher.group(3);
|
||||||
|
|
||||||
|
EnumFacing enumFacing = EnumFacing.byName(nameFacing);
|
||||||
|
if (enumFacing == null) {
|
||||||
|
throw new RuntimeException(String.format("Failed to parse reactor facing %s: unrecognized facing %s",
|
||||||
|
reactorFaceOriginal, nameFacing));
|
||||||
|
}
|
||||||
switch (rotationSteps) {
|
switch (rotationSteps) {
|
||||||
case 1:
|
case 1:
|
||||||
return mrotDirection[metadata];
|
enumFacing = enumFacing.rotateY();
|
||||||
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
return mrotDirection[mrotDirection[metadata]];
|
enumFacing = enumFacing.rotateY().rotateY();
|
||||||
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
return mrotDirection[mrotDirection[mrotDirection[metadata]]];
|
enumFacing = enumFacing.rotateY().rotateY().rotateY();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return metadata;
|
assert false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String reactorFaceUpdated = prefix + enumFacing.name().toLowerCase() + suffix;
|
||||||
|
nbtTileEntity.setString("reactorFace", reactorFaceUpdated);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Force field projector
|
// Rotating blocks
|
||||||
if ( block instanceof BlockAirGeneratorTiered
|
if ( block instanceof BlockAbstractRotatingContainer
|
||||||
|| block instanceof BlockForceFieldProjector
|
|| block instanceof BlockAbstractLamp
|
||||||
|| block instanceof BlockShipCore ) {
|
|| block instanceof BlockForceFieldProjector ) {
|
||||||
switch (rotationSteps) {
|
switch (rotationSteps) {
|
||||||
case 1:
|
case 1:
|
||||||
return mrotDirection[metadata & 0x7] | (metadata & 0x8);
|
return mrotDirection[metadata & 0x7] | (metadata & 0x8);
|
||||||
|
@ -151,10 +182,6 @@ public class CompatWarpDrive implements IBlockTransformer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// subspace capacitor sides
|
|
||||||
if (nbtTileEntity != null && nbtTileEntity.hasKey("modeSide")) {
|
|
||||||
nbtTileEntity.setByteArray("modeSide", rotate_byteArray(rotationSteps, nbtTileEntity.getByteArray("modeSide")));
|
|
||||||
}
|
|
||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue