Skip to content

Commit

Permalink
now emits EU
Browse files Browse the repository at this point in the history
  • Loading branch information
RecursivePineapple committed Jun 9, 2024
1 parent 5a87ead commit 6a6b089
Show file tree
Hide file tree
Showing 6 changed files with 377 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

public class Config {

public static int ROD_EU_MULTIPLIER = 1;
public static double ROD_EU_MULTIPLIER = 1;
public static double ROD_HU_MULTIPLIER = 1;
public static double MOX_EU_COEFFICIENT = 4;

public static void synchronizeConfiguration(File configFile) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,35 @@
package com.recursive_pineapple.nuclear_horizons.reactors.blocks;

import com.gtnewhorizons.modularui.api.UIInfos;
import com.recursive_pineapple.nuclear_horizons.reactors.tile.TileReactorChamber;
import com.recursive_pineapple.nuclear_horizons.reactors.tile.TileReactorCore;
import com.recursive_pineapple.nuclear_horizons.utils.DirectionUtil;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

public class ReactorChamber extends Block {
public class ReactorChamber extends BlockContainer {

private IIcon icon;

public ReactorChamber() {
super(Material.iron);

setHardness(5.0f);
setBlockName(BlockList.REACTOR_CHAMBER_NAME);
setStepSound(soundTypeMetal);
setBlockTextureName("nuclear_horizons:reactor_chamber");
}

@Override
public void registerBlockIcons(IIconRegister reg) {
this.icon = reg.registerIcon("nuclear_horizons:reactor_chamber");
}

@Override
public IIcon getIcon(int side, int meta) {
return icon;
public TileEntity createNewTileEntity(World worldIn, int meta) {
return new TileReactorChamber();
}

@Override
Expand All @@ -42,34 +39,50 @@ public boolean canPlaceBlockAt(World worldIn, int x, int y, int z) {

@Override
public void onNeighborBlockChange(World worldIn, int x, int y, int z, Block neighbor) {
onBlocksChanged(worldIn, x, y, z);
}

@Override
public void onBlockAdded(World worldIn, int x, int y, int z) {
onBlocksChanged(worldIn, x, y, z);
}

private void onBlocksChanged(World worldIn, int x, int y, int z) {
if(getAttachedReactors(worldIn, x, y, z) != 1) {
worldIn.setBlock(x, y, z, Blocks.air);
worldIn.spawnEntityInWorld(new EntityItem(worldIn, x + 0.5, y + 0.5, z + 0.5, new ItemStack(this, 1)));

var worldclient = Minecraft.getMinecraft().theWorld;

worldclient.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(this) + (worldclient.getBlockMetadata(x, y, z) << 12));
} else {
((TileReactorChamber)worldIn.getTileEntity(x, y, z)).setReactor(null);

for(var d : DirectionUtil.values()) {
if(d.getTileEntity(worldIn, x, y, z) instanceof TileReactorCore reactor) {
((TileReactorChamber)worldIn.getTileEntity(x, y, z)).setReactor(reactor);
break;
}
}
}
}

@Override
public boolean onBlockActivated(World worldIn, int x, int y, int z, EntityPlayer player, int side, float subX, float subY, float subZ) {
for(var d : DirectionUtil.values()) {
if(d.getBlock(worldIn, x, y, z) == BlockList.REACTOR_CORE) {
return BlockList.REACTOR_CORE.onBlockActivated(
worldIn,
d.offsetX + x, d.offsetY + y, d.offsetZ + z,
player,
side,
0f, 0f, 0f
);
var reactor = ((TileReactorChamber)worldIn.getTileEntity(x, y, z)).getReactor();

if(reactor != null) {
if(!worldIn.isRemote) {
UIInfos.TILE_MODULAR_UI.open(player, worldIn, reactor.xCoord, reactor.yCoord, reactor.zCoord);
}
}

return false;
return true;
} else {
return false;
}
}

private int getAttachedReactors(World worldIn, int x, int y, int z) {
private static int getAttachedReactors(World worldIn, int x, int y, int z) {
int reactorCount = 0;

for(var d : DirectionUtil.values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void onHeatTick() {
}

int pulses = this.getPulseCount();
int heat = (int) (fuelRod.getHeatMult(itemStack) * pulses * (pulses + 1));
int heat = (int) (fuelRod.getHeatMult(itemStack) * pulses * (pulses + 1) * Config.ROD_HU_MULTIPLIER);

if(fuelRod.isMox(itemStack) && reactor.isFluid() && (reactor.getHullHeat() / reactor.getMaxHullHeat()) >= 0.5) {
heat *= 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void addInformation(ItemStack itemStack, EntityPlayer player, List<String
if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
desc.add("Every two seconds, this component will:");

desc.add(String.format("Generate %,d * n * (n + 1) HU", (int)this.heatMult));
desc.add(String.format("Generate %,d * n * (n + 1) HU", (int)(this.heatMult * Config.ROD_HU_MULTIPLIER)));
desc.add(String.format("Generate %,d * n * (n + 1) EU", (int)(this.energyMult * Config.ROD_EU_MULTIPLIER)));

desc.add(String.format("Where n = %d + Number of adjacent rods and reflectors", 1 + this.rodCount / 2));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
package com.recursive_pineapple.nuclear_horizons.reactors.tile;

import javax.annotation.Nullable;

import gregtech.api.interfaces.tileentity.IEnergyConnected;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;

public class TileReactorChamber extends TileEntity implements IReactorBlock, IInventory, IEnergyConnected {

public int reactorRelX, reactorRelY, reactorRelZ;

@Override
public @Nullable TileReactorCore getReactor() {
if(worldObj.getTileEntity(xCoord + reactorRelX, yCoord + reactorRelY, zCoord + reactorRelZ) instanceof TileReactorCore reactor) {
return reactor;
} else {
return null;
}
}

@Override
public void setReactor(TileReactorCore reactor) {
if(getReactor() != reactor) {
this.reactorRelX = reactor != null ? reactor.xCoord - xCoord : 0;
this.reactorRelY = reactor != null ? reactor.yCoord - yCoord : 0;
this.reactorRelZ = reactor != null ? reactor.zCoord - zCoord : 0;
this.markDirty();
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}

@Override
public Packet getDescriptionPacket() {
var data = new NBTTagCompound();

data.setInteger("reactorRelX", reactorRelX);
data.setInteger("reactorRelY", reactorRelY);
data.setInteger("reactorRelZ", reactorRelZ);

return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, blockMetadata, data);
}

@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
var data = pkt.func_148857_g();

this.reactorRelX = data.getInteger("reactorRelX");
this.reactorRelY = data.getInteger("reactorRelY");
this.reactorRelZ = data.getInteger("reactorRelZ");
}

@Override
public void writeToNBT(NBTTagCompound compound) {
super.writeToNBT(compound);

compound.setInteger("version", 1);

compound.setInteger("reactorRelX", this.reactorRelX);
compound.setInteger("reactorRelY", this.reactorRelY);
compound.setInteger("reactorRelZ", this.reactorRelZ);
}

@Override
public void readFromNBT(NBTTagCompound compound) {
super.readFromNBT(compound);

switch(compound.getInteger("version")) {
case 1: {
this.reactorRelX = compound.getInteger("reactorRelX");
this.reactorRelY = compound.getInteger("reactorRelY");
this.reactorRelZ = compound.getInteger("reactorRelZ");
break;
}
}
}

@Override
public byte getColorization() {
return -1;
}

@Override
public byte setColorization(byte arg0) {
return -1;
}

@Override
public long injectEnergyUnits(ForgeDirection arg0, long arg1, long arg2) {
return 0;
}

@Override
public boolean inputEnergyFrom(ForgeDirection arg0) {
return false;
}

@Override
public boolean outputsEnergyTo(ForgeDirection arg0) {
return true;
}

@Override
public int getSizeInventory() {
var reactor = getReactor();

if(reactor != null) {
return reactor.getSizeInventory();
} else {
return 0;
}
}

@Override
public ItemStack getStackInSlot(int slotIn) {
var reactor = getReactor();

if(reactor != null) {
return reactor.getStackInSlot(slotIn);
} else {
return null;
}
}

@Override
public ItemStack decrStackSize(int index, int count) {
var reactor = getReactor();

if(reactor != null) {
return reactor.decrStackSize(index, count);
} else {
return null;
}
}

@Override
public ItemStack getStackInSlotOnClosing(int index) {
var reactor = getReactor();

if(reactor != null) {
return reactor.getStackInSlotOnClosing(index);
} else {
return null;
}
}

@Override
public void setInventorySlotContents(int index, ItemStack stack) {
var reactor = getReactor();

if(reactor != null) {
reactor.setInventorySlotContents(index, stack);;
}
}

@Override
public String getInventoryName() {
var reactor = getReactor();

if(reactor != null) {
return reactor.getInventoryName();
} else {
return "Reactor Access Hatch";
}
}

@Override
public boolean hasCustomInventoryName() {
var reactor = getReactor();

if(reactor != null) {
return reactor.hasCustomInventoryName();
} else {
return false;
}
}

@Override
public int getInventoryStackLimit() {
var reactor = getReactor();

if(reactor != null) {
return reactor.getInventoryStackLimit();
} else {
return 0;
}
}

@Override
public boolean isUseableByPlayer(EntityPlayer player) {
var reactor = getReactor();

if(reactor != null) {
return reactor.isUseableByPlayer(player);
} else {
return false;
}
}

@Override
public void openInventory() {
var reactor = getReactor();

if(reactor != null) {
reactor.openInventory();
}
}

@Override
public void closeInventory() {
var reactor = getReactor();

if(reactor != null) {
reactor.closeInventory();
}
}

@Override
public boolean isItemValidForSlot(int index, ItemStack stack) {
var reactor = getReactor();

if(reactor != null) {
return reactor.isItemValidForSlot(index, stack);
} else {
return false;
}
}
}
Loading

0 comments on commit 6a6b089

Please sign in to comment.