Added ship core & ship controller blockstate properties
This commit is contained in:
parent
67bec007d0
commit
9ae55b3f31
7 changed files with 277 additions and 32 deletions
|
@ -85,6 +85,23 @@ public abstract class TileEntityAbstractBase extends TileEntity implements IBloc
|
|||
}
|
||||
}
|
||||
|
||||
protected void updateBlockState(final IBlockState blockState_in, @Nonnull final IBlockState blockState_new) {
|
||||
IBlockState blockState_old = blockState_in;
|
||||
if (blockState_old == null) {
|
||||
blockState_old = worldObj.getBlockState(pos);
|
||||
}
|
||||
try {
|
||||
final int metadata_old = blockState_old.getBlock().getMetaFromState(blockState_old);
|
||||
final int metadata_new = blockState_new.getBlock().getMetaFromState(blockState_new);
|
||||
if (metadata_old != metadata_new) {
|
||||
worldObj.setBlockState(pos, blockState_new, 2);
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
WarpDrive.logger.error("Exception in " + this);
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
protected void updateMetadata(final int metadata) {
|
||||
if (getBlockMetadata() != metadata) {
|
||||
|
|
|
@ -3,11 +3,14 @@ package cr0s.warpdrive.block.movement;
|
|||
import cr0s.warpdrive.Commons;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.block.BlockAbstractContainer;
|
||||
import cr0s.warpdrive.data.EnumShipControllerCommand;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -21,12 +24,37 @@ import net.minecraftforge.fml.common.registry.GameRegistry;
|
|||
|
||||
public class BlockShipController extends BlockAbstractContainer {
|
||||
|
||||
public static final PropertyEnum<EnumShipControllerCommand> COMMAND = PropertyEnum.create("command", EnumShipControllerCommand.class);
|
||||
|
||||
public BlockShipController(final String registryName) {
|
||||
super(registryName, Material.IRON);
|
||||
setUnlocalizedName("warpdrive.movement.ship_controller");
|
||||
|
||||
setDefaultState(getDefaultState()
|
||||
.withProperty(COMMAND, EnumShipControllerCommand.OFFLINE)
|
||||
);
|
||||
GameRegistry.registerTileEntity(TileEntityShipController.class, WarpDrive.PREFIX + registryName);
|
||||
}
|
||||
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState() {
|
||||
return new BlockStateContainer(this, COMMAND);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Nonnull
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(final int metadata) {
|
||||
return getDefaultState()
|
||||
.withProperty(COMMAND, EnumShipControllerCommand.get(metadata));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
return blockState.getValue(COMMAND).ordinal();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(@Nonnull final World world, final int metadata) {
|
||||
|
|
|
@ -111,9 +111,6 @@ public class TileEntityShipController extends TileEntityAbstractInterfaced imple
|
|||
tileEntityShipCoreWeakReference = new WeakReference<>(tileEntityShipCore);
|
||||
}
|
||||
|
||||
if (command.getCode() != getBlockMetadata()) {
|
||||
updateMetadata(command.getCode()); // Activated
|
||||
}
|
||||
if ( isPendingScan
|
||||
&& tileEntityShipCore.isAttached(this) ) {
|
||||
isPendingScan = false;
|
||||
|
@ -127,9 +124,9 @@ public class TileEntityShipController extends TileEntityAbstractInterfaced imple
|
|||
WarpDrive.logger.info(this + " Exception in validateShipSpatialParameters, reason: " + reason.toString());
|
||||
}
|
||||
}
|
||||
} else if (getBlockMetadata() != 0) {
|
||||
updateMetadata(0); // Inactive
|
||||
}
|
||||
|
||||
updateBlockState(null, BlockShipController.COMMAND, command);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -359,7 +356,7 @@ public class TileEntityShipController extends TileEntityAbstractInterfaced imple
|
|||
markDirty();
|
||||
if (WarpDriveConfig.LOGGING_LUA && hasWorldObj()) {
|
||||
WarpDrive.logger.info(String.format("%s Command set to %s (%d)",
|
||||
this, this.command, this.command.getCode()));
|
||||
this, this.command, this.command.ordinal()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -371,7 +368,7 @@ public class TileEntityShipController extends TileEntityAbstractInterfaced imple
|
|||
if (!success) {
|
||||
final TileEntityShipCore tileEntityShipCore = tileEntityShipCoreWeakReference == null ? null : tileEntityShipCoreWeakReference.get();
|
||||
if (tileEntityShipCore != null) {
|
||||
tileEntityShipCore.messageToAllPlayersOnShip(new TextComponentString(reason.toString()));
|
||||
tileEntityShipCore.messageToAllPlayersOnShip(new TextComponentString(reason));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import cr0s.warpdrive.block.TileEntityAbstractEnergy;
|
|||
import cr0s.warpdrive.config.Dictionary;
|
||||
import cr0s.warpdrive.config.ShipMovementCosts;
|
||||
import cr0s.warpdrive.config.WarpDriveConfig;
|
||||
import cr0s.warpdrive.data.BlockProperties;
|
||||
import cr0s.warpdrive.data.CelestialObjectManager;
|
||||
import cr0s.warpdrive.data.EnumShipControllerCommand;
|
||||
import cr0s.warpdrive.data.EnumShipCoreState;
|
||||
|
@ -135,8 +136,8 @@ public class TileEntityShipCore extends TileEntityAbstractEnergy implements ISta
|
|||
}
|
||||
|
||||
TileEntityShipController tileEntityShipController = tileEntityShipControllerWeakReference == null ? null : tileEntityShipControllerWeakReference.get();
|
||||
if ( tileEntityShipController != null
|
||||
&& tileEntityShipController.isInvalid() ) {
|
||||
if (tileEntityShipController != null
|
||||
&& tileEntityShipController.isInvalid()) {
|
||||
tileEntityShipControllerWeakReference = null;
|
||||
tileEntityShipController = null;
|
||||
}
|
||||
|
@ -169,11 +170,6 @@ public class TileEntityShipCore extends TileEntityAbstractEnergy implements ISta
|
|||
}
|
||||
}
|
||||
|
||||
// Refresh rendering
|
||||
if (getBlockMetadata() != stateCurrent.getMetadata()) {
|
||||
updateMetadata(stateCurrent.getMetadata());
|
||||
}
|
||||
|
||||
// accelerate update ticks during boot
|
||||
if (bootTicks > 0) {
|
||||
bootTicks--;
|
||||
|
@ -211,9 +207,9 @@ public class TileEntityShipCore extends TileEntityAbstractEnergy implements ISta
|
|||
this,
|
||||
stateCurrent,
|
||||
tileEntityShipController == null ? "NA" : tileEntityShipController.isEnabled,
|
||||
tileEntityShipController,
|
||||
warmupTime_ticks,
|
||||
cooldownTime_ticks));
|
||||
tileEntityShipController,
|
||||
warmupTime_ticks,
|
||||
cooldownTime_ticks));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -224,6 +220,12 @@ public class TileEntityShipCore extends TileEntityAbstractEnergy implements ISta
|
|||
updateIsolationState();
|
||||
}
|
||||
|
||||
// Refresh rendering
|
||||
final boolean isActive = stateCurrent != EnumShipCoreState.DISCONNECTED
|
||||
&& tileEntityShipController != null
|
||||
&& commandCurrent != EnumShipControllerCommand.OFFLINE;
|
||||
updateBlockState(null, BlockProperties.ACTIVE, isActive);
|
||||
|
||||
if (tileEntityShipController == null) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,23 +1,45 @@
|
|||
package cr0s.warpdrive.data;
|
||||
|
||||
public enum EnumShipControllerCommand {
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
|
||||
public enum EnumShipControllerCommand implements IStringSerializable {
|
||||
|
||||
OFFLINE(0), // Offline allows to move sub-ships
|
||||
IDLE(1),
|
||||
MANUAL(2), // Move ship around including take off and landing
|
||||
// AUTOPILOT(3), // Move ship towards a far destination
|
||||
SUMMON(4), // Summoning crew
|
||||
HYPERDRIVE(5), // Jump to/from Hyperspace
|
||||
GATE(6), // Jump via jumpgate
|
||||
MAINTENANCE(7); // Maintenance mode
|
||||
OFFLINE ("offline"), // Offline allows to move sub-ships
|
||||
IDLE ("idle"), //
|
||||
MANUAL ("manual"), // Move ship around including take off and landing
|
||||
// AUTOPILOT("autopilot"), // Move ship towards a far destination
|
||||
SUMMON ("summon"), // Summoning crew
|
||||
HYPERDRIVE ("hyperdrive"), // Jump to/from Hyperspace
|
||||
GATE ("gate"), // Jump via jumpgate
|
||||
MAINTENANCE ("maintenance"); // Maintenance mode
|
||||
|
||||
private final int code;
|
||||
private final String name;
|
||||
|
||||
EnumShipControllerCommand(final int code) {
|
||||
this.code = code;
|
||||
// cached values
|
||||
public static final int length;
|
||||
private static final HashMap<Integer, EnumShipControllerCommand> ID_MAP = new HashMap<>();
|
||||
|
||||
static {
|
||||
length = EnumShipControllerCommand.values().length;
|
||||
for (final EnumShipControllerCommand forceFieldShape : values()) {
|
||||
ID_MAP.put(forceFieldShape.ordinal(), forceFieldShape);
|
||||
}
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
EnumShipControllerCommand(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static EnumShipControllerCommand get(final int damage) {
|
||||
return ID_MAP.get(damage);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
{
|
||||
"forge_marker": 1,
|
||||
"defaults": {
|
||||
"model": "minecraft:cube_bottom_top",
|
||||
"textures": {
|
||||
"side" : "warpdrive:blocks/movement/ship_controller-side_inactive",
|
||||
"bottom": "warpdrive:blocks/movement/ship_controller-bottom",
|
||||
"top" : "warpdrive:blocks/movement/ship_controller-top"
|
||||
},
|
||||
"transform": "forge:default-block"
|
||||
},
|
||||
"variants": {
|
||||
"normal": [{}],
|
||||
"inventory": [{}],
|
||||
"command": {
|
||||
"offline": {},
|
||||
"idle": {
|
||||
"textures": {
|
||||
"side" : "warpdrive:blocks/movement/ship_controller-side_active0"
|
||||
}
|
||||
},
|
||||
"manual": {
|
||||
"textures": {
|
||||
"side" : "warpdrive:blocks/movement/ship_controller-side_active1"
|
||||
}
|
||||
},
|
||||
"autopilot": {
|
||||
"textures": {
|
||||
"side" : "warpdrive:blocks/movement/ship_controller-side_active2"
|
||||
}
|
||||
},
|
||||
"summon": {
|
||||
"textures": {
|
||||
"side" : "warpdrive:blocks/movement/ship_controller-side_active3"
|
||||
}
|
||||
},
|
||||
"hyperdrive": {
|
||||
"textures": {
|
||||
"side" : "warpdrive:blocks/movement/ship_controller-side_active4"
|
||||
}
|
||||
},
|
||||
"gate": {
|
||||
"textures": {
|
||||
"side" : "warpdrive:blocks/movement/ship_controller-side_active5"
|
||||
}
|
||||
},
|
||||
"maintenance": {
|
||||
"textures": {
|
||||
"side" : "warpdrive:blocks/movement/ship_controller-side_active7"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,125 @@
|
|||
{
|
||||
"forge_marker": 1,
|
||||
"variants": {
|
||||
"normal": [{}],
|
||||
"inventory": { "model": "minecraft:cube", "textures": {
|
||||
"particle": "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"down" : "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"up" : "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"north" : "warpdrive:blocks/movement/ship_core-right_online",
|
||||
"south" : "warpdrive:blocks/movement/ship_core-left_online",
|
||||
"west" : "warpdrive:blocks/movement/ship_controller-top",
|
||||
"east" : "warpdrive:blocks/movement/ship_controller-side_active2"
|
||||
} },
|
||||
|
||||
"active=false,facing=down" : { "model": "minecraft:cube", "textures": {
|
||||
"particle": "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"down" : "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"up" : "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"north" : "warpdrive:blocks/movement/ship_controller-side_inactive",
|
||||
"south" : "warpdrive:blocks/movement/ship_controller-side_inactive",
|
||||
"west" : "warpdrive:blocks/movement/ship_controller-side_inactive",
|
||||
"east" : "warpdrive:blocks/movement/ship_controller-side_inactive"
|
||||
} },
|
||||
"active=false,facing=up" : { "model": "minecraft:cube", "textures": {
|
||||
"particle": "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"down" : "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"up" : "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"north" : "warpdrive:blocks/movement/ship_controller-side_inactive",
|
||||
"south" : "warpdrive:blocks/movement/ship_controller-side_inactive",
|
||||
"west" : "warpdrive:blocks/movement/ship_controller-side_inactive",
|
||||
"east" : "warpdrive:blocks/movement/ship_controller-side_inactive"
|
||||
} },
|
||||
"active=false,facing=north": { "model": "minecraft:cube", "textures": {
|
||||
"particle": "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"down" : "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"up" : "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"north" : "warpdrive:blocks/movement/ship_controller-top",
|
||||
"south" : "warpdrive:blocks/movement/ship_controller-side_active1",
|
||||
"west" : "warpdrive:blocks/movement/ship_core-left_offline",
|
||||
"east" : "warpdrive:blocks/movement/ship_core-right_offline"
|
||||
} },
|
||||
"active=false,facing=south": { "model": "minecraft:cube", "textures": {
|
||||
"particle": "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"down" : "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"up" : "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"north" : "warpdrive:blocks/movement/ship_controller-side_active2",
|
||||
"south" : "warpdrive:blocks/movement/ship_controller-top",
|
||||
"west" : "warpdrive:blocks/movement/ship_core-right_offline",
|
||||
"east" : "warpdrive:blocks/movement/ship_core-left_offline"
|
||||
} },
|
||||
"active=false,facing=west" : { "model": "minecraft:cube", "textures": {
|
||||
"particle": "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"down" : "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"up" : "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"north" : "warpdrive:blocks/movement/ship_core-right_offline",
|
||||
"south" : "warpdrive:blocks/movement/ship_core-left_offline",
|
||||
"west" : "warpdrive:blocks/movement/ship_controller-top",
|
||||
"east" : "warpdrive:blocks/movement/ship_controller-side_active3"
|
||||
} },
|
||||
"active=false,facing=east" : { "model": "minecraft:cube", "textures": {
|
||||
"particle": "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"down" : "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"up" : "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"north" : "warpdrive:blocks/movement/ship_core-left_offline",
|
||||
"south" : "warpdrive:blocks/movement/ship_core-right_offline",
|
||||
"west" : "warpdrive:blocks/movement/ship_controller-side_active4",
|
||||
"east" : "warpdrive:blocks/movement/ship_controller-top"
|
||||
} },
|
||||
|
||||
"active=true,facing=down" : { "model": "minecraft:cube", "textures": {
|
||||
"particle": "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"down" : "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"up" : "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"north" : "warpdrive:blocks/movement/ship_controller-side_inactive",
|
||||
"south" : "warpdrive:blocks/movement/ship_controller-side_inactive",
|
||||
"west" : "warpdrive:blocks/movement/ship_controller-side_inactive",
|
||||
"east" : "warpdrive:blocks/movement/ship_controller-side_inactive"
|
||||
} },
|
||||
"active=true,facing=up" : { "model": "minecraft:cube", "textures": {
|
||||
"particle": "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"down" : "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"up" : "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"north" : "warpdrive:blocks/movement/ship_controller-side_inactive",
|
||||
"south" : "warpdrive:blocks/movement/ship_controller-side_inactive",
|
||||
"west" : "warpdrive:blocks/movement/ship_controller-side_inactive",
|
||||
"east" : "warpdrive:blocks/movement/ship_controller-side_inactive"
|
||||
} },
|
||||
"active=true,facing=north": { "model": "minecraft:cube", "textures": {
|
||||
"particle": "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"down" : "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"up" : "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"north" : "warpdrive:blocks/movement/ship_controller-top",
|
||||
"south" : "warpdrive:blocks/movement/ship_controller-side_active1",
|
||||
"west" : "warpdrive:blocks/movement/ship_core-left_online",
|
||||
"east" : "warpdrive:blocks/movement/ship_core-right_online"
|
||||
} },
|
||||
"active=true,facing=south": { "model": "minecraft:cube", "textures": {
|
||||
"particle": "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"down" : "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"up" : "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"north" : "warpdrive:blocks/movement/ship_controller-side_active2",
|
||||
"south" : "warpdrive:blocks/movement/ship_controller-top",
|
||||
"west" : "warpdrive:blocks/movement/ship_core-right_online",
|
||||
"east" : "warpdrive:blocks/movement/ship_core-left_online"
|
||||
} },
|
||||
"active=true,facing=west" : { "model": "minecraft:cube", "textures": {
|
||||
"particle": "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"down" : "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"up" : "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"north" : "warpdrive:blocks/movement/ship_core-right_online",
|
||||
"south" : "warpdrive:blocks/movement/ship_core-left_online",
|
||||
"west" : "warpdrive:blocks/movement/ship_controller-top",
|
||||
"east" : "warpdrive:blocks/movement/ship_controller-side_active3"
|
||||
} },
|
||||
"active=true,facing=east" : { "model": "minecraft:cube", "textures": {
|
||||
"particle": "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"down" : "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"up" : "warpdrive:blocks/movement/ship_core-top-bottom",
|
||||
"north" : "warpdrive:blocks/movement/ship_core-left_online",
|
||||
"south" : "warpdrive:blocks/movement/ship_core-right_online",
|
||||
"west" : "warpdrive:blocks/movement/ship_controller-side_active4",
|
||||
"east" : "warpdrive:blocks/movement/ship_controller-top"
|
||||
} }
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue