Added enantiomorphic reactor core blockstate properties
This commit is contained in:
parent
1277b2de9f
commit
67bec007d0
2 changed files with 37 additions and 8 deletions
|
@ -5,6 +5,8 @@ import cr0s.warpdrive.block.BlockAbstractContainer;
|
|||
import cr0s.warpdrive.data.EnumReactorFace;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.PropertyInteger;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
@ -18,12 +20,41 @@ import javax.annotation.Nonnull;
|
|||
|
||||
public class BlockEnanReactorCore extends BlockAbstractContainer {
|
||||
|
||||
public static final PropertyInteger ENERGY = PropertyInteger.create("energy", 0, 3);
|
||||
public static final PropertyInteger INSTABILITY = PropertyInteger.create("stability", 0, 3);
|
||||
|
||||
public BlockEnanReactorCore(final String registryName) {
|
||||
super(registryName, Material.IRON);
|
||||
setUnlocalizedName("warpdrive.energy.enan_reactor_core");
|
||||
|
||||
setDefaultState(getDefaultState()
|
||||
.withProperty(ENERGY, 0)
|
||||
.withProperty(INSTABILITY, 0)
|
||||
);
|
||||
GameRegistry.registerTileEntity(TileEntityEnanReactorCore.class, WarpDrive.PREFIX + registryName);
|
||||
}
|
||||
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState() {
|
||||
return new BlockStateContainer(this, ENERGY, INSTABILITY);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Nonnull
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(final int metadata) {
|
||||
return getDefaultState()
|
||||
.withProperty(ENERGY, metadata & 0x3)
|
||||
.withProperty(INSTABILITY, metadata >> 2);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
return blockState.getValue(ENERGY) + (blockState.getValue(INSTABILITY) << 2);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(@Nonnull final World world, final int metadata) {
|
||||
|
|
|
@ -155,7 +155,7 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
|
|||
}
|
||||
}
|
||||
|
||||
public void decreaseInstability(final EnumReactorFace reactorFace, final int energy) {
|
||||
void decreaseInstability(final EnumReactorFace reactorFace, final int energy) {
|
||||
if (reactorFace.indexStability < 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -191,8 +191,6 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
|
|||
}
|
||||
|
||||
instabilityValues[indexStability] = Math.max(0, instabilityValues[indexStability] - amountToRemove);
|
||||
|
||||
updateMetadata();
|
||||
}
|
||||
|
||||
private void generateEnergy() {
|
||||
|
@ -315,10 +313,10 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
|
|||
final int instabilityNibble = (int) Math.max(0, Math.min(3, Math.round(maxInstability / 25.0D)));
|
||||
final int energyNibble = (int) Math.max(0, Math.min(3, Math.round(4.0D * containedEnergy / WarpDriveConfig.ENAN_REACTOR_MAX_ENERGY_STORED)));
|
||||
|
||||
final int metadata = 4 * instabilityNibble + energyNibble;
|
||||
if (getBlockMetadata() != metadata) {
|
||||
updateMetadata(metadata);
|
||||
}
|
||||
final IBlockState blockStateNew = blockType.getDefaultState()
|
||||
.withProperty(BlockEnanReactorCore.ENERGY, energyNibble)
|
||||
.withProperty(BlockEnanReactorCore.INSTABILITY, instabilityNibble);
|
||||
updateBlockState(null, blockStateNew);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Reference in a new issue