Added basic fustion reactor multiblock checking.

This commit is contained in:
Modmuss50 2015-11-16 15:20:13 +00:00
parent 962a165249
commit f42c127201
9 changed files with 288 additions and 61 deletions

View file

@ -4,8 +4,14 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon; import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import techreborn.Core;
import techreborn.client.GuiHandler;
import techreborn.tiles.fusionReactor.TileEntityFusionController;
public class BlockFusionControlComputer extends BlockMachineBase { public class BlockFusionControlComputer extends BlockMachineBase {
@ -45,4 +51,18 @@ public class BlockFusionControlComputer extends BlockMachineBase {
: (side == metadata ? this.iconFront : this.blockIcon)); : (side == metadata ? this.iconFront : this.blockIcon));
} }
@Override
public boolean onBlockActivated(World world, int x, int y, int z,
EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
if (!player.isSneaking())
player.openGui(Core.INSTANCE, GuiHandler.fusionID, world, x, y,
z);
return true;
}
@Override
public TileEntity createNewTileEntity(World world, int meta) {
return new TileEntityFusionController();
}
} }

View file

@ -7,6 +7,7 @@ import techreborn.client.container.*;
import techreborn.client.gui.*; import techreborn.client.gui.*;
import techreborn.pda.GuiManual; import techreborn.pda.GuiManual;
import techreborn.tiles.*; import techreborn.tiles.*;
import techreborn.tiles.fusionReactor.TileEntityFusionController;
import techreborn.tiles.idsu.TileIDSU; import techreborn.tiles.idsu.TileIDSU;
import techreborn.tiles.lesu.TileLesu; import techreborn.tiles.lesu.TileLesu;
@ -38,7 +39,7 @@ public class GuiHandler implements IGuiHandler {
public static final int lesuID = 26; public static final int lesuID = 26;
public static final int idsuID = 27; public static final int idsuID = 27;
public static final int chargeBench = 28; public static final int chargeBench = 28;
public static final int farmID = 29; public static final int fusionID = 29;
@Override @Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, public Object getServerGuiElement(int ID, EntityPlayer player, World world,
@ -116,6 +117,8 @@ public class GuiHandler implements IGuiHandler {
return new ContainerIDSU((TileIDSU) world.getTileEntity(x, y, z), player); return new ContainerIDSU((TileIDSU) world.getTileEntity(x, y, z), player);
} else if (ID == chargeBench) { } else if (ID == chargeBench) {
return new ContainerChargeBench((TileChargeBench) world.getTileEntity(x, y, z), player); return new ContainerChargeBench((TileChargeBench) world.getTileEntity(x, y, z), player);
} else if (ID == fusionID) {
return new ContainerFusionReactor((TileEntityFusionController) world.getTileEntity(x, y, z), player);
} }
@ -198,6 +201,8 @@ public class GuiHandler implements IGuiHandler {
return new GuiIDSU(player, (TileIDSU) world.getTileEntity(x, y, z)); return new GuiIDSU(player, (TileIDSU) world.getTileEntity(x, y, z));
} else if (ID == chargeBench) { } else if (ID == chargeBench) {
return new GuiChargeBench(player, (TileChargeBench) world.getTileEntity(x, y, z)); return new GuiChargeBench(player, (TileChargeBench) world.getTileEntity(x, y, z));
}else if (ID == fusionID) {
return new GuiFusionReactor(player, (TileEntityFusionController) world.getTileEntity(x, y, z));
} }
return null; return null;
} }

View file

@ -0,0 +1,80 @@
package techreborn.client.container;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import reborncore.client.gui.SlotOutput;
import reborncore.common.container.RebornContainer;
import techreborn.tiles.fusionReactor.TileEntityFusionController;
public class ContainerFusionReactor extends RebornContainer {
public int coilStatus;
public int energy;
TileEntityFusionController fusionController;
public ContainerFusionReactor(TileEntityFusionController tileEntityFusionController,
EntityPlayer player) {
super();
this.fusionController = tileEntityFusionController;
addSlotToContainer(new Slot(tileEntityFusionController, 0, 88, 17));
addSlotToContainer(new Slot(tileEntityFusionController, 1, 88, 53));
addSlotToContainer(new SlotOutput(tileEntityFusionController, 2, 148, 35));
int i;
for (i = 0; i < 3; ++i) {
for (int j = 0; j < 9; ++j) {
this.addSlotToContainer(new Slot(player.inventory, j + i * 9
+ 9, 8 + j * 18, 84 + i * 18));
}
}
for (i = 0; i < 9; ++i) {
this.addSlotToContainer(new Slot(player.inventory, i, 8 + i * 18,
142));
}
}
@Override
public boolean canInteractWith(EntityPlayer player) {
return true;
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
for (int i = 0; i < this.crafters.size(); i++) {
ICrafting icrafting = (ICrafting) this.crafters.get(i);
if (this.coilStatus != fusionController.coilStatus) {
icrafting.sendProgressBarUpdate(this, 0, fusionController.coilStatus);
}
if (this.energy != (int) fusionController.getEnergy()) {
icrafting.sendProgressBarUpdate(this, 1, (int) fusionController.getEnergy());
}
}
}
@Override
public void addCraftingToCrafters(ICrafting crafting) {
super.addCraftingToCrafters(crafting);
crafting.sendProgressBarUpdate(this, 0, fusionController.coilStatus);
crafting.sendProgressBarUpdate(this, 1, (int) fusionController.getEnergy());
}
@SideOnly(Side.CLIENT)
@Override
public void updateProgressBar(int id, int value) {
if (id == 0) {
this.coilStatus = value;
} else if (id == 1) {
this.energy = value;
}
}
}

View file

@ -1,18 +0,0 @@
package techreborn.client.container;
import net.minecraft.entity.player.EntityPlayer;
import reborncore.common.container.RebornContainer;
import techreborn.tiles.fusionReactor.TileEntityFustionController;
public class ContainerFustionReactor extends RebornContainer {
public ContainerFustionReactor(TileEntityFustionController tileEntityFustionController,
EntityPlayer player) {
}
@Override
public boolean canInteractWith(EntityPlayer player) {
return true;
}
}

View file

@ -2,17 +2,23 @@ package techreborn.client.gui;
import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n; import net.minecraft.client.resources.I18n;
import net.minecraft.inventory.Container; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector; import net.minecraft.util.StatCollector;
import techreborn.client.container.ContainerFusionReactor;
import techreborn.tiles.fusionReactor.TileEntityFusionController;
public class GuiFusionReactor extends GuiContainer { public class GuiFusionReactor extends GuiContainer {
private static final ResourceLocation texture = new ResourceLocation("techreborn", "textures/gui/fusion_reactor.png"); private static final ResourceLocation texture = new ResourceLocation("techreborn", "textures/gui/fusion_reactor.png");
public GuiFusionReactor(Container container) { ContainerFusionReactor containerFusionReactor;
super(container);
public GuiFusionReactor(EntityPlayer player,
TileEntityFusionController tileaesu) {
super(new ContainerFusionReactor(tileaesu, player));
containerFusionReactor = (ContainerFusionReactor) this.inventorySlots;
} }
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) { protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) {
@ -20,8 +26,8 @@ public class GuiFusionReactor extends GuiContainer {
this.fontRendererObj.drawString(name, 87, 6, 4210752); this.fontRendererObj.drawString(name, 87, 6, 4210752);
this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752); this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752);
this.fontRendererObj.drawString("EU: xxxx", 11, 8, 16448255); this.fontRendererObj.drawString("EU: " + containerFusionReactor.energy, 11, 8, 16448255);
this.fontRendererObj.drawString("Coils: " + "Yes" , 11, 16, 16448255); this.fontRendererObj.drawString("Coils: " + (containerFusionReactor.coilStatus == 1 ? "Yes" : "No") , 11, 16, 16448255);
} }
@Override @Override

View file

@ -16,6 +16,7 @@ import techreborn.blocks.storage.BlockLesu;
import techreborn.blocks.storage.BlockLesuStorage; import techreborn.blocks.storage.BlockLesuStorage;
import techreborn.itemblocks.*; import techreborn.itemblocks.*;
import techreborn.tiles.*; import techreborn.tiles.*;
import techreborn.tiles.fusionReactor.TileEntityFusionController;
import techreborn.tiles.idsu.TileIDSU; import techreborn.tiles.idsu.TileIDSU;
import techreborn.tiles.lesu.TileLesu; import techreborn.tiles.lesu.TileLesu;
import techreborn.tiles.lesu.TileLesuStorage; import techreborn.tiles.lesu.TileLesuStorage;
@ -211,6 +212,7 @@ public class ModBlocks {
FusionControlComputer = new BlockFusionControlComputer(Material.rock); FusionControlComputer = new BlockFusionControlComputer(Material.rock);
GameRegistry.registerBlock(FusionControlComputer, "fusioncontrolcomputer"); GameRegistry.registerBlock(FusionControlComputer, "fusioncontrolcomputer");
GameRegistry.registerTileEntity(TileEntityFusionController.class, "TileEntityFustionControllerTR");
FusionCoil = new BlockFusionCoil(Material.rock); FusionCoil = new BlockFusionCoil(Material.rock);
GameRegistry.registerBlock(FusionCoil, "fusioncoil"); GameRegistry.registerBlock(FusionCoil, "fusioncoil");

View file

@ -0,0 +1,168 @@
package techreborn.tiles.fusionReactor;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import reborncore.common.util.Inventory;
import techreborn.init.ModBlocks;
import techreborn.powerSystem.TilePowerAcceptor;
public class TileEntityFusionController extends TilePowerAcceptor implements IInventory {
public Inventory inventory = new Inventory(3, "TileEntityFusionController", 64);
//0= no coils, 1 = coils
public int coilStatus = 0;
public TileEntityFusionController() {
super(4);
}
@Override
public double getMaxPower() {
return 100000000;
}
@Override
public boolean canAcceptEnergy(ForgeDirection direction) {
return true;
}
@Override
public boolean canProvideEnergy(ForgeDirection direction) {
return true;
}
@Override
public double getMaxOutput() {
return 1000000;
}
@Override
public double getMaxInput() {
return 8192;
}
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
inventory.readFromNBT(tagCompound);
}
@Override
public void writeToNBT(NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
inventory.writeToNBT(tagCompound);
}
@Override
public int getSizeInventory() {
return inventory.getSizeInventory();
}
@Override
public ItemStack getStackInSlot(int slot) {
return inventory.getStackInSlot(slot);
}
@Override
public ItemStack decrStackSize(int slot, int amount) {
return inventory.decrStackSize(slot, amount);
}
@Override
public ItemStack getStackInSlotOnClosing(int slot) {
return inventory.getStackInSlotOnClosing(slot);
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
inventory.setInventorySlotContents(slot, stack);
}
@Override
public String getInventoryName() {
return inventory.getInventoryName();
}
@Override
public boolean hasCustomInventoryName() {
return inventory.hasCustomInventoryName();
}
@Override
public int getInventoryStackLimit() {
return inventory.getInventoryStackLimit();
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
return inventory.isUseableByPlayer(player);
}
@Override
public void openInventory() {
inventory.openInventory();
}
@Override
public void closeInventory() {
inventory.closeInventory();
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
return inventory.isItemValidForSlot(slot, stack);
}
private boolean checkCoils() {
if ((isCoil(this.xCoord + 3, this.yCoord, this.zCoord + 1)) &&
(isCoil(this.xCoord + 3, this.yCoord, this.zCoord)) &&
(isCoil(this.xCoord + 3, this.yCoord, this.zCoord - 1)) &&
(isCoil(this.xCoord - 3, this.yCoord, this.zCoord + 1)) &&
(isCoil(this.xCoord - 3, this.yCoord, this.zCoord)) &&
(isCoil(this.xCoord - 3, this.yCoord, this.zCoord - 1)) &&
(isCoil(this.xCoord + 2, this.yCoord, this.zCoord + 2)) &&
(isCoil(this.xCoord + 2, this.yCoord, this.zCoord + 1)) &&
(isCoil(this.xCoord + 2, this.yCoord, this.zCoord - 1)) &&
(isCoil(this.xCoord + 2, this.yCoord, this.zCoord - 2)) &&
(isCoil(this.xCoord - 2, this.yCoord, this.zCoord + 2)) &&
(isCoil(this.xCoord - 2, this.yCoord, this.zCoord + 1)) &&
(isCoil(this.xCoord - 2, this.yCoord, this.zCoord - 1)) &&
(isCoil(this.xCoord - 2, this.yCoord, this.zCoord - 2)) &&
(isCoil(this.xCoord + 1, this.yCoord, this.zCoord + 3)) &&
(isCoil(this.xCoord + 1, this.yCoord, this.zCoord + 2)) &&
(isCoil(this.xCoord + 1, this.yCoord, this.zCoord - 2)) &&
(isCoil(this.xCoord + 1, this.yCoord, this.zCoord - 3)) &&
(isCoil(this.xCoord - 1, this.yCoord, this.zCoord + 3)) &&
(isCoil(this.xCoord - 1, this.yCoord, this.zCoord + 2)) &&
(isCoil(this.xCoord - 1, this.yCoord, this.zCoord - 2)) &&
(isCoil(this.xCoord - 1, this.yCoord, this.zCoord - 3)) &&
(isCoil(this.xCoord, this.yCoord, this.zCoord + 3)) &&
(isCoil(this.xCoord, this.yCoord, this.zCoord - 3))) {
coilStatus = 1;
return true;
}
coilStatus = 0;
return false;
}
private boolean isCoil(int x, int y, int z) {
return worldObj.getBlock(x, y, z) == ModBlocks.FusionCoil;
}
@Override
public void updateEntity() {
super.updateEntity();
//TODO improve this code a lot
if(worldObj.getTotalWorldTime() % 20 == 0){
checkCoils();
}
}
}

View file

@ -1,36 +0,0 @@
package techreborn.tiles.fusionReactor;
import net.minecraftforge.common.util.ForgeDirection;
import techreborn.powerSystem.TilePowerAcceptor;
public class TileEntityFustionController extends TilePowerAcceptor {
public TileEntityFustionController() {
super(4);
}
@Override
public double getMaxPower() {
return 100000000;
}
@Override
public boolean canAcceptEnergy(ForgeDirection direction) {
return true;
}
@Override
public boolean canProvideEnergy(ForgeDirection direction) {
return true;
}
@Override
public double getMaxOutput() {
return 1000000;
}
@Override
public double getMaxInput() {
return 8192;
}
}

View file

@ -36,7 +36,7 @@ tile.techreborn.distillationtower.name=Distillation Tower
tile.techreborn.electriccraftingtable.name=Electric Autocrafting Table tile.techreborn.electriccraftingtable.name=Electric Autocrafting Table
tile.techreborn.vacuumfreezer.name=Vacuum Freezer tile.techreborn.vacuumfreezer.name=Vacuum Freezer
tile.techreborn.plasmagenerator.name=Plasma Generator tile.techreborn.plasmagenerator.name=Plasma Generator
tile.techreborn.fusioncontrolcomputer.name=Fusion Control Computer tile.techreborn.fusioncontrolcomputer.name=Fusion Reactor
tile.techreborn.computercube.name=TechReborn Computer Cube tile.techreborn.computercube.name=TechReborn Computer Cube
tile.techreborn.fusioncoil.name=Fusion Coil tile.techreborn.fusioncoil.name=Fusion Coil
tile.techreborn.lightningrod.name=Lightning Rod tile.techreborn.lightningrod.name=Lightning Rod