v5.5.6 Beta #11

*Fixed liquid update packets.
*SideOnly checks in client classes.
*Robits have nameplates and can be renamed.
*Robits can now breath in outer space.
This commit is contained in:
Aidan Brady 2013-05-29 11:35:30 -04:00
parent 124d4a5998
commit 9c189116fa
21 changed files with 250 additions and 17 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.5 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View file

@ -11,6 +11,10 @@ import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiRobitCrafting extends GuiContainer
{
public int entityId;

View file

@ -10,6 +10,10 @@ import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiRobitInventory extends GuiContainer
{
public EntityRobit robit;

View file

@ -5,18 +5,29 @@ import mekanism.common.EntityRobit;
import mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import universalelectricity.core.electricity.ElectricityDisplay;
import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit;
@SideOnly(Side.CLIENT)
public class GuiRobitMain extends GuiContainer
{
public EntityRobit robit;
public boolean displayNameChange;
private GuiTextField nameChangeField;
private GuiButton confirmName;
public GuiRobitMain(InventoryPlayer inventory, EntityRobit entity)
{
super(new ContainerRobitMain(inventory, entity));
@ -24,20 +35,87 @@ public class GuiRobitMain extends GuiContainer
robit = entity;
}
private void toggleNameChange()
{
displayNameChange = !displayNameChange;
confirmName.drawButton = displayNameChange;
nameChangeField.setFocused(displayNameChange);
}
private void changeName()
{
if(nameChangeField.getText() != null && !nameChangeField.getText().isEmpty())
{
PacketHandler.sendNameUpdate(nameChangeField.getText(), robit.entityId);
toggleNameChange();
nameChangeField.setText("");
}
}
@Override
protected void actionPerformed(GuiButton guibutton)
{
if(guibutton.id == 0)
{
changeName();
}
}
@Override
public void initGui()
{
super.initGui();
int guiWidth = (width - xSize) / 2;
int guiHeight = (height - ySize) / 2;
buttonList.clear();
buttonList.add(confirmName = new GuiButton(0, guiWidth + 58, guiHeight + 47, 60, 20, "Confirm"));
confirmName.drawButton = displayNameChange;
nameChangeField = new GuiTextField(fontRenderer, guiWidth + 48, guiHeight + 21, 80, 12);
nameChangeField.setMaxStringLength(12);
nameChangeField.setFocused(true);
}
@Override
public void keyTyped(char c, int i)
{
if(!displayNameChange)
{
super.keyTyped(c, i);
}
else {
if(i == Keyboard.KEY_RETURN)
{
changeName();
}
else if(i == Keyboard.KEY_ESCAPE)
{
mc.thePlayer.closeScreen();
}
nameChangeField.textboxKeyTyped(c, i);
}
}
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
fontRenderer.drawString("Robit", 76, 6, 0x404040);
fontRenderer.drawString("Inventory", 8, (ySize - 96) + 3, 0x404040);
fontRenderer.drawString("Hi, I'm Robit!", 29, 18, 0x00CD00);
fontRenderer.drawString("Energy: " + ElectricityDisplay.getDisplayShort(robit.getEnergy(), ElectricUnit.JOULES), 29, 36, 0x00CD00);
fontRenderer.drawString("Following: " + robit.getFollowing(), 29, 45, 0x00CD00);
fontRenderer.drawString("Owner: " + robit.getOwnerName(), 29, 54, 0x00CD00);
if(!displayNameChange)
{
fontRenderer.drawString("Hi, I'm " + robit.getTranslatedEntityName() + "!", 29, 18, 0x00CD00);
fontRenderer.drawString("Energy: " + ElectricityDisplay.getDisplayShort(robit.getEnergy(), ElectricUnit.JOULES), 29, 36, 0x00CD00);
fontRenderer.drawString("Following: " + robit.getFollowing(), 29, 45, 0x00CD00);
fontRenderer.drawString("Owner: " + robit.getOwnerName(), 29, 54, 0x00CD00);
}
int xAxis = (mouseX - (width - xSize) / 2);
int yAxis = (mouseY - (height - ySize) / 2);
if(xAxis >= 20 && xAxis <= 24 && yAxis >= 17 && yAxis <= 70)
if(xAxis >= 28 && xAxis <= 148 && yAxis >= 74 && yAxis <= 78)
{
drawCreativeTabHoveringText(ElectricityDisplay.getDisplayShort(robit.getEnergy(), ElectricUnit.JOULES), xAxis, yAxis);
}
@ -45,6 +123,10 @@ public class GuiRobitMain extends GuiContainer
{
drawCreativeTabHoveringText("Toggle 'follow' mode", xAxis, yAxis);
}
else if(xAxis >= 6 && xAxis <= 24 && yAxis >= 53 && yAxis <= 71)
{
drawCreativeTabHoveringText("Rename this Robit", xAxis, yAxis);
}
}
@Override
@ -107,10 +189,24 @@ public class GuiRobitMain extends GuiContainer
drawTexturedModalRect(guiWidth + 152, guiHeight + 53, 176 + 25, 198, 18, 18);
}
if(xAxis >= 6 && xAxis <= 24 && yAxis >= 53 && yAxis <= 71)
{
drawTexturedModalRect(guiWidth + 6, guiHeight + 53, 176 + 25, 216, 18, 18);
}
else {
drawTexturedModalRect(guiWidth + 6, guiHeight + 53, 176 + 25, 234, 18, 18);
}
int displayInt;
displayInt = getScaledEnergyLevel(53);
drawTexturedModalRect(guiWidth + 20, guiHeight + 17 + 53 - displayInt, 176 + 25 + 18, 36 + 53 - displayInt, 4, displayInt);
displayInt = getScaledEnergyLevel(120);
drawTexturedModalRect(guiWidth + 28, guiHeight + 74, 0, 166, displayInt, 4);
if(displayNameChange)
{
drawTexturedModalRect(guiWidth + 28, guiHeight + 17, 0, 166 + 4, 120, 53);
nameChangeField.drawTextBox();
}
}
private int getScaledEnergyLevel(int i)
@ -123,6 +219,8 @@ public class GuiRobitMain extends GuiContainer
{
super.mouseClicked(mouseX, mouseY, button);
nameChangeField.mouseClicked(mouseX, mouseY, button);
if(button == 0)
{
int xAxis = (mouseX - (width - xSize) / 2);
@ -161,6 +259,11 @@ public class GuiRobitMain extends GuiContainer
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
PacketHandler.sendFollowUpdate(!robit.getFollowing(), robit.entityId);
}
else if(xAxis >= 6 && xAxis <= 24 && yAxis >= 53 && yAxis <= 71)
{
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
toggleNameChange();
}
}
}
}

View file

@ -20,6 +20,10 @@ import net.minecraft.world.World;
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 GuiRobitRepair extends GuiContainer implements ICrafting
{
public int entityId;

View file

@ -11,9 +11,13 @@ import net.minecraft.world.IBlockAccess;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/*
* Credit to BuildCraft
*/
@SideOnly(Side.CLIENT)
public class MekanismRenderer
{
private static RenderBlocks renderBlocks = new RenderBlocks();

View file

@ -1,9 +1,12 @@
package mekanism.client;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
@SideOnly(Side.CLIENT)
public class ModelChargepad extends ModelBase
{
ModelRenderer Shape1;

View file

@ -2,10 +2,14 @@ package mekanism.client;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
@SideOnly(Side.CLIENT)
public class ModelRobit extends ModelBase
{
public ModelRenderer Body;

View file

@ -2,10 +2,14 @@ package mekanism.client;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mekanism.common.TileEntityChargepad;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
@SideOnly(Side.CLIENT)
public class RenderChargepad extends TileEntitySpecialRenderer
{
private ModelChargepad model = new ModelChargepad();

View file

@ -26,7 +26,10 @@ import net.minecraftforge.common.ForgeDirection;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class RenderConfigurableMachine extends TileEntitySpecialRenderer
{
private static Icon[] coloredOverlays;

View file

@ -20,6 +20,10 @@ import net.minecraftforge.liquids.LiquidStack;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class RenderDynamicTank extends TileEntitySpecialRenderer
{
private static Map<RenderData, HashMap<LiquidStack, int[]>> cachedCenterLiquids = new HashMap<RenderData, HashMap<LiquidStack, int[]>>();

View file

@ -1,9 +1,12 @@
package mekanism.client;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mekanism.common.EntityRobit;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.entity.RenderLiving;
@SideOnly(Side.CLIENT)
public class RenderRobit extends RenderLiving
{
public RenderRobit()

View file

@ -14,7 +14,10 @@ import net.minecraft.world.World;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class RenderTickHandler implements ITickHandler
{
@Override

View file

@ -4,6 +4,9 @@ import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mekanism.api.Object3D;
import mekanism.common.Mekanism;
import mekanism.common.TileEntityDynamicTank;
@ -11,6 +14,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
@SideOnly(Side.CLIENT)
public class ThreadTankSparkle extends Thread
{
public TileEntityDynamicTank pointer;

View file

@ -9,6 +9,7 @@ import java.math.RoundingMode;
import mekanism.api.EnergizedItemManager;
import mekanism.api.IEnergizedItem;
import mekanism.api.Object3D;
import micdoodle8.mods.galacticraft.API.IEntityBreathable;
import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAISwimming;
@ -30,7 +31,7 @@ import universalelectricity.core.item.ElectricItemHelper;
import universalelectricity.core.item.IItemElectric;
import codechicken.core.alg.MathHelper;
public class EntityRobit extends EntityCreature implements IInventory, ISustainedInventory
public class EntityRobit extends EntityCreature implements IInventory, ISustainedInventory, IEntityBreathable
{
public double MAX_ELECTRICITY = 100000;
@ -46,7 +47,7 @@ public class EntityRobit extends EntityCreature implements IInventory, ISustaine
{
super(world);
setSize(1, 1);
setSize(0.5F, 0.5F);
moveSpeed = 0.35F;
texture = "/mods/mekanism/render/Robit.png";
@ -56,6 +57,8 @@ public class EntityRobit extends EntityCreature implements IInventory, ISustaine
tasks.addTask(2, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
tasks.addTask(2, new EntityAILookIdle(this));
tasks.addTask(3, new EntityAISwimming(this));
func_94061_f(true);
}
public EntityRobit(World world, double x, double y, double z)
@ -92,6 +95,7 @@ public class EntityRobit extends EntityCreature implements IInventory, ISustaine
dataWatcher.addObject(11, new String("")); /* Electricity */
dataWatcher.addObject(12, new String("")); /* Owner */
dataWatcher.addObject(13, new Byte((byte)0)); /* Follow */
dataWatcher.addObject(14, new String("")); /* Name */
}
public double getRoundedTravelEnergy()
@ -328,6 +332,8 @@ public class EntityRobit extends EntityCreature implements IInventory, ISustaine
nbtTags.setDouble("electricityStored", getEnergy());
nbtTags.setString("name", getName());
if(getOwnerName() != null)
{
nbtTags.setString("owner", getOwnerName());
@ -360,6 +366,8 @@ public class EntityRobit extends EntityCreature implements IInventory, ISustaine
setEnergy(nbtTags.getDouble("electricityStored"));
setName(nbtTags.getString("name"));
if(nbtTags.hasKey("owner"))
{
setOwner(nbtTags.getString("owner"));
@ -451,6 +459,16 @@ public class EntityRobit extends EntityCreature implements IInventory, ISustaine
dataWatcher.updateObject(13, follow ? (byte)1 : (byte)0);
}
public String getName()
{
return dataWatcher.getWatchableObjectString(14);
}
public void setName(String name)
{
dataWatcher.updateObject(14, name);
}
@Override
public int getMaxHealth()
{
@ -603,9 +621,21 @@ public class EntityRobit extends EntityCreature implements IInventory, ISustaine
return tagList;
}
@Override
public String getTranslatedEntityName()
{
return getName().isEmpty() ? "Robit" : getName();
}
@Override
public float getShadowSize()
{
return 0.25F;
}
@Override
public boolean canBreath()
{
return true;
}
}

View file

@ -72,6 +72,9 @@ public enum EnumPacketType
/** Used to send a Robit follow update packet to the server. */
FOLLOW_UPDATE(20),
/** Used to send a Robit name update packet to the server. */
NAME_UPDATE(21),
/** A custom packet type. Handled in PacketHandler. */
CUSTOM(-1);

View file

@ -516,6 +516,23 @@ public class PacketHandler implements IPacketHandler
e.printStackTrace();
}
}
else if(packetType == EnumPacketType.NAME_UPDATE.id)
{
try {
String name = dataStream.readUTF();
int id = dataStream.readInt();
EntityRobit robit = (EntityRobit)entityplayer.worldObj.getEntityByID(id);
if(robit != null)
{
robit.setName(name);
}
} catch(Exception e) {
System.err.println("[Mekanism] Error while handling name update packet.");
e.printStackTrace();
}
}
} catch(Exception e) {
System.err.println("[Mekanism] Error while handling packet.");
e.printStackTrace();
@ -1150,6 +1167,37 @@ public class PacketHandler implements IPacketHandler
}
}
/**
* Sends a Robit name update packet to the server.
* @param value - new follow value
* @param id - the robit's entity ID
*/
public static void sendNameUpdate(String name, int id)
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream data = new DataOutputStream(bytes);
try {
data.writeInt(EnumPacketType.NAME_UPDATE.id);
data.writeUTF(name);
data.writeInt(id);
} catch (IOException e) {
System.out.println("[Mekanism] An error occured while writing packet data.");
e.printStackTrace();
}
Packet250CustomPayload packet = new Packet250CustomPayload();
packet.channel = "Mekanism";
packet.data = bytes.toByteArray();
packet.length = packet.data.length;
PacketDispatcher.sendPacketToServer(packet);
if(Mekanism.logPackets)
{
System.out.println("[Mekanism] Sentname update packet to server.");
}
}
/**
* Sends the server the defined packet data int.
* @param type - packet type

View file

@ -78,7 +78,7 @@ public class TileEntityChargepad extends TileEntityElectricBlock implements IAct
double prevEnergy = getEnergy();
for(ItemStack itemstack : player.inventory.mainInventory)
for(ItemStack itemstack : player.inventory.armorInventory)
{
chargeItemStack(itemstack);
@ -88,7 +88,7 @@ public class TileEntityChargepad extends TileEntityElectricBlock implements IAct
}
}
for(ItemStack itemstack : player.inventory.armorInventory)
for(ItemStack itemstack : player.inventory.mainInventory)
{
chargeItemStack(itemstack);

View file

@ -281,11 +281,7 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
if(dataStream.readInt() == 1)
{
int amount = dataStream.readInt();
int itemID = dataStream.readInt();
int itemMeta = dataStream.readInt();
liquidTank.setLiquid(new LiquidStack(itemID, amount, itemMeta));
liquidTank.setLiquid(new LiquidStack(dataStream.readInt(), dataStream.readInt(), dataStream.readInt()));
}
else {
liquidTank.setLiquid(null);

View file

@ -414,6 +414,9 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
{
waterTank.setLiquid(new LiquidStack(Block.waterStill.blockID, amount, 0));
}
else {
waterTank.setLiquid(null);
}
oxygenStored = dataStream.readInt();
hydrogenStored = dataStream.readInt();

View file

@ -72,9 +72,11 @@ public class TileEntityHeatGenerator extends TileEntityGenerator implements ITan
}
else {
int fuel = getFuel(inventory[0]);
if(fuel > 0)
{
int fuelNeeded = lavaTank.getCapacity() - (lavaTank.getLiquid() != null ? lavaTank.getLiquid().amount : 0);
if(fuel <= fuelNeeded)
{
lavaTank.fill(new LiquidStack(Block.lavaStill.blockID, fuel), true);
@ -235,10 +237,14 @@ public class TileEntityHeatGenerator extends TileEntityGenerator implements ITan
super.handlePacketData(dataStream);
int amount = dataStream.readInt();
if(amount != 0)
{
lavaTank.setLiquid(new LiquidStack(Block.lavaStill.blockID, amount, 0));
}
else {
lavaTank.setLiquid(null);
}
}
@Override