v5.5.6 Beta #12

*Fixed up new upgrade behavior.
*Added button to teleport Robit back home.
*Robit now picks up items off the ground.
*Fixed Robit's inventory shift-clicking.
*Robit now stores his name in item form.
This commit is contained in:
Aidan Brady 2013-05-29 21:51:48 -04:00
parent 1f7dc818f7
commit 6d0a68e47e
10 changed files with 140 additions and 31 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View file

@ -2,6 +2,7 @@ package mekanism.client;
import mekanism.common.ContainerRobitMain; import mekanism.common.ContainerRobitMain;
import mekanism.common.EntityRobit; import mekanism.common.EntityRobit;
import mekanism.common.EnumPacketType;
import mekanism.common.Mekanism; import mekanism.common.Mekanism;
import mekanism.common.PacketHandler; import mekanism.common.PacketHandler;
import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiButton;
@ -12,11 +13,10 @@ import net.minecraft.entity.player.InventoryPlayer;
import org.lwjgl.input.Keyboard; import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11; 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;
import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit; import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public class GuiRobitMain extends GuiContainer public class GuiRobitMain extends GuiContainer
@ -127,6 +127,10 @@ public class GuiRobitMain extends GuiContainer
{ {
drawCreativeTabHoveringText("Rename this Robit", xAxis, yAxis); drawCreativeTabHoveringText("Rename this Robit", xAxis, yAxis);
} }
else if(xAxis >= 6 && xAxis <= 24 && yAxis >= 16 && yAxis <= 34)
{
drawCreativeTabHoveringText("Teleport back home", xAxis, yAxis);
}
} }
@Override @Override
@ -197,6 +201,14 @@ public class GuiRobitMain extends GuiContainer
drawTexturedModalRect(guiWidth + 6, guiHeight + 53, 176 + 25, 234, 18, 18); drawTexturedModalRect(guiWidth + 6, guiHeight + 53, 176 + 25, 234, 18, 18);
} }
if(xAxis >= 6 && xAxis <= 24 && yAxis >= 16 && yAxis <= 34)
{
drawTexturedModalRect(guiWidth + 6, guiHeight + 16, 176 + 25 + 18, 36, 18, 18);
}
else {
drawTexturedModalRect(guiWidth + 6, guiHeight + 16, 176 + 25 + 18, 54, 18, 18);
}
int displayInt; int displayInt;
displayInt = getScaledEnergyLevel(120); displayInt = getScaledEnergyLevel(120);
@ -264,6 +276,11 @@ public class GuiRobitMain extends GuiContainer
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F); mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
toggleNameChange(); toggleNameChange();
} }
else if(xAxis >= 6 && xAxis <= 24 && yAxis >= 16 && yAxis <= 34)
{
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
PacketHandler.sendPacketDataInt(EnumPacketType.GO_HOME, robit.entityId);
}
} }
} }
} }

View file

@ -60,26 +60,17 @@ public class ContainerRobitInventory extends Container
ItemStack slotStack = currentSlot.getStack(); ItemStack slotStack = currentSlot.getStack();
stack = slotStack.copy(); stack = slotStack.copy();
if(slotID >= 27 && slotID <= 53) if(slotID < 27)
{ {
if(!mergeItemStack(slotStack, 54, inventorySlots.size(), false))
{
return null;
}
}
else if(slotID > 53)
{
if(!mergeItemStack(slotStack, 27, 53, false))
{
return null;
}
}
else {
if(!mergeItemStack(slotStack, 27, inventorySlots.size(), true)) if(!mergeItemStack(slotStack, 27, inventorySlots.size(), true))
{ {
return null; return null;
} }
} }
else if(!mergeItemStack(slotStack, 0, 27, false))
{
return null;
}
if(slotStack.stackSize == 0) if(slotStack.stackSize == 0)
{ {

View file

@ -5,6 +5,7 @@ import ic2.api.item.IElectricItem;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.List;
import mekanism.api.EnergizedItemManager; import mekanism.api.EnergizedItemManager;
import mekanism.api.IEnergizedItem; import mekanism.api.IEnergizedItem;
@ -118,6 +119,8 @@ public class EntityRobit extends EntityCreature implements IInventory, ISustaine
if(!worldObj.isRemote) if(!worldObj.isRemote)
{ {
collectItems();
if(homeLocation == null) if(homeLocation == null)
{ {
setDead(); setDead();
@ -135,12 +138,7 @@ public class EntityRobit extends EntityCreature implements IInventory, ISustaine
if(getEnergy() == 0 && !isOnChargepad()) if(getEnergy() == 0 && !isOnChargepad())
{ {
setFollowing(false); goHome();
setPositionAndUpdate(homeLocation.xCoord+0.5, homeLocation.yCoord+0.3, homeLocation.zCoord+0.5);
motionX = 0;
motionY = 0;
motionZ = 0;
} }
if(inventory[27] != null && getEnergy() < MAX_ELECTRICITY) if(inventory[27] != null && getEnergy() < MAX_ELECTRICITY)
@ -227,6 +225,65 @@ public class EntityRobit extends EntityCreature implements IInventory, ISustaine
} }
} }
} }
private void collectItems()
{
List<EntityItem> items = worldObj.getEntitiesWithinAABB(EntityItem.class, boundingBox.expand(1.5, 1.5, 1.5));
if(items != null && !items.isEmpty())
{
for(EntityItem item : items)
{
if(item.delayBeforeCanPickup > 0)
{
continue;
}
for(int i = 0; i < 27; i++)
{
ItemStack itemStack = inventory[i];
if(itemStack == null)
{
inventory[i] = item.getEntityItem();
item.setPosition(posX, posY, posZ);
item.setDead();
playSound("random.pop", 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
break;
}
else if(itemStack.isItemEqual(item.getEntityItem()) && itemStack.stackSize < itemStack.getMaxStackSize())
{
int needed = itemStack.getMaxStackSize() - itemStack.stackSize;
int toAdd = Math.min(needed, item.getEntityItem().stackSize);
itemStack.stackSize += toAdd;
item.getEntityItem().stackSize -= toAdd;
if(item.getEntityItem().stackSize == 0)
{
item.setPosition(posX, posY, posZ);
item.setDead();
}
playSound("random.pop", 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
break;
}
}
}
}
}
public void goHome()
{
setFollowing(false);
setPositionAndUpdate(homeLocation.xCoord+0.5, homeLocation.yCoord+0.3, homeLocation.zCoord+0.5);
motionX = 0;
motionY = 0;
motionZ = 0;
}
private boolean canSmelt() private boolean canSmelt()
{ {
@ -316,6 +373,7 @@ public class EntityRobit extends EntityCreature implements IInventory, ISustaine
ItemRobit item = (ItemRobit)entityItem.getEntityItem().getItem(); ItemRobit item = (ItemRobit)entityItem.getEntityItem().getItem();
item.setEnergy(entityItem.getEntityItem(), getEnergy()); item.setEnergy(entityItem.getEntityItem(), getEnergy());
item.setInventory(getInventory(), entityItem.getEntityItem()); item.setInventory(getInventory(), entityItem.getEntityItem());
item.setName(entityItem.getEntityItem(), getName());
float k = 0.05F; float k = 0.05F;
entityItem.motionX = 0; entityItem.motionX = 0;

View file

@ -75,6 +75,9 @@ public enum EnumPacketType
/** Used to send a Robit name update packet to the server. */ /** Used to send a Robit name update packet to the server. */
NAME_UPDATE(21), NAME_UPDATE(21),
/** Used to send a Robit 'go home' packet to the server. */
GO_HOME(22),
/** A custom packet type. Handled in PacketHandler. */ /** A custom packet type. Handled in PacketHandler. */
CUSTOM(-1); CUSTOM(-1);

View file

@ -36,8 +36,10 @@ public class ItemRobit extends ItemEnergized implements ISustainedInventory
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void addInformation(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) public void addInformation(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag)
{ {
list.add(EnumColor.INDIGO + "Name: " + EnumColor.GREY + (getName(itemstack).isEmpty() ? "Robit" : getName(itemstack)));
super.addInformation(itemstack, entityplayer, list, flag); super.addInformation(itemstack, entityplayer, list, flag);
list.add(EnumColor.AQUA + "Inventory: " + EnumColor.GREY + (getInventory(itemstack) != null && getInventory(itemstack).tagCount() != 0)); list.add(EnumColor.AQUA + "Inventory: " + EnumColor.GREY + (getInventory(itemstack) != null && getInventory(itemstack).tagCount() != 0));
} }
@ -58,6 +60,7 @@ public class ItemRobit extends ItemEnergized implements ISustainedInventory
robit.setEnergy(getEnergy(itemstack)); robit.setEnergy(getEnergy(itemstack));
robit.setOwner(entityplayer.username); robit.setOwner(entityplayer.username);
robit.setInventory(getInventory(itemstack)); robit.setInventory(getInventory(itemstack));
robit.setName(getName(itemstack));
world.spawnEntityInWorld(robit); world.spawnEntityInWorld(robit);
} }
@ -77,6 +80,27 @@ public class ItemRobit extends ItemEnergized implements ISustainedInventory
return false; return false;
} }
public void setName(ItemStack itemstack, String name)
{
if(itemstack.stackTagCompound == null)
{
itemstack.setTagCompound(new NBTTagCompound());
}
itemstack.stackTagCompound.setString("name", name);
}
public String getName(ItemStack itemstack)
{
if(itemstack.stackTagCompound == null)
{
return null;
}
String name = itemstack.stackTagCompound.getString("name");
return name != null ? name : "";
}
@Override @Override
public void setInventory(NBTTagList nbtTags, Object... data) public void setInventory(NBTTagList nbtTags, Object... data)
{ {

View file

@ -517,7 +517,7 @@ public final class MekanismUtils
} }
/** /**
* Gets the energy required per tick for a machine via it's upgrades. * Gets the energy required per tick for a machine via it's upgrades.
* @param speedUpgrade - number of speed upgrades * @param speedUpgrade - number of speed upgrades
* @param energyUpgrade - number of energy upgrades * @param energyUpgrade - number of energy upgrades
* @param def - the original, default energy required * @param def - the original, default energy required
@ -529,7 +529,7 @@ public final class MekanismUtils
} }
/** /**
* Gets the energy required per tick for a machine via it's upgrades. * Gets the energy required per tick for a machine via it's upgrades.
* @param speedUpgrade - number of speed upgrades * @param speedUpgrade - number of speed upgrades
* @param energyUpgrade - number of energy upgrades * @param energyUpgrade - number of energy upgrades
* @param def - the original, default energy required * @param def - the original, default energy required

View file

@ -533,6 +533,22 @@ public class PacketHandler implements IPacketHandler
e.printStackTrace(); e.printStackTrace();
} }
} }
else if(packetType == EnumPacketType.GO_HOME.id)
{
try {
int id = dataStream.readInt();
EntityRobit robit = (EntityRobit)entityplayer.worldObj.getEntityByID(id);
if(robit != null)
{
robit.goHome();
}
} catch(Exception e) {
System.err.println("[Mekanism] Error while handling go home packet.");
e.printStackTrace();
}
}
} catch(Exception e) { } catch(Exception e) {
System.err.println("[Mekanism] Error while handling packet."); System.err.println("[Mekanism] Error while handling packet.");
e.printStackTrace(); e.printStackTrace();

View file

@ -98,7 +98,7 @@ public class RobitAIFollow extends EntityAIBase
@Override @Override
public void updateTask() public void updateTask()
{ {
theRobit.getLookHelper().setLookPositionWithEntity(theOwner, 12.0F, theRobit.getVerticalFaceSpeed()); theRobit.getLookHelper().setLookPositionWithEntity(theOwner, 6.0F, theRobit.getVerticalFaceSpeed());
if(theRobit.getFollowing()) if(theRobit.getFollowing())
{ {

View file

@ -175,19 +175,19 @@ public class TileEntityMetallurgicInfuser extends TileEntityElectricBlock implem
} }
} }
if(electricityStored >= ENERGY_PER_TICK) if(electricityStored >= MekanismUtils.getEnergyPerTick(speedMultiplier, energyMultiplier, ENERGY_PER_TICK))
{ {
if(canOperate() && (operatingTicks+1) < MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED)) if(canOperate() && (operatingTicks+1) < MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED))
{ {
operatingTicks++; operatingTicks++;
electricityStored -= ENERGY_PER_TICK; electricityStored -= MekanismUtils.getEnergyPerTick(speedMultiplier, energyMultiplier, ENERGY_PER_TICK);
} }
else if(canOperate() && (operatingTicks+1) >= MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED)) else if(canOperate() && (operatingTicks+1) >= MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED))
{ {
operate(); operate();
operatingTicks = 0; operatingTicks = 0;
electricityStored -= ENERGY_PER_TICK; electricityStored -= MekanismUtils.getEnergyPerTick(speedMultiplier, energyMultiplier, ENERGY_PER_TICK);
} }
} }
@ -202,7 +202,7 @@ public class TileEntityMetallurgicInfuser extends TileEntityElectricBlock implem
type = InfusionType.NONE; type = InfusionType.NONE;
} }
if(canOperate() && electricityStored >= ENERGY_PER_TICK) if(canOperate() && electricityStored >= MekanismUtils.getEnergyPerTick(speedMultiplier, energyMultiplier, ENERGY_PER_TICK))
{ {
setActive(true); setActive(true);
} }