mirror of
https://github.com/GTNewHorizons/Draconic-Evolution.git
synced 2026-11-25 22:44:30 +00:00
Optimized Reactor Energy Injector
This commit is contained in:
1 parent
63b00bea6c
commit
72b65b8c12
2 files changed
+109
-168
No files matched your search
+37
-59
@@ -1,5 +1,6 @@
|
||||
package com.brandon3055.draconicevolution.common.blocks.multiblock;
|
||||
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -16,7 +17,6 @@ import com.brandon3055.draconicevolution.DraconicEvolution;
|
||||
import com.brandon3055.draconicevolution.common.ModBlocks;
|
||||
import com.brandon3055.draconicevolution.common.blocks.BlockDE;
|
||||
import com.brandon3055.draconicevolution.common.lib.References;
|
||||
import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.reactor.TileReactorCore;
|
||||
import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.reactor.TileReactorEnergyInjector;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
@@ -25,7 +25,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
/**
|
||||
* Created by Brandon on 23/7/2015.
|
||||
*/
|
||||
public class ReactorEnergyInjector extends BlockDE {
|
||||
public class ReactorEnergyInjector extends BlockDE implements ITileEntityProvider {
|
||||
|
||||
public ReactorEnergyInjector() {
|
||||
this.setCreativeTab(DraconicEvolution.tabBlocksItems);
|
||||
@@ -34,49 +34,29 @@ public class ReactorEnergyInjector extends BlockDE {
|
||||
ModBlocks.register(this);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerBlockIcons(IIconRegister iconRegister) {
|
||||
blockIcon = iconRegister.registerIcon(References.RESOURCESPREFIX + "transparency");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockBoundsBasedOnState(IBlockAccess access, int x, int y, int z) {
|
||||
TileReactorEnergyInjector tile = access.getTileEntity(x, y, z) instanceof TileReactorEnergyInjector
|
||||
? (TileReactorEnergyInjector) access.getTileEntity(x, y, z)
|
||||
: null;
|
||||
if (tile != null) {
|
||||
switch (tile.facingDirection) {
|
||||
case 0:
|
||||
this.setBlockBounds(0F, 0.885F, 0F, 1F, 1F, 1F);
|
||||
break;
|
||||
case 1:
|
||||
this.setBlockBounds(0F, 0F, 0F, 1F, 0.125F, 1F);
|
||||
break;
|
||||
case 2:
|
||||
this.setBlockBounds(0F, 0F, 0.885F, 1F, 1F, 1F);
|
||||
break;
|
||||
case 3:
|
||||
this.setBlockBounds(0F, 0F, 0F, 1F, 1F, 0.125F);
|
||||
break;
|
||||
case 4:
|
||||
this.setBlockBounds(0.885F, 0F, 0F, 1F, 1F, 1F);
|
||||
break;
|
||||
case 5:
|
||||
this.setBlockBounds(0F, 0F, 0F, 0.125F, 1F, 1F);
|
||||
break;
|
||||
}
|
||||
}
|
||||
super.setBlockBoundsBasedOnState(access, x, y, z);
|
||||
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) {
|
||||
initializeBoundingBox(world, x, y, z);
|
||||
super.setBlockBoundsBasedOnState(world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) {
|
||||
TileReactorEnergyInjector tile = world.getTileEntity(x, y, z) instanceof TileReactorEnergyInjector
|
||||
? (TileReactorEnergyInjector) world.getTileEntity(x, y, z)
|
||||
: null;
|
||||
if (tile != null) {
|
||||
switch (tile.facingDirection) {
|
||||
initializeBoundingBox(world, x, y, z);
|
||||
return super.getCollisionBoundingBoxFromPool(world, x, y, z);
|
||||
}
|
||||
|
||||
private void initializeBoundingBox(IBlockAccess world, int x, int y, int z) {
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
if (tile instanceof TileReactorEnergyInjector) {
|
||||
TileReactorEnergyInjector injector = (TileReactorEnergyInjector) tile;
|
||||
switch (injector.facingDirection) {
|
||||
case 0:
|
||||
this.setBlockBounds(0F, 0.885F, 0F, 1F, 1F, 1F);
|
||||
break;
|
||||
@@ -97,7 +77,6 @@ public class ReactorEnergyInjector extends BlockDE {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return super.getCollisionBoundingBoxFromPool(world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -117,41 +96,40 @@ public class ReactorEnergyInjector extends BlockDE {
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack) {
|
||||
int d = Utills.determineOrientation(x, y, z, entity);
|
||||
TileReactorEnergyInjector tile = (TileReactorEnergyInjector) world.getTileEntity(x, y, z);
|
||||
tile.facingDirection = ForgeDirection.getOrientation(d).getOpposite().ordinal();
|
||||
tile.onPlaced();
|
||||
int facing = Utills.determineOrientation(x, y, z, entity);
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
if (tile instanceof TileReactorEnergyInjector) {
|
||||
TileReactorEnergyInjector injector = (TileReactorEnergyInjector) tile;
|
||||
injector.facingDirection = entity.isSneaking()
|
||||
? ForgeDirection.getOrientation(facing).getOpposite().ordinal()
|
||||
: ForgeDirection.getOrientation(facing).ordinal();
|
||||
injector.onPlaced();
|
||||
}
|
||||
}
|
||||
|
||||
@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_) {
|
||||
IReactorPart tile = world.getTileEntity(x, y, z) instanceof IReactorPart
|
||||
? (IReactorPart) world.getTileEntity(x, y, z)
|
||||
: null;
|
||||
if (tile != null && player.isSneaking()) {
|
||||
tile.changeRedstoneMode();
|
||||
if (!world.isRemote) player.addChatComponentMessage(new ChatComponentText(tile.getRedstoneModeString()));
|
||||
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 && player.isSneaking()) {
|
||||
IReactorPart part = (IReactorPart) tile;
|
||||
part.changeRedstoneMode();
|
||||
if (!world.isRemote) {
|
||||
player.addChatComponentMessage(new ChatComponentText(part.getRedstoneModeAsString()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -160,7 +138,7 @@ public class ReactorEnergyInjector extends BlockDE {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(World world, int metadata) {
|
||||
public TileEntity createNewTileEntity(World world, int metadata) {
|
||||
return new TileReactorEnergyInjector();
|
||||
}
|
||||
}
|
||||
+72
-109
@@ -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;
|
||||
@@ -12,11 +9,10 @@ import net.minecraft.util.AxisAlignedBB;
|
||||
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;
|
||||
import com.brandon3055.draconicevolution.common.blocks.multiblock.MultiblockHelper;
|
||||
import com.brandon3055.draconicevolution.common.blocks.multiblock.MultiblockHelper.TileLocation;
|
||||
import com.brandon3055.draconicevolution.integration.computers.IDEPeripheral;
|
||||
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
@@ -30,30 +26,32 @@ public class TileReactorEnergyInjector extends TileEntity implements IReactorPar
|
||||
|
||||
public float modelIllumination = 1F;
|
||||
public int facingDirection = ForgeDirection.UP.ordinal();
|
||||
public MultiblockHelper.TileLocation masterLocation = new MultiblockHelper.TileLocation();
|
||||
public TileLocation masterLocation = new TileLocation();
|
||||
public boolean isValid = false;
|
||||
public int tick = 0;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private ParticleReactorBeam beam;
|
||||
|
||||
private TileReactorCore core = null;
|
||||
private int redstoneMode = 0;
|
||||
private int rs = -1;
|
||||
private int rsCach = -1;
|
||||
private int redstoneMode = IReactorPart.RMODE_TEMP;
|
||||
private int comparatorOutputCache = -1;
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
if (worldObj.isRemote && isValid) {
|
||||
updateBeam();
|
||||
return;
|
||||
}
|
||||
|
||||
TileEntity master = masterLocation.getTileEntity(worldObj);
|
||||
if (!worldObj.isRemote && master instanceof TileReactorCore) {
|
||||
rs = ((TileReactorCore) master).getComparatorOutput(redstoneMode);
|
||||
if (rs != rsCach) {
|
||||
rsCach = rs;
|
||||
Utills.updateNeabourBlocks(worldObj, xCoord, yCoord, zCoord);
|
||||
TileReactorCore core = getMaster();
|
||||
if (core != null) {
|
||||
int comparatorOutput = core.getComparatorOutput(redstoneMode);
|
||||
if (comparatorOutput != comparatorOutputCache) {
|
||||
comparatorOutputCache = comparatorOutput;
|
||||
worldObj.notifyBlocksOfNeighborChange(
|
||||
xCoord,
|
||||
yCoord,
|
||||
zCoord,
|
||||
worldObj.getBlock(xCoord, yCoord, zCoord));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,30 +62,43 @@ public class TileReactorEnergyInjector extends TileEntity implements IReactorPar
|
||||
}
|
||||
|
||||
public void onPlaced() {
|
||||
checkForMaster();
|
||||
}
|
||||
|
||||
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) {
|
||||
masterLocation.set(x, y, z);
|
||||
isValid = true;
|
||||
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++) {
|
||||
int targetX = xCoord + facing.offsetX * distance;
|
||||
int targetY = yCoord + facing.offsetY * distance;
|
||||
int targetZ = zCoord + facing.offsetZ * distance;
|
||||
TileEntity tile = worldObj.getTileEntity(targetX, targetY, targetZ);
|
||||
if (tile instanceof TileReactorCore) {
|
||||
setUp(new TileLocation(targetX, targetY, targetZ));
|
||||
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() {
|
||||
masterLocation = new TileLocation();
|
||||
isValid = false;
|
||||
return false;
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -96,14 +107,8 @@ public class TileReactorEnergyInjector extends TileEntity implements IReactorPar
|
||||
}
|
||||
|
||||
@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
|
||||
@@ -112,10 +117,17 @@ public class TileReactorEnergyInjector extends TileEntity implements IReactorPar
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutDown() {
|
||||
masterLocation = new MultiblockHelper.TileLocation();
|
||||
isValid = false;
|
||||
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
|
||||
@@ -136,15 +148,6 @@ public class TileReactorEnergyInjector extends TileEntity implements IReactorPar
|
||||
super.onDataPacket(net, pkt);
|
||||
}
|
||||
|
||||
public TileReactorCore getCore() {
|
||||
if (core == null || core.isInvalid()) {
|
||||
if (getMaster().getTileEntity(worldObj) instanceof TileReactorCore)
|
||||
core = (TileReactorCore) getMaster().getTileEntity(worldObj);
|
||||
else core = null;
|
||||
}
|
||||
return core;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound compound) {
|
||||
super.writeToNBT(compound);
|
||||
@@ -163,11 +166,6 @@ public class TileReactorEnergyInjector extends TileEntity implements IReactorPar
|
||||
redstoneMode = compound.getInteger("RedstoneMode");
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiblockHelper.TileLocation getMaster() {
|
||||
return masterLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
return AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1);
|
||||
@@ -175,8 +173,13 @@ public class TileReactorEnergyInjector extends TileEntity implements IReactorPar
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) {
|
||||
if (simulate) return Integer.MAX_VALUE;
|
||||
else if (getCore() != null) return getCore().injectEnergy(maxReceive);
|
||||
if (simulate) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
TileReactorCore core = getMaster();
|
||||
if (core != null) {
|
||||
return core.injectEnergy(maxReceive);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -206,48 +209,8 @@ public class TileReactorEnergyInjector extends TileEntity implements IReactorPar
|
||||
}
|
||||
|
||||
@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