mirror of
https://github.com/GTNewHorizons/Draconic-Evolution.git
synced 2026-11-20 04:09:34 +00:00
Optimized Reactor Stabilizer
This commit is contained in:
1 parent
72b65b8c12
commit
2221ed2a14
2 files changed
+131
-190
No files matched your search
+36
-48
@@ -1,6 +1,7 @@
|
||||
package com.brandon3055.draconicevolution.common.blocks.multiblock;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -24,7 +25,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
/**
|
||||
* Created by Brandon on 5/7/2015.
|
||||
*/
|
||||
public class ReactorStabilizer extends BlockDE {
|
||||
public class ReactorStabilizer extends BlockDE implements ITileEntityProvider {
|
||||
|
||||
public ReactorStabilizer() {
|
||||
this.setCreativeTab(DraconicEvolution.tabBlocksItems);
|
||||
@@ -32,8 +33,8 @@ public class ReactorStabilizer extends BlockDE {
|
||||
ModBlocks.register(this);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerBlockIcons(IIconRegister iconRegister) {
|
||||
blockIcon = iconRegister.registerIcon(References.RESOURCESPREFIX + "transparency");
|
||||
}
|
||||
@@ -44,27 +45,21 @@ public class ReactorStabilizer extends BlockDE {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_,
|
||||
float p_149727_7_, float p_149727_8_, float p_149727_9_) {
|
||||
if (!player.isSneaking()) {
|
||||
TileReactorStabilizer tile = world.getTileEntity(x, y, z) instanceof TileReactorStabilizer
|
||||
? (TileReactorStabilizer) world.getTileEntity(x, y, z)
|
||||
: null;
|
||||
TileEntity core = null;
|
||||
if (tile != null) core = tile.getMaster().getTileEntity(world);
|
||||
if (core instanceof TileReactorCore) {
|
||||
((TileReactorCore) core).onStructureRightClicked(player);
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float subX,
|
||||
float subY, float subZ) {
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
if (tile instanceof IReactorPart) {
|
||||
IReactorPart part = (IReactorPart) tile;
|
||||
if (player.isSneaking()) {
|
||||
part.changeRedstoneMode();
|
||||
if (!world.isRemote) {
|
||||
player.addChatComponentMessage(new ChatComponentText(part.getRedstoneModeAsString()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} else if (!world.isRemote) {
|
||||
IReactorPart tile = world.getTileEntity(x, y, z) instanceof IReactorPart
|
||||
? (IReactorPart) world.getTileEntity(x, y, z)
|
||||
: null;
|
||||
if (tile != null) {
|
||||
tile.changeRedstoneMode();
|
||||
if (!world.isRemote)
|
||||
player.addChatComponentMessage(new ChatComponentText(tile.getRedstoneModeString()));
|
||||
return true;
|
||||
TileReactorCore core = part.getMaster();
|
||||
if (core != null) {
|
||||
return core.onStructureRightClicked(player);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -86,48 +81,41 @@ public class ReactorStabilizer extends BlockDE {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(World world, int metadata) {
|
||||
public TileEntity createNewTileEntity(World world, int metadata) {
|
||||
return new TileReactorStabilizer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack) {
|
||||
int d = Utills.determineOrientation(x, y, z, entity);
|
||||
TileReactorStabilizer tile = world.getTileEntity(x, y, z) instanceof TileReactorStabilizer
|
||||
? (TileReactorStabilizer) world.getTileEntity(x, y, z)
|
||||
: null;
|
||||
if (tile != null) {
|
||||
if (entity.isSneaking()) tile.facingDirection = ForgeDirection.getOrientation(d).getOpposite().ordinal();
|
||||
else tile.facingDirection = ForgeDirection.getOrientation(d).ordinal();
|
||||
tile.onPlaced();
|
||||
int facing = Utills.determineOrientation(x, y, z, entity);
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
if (tile instanceof TileReactorStabilizer) {
|
||||
TileReactorStabilizer stabilizer = (TileReactorStabilizer) tile;
|
||||
stabilizer.facingDirection = entity.isSneaking()
|
||||
? ForgeDirection.getOrientation(facing).getOpposite().ordinal()
|
||||
: ForgeDirection.getOrientation(facing).ordinal();
|
||||
stabilizer.onPlaced();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World world, int x, int y, int z, Block p_149749_5_, int p_149749_6_) {
|
||||
TileReactorStabilizer tile = world.getTileEntity(x, y, z) instanceof TileReactorStabilizer
|
||||
? (TileReactorStabilizer) world.getTileEntity(x, y, z)
|
||||
: null;
|
||||
TileEntity core = null;
|
||||
if (tile != null) core = tile.getMaster().getTileEntity(world);
|
||||
super.breakBlock(world, x, y, z, p_149749_5_, p_149749_6_);
|
||||
if (core instanceof TileReactorCore) ((TileReactorCore) core).validateStructure();
|
||||
public void breakBlock(World world, int x, int y, int z, Block blockBroken, int metadata) {
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
TileReactorCore core = tile instanceof IReactorPart ? ((IReactorPart) tile).getMaster() : null;
|
||||
super.breakBlock(world, x, y, z, blockBroken, metadata);
|
||||
if (core != null) {
|
||||
core.updateReactorParts(false);
|
||||
core.validateStructure();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasComparatorInputOverride() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getComparatorInputOverride(World world, int x, int y, int z, int p_149736_5_) {
|
||||
IReactorPart tile = world.getTileEntity(x, y, z) instanceof IReactorPart
|
||||
? (IReactorPart) world.getTileEntity(x, y, z)
|
||||
: null;
|
||||
if (tile == null) return 0;
|
||||
TileReactorCore core = tile.getMaster().getTileEntity(world) instanceof TileReactorCore
|
||||
? (TileReactorCore) tile.getMaster().getTileEntity(world)
|
||||
: null;
|
||||
if (core != null) return core.getComparatorOutput(tile.getRedstoneMode());
|
||||
return 0;
|
||||
public int getComparatorInputOverride(World world, int x, int y, int z, int side) {
|
||||
return IReactorPart.getComparatorOutput(world, x, y, z);
|
||||
}
|
||||
}
|
||||
+95
-142
@@ -1,8 +1,5 @@
|
||||
package com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.reactor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
@@ -11,7 +8,6 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.brandon3055.brandonscore.common.utills.Utills;
|
||||
import com.brandon3055.draconicevolution.DraconicEvolution;
|
||||
import com.brandon3055.draconicevolution.client.render.particle.ParticleReactorBeam;
|
||||
import com.brandon3055.draconicevolution.common.blocks.multiblock.IReactorPart;
|
||||
@@ -37,111 +33,112 @@ public class TileReactorStabilizer extends TileEntity implements IReactorPart, I
|
||||
public TileLocation masterLocation = new TileLocation();
|
||||
public boolean isValid = false;
|
||||
public int tick = 0;
|
||||
private int redstoneMode = 0;
|
||||
private int redstoneMode = IReactorPart.RMODE_TEMP;
|
||||
private int comparatorOutputCache = -1;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private ParticleReactorBeam beam;
|
||||
|
||||
private int rs = -1;
|
||||
private int rsCach = -1;
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
tick++;
|
||||
|
||||
if (worldObj.isRemote) {
|
||||
updateBeam();
|
||||
return;
|
||||
}
|
||||
|
||||
TileEntity master = masterLocation.getTileEntity(worldObj);
|
||||
if (master instanceof TileReactorCore
|
||||
&& ((TileReactorCore) master).reactorState == TileReactorCore.STATE_ONLINE) {
|
||||
ForgeDirection back = ForgeDirection.getOrientation(facingDirection).getOpposite();
|
||||
TileEntity output = worldObj
|
||||
.getTileEntity(xCoord + back.offsetX, yCoord + back.offsetY, zCoord + back.offsetZ);
|
||||
if (output instanceof IEnergyReceiver) {
|
||||
int sent = ((IEnergyReceiver) output).receiveEnergy(
|
||||
back.getOpposite(),
|
||||
Math.min(
|
||||
((TileReactorCore) master).energySaturation,
|
||||
((TileReactorCore) master).maxEnergySaturation / 100),
|
||||
false);
|
||||
((TileReactorCore) master).energySaturation -= sent;
|
||||
TileReactorCore core = getMaster();
|
||||
if (core != null) {
|
||||
if (core.reactorState == TileReactorCore.STATE_ONLINE) {
|
||||
ForgeDirection facing = ForgeDirection.getOrientation(facingDirection);
|
||||
ForgeDirection back = facing.getOpposite();
|
||||
TileEntity tile = worldObj
|
||||
.getTileEntity(xCoord + back.offsetX, yCoord + back.offsetY, zCoord + back.offsetZ);
|
||||
if (tile instanceof IEnergyReceiver) {
|
||||
IEnergyReceiver receiver = (IEnergyReceiver) tile;
|
||||
int energyToReceive = Math.min(core.energySaturation, core.maxEnergySaturation / 100);
|
||||
int energyReceived = receiver.receiveEnergy(facing, energyToReceive, false);
|
||||
core.energySaturation -= energyReceived;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!worldObj.isRemote && master instanceof TileReactorCore) {
|
||||
rs = ((TileReactorCore) master).getComparatorOutput(redstoneMode);
|
||||
if (rs != rsCach) {
|
||||
rsCach = rs;
|
||||
Utills.updateNeabourBlocks(worldObj, xCoord, yCoord, zCoord);
|
||||
int comparatorOutput = core.getComparatorOutput(redstoneMode);
|
||||
if (comparatorOutput != comparatorOutputCache) {
|
||||
comparatorOutputCache = comparatorOutput;
|
||||
worldObj.notifyBlocksOfNeighborChange(
|
||||
xCoord,
|
||||
yCoord,
|
||||
zCoord,
|
||||
worldObj.getBlock(xCoord, yCoord, zCoord));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private void updateBeam() {
|
||||
if (worldObj.isRemote) {
|
||||
if (!(masterLocation.getTileEntity(worldObj) instanceof TileReactorCore)) {
|
||||
coreSpeed = 0;
|
||||
ringSpeed = 0;
|
||||
modelIllumination = 0;
|
||||
return;
|
||||
}
|
||||
TileReactorCore core = (TileReactorCore) masterLocation.getTileEntity(worldObj);
|
||||
coreRotation += coreSpeed;
|
||||
ringRotation += ringSpeed;
|
||||
coreSpeed = 30F * core.renderSpeed;
|
||||
ringSpeed = 5F * core.renderSpeed;
|
||||
modelIllumination = core.renderSpeed;
|
||||
if (tick % 100 == 0) beam = null;
|
||||
if (isValid) beam = DraconicEvolution.proxy.reactorBeam(this, beam, true);
|
||||
TileReactorCore core = getMaster();
|
||||
if (core == null) {
|
||||
coreSpeed = 0;
|
||||
ringSpeed = 0;
|
||||
modelIllumination = 0;
|
||||
return;
|
||||
}
|
||||
coreRotation += coreSpeed;
|
||||
ringRotation += ringSpeed;
|
||||
coreSpeed = 30F * core.renderSpeed;
|
||||
ringSpeed = 5F * core.renderSpeed;
|
||||
modelIllumination = core.renderSpeed;
|
||||
if (tick % 100 == 0) {
|
||||
beam = null;
|
||||
}
|
||||
if (isValid) {
|
||||
beam = DraconicEvolution.proxy.reactorBeam(this, beam, true);
|
||||
}
|
||||
}
|
||||
|
||||
public void onPlaced() {
|
||||
|
||||
checkForMaster();
|
||||
}
|
||||
|
||||
public void onBroken() {}
|
||||
|
||||
public boolean checkForMaster() {
|
||||
for (int i = 1; i < 10; i++) {
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(facingDirection);
|
||||
int x = xCoord + (dir.offsetX * i);
|
||||
int y = yCoord + (dir.offsetY * i);
|
||||
int z = zCoord + (dir.offsetZ * i);
|
||||
if (!worldObj.isAirBlock(x, y, z)) {
|
||||
TileEntity tile = worldObj.getTileEntity(x, y, z);
|
||||
if (tile instanceof TileReactorCore && ((TileReactorCore) tile).stabilizerLocations.size() < 4) // todo
|
||||
// add
|
||||
// check
|
||||
// reactor
|
||||
// side
|
||||
// to
|
||||
// make
|
||||
// sure
|
||||
// this
|
||||
// aligns
|
||||
// with
|
||||
// other
|
||||
// stabilizers
|
||||
{
|
||||
((TileReactorCore) tile).stabilizerLocations.add(new TileLocation(xCoord, yCoord, zCoord));
|
||||
masterLocation.set(x, y, z);
|
||||
isValid = true;
|
||||
((TileReactorCore) tile).validateStructure();
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
return true;
|
||||
} else {
|
||||
isValid = false;
|
||||
return false;
|
||||
}
|
||||
ForgeDirection facing = ForgeDirection.getOrientation(facingDirection);
|
||||
for (int distance = 1; distance <= TileReactorCore.MAX_SLAVE_RANGE; distance++) {
|
||||
TileLocation location = new TileLocation(
|
||||
xCoord + facing.offsetX * distance,
|
||||
yCoord + facing.offsetY * distance,
|
||||
zCoord + facing.offsetZ * distance);
|
||||
TileEntity tile = location.getTileEntity(worldObj);
|
||||
if (tile instanceof TileReactorCore) {
|
||||
setUp(location);
|
||||
TileReactorCore core = (TileReactorCore) tile;
|
||||
core.updateReactorParts(false);
|
||||
core.validateStructure();
|
||||
return;
|
||||
}
|
||||
}
|
||||
shutDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileLocation getMasterLocation() {
|
||||
return masterLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileReactorCore getMaster() {
|
||||
TileEntity tile = masterLocation.getTileEntity(worldObj);
|
||||
return tile instanceof TileReactorCore ? (TileReactorCore) tile : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp(TileLocation masterLocation) {
|
||||
this.masterLocation = masterLocation;
|
||||
isValid = true;
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutDown() {
|
||||
isValid = false;
|
||||
return false;
|
||||
masterLocation = new TileLocation();
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -150,14 +147,8 @@ public class TileReactorStabilizer extends TileEntity implements IReactorPart, I
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRedstoneModeString() {
|
||||
return StatCollector.translateToLocal("msg.de.reactorRSMode." + redstoneMode + ".txt");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeRedstoneMode() {
|
||||
if (redstoneMode == IReactorPart.RMODE_FUEL_INV) redstoneMode = 0;
|
||||
else redstoneMode++;
|
||||
public ForgeDirection getFacing() {
|
||||
return ForgeDirection.getOrientation(facingDirection);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -166,10 +157,17 @@ public class TileReactorStabilizer extends TileEntity implements IReactorPart, I
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutDown() {
|
||||
isValid = false;
|
||||
masterLocation = new TileLocation();
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
public void changeRedstoneMode() {
|
||||
if (redstoneMode == IReactorPart.RMODE_FUEL_INV) {
|
||||
redstoneMode = IReactorPart.RMODE_TEMP;
|
||||
} else {
|
||||
redstoneMode++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRedstoneModeAsString() {
|
||||
return StatCollector.translateToLocal("msg.de.reactorRSMode." + redstoneMode + ".txt");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -208,11 +206,6 @@ public class TileReactorStabilizer extends TileEntity implements IReactorPart, I
|
||||
redstoneMode = compound.getInteger("RedstoneMode");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileLocation getMaster() {
|
||||
return masterLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) {
|
||||
return 0;
|
||||
@@ -249,48 +242,8 @@ public class TileReactorStabilizer extends TileEntity implements IReactorPart, I
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] callMethod(String method, Object... args) {
|
||||
if (!(getMaster().getTileEntity(worldObj) instanceof TileReactorCore)) return null;
|
||||
TileReactorCore reactor = (TileReactorCore) getMaster().getTileEntity(worldObj);
|
||||
|
||||
if (args.length > 0) throw new IllegalArgumentException("This method dose not accept arguments");
|
||||
|
||||
if (method.equals("getReactorInfo")) {
|
||||
Map<Object, Object> map = new HashMap<Object, Object>();
|
||||
map.put("temperature", Utills.round(reactor.reactionTemperature, 100));
|
||||
map.put("fieldStrength", Utills.round(reactor.fieldCharge, 100));
|
||||
map.put("maxFieldStrength", Utills.round(reactor.maxFieldCharge, 100));
|
||||
map.put("energySaturation", reactor.energySaturation);
|
||||
map.put("maxEnergySaturation", reactor.maxEnergySaturation);
|
||||
map.put("fuelConversion", Utills.round((double) reactor.convertedFuel + reactor.conversionUnit, 1000));
|
||||
map.put("maxFuelConversion", reactor.reactorFuel + reactor.convertedFuel);
|
||||
map.put("generationRate", (int) reactor.generationRate);
|
||||
map.put("fieldDrainRate", reactor.fieldDrain);
|
||||
map.put("fuelConversionRate", (int) Math.round(reactor.fuelUseRate * 1000000D));
|
||||
map.put(
|
||||
"status",
|
||||
reactor.reactorState == 0 ? "offline"
|
||||
: reactor.reactorState == 1 && !reactor.canStart() ? "charging"
|
||||
: reactor.reactorState == 1 && reactor.canStart() ? "charged"
|
||||
: reactor.reactorState == 2 ? "online"
|
||||
: reactor.reactorState == 3 ? "stopping" : "invalid");
|
||||
return new Object[] { map };
|
||||
} else if (method.equals("chargeReactor")) {
|
||||
if (reactor.canCharge()) {
|
||||
reactor.reactorState = TileReactorCore.STATE_START;
|
||||
return new Object[] { true };
|
||||
} else return new Object[] { false };
|
||||
} else if (method.equals("activateReactor")) {
|
||||
if (reactor.canStart()) {
|
||||
reactor.reactorState = TileReactorCore.STATE_ONLINE;
|
||||
return new Object[] { true };
|
||||
} else return new Object[] { false };
|
||||
} else if (method.equals("stopReactor")) {
|
||||
if (reactor.canStop()) {
|
||||
reactor.reactorState = TileReactorCore.STATE_STOP;
|
||||
return new Object[] { true };
|
||||
} else return new Object[] { false };
|
||||
}
|
||||
return new Object[] {};
|
||||
public Object[] callMethod(String methodName, Object... args) {
|
||||
TileReactorCore core = getMaster();
|
||||
return core != null ? core.callMethod(methodName, args) : null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user