Removed EnumValidPowered in favor of just isValid

This commit is contained in:
Unknown 2018-08-01 22:31:58 +02:00 committed by unknown
parent f5df4549f4
commit 193bfa8ae6
5 changed files with 27 additions and 100 deletions

View file

@ -3,7 +3,6 @@ package cr0s.warpdrive.block.energy;
import cr0s.warpdrive.block.BlockAbstractContainer;
import cr0s.warpdrive.data.BlockProperties;
import cr0s.warpdrive.data.EnumTier;
import cr0s.warpdrive.data.EnumValidPowered;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockStateContainer;
@ -24,32 +23,31 @@ public class BlockIC2reactorLaserCooler extends BlockAbstractContainer {
setTranslationKey("warpdrive.energy.ic2_reactor_laser_cooler");
setDefaultState(blockState.getBaseState()
.withProperty(BlockProperties.FACING, EnumFacing.DOWN)
.withProperty(BlockProperties.VALID_POWERED, EnumValidPowered.INVALID));
setDefaultState(getDefaultState()
.withProperty(BlockProperties.ACTIVE, false)
.withProperty(BlockProperties.FACING, EnumFacing.DOWN)
);
}
@Nonnull
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, BlockProperties.FACING, BlockProperties.VALID_POWERED);
return new BlockStateContainer(this, BlockProperties.FACING, BlockProperties.ACTIVE);
}
@SuppressWarnings("deprecation")
@Nonnull
@Override
public IBlockState getStateFromMeta(final int metadata) {
final int facing = (metadata & 7) < 6 ? (metadata & 7) : 0;
final EnumValidPowered enumValidPowered = EnumValidPowered.get(metadata - facing);
return getDefaultState()
.withProperty(BlockProperties.FACING, EnumFacing.byIndex(facing))
.withProperty(BlockProperties.VALID_POWERED, enumValidPowered != null ? enumValidPowered : EnumValidPowered.INVALID);
.withProperty(BlockProperties.ACTIVE, (metadata & 0x8) != 0)
.withProperty(BlockProperties.FACING, EnumFacing.byIndex(metadata & 0x7));
}
@Override
public int getMetaFromState(final IBlockState blockState) {
return blockState.getValue(BlockProperties.FACING).getIndex()
+ blockState.getValue(BlockProperties.VALID_POWERED).getIndex();
return (blockState.getValue(BlockProperties.ACTIVE) ? 8 : 0)
+ blockState.getValue(BlockProperties.FACING).getIndex();
}
@Nonnull
@ -63,7 +61,7 @@ public class BlockIC2reactorLaserCooler extends BlockAbstractContainer {
final EntityLivingBase entityLiving, final ItemStack itemStack) {
super.onBlockPlacedBy(world, blockPos, blockState, entityLiving, itemStack);
world.setBlockState(blockPos, blockState
.withProperty(BlockProperties.FACING, EnumFacing.NORTH)
.withProperty(BlockProperties.VALID_POWERED, EnumValidPowered.INVALID));
.withProperty(BlockProperties.FACING, EnumFacing.DOWN)
.withProperty(BlockProperties.ACTIVE, false));
}
}

View file

@ -5,7 +5,6 @@ import cr0s.warpdrive.api.WarpDriveText;
import cr0s.warpdrive.block.TileEntityAbstractLaser;
import cr0s.warpdrive.config.WarpDriveConfig;
import cr0s.warpdrive.data.BlockProperties;
import cr0s.warpdrive.data.EnumValidPowered;
import cr0s.warpdrive.data.Vector3;
import cr0s.warpdrive.item.ItemIC2reactorLaserFocus;
import cr0s.warpdrive.network.PacketHandler;
@ -145,14 +144,9 @@ public class TileEntityIC2reactorLaserMonitor extends TileEntityAbstractLaser {
}
private void updateBlockState() {
IBlockState blockStateNew = getBlockType().getDefaultState().withProperty(BlockProperties.FACING, facing != null ? facing : EnumFacing.NORTH);
if (!isValid) {
blockStateNew = blockStateNew.withProperty(BlockProperties.VALID_POWERED, EnumValidPowered.INVALID);
} else if (cache_laserMedium_energyStored < WarpDriveConfig.IC2_REACTOR_ENERGY_PER_HEAT) {
blockStateNew = blockStateNew.withProperty(BlockProperties.VALID_POWERED, EnumValidPowered.VALID);
} else {
blockStateNew = blockStateNew.withProperty(BlockProperties.VALID_POWERED, EnumValidPowered.POWERED);
}
final IBlockState blockStateNew = getBlockType().getDefaultState()
.withProperty(BlockProperties.ACTIVE, isValid)
.withProperty(BlockProperties.FACING, facing != null ? facing : EnumFacing.DOWN);
updateBlockState(blockStateNew, null, null);
}

View file

@ -8,9 +8,8 @@ public class BlockProperties {
// Common block properties
public static final PropertyBool ACTIVE = PropertyBool.create("active");
public static final PropertyDirection FACING = PropertyDirection.create("facing");
public static final UnlistedPropertyBlockState CAMOUFLAGE = new UnlistedPropertyBlockState("camouflage");
public static final PropertyEnum<EnumValidPowered> VALID_POWERED = PropertyEnum.create("valid_powered", EnumValidPowered.class);
public static final PropertyDirection FACING = PropertyDirection.create("facing");
public static final PropertyEnum<EnumFrameType> FRAME = PropertyEnum.create("frame", EnumFrameType.class);
}

View file

@ -1,46 +0,0 @@
package cr0s.warpdrive.data;
import javax.annotation.Nonnull;
import java.util.HashMap;
import net.minecraft.util.IStringSerializable;
public enum EnumValidPowered implements IStringSerializable {
INVALID("invalid", 6),
VALID ("valid" , 0),
POWERED("powered", 8);
private final String name;
private final int index;
// cached values
public static final int length;
private static final HashMap<Integer, EnumValidPowered> ID_MAP = new HashMap<>();
static {
length = EnumValidPowered.values().length;
for (final EnumValidPowered validPowered : values()) {
ID_MAP.put(validPowered.index, validPowered);
}
}
EnumValidPowered(final String name, final int index) {
this.name = name;
this.index = index;
}
@Nonnull
@Override
public String getName() {
return name;
}
public static EnumValidPowered get(final int index) {
return ID_MAP.get(index);
}
public int getIndex() {
return index;
}
}

View file

@ -11,26 +11,8 @@
"west" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-valid",
"east" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-valid"
} },
"facing=down,valid_powered=invalid" : { "model": "minecraft:cube_all", "textures": {
"all": "warpdrive:blocks/energy/ic2_reactor_laser_cooler-invalid"
} },
"facing=up,valid_powered=invalid" : { "model": "minecraft:cube_all", "textures": {
"all": "warpdrive:blocks/energy/ic2_reactor_laser_cooler-invalid"
} },
"facing=north,valid_powered=invalid": { "model": "minecraft:cube_all", "textures": {
"all": "warpdrive:blocks/energy/ic2_reactor_laser_cooler-invalid"
} },
"facing=south,valid_powered=invalid": { "model": "minecraft:cube_all", "textures": {
"all": "warpdrive:blocks/energy/ic2_reactor_laser_cooler-invalid"
} },
"facing=west,valid_powered=invalid" : { "model": "minecraft:cube_all", "textures": {
"all": "warpdrive:blocks/energy/ic2_reactor_laser_cooler-invalid"
} },
"facing=east,valid_powered=invalid" : { "model": "minecraft:cube_all", "textures": {
"all": "warpdrive:blocks/energy/ic2_reactor_laser_cooler-invalid"
} },
"facing=down,valid_powered=valid" : { "model": "minecraft:cube", "textures": {
"active=false,facing=down" : { "model": "minecraft:cube", "textures": {
"particle": "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-valid",
"down" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-head-valid",
"up" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-valid",
@ -39,7 +21,7 @@
"west" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-valid",
"east" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-valid"
} },
"facing=up,valid_powered=valid" : { "model": "minecraft:cube", "textures": {
"active=false,facing=up" : { "model": "minecraft:cube", "textures": {
"particle": "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-valid",
"down" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-valid",
"up" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-head-valid",
@ -48,7 +30,7 @@
"west" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-valid",
"east" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-valid"
} },
"facing=north,valid_powered=valid": { "model": "minecraft:cube", "textures": {
"active=false,facing=north": { "model": "minecraft:cube", "textures": {
"particle": "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-valid",
"down" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-valid",
"up" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-valid",
@ -57,7 +39,7 @@
"west" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-valid",
"east" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-valid"
} },
"facing=south,valid_powered=valid": { "model": "minecraft:cube", "textures": {
"active=false,facing=south": { "model": "minecraft:cube", "textures": {
"particle": "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-valid",
"down" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-valid",
"up" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-valid",
@ -66,7 +48,7 @@
"west" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-valid",
"east" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-valid"
} },
"facing=west,valid_powered=valid" : { "model": "minecraft:cube", "textures": {
"active=false,facing=west" : { "model": "minecraft:cube", "textures": {
"particle": "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-valid",
"down" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-valid",
"up" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-valid",
@ -75,7 +57,7 @@
"west" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-head-valid",
"east" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-valid"
} },
"facing=east,valid_powered=valid" : { "model": "minecraft:cube", "textures": {
"active=false,facing=east" : { "model": "minecraft:cube", "textures": {
"particle": "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-valid",
"down" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-valid",
"up" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-valid",
@ -85,7 +67,7 @@
"east" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-head-valid"
} },
"facing=down,valid_powered=powered" : { "model": "minecraft:cube", "textures": {
"active=true,facing=down" : { "model": "minecraft:cube", "textures": {
"particle": "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-powered",
"down" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-head-powered",
"up" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-powered",
@ -94,7 +76,7 @@
"west" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-powered",
"east" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-powered"
} },
"facing=up,valid_powered=powered" : { "model": "minecraft:cube", "textures": {
"active=true,facing=up" : { "model": "minecraft:cube", "textures": {
"particle": "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-powered",
"down" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-powered",
"up" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-head-powered",
@ -103,7 +85,7 @@
"west" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-powered",
"east" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-powered"
} },
"facing=north,valid_powered=powered": { "model": "minecraft:cube", "textures": {
"active=true,facing=north": { "model": "minecraft:cube", "textures": {
"particle": "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-powered",
"down" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-powered",
"up" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-powered",
@ -112,7 +94,7 @@
"west" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-powered",
"east" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-powered"
} },
"facing=south,valid_powered=powered": { "model": "minecraft:cube", "textures": {
"active=true,facing=south": { "model": "minecraft:cube", "textures": {
"particle": "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-powered",
"down" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-powered",
"up" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-powered",
@ -121,7 +103,7 @@
"west" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-powered",
"east" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-powered"
} },
"facing=west,valid_powered=powered" : { "model": "minecraft:cube", "textures": {
"active=true,facing=west" : { "model": "minecraft:cube", "textures": {
"particle": "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-powered",
"down" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-powered",
"up" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-powered",
@ -130,7 +112,7 @@
"west" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-head-powered",
"east" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-powered"
} },
"facing=east,valid_powered=powered" : { "model": "minecraft:cube", "textures": {
"active=true,facing=east" : { "model": "minecraft:cube", "textures": {
"particle": "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-powered",
"down" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-powered",
"up" : "warpdrive:blocks/energy/ic2_reactor_laser_cooler-side-powered",