Updated cloaking core to use Diamond Crystal to upgrade tier

(this replace the previous tier() API)
This commit is contained in:
Unknown 2018-07-25 12:45:43 +02:00 committed by unknown
parent e1e43fd27a
commit 25a22136a1
4 changed files with 41 additions and 80 deletions

View file

@ -7,6 +7,7 @@ import cr0s.warpdrive.block.TileEntityAbstractEnergyConsumer;
import cr0s.warpdrive.config.WarpDriveConfig; import cr0s.warpdrive.config.WarpDriveConfig;
import cr0s.warpdrive.data.BlockProperties; import cr0s.warpdrive.data.BlockProperties;
import cr0s.warpdrive.data.CloakedArea; import cr0s.warpdrive.data.CloakedArea;
import cr0s.warpdrive.data.EnumComponentType;
import cr0s.warpdrive.data.SoundEvents; import cr0s.warpdrive.data.SoundEvents;
import cr0s.warpdrive.data.Vector3; import cr0s.warpdrive.data.Vector3;
import cr0s.warpdrive.network.PacketHandler; import cr0s.warpdrive.network.PacketHandler;
@ -21,7 +22,6 @@ import java.util.Arrays;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
@ -37,7 +37,7 @@ public class TileEntityCloakingCore extends TileEntityAbstractEnergyConsumer {
private static final int LASER_REFRESH_TICKS = 100; private static final int LASER_REFRESH_TICKS = 100;
private static final int LASER_DURATION_TICKS = 110; private static final int LASER_DURATION_TICKS = 110;
public byte tier = 1; // cloaking field tier, 1 or 2 public boolean isFullyTransparent = false;
// inner coils color map // inner coils color map
private final float[] innerCoilColor_r = { 1.00f, 1.00f, 1.00f, 1.00f, 0.75f, 0.25f, 0.00f, 0.00f, 0.00f, 0.00f, 0.50f, 1.00f }; private final float[] innerCoilColor_r = { 1.00f, 1.00f, 1.00f, 1.00f, 0.75f, 0.25f, 0.00f, 0.00f, 0.00f, 0.00f, 0.50f, 1.00f };
@ -70,10 +70,10 @@ public class TileEntityCloakingCore extends TileEntityAbstractEnergyConsumer {
peripheralName = "warpdriveCloakingCore"; peripheralName = "warpdriveCloakingCore";
addMethods(new String[] { addMethods(new String[] {
"tier", // set field tier to 1 or 2, return field tier
"isAssemblyValid", // returns true or false
}); });
CC_scripts = Arrays.asList("cloak1", "cloak2", "uncloak"); CC_scripts = Arrays.asList("enable", "disable");
setUpgradeMaxCount(EnumComponentType.DIAMOND_CRYSTAL, 1);
} }
@Override @Override
@ -95,7 +95,8 @@ public class TileEntityCloakingCore extends TileEntityAbstractEnergyConsumer {
updateTicks--; updateTicks--;
if (updateTicks <= 0) { if (updateTicks <= 0) {
updateTicks = ((tier == 1) ? 20 : (tier == 2) ? 10 : 20) * WarpDriveConfig.CLOAKING_FIELD_REFRESH_INTERVAL_SECONDS; // resetting timer isFullyTransparent = hasUpgrade(EnumComponentType.DIAMOND_CRYSTAL);
updateTicks = ((!isFullyTransparent) ? 20 : 10) * WarpDriveConfig.CLOAKING_FIELD_REFRESH_INTERVAL_SECONDS; // resetting timer
isRefreshNeeded = validateAssembly(); isRefreshNeeded = validateAssembly();
@ -123,9 +124,8 @@ public class TileEntityCloakingCore extends TileEntityAbstractEnergyConsumer {
isRefreshNeeded = true; isRefreshNeeded = true;
// Register cloak // Register cloak
WarpDrive.cloaks.updateCloakedArea(world, WarpDrive.cloaks.updateCloakedArea(world, pos, isFullyTransparent,
world.provider.getDimension(), pos, tier, minX, minY, minZ, maxX, maxY, maxZ);
minX, minY, minZ, maxX, maxY, maxZ);
if (!soundPlayed) { if (!soundPlayed) {
soundPlayed = true; soundPlayed = true;
world.playSound(null, pos, SoundEvents.CLOAK, SoundCategory.BLOCKS, 4F, 1F); world.playSound(null, pos, SoundEvents.CLOAK, SoundCategory.BLOCKS, 4F, 1F);
@ -157,9 +157,8 @@ public class TileEntityCloakingCore extends TileEntityAbstractEnergyConsumer {
} else {// enabled, cloaking and valid } else {// enabled, cloaking and valid
if (hasEnoughPower) {// enabled, cloaking and able to if (hasEnoughPower) {// enabled, cloaking and able to
if (isRefreshNeeded) { if (isRefreshNeeded) {
WarpDrive.cloaks.updateCloakedArea(world, WarpDrive.cloaks.updateCloakedArea(world, pos, isFullyTransparent,
world.provider.getDimension(), pos, tier, minX, minY, minZ, maxX, maxY, maxZ);
minX, minY, minZ, maxX, maxY, maxZ);
} }
// IDLE // IDLE
@ -221,18 +220,18 @@ public class TileEntityCloakingCore extends TileEntityAbstractEnergyConsumer {
} }
private void drawLasers() { private void drawLasers() {
float r = 0.0f; float r;
float g = 1.0f; float g;
float b = 0.0f; float b;
if (!isCloaking) {// out of energy if (!isCloaking) {// out of energy
r = 0.75f; r = 0.75f;
g = 0.50f; g = 0.50f;
b = 0.50f; b = 0.50f;
} else if (tier == 1) { } else if (!isFullyTransparent) {
r = 0.00f; r = 0.00f;
g = 1.00f; g = 1.00f;
b = 0.25f; b = 0.25f;
} else if (tier == 2) { } else {
r = 0.00f; r = 0.00f;
g = 0.25f; g = 0.25f;
b = 1.00f; b = 1.00f;
@ -306,7 +305,7 @@ public class TileEntityCloakingCore extends TileEntityAbstractEnergyConsumer {
final int energyRequired_new; final int energyRequired_new;
int volume_new = 0; int volume_new = 0;
final MutableBlockPos mutableBlockPos = new MutableBlockPos(pos); final MutableBlockPos mutableBlockPos = new MutableBlockPos(pos);
if (tier == 1) {// tier1 = gaz and air blocks don't count if (!isFullyTransparent) {// partial transparency = gaz and air blocks don't count
for (y = minY; y <= maxY; y++) { for (y = minY; y <= maxY; y++) {
for (x = minX; x <= maxX; x++) { for (x = minX; x <= maxX; x++) {
for (z = minZ; z <= maxZ; z++) { for (z = minZ; z <= maxZ; z++) {
@ -318,7 +317,7 @@ public class TileEntityCloakingCore extends TileEntityAbstractEnergyConsumer {
} }
} }
energyRequired_new = volume_new * WarpDriveConfig.CLOAKING_TIER1_ENERGY_PER_BLOCK; energyRequired_new = volume_new * WarpDriveConfig.CLOAKING_TIER1_ENERGY_PER_BLOCK;
} else {// tier2 = everything counts } else {// full transparency = everything counts
for (y = minY; y <= maxY; y++) { for (y = minY; y <= maxY; y++) {
for (x = minX; x <= maxX; x++) { for (x = minX; x <= maxX; x++) {
for (z = minZ; z <= maxZ; z++) { for (z = minZ; z <= maxZ; z++) {
@ -341,20 +340,6 @@ public class TileEntityCloakingCore extends TileEntityAbstractEnergyConsumer {
} }
} }
@Override
public void readFromNBT(final NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
tier = tagCompound.getByte("tier");
}
@Nonnull
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
tagCompound = super.writeToNBT(tagCompound);
tagCompound.setByte("tier", tier);
return tagCompound;
}
public boolean validateAssembly() { public boolean validateAssembly() {
final int maxOuterCoilDistance = WarpDriveConfig.CLOAKING_MAX_FIELD_RADIUS - WarpDriveConfig.CLOAKING_COIL_CAPTURE_BLOCKS; final int maxOuterCoilDistance = WarpDriveConfig.CLOAKING_MAX_FIELD_RADIUS - WarpDriveConfig.CLOAKING_COIL_CAPTURE_BLOCKS;
boolean isRefreshNeeded = false; boolean isRefreshNeeded = false;
@ -462,39 +447,21 @@ public class TileEntityCloakingCore extends TileEntityAbstractEnergyConsumer {
textStatus = textValidityIssues; textStatus = textValidityIssues;
} else if (!isEnabled) { } else if (!isEnabled) {
textStatus = new WarpDriveText(null, "warpdrive.cloaking_core.disabled", textStatus = new WarpDriveText(null, "warpdrive.cloaking_core.disabled",
tier, isFullyTransparent ? 2 : 1,
volume); volume);
} else if (!isCloaking) { } else if (!isCloaking) {
textStatus = new WarpDriveText(Commons.styleWarning, "warpdrive.cloaking_core.low_power", textStatus = new WarpDriveText(Commons.styleWarning, "warpdrive.cloaking_core.low_power",
tier, isFullyTransparent ? 2 : 1,
volume); volume);
} else { } else {
textStatus = new WarpDriveText(Commons.styleCorrect, "warpdrive.cloaking_core.cloaking", textStatus = new WarpDriveText(Commons.styleCorrect, "warpdrive.cloaking_core.cloaking",
tier, isFullyTransparent ? 2 : 1,
volume); volume);
} }
return super.getStatusHeader().append(textStatus); return super.getStatusHeader().append(textStatus);
} }
// Common OC/CC methods // Common OC/CC methods
public Object[] tier(final Object[] arguments) {
if (arguments.length == 1 && arguments[0] != null) {
final int tier_new;
try {
tier_new = Commons.toInt(arguments[0]);
} catch (final Exception exception) {
return new Integer[] { (int) tier };
}
if (tier_new == 2) {
tier = 2;
} else {
tier = 1;
}
markDirty();
}
return new Integer[] { (int) tier };
}
@Override @Override
public Object[] getEnergyRequired() { public Object[] getEnergyRequired() {
final int updateRate = ((!isFullyTransparent) ? 20 : 10) * WarpDriveConfig.CLOAKING_FIELD_REFRESH_INTERVAL_SECONDS; final int updateRate = ((!isFullyTransparent) ? 20 : 10) * WarpDriveConfig.CLOAKING_FIELD_REFRESH_INTERVAL_SECONDS;
@ -506,12 +473,6 @@ public class TileEntityCloakingCore extends TileEntityAbstractEnergyConsumer {
} }
// OpenComputer callback methods // OpenComputer callback methods
@Callback
@Optional.Method(modid = "opencomputers")
public Object[] tier(final Context context, final Arguments arguments) {
return tier(OC_convertArgumentsAndLogCall(context, arguments));
}
@Callback @Callback
@Optional.Method(modid = "opencomputers") @Optional.Method(modid = "opencomputers")
public Object[] isAssemblyValid(final Context context, final Arguments arguments) { public Object[] isAssemblyValid(final Context context, final Arguments arguments) {
@ -525,9 +486,6 @@ public class TileEntityCloakingCore extends TileEntityAbstractEnergyConsumer {
final String methodName = CC_getMethodNameAndLogCall(method, arguments); final String methodName = CC_getMethodNameAndLogCall(method, arguments);
switch (methodName) { switch (methodName) {
case "tier":
return tier(arguments);
case "isAssemblyValid": case "isAssemblyValid":
return isAssemblyValid(); return isAssemblyValid();
} }

View file

@ -4,6 +4,7 @@ import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.config.WarpDriveConfig; import cr0s.warpdrive.config.WarpDriveConfig;
import cr0s.warpdrive.network.PacketHandler; import cr0s.warpdrive.network.PacketHandler;
import javax.annotation.Nonnull;
import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.CopyOnWriteArraySet;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
@ -80,11 +81,10 @@ public class CloakManager {
} }
public void updateCloakedArea( public void updateCloakedArea(
final World world, @Nonnull final World world, @Nonnull final BlockPos blockPosCore, final boolean isFullyTransparent,
final int dimensionId, final BlockPos blockPosCore, final byte tier,
final int minX, final int minY, final int minZ, final int minX, final int minY, final int minZ,
final int maxX, final int maxY, final int maxZ) { final int maxX, final int maxY, final int maxZ) {
final CloakedArea newArea = new CloakedArea(world, dimensionId, blockPosCore, tier, minX, minY, minZ, maxX, maxY, maxZ); final CloakedArea newArea = new CloakedArea(world, world.provider.getDimension(), blockPosCore, isFullyTransparent, minX, minY, minZ, maxX, maxY, maxZ);
// find existing one // find existing one
for (final CloakedArea area : cloaks) { for (final CloakedArea area : cloaks) {

View file

@ -7,6 +7,7 @@ import cr0s.warpdrive.config.WarpDriveConfig;
import cr0s.warpdrive.network.PacketHandler; import cr0s.warpdrive.network.PacketHandler;
import cr0s.warpdrive.render.EntityFXBeam; import cr0s.warpdrive.render.EntityFXBeam;
import javax.annotation.Nonnull;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.CopyOnWriteArraySet;
@ -38,16 +39,16 @@ public class CloakedArea {
public int minX, minY, minZ; public int minX, minY, minZ;
public int maxX, maxY, maxZ; public int maxX, maxY, maxZ;
private CopyOnWriteArraySet<UUID> playersInArea; private CopyOnWriteArraySet<UUID> playersInArea;
public byte tier; public boolean isFullyTransparent;
public IBlockState blockStateFog; public IBlockState blockStateFog;
public CloakedArea(final World world, public CloakedArea(final World world,
final int dimensionId, final BlockPos blockPosCore, final byte tier, final int dimensionId, @Nonnull final BlockPos blockPosCore, final boolean isFullyTransparent,
final int minX, final int minY, final int minZ, final int minX, final int minY, final int minZ,
final int maxX, final int maxY, final int maxZ) { final int maxX, final int maxY, final int maxZ) {
this.dimensionId = dimensionId; this.dimensionId = dimensionId;
this.blockPosCore = blockPosCore; this.blockPosCore = blockPosCore;
this.tier = tier; this.isFullyTransparent = isFullyTransparent;
this.minX = minX; this.minX = minX;
this.minY = minY; this.minY = minY;
@ -70,7 +71,7 @@ public class CloakedArea {
} }
} }
if (tier == 1) { if (!isFullyTransparent) {
blockStateFog = WarpDrive.blockGas.getDefaultState().withProperty(BlockGas.COLOR, EnumGasColor.DARKNESS); blockStateFog = WarpDrive.blockGas.getDefaultState().withProperty(BlockGas.COLOR, EnumGasColor.DARKNESS);
} else { } else {
blockStateFog = Blocks.AIR.getDefaultState(); blockStateFog = Blocks.AIR.getDefaultState();

View file

@ -16,6 +16,7 @@ import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
public class MessageCloak implements IMessage, IMessageHandler<MessageCloak, IMessage> { public class MessageCloak implements IMessage, IMessageHandler<MessageCloak, IMessage> {
private int coreX; private int coreX;
private int coreY; private int coreY;
private int coreZ; private int coreZ;
@ -25,7 +26,7 @@ public class MessageCloak implements IMessage, IMessageHandler<MessageCloak, IMe
private int maxX; private int maxX;
private int maxY; private int maxY;
private int maxZ; private int maxZ;
private byte tier; private boolean isFullyTransparent;
private boolean isUncloaking; private boolean isUncloaking;
@SuppressWarnings("unused") @SuppressWarnings("unused")
@ -43,7 +44,7 @@ public class MessageCloak implements IMessage, IMessageHandler<MessageCloak, IMe
this.maxX = area.maxX; this.maxX = area.maxX;
this.maxY = area.maxY; this.maxY = area.maxY;
this.maxZ = area.maxZ; this.maxZ = area.maxZ;
this.tier = area.tier; this.isFullyTransparent = area.isFullyTransparent;
this.isUncloaking = isUncloaking; this.isUncloaking = isUncloaking;
} }
@ -58,8 +59,8 @@ public class MessageCloak implements IMessage, IMessageHandler<MessageCloak, IMe
maxX = buffer.readInt(); maxX = buffer.readInt();
maxY = buffer.readInt(); maxY = buffer.readInt();
maxZ = buffer.readInt(); maxZ = buffer.readInt();
isFullyTransparent = buffer.readBoolean();
isUncloaking = buffer.readBoolean(); isUncloaking = buffer.readBoolean();
tier = buffer.readByte();
} }
@Override @Override
@ -73,8 +74,8 @@ public class MessageCloak implements IMessage, IMessageHandler<MessageCloak, IMe
buffer.writeInt(maxX); buffer.writeInt(maxX);
buffer.writeInt(maxY); buffer.writeInt(maxY);
buffer.writeInt(maxZ); buffer.writeInt(maxZ);
buffer.writeBoolean(isFullyTransparent);
buffer.writeBoolean(isUncloaking); buffer.writeBoolean(isUncloaking);
buffer.writeByte(tier);
} }
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
@ -84,7 +85,8 @@ public class MessageCloak implements IMessage, IMessageHandler<MessageCloak, IMe
WarpDrive.cloaks.removeCloakedArea(player.world.provider.getDimension(), new BlockPos(coreX, coreY, coreZ)); WarpDrive.cloaks.removeCloakedArea(player.world.provider.getDimension(), new BlockPos(coreX, coreY, coreZ));
} else { } else {
// Hide the area // Hide the area
WarpDrive.cloaks.updateCloakedArea(player.world, player.world.provider.getDimension(), new BlockPos(coreX, coreY, coreZ), tier, minX, minY, minZ, maxX, maxY, maxZ); WarpDrive.cloaks.updateCloakedArea(player.world, new BlockPos(coreX, coreY, coreZ), isFullyTransparent,
minX, minY, minZ, maxX, maxY, maxZ);
} }
} }
@ -101,7 +103,7 @@ public class MessageCloak implements IMessage, IMessageHandler<MessageCloak, IMe
WarpDrive.logger.info(String.format("Received cloak packet: %s area (%d %d %d) -> (%d %d %d) tier %d", WarpDrive.logger.info(String.format("Received cloak packet: %s area (%d %d %d) -> (%d %d %d) tier %d",
((cloakMessage.isUncloaking) ? "UNCLOAKING" : "cloaking"), ((cloakMessage.isUncloaking) ? "UNCLOAKING" : "cloaking"),
cloakMessage.minX, cloakMessage.minY, cloakMessage.minZ, cloakMessage.minX, cloakMessage.minY, cloakMessage.minZ,
cloakMessage.maxX, cloakMessage.maxY, cloakMessage.maxZ, cloakMessage.tier)); cloakMessage.maxX, cloakMessage.maxY, cloakMessage.maxZ, cloakMessage.isFullyTransparent ? 2 : 1));
} }
final EntityPlayerSP player = Minecraft.getMinecraft().player; final EntityPlayerSP player = Minecraft.getMinecraft().player;