Get basic functionality working for the Laser Amplifier. No mode changing yet, and using the laser model in lieu of the actual one.

This commit is contained in:
Ben Spiers 2014-07-30 22:26:03 +01:00
parent bfe3b545d2
commit b62c5c8a3a
10 changed files with 403 additions and 22 deletions

View file

@ -27,6 +27,7 @@ import mekanism.client.gui.GuiEnrichmentChamber;
import mekanism.client.gui.GuiFactory;
import mekanism.client.gui.GuiFluidicPlenisher;
import mekanism.client.gui.GuiGasTank;
import mekanism.client.gui.GuiLaserAmplifier;
import mekanism.client.gui.GuiMetallurgicInfuser;
import mekanism.client.gui.GuiOsmiumCompressor;
import mekanism.client.gui.GuiPRC;
@ -473,6 +474,8 @@ public class ClientProxy extends CommonProxy
return new GuiFluidicPlenisher(player.inventory, (TileEntityFluidicPlenisher)tileEntity);
case 43:
return new GuiUpgradeManagement(player.inventory, (IUpgradeTile)tileEntity);
case 44:
return new GuiLaserAmplifier(player.inventory, (TileEntityLaserAmplifier)tileEntity);
}
return null;

View file

@ -0,0 +1,196 @@
package mekanism.client.gui;
import java.util.ArrayList;
import mekanism.api.Coord4D;
import mekanism.client.gui.GuiGauge.Type;
import mekanism.client.gui.GuiNumberGauge.INumberInfoHandler;
import mekanism.client.render.MekanismRenderer;
import mekanism.common.Mekanism;
import mekanism.common.inventory.container.ContainerLaserAmplifier;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.tile.TileEntityLaserAmplifier;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.IIcon;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiLaserAmplifier extends GuiMekanism
{
public TileEntityLaserAmplifier tileEntity;
public GuiTextField thresholdField;
public GuiTextField timerField;
public GuiLaserAmplifier(InventoryPlayer inventory, TileEntityLaserAmplifier tentity)
{
super(new ContainerLaserAmplifier(inventory, tentity));
tileEntity = tentity;
guiElements.add(new GuiNumberGauge(new INumberInfoHandler()
{
@Override
public IIcon getIcon()
{
return MekanismRenderer.energyIcon;
}
@Override
public double getLevel()
{
return tileEntity.collectedEnergy;
}
@Override
public double getMaxLevel()
{
return tileEntity.MAX_ENERGY;
}
@Override
public String getText(double level)
{
return "Stored: " + MekanismUtils.getEnergyDisplay(level);
}
}, Type.STANDARD, this, MekanismUtils.getResource(ResourceType.GUI, "GuiBlank.png"), 6, 16));
}
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
int xAxis = (mouseX - (width - xSize) / 2);
int yAxis = (mouseY - (height - ySize) / 2);
fontRendererObj.drawString(tileEntity.getInventoryName(), 55, 6, 0x404040);
fontRendererObj.drawString(MekanismUtils.localize("container.inventory"), 8, (ySize - 96) + 2, 0x404040);
if(xAxis >= 165 && xAxis <= 169 && yAxis >= 17 && yAxis <= 69)
{
drawCreativeTabHoveringText(MekanismUtils.getEnergyDisplay(tileEntity.getEnergy()), xAxis, yAxis);
}
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
}
@Override
protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, int mouseY)
{
mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiBlank.png"));
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
int guiWidth = (width - xSize) / 2;
int guiHeight = (height - ySize) / 2;
drawTexturedModalRect(guiWidth, guiHeight, 0, 0, xSize, ySize);
super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY);
thresholdField.drawTextBox();
timerField.drawTextBox();
}
@Override
public void updateScreen()
{
super.updateScreen();
thresholdField.updateCursorCounter();
timerField.updateCursorCounter();
}
@Override
public void mouseClicked(int mouseX, int mouseY, int button)
{
super.mouseClicked(mouseX, mouseY, button);
thresholdField.mouseClicked(mouseX, mouseY, button);
timerField.mouseClicked(mouseX, mouseY, button);
}
@Override
public void keyTyped(char c, int i)
{
if(!(thresholdField.isFocused() || timerField.isFocused()) || i == Keyboard.KEY_ESCAPE)
{
super.keyTyped(c, i);
}
if(i == Keyboard.KEY_RETURN)
{
if(thresholdField.isFocused())
{
setThreshold();
}
if(timerField.isFocused())
{
setTime();
}
}
if(Character.isDigit(c) || i == Keyboard.KEY_BACK || i == Keyboard.KEY_DELETE || i == Keyboard.KEY_LEFT || i == Keyboard.KEY_RIGHT)
{
thresholdField.textboxKeyTyped(c, i);
timerField.textboxKeyTyped(c, i);
}
}
private void setThreshold()
{
if(!thresholdField.getText().isEmpty())
{
int toUse = Math.max(0, Integer.parseInt(thresholdField.getText()));
ArrayList data = new ArrayList();
data.add(1);
data.add((double)toUse);
Mekanism.packetHandler.sendToServer(new TileEntityMessage(Coord4D.get(tileEntity), data));
thresholdField.setText("");
}
}
private void setTime()
{
if(!timerField.getText().isEmpty())
{
int toUse = Math.max(0, Integer.parseInt(timerField.getText()));
ArrayList data = new ArrayList();
data.add(2);
data.add(toUse);
Mekanism.packetHandler.sendToServer(new TileEntityMessage(Coord4D.get(tileEntity), data));
timerField.setText("");
}
}
@Override
public void initGui()
{
super.initGui();
int guiWidth = (width - xSize) / 2;
int guiHeight = (height - ySize) / 2;
String prevThresh = thresholdField != null ? thresholdField.getText() : "";
thresholdField = new GuiTextField(fontRendererObj, guiWidth + 75, guiHeight + 55, 56, 11);
thresholdField.setMaxStringLength(10);
thresholdField.setText(prevThresh);
String prevTime = timerField != null ? timerField.getText() : "";
timerField = new GuiTextField(fontRendererObj, guiWidth + 75, guiHeight + 15, 26, 11);
timerField.setMaxStringLength(4);
timerField.setText(prevTime);
}
}

View file

@ -185,7 +185,7 @@ public class MachineRenderingHandler implements ISimpleBlockRenderingHandler
Minecraft.getMinecraft().renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.RENDER, "FluidicPlenisher.png"));
fluidicPlenisher.render(0.0560F);
}
else if(type == MachineType.LASER)
else if(type == MachineType.LASER || type == MachineType.LASER_AMPLIFIER)
{
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
GL11.glRotatef(90F, 0.0F, -1.0F, 0.0F);

View file

@ -2,6 +2,7 @@ package mekanism.client.render.tileentity;
import mekanism.client.model.ModelLaser;
import mekanism.common.tile.TileEntityLaser;
import mekanism.common.tile.TileEntityLaserAmplifier;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
@ -20,10 +21,10 @@ public class RenderLaserAmplifier extends TileEntitySpecialRenderer
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float partialTick)
{
renderAModelAt((TileEntityLaser)tileEntity, x, y, z, partialTick);
renderAModelAt((TileEntityLaserAmplifier)tileEntity, x, y, z, partialTick);
}
private void renderAModelAt(TileEntityLaser tileEntity, double x, double y, double z, float partialTick)
private void renderAModelAt(TileEntityLaserAmplifier tileEntity, double x, double y, double z, float partialTick)
{
GL11.glPushMatrix();
GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z + 0.5F);

View file

@ -432,6 +432,8 @@ public class CommonProxy
return new ContainerFluidicPlenisher(player.inventory, (TileEntityFluidicPlenisher)tileEntity);
case 43:
return new ContainerUpgradeManagement(player.inventory, (IUpgradeTile)tileEntity);
case 44:
return new ContainerNull(player, (TileEntityContainerBlock)tileEntity);
}
return null;

View file

@ -1182,7 +1182,7 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IPer
PORTABLE_TANK(Mekanism.MachineBlock2, 11, "PortableTank", 41, 0, TileEntityPortableTank.class, false, true, false),
FLUIDIC_PLENISHER(Mekanism.MachineBlock2, 12, "FluidicPlenisher", 42, 10000, TileEntityFluidicPlenisher.class, true, true, false),
LASER(Mekanism.MachineBlock2, 13, "Laser", -1, 100000, TileEntityLaser.class, true, true, false),
LASER_AMPLIFIER(Mekanism.MachineBlock2, 14, "LaserAmplifier", -1, 0, TileEntityLaserAmplifier.class, false, true, false);
LASER_AMPLIFIER(Mekanism.MachineBlock2, 14, "LaserAmplifier", 44, 0, TileEntityLaserAmplifier.class, false, true, false);
public Block typeBlock;
public int meta;

View file

@ -0,0 +1,55 @@
package mekanism.common.inventory.container;
import mekanism.common.inventory.slot.SlotEnergy.SlotDischarge;
import mekanism.common.inventory.slot.SlotOutput;
import mekanism.common.recipe.RecipeHandler;
import mekanism.common.tile.TileEntityElectricMachine;
import mekanism.common.tile.TileEntityLaserAmplifier;
import mekanism.common.util.ChargeUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class ContainerLaserAmplifier extends Container
{
private TileEntityLaserAmplifier tileEntity;
public ContainerLaserAmplifier(InventoryPlayer inventory, TileEntityLaserAmplifier tentity)
{
tileEntity = tentity;
int slotX;
for(slotX = 0; slotX < 3; slotX++)
{
for(int slotY = 0; slotY < 9; slotY++)
{
addSlotToContainer(new Slot(inventory, slotY + slotX * 9 + 9, 8 + slotY * 18, 84 + slotX * 18));
}
}
for(slotX = 0; slotX < 9; slotX++)
{
addSlotToContainer(new Slot(inventory, slotX, 8 + slotX * 18, 142));
}
tileEntity.open(inventory.player);
tileEntity.openInventory();
}
@Override
public void onContainerClosed(EntityPlayer entityplayer)
{
super.onContainerClosed(entityplayer);
tileEntity.close(entityplayer);
tileEntity.closeInventory();
}
@Override
public boolean canInteractWith(EntityPlayer entityplayer)
{
return tileEntity.isUseableByPlayer(entityplayer);
}
}

View file

@ -306,7 +306,10 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, ISpec
((TileEntityElectricChest)tileEntity).password = getPassword(stack);
}
if(tileEntity instanceof ISustainedInventory)
{
((ISustainedInventory)tileEntity).setInventory(getInventory(stack));
}
if(tileEntity instanceof TileEntityElectricBlock)
{

View file

@ -13,7 +13,7 @@ import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityLaser extends TileEntityElectricBlock
{
public static final double LASER_ENERGY = 1E10;
public static final double LASER_ENERGY = 5000;
public boolean on;

View file

@ -1,29 +1,43 @@
package mekanism.common.tile;
import java.util.ArrayList;
import mekanism.api.Coord4D;
import mekanism.api.lasers.ILaserReceptor;
import mekanism.api.lasers.LaserManager;
import mekanism.common.Mekanism;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityLaserAmplifier extends TileEntity implements ILaserReceptor
import io.netty.buffer.ByteBuf;
public class TileEntityLaserAmplifier extends TileEntityContainerBlock implements ILaserReceptor
{
public static final double MAX_ENERGY = 10000000;
public static final double MAX_ENERGY = 5E9;
public double collectedEnergy = 0;
public double threshold = 0;
public int ticks = 0;
public int time = 0;
public int ticks;
public int time;
public LaserEmitterMode mode = LaserEmitterMode.THRESHOLD;
public boolean poweredNow = false;
public boolean poweredLastTick = false;
public boolean on = false;
public ForgeDirection facing;
public LaserEmitterMode mode;
public TileEntityLaserAmplifier()
{
super("LaserAmplifier");
inventory = new ItemStack[0];
}
@Override
public void receiveLaserEnergy(double energy, ForgeDirection side)
{
collectedEnergy += energy;
setEnergy(getEnergy() + energy);
}
@Override
@ -39,30 +53,137 @@ public class TileEntityLaserAmplifier extends TileEntity implements ILaserRecept
}
@Override
public void updateEntity()
public void onUpdate()
{
if(shouldFire())
if(worldObj.isRemote)
{
LaserManager.fireLaser(Coord4D.get(this), facing, collectedEnergy, worldObj);
if(on)
{
LaserManager.fireLaserClient(Coord4D.get(this), ForgeDirection.getOrientation(facing), worldObj);
}
}
else
{
poweredNow = worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
if(ticks < time)
{
ticks++;
}
else
{
ticks = 0;
}
if(shouldFire() && toFire() > 0)
{
if(!on)
{
on = true;
Mekanism.packetHandler.sendToAllAround(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), Coord4D.get(this).getTargetPoint(50D));
}
LaserManager.fireLaser(Coord4D.get(this), ForgeDirection.getOrientation(facing), toFire(), worldObj);
setEnergy(getEnergy() - toFire());
}
else if(on)
{
on = false;
Mekanism.packetHandler.sendToAllAround(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), Coord4D.get(this).getTargetPoint(50D));
}
poweredLastTick = poweredNow;
}
}
public void setEnergy(double energy)
{
collectedEnergy = Math.max(0, Math.min(energy, MAX_ENERGY));
}
public double getEnergy()
{
return collectedEnergy;
}
public boolean shouldFire()
{
switch(mode)
{
case THRESHOLD:
return collectedEnergy > threshold;
return collectedEnergy >= threshold;
case REDSTONE:
return false; //TODO implement
return poweredNow;
case REDSTONE_PULSE:
return false; // TODO implement
return poweredNow && !poweredLastTick;
case TIMER:
return ticks > time;
return ticks == time;
}
return false;
}
public double toFire()
{
switch(mode)
{
case THRESHOLD:
return collectedEnergy;
case REDSTONE:
return collectedEnergy;
case REDSTONE_PULSE:
return collectedEnergy;
case TIMER:
return collectedEnergy;
}
return 0;
}
@Override
public ArrayList getNetworkedData(ArrayList data)
{
super.getNetworkedData(data);
data.add(on);
data.add(mode.ordinal());
data.add(threshold);
data.add(time);
data.add(collectedEnergy);
return data;
}
@Override
public void handlePacketData(ByteBuf dataStream)
{
if(worldObj.isRemote)
{
super.handlePacketData(dataStream);
on = dataStream.readBoolean();
mode = LaserEmitterMode.values()[dataStream.readInt()];
threshold = dataStream.readDouble();
time = dataStream.readInt();
collectedEnergy = dataStream.readDouble();
return;
}
switch(dataStream.readInt())
{
case(0):
mode = LaserEmitterMode.values()[dataStream.readInt()];
break;
case(1):
threshold = dataStream.readDouble();
break;
case(2):
time = dataStream.readInt();
break;
}
}
public static enum LaserEmitterMode
{
THRESHOLD,