Fixed charger packet and function

This commit is contained in:
Calclavia 2014-02-20 22:30:08 +08:00
parent 53124c1800
commit b72fb66ea8
4 changed files with 97 additions and 21 deletions

View file

@ -43,7 +43,7 @@ public class RenderBattery extends TileEntitySpecialRenderer implements ISimpleI
public void renderInventoryItem(ItemStack itemStack)
{
glPushMatrix();
GL11.glTranslated(0.5f, 0, 0.5f);
GL11.glTranslated(0, -0.5f, 0);
for (int i = 2; i < 6; i++)
{

View file

@ -1,5 +1,8 @@
package resonantinduction.electrical.charger;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
@ -8,39 +11,83 @@ import net.minecraft.util.MovingObjectPosition;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.core.prefab.part.PartFace;
import resonantinduction.electrical.Electrical;
import scala.xml.persistent.SetStorage;
import universalelectricity.api.CompatibilityModule;
import universalelectricity.api.UniversalClass;
import universalelectricity.api.energy.IEnergyInterface;
import calclavia.lib.utility.WorldUtility;
import calclavia.lib.utility.WrenchUtility;
import calclavia.lib.utility.inventory.ExternalInventory;
import calclavia.lib.utility.inventory.IExternalInventory;
import calclavia.lib.utility.inventory.IExternalInventoryBox;
import calclavia.lib.utility.inventory.InventoryUtility;
import codechicken.lib.data.MCDataInput;
import codechicken.lib.data.MCDataOutput;
import codechicken.lib.vec.Vector3;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* TODO: This DOES NOT WORK when @UniversalClass is not annotated. Flat wires seem to only interact
* with TE multiparts.
*
* @author Calclavia
*
*/
@UniversalClass
public class PartCharger extends PartFace implements IExternalInventory, ISidedInventory, IEnergyInterface
{
private long lastPacket;
@Override
public void readDesc(MCDataInput packet)
{
super.readDesc(packet);
getInventory().load(packet.readNBTTagCompound());
}
@Override
public void writeDesc(MCDataOutput packet)
{
super.writeDesc(packet);
NBTTagCompound nbt = new NBTTagCompound();
getInventory().save(nbt);
packet.writeNBTTagCompound(nbt);
}
@Override
public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item)
{
if (WrenchUtility.isUsableWrench(player, player.inventory.getCurrentItem(), x(), y(), z()))
{
if (!this.world().isRemote)
{
WrenchUtility.damageWrench(player, player.inventory.getCurrentItem(), x(), y(), z());
facing = (byte) ((facing + 1) % 4);
sendDescUpdate();
tile().notifyPartChange(this);
}
return true;
}
if (item != null)
{
if (getStackInSlot(0) == null)
if (getStackInSlot(0) == null && item != null && CompatibilityModule.isHandler(item.getItem()))
{
setInventorySlotContents(0, item);
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
if (!world().isRemote)
sendDescUpdate();
return true;
}
}
if (getStackInSlot(0) != null)
{
InventoryUtility.dropItemStack(player.worldObj, new universalelectricity.api.vector.Vector3(player), getStackInSlot(0), 0);
InventoryUtility.dropItemStack(world(), new universalelectricity.api.vector.Vector3(player), getStackInSlot(0), 0);
setInventorySlotContents(0, null);
sendDescUpdate();
}
return true;
@ -49,7 +96,7 @@ public class PartCharger extends PartFace implements IExternalInventory, ISidedI
@Override
public boolean canConnect(ForgeDirection direction, Object obj)
{
return obj instanceof IEnergyInterface && direction == getFacing().getOpposite();
return obj instanceof IEnergyInterface;
}
@Override
@ -101,6 +148,19 @@ public class PartCharger extends PartFace implements IExternalInventory, ISidedI
return "resonant_induction_charger";
}
@Override
public Iterable<ItemStack> getDrops()
{
List<ItemStack> drops = new ArrayList<ItemStack>();
drops.add(getItem());
for (int i = 0; i < getSizeInventory(); i++)
if (getStackInSlot(i) != null)
drops.add(getStackInSlot(i));
return drops;
}
/**
* Save and load
*/

View file

@ -1,7 +1,11 @@
package resonantinduction.electrical.charger;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.AdvancedModelLoader;
import net.minecraftforge.client.model.IModelCustom;
@ -38,24 +42,37 @@ public class RenderCharger implements ISimpleItemRenderer
GL11.glTranslatef((float) x + 0.5F, (float) y + 0.5F, (float) z + 0.5F);
RenderUtility.rotateFaceToSideNoTranslate(part.placementSide);
RenderUtility.rotateBlockBasedOnDirection(part.getFacing());
RenderUtility.bind(TEXTURE);
MODEL.renderAll();
if (part.getStackInSlot(0) != null)
{
RenderItemOverlayTile.renderItem(part.world(), part.placementSide, part.getStackInSlot(0), new Vector3(0.09, -0.4, -0.09), 0, 4);
/**
* Render item and tool tip
*/
if (CompatibilityModule.getMaxEnergyItem(part.getStackInSlot(0)) > 0)
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240);
RenderItemOverlayTile.renderItem(part.world(), part.placementSide, part.getStackInSlot(0), new Vector3(0.00, -0.4, -0.00), 0, 4);
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
boolean isLooking = false;
MovingObjectPosition objectPosition = player.rayTrace(8, 1);
if (objectPosition != null)
{
long energy = CompatibilityModule.getEnergyItem(part.getStackInSlot(0));
long maxEnergy = CompatibilityModule.getMaxEnergyItem(part.getStackInSlot(0));
GL11.glTranslatef(0, 0.1F, 0);
GL11.glRotatef(90, 1, 0, 0);
RenderUtility.renderText(UnitDisplay.getDisplay(energy, Unit.JOULES, 2, true) + "/" + UnitDisplay.getDisplay(maxEnergy, Unit.JOULES, 2, true), 1, 1);
if (objectPosition.blockX == part.x() && objectPosition.blockY == part.y() && objectPosition.blockZ == part.z())
{
/**
* Render item and tool tip
*/
if (CompatibilityModule.getMaxEnergyItem(part.getStackInSlot(0)) > 0)
{
long energy = CompatibilityModule.getEnergyItem(part.getStackInSlot(0));
long maxEnergy = CompatibilityModule.getMaxEnergyItem(part.getStackInSlot(0));
GL11.glTranslatef(0, 0.1F, 0);
GL11.glRotatef(90, 1, 0, 0);
RenderUtility.renderText(UnitDisplay.getDisplay(energy, Unit.JOULES, 2, true) + "/" + UnitDisplay.getDisplay(maxEnergy, Unit.JOULES, 2, true), 1, 1);
}
}
}
}

View file

@ -64,15 +64,14 @@ public abstract class RenderItemOverlayTile extends TileEntitySpecialRenderer
if (inventory[i] != null)
{
Vector3 translation = new Vector3((double) (i / matrixX) / ((double) matrixX) + (0.5 / (matrixX)), 1.1, (double) (i % matrixZ) / ((double) matrixZ) + (0.5 / (matrixZ))).translate(-0.5);
translation.scale(0.9);
translation.translate(0, 0, 0.06);
translation.scale(0.85);
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5f, y + 0.5f, z + 0.5f);
RenderUtility.rotateBlockBasedOnDirection(dir);
GL11.glTranslated(translation.x, translation.y, translation.z);
GL11.glScalef(0.7f, 0.7f, 0.7f);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240);
renderItem(tileEntity.worldObj, ForgeDirection.UP, inventory[i], new Vector3(0, 0, 0), 0, 1);
renderItem(tileEntity.worldObj, ForgeDirection.UP, inventory[i], new Vector3(0, 0, 0), 0, 4);
GL11.glPopMatrix();
if (isLooking)
@ -206,7 +205,7 @@ public abstract class RenderItemOverlayTile extends TileEntitySpecialRenderer
entityItem.getEntityItem().stackSize = 1;
entityItem.hoverStart = 0.0F;
GL11.glPushMatrix();
GL11.glTranslated( position.x, position.y, - position.z);
GL11.glTranslated(position.x, position.y, -position.z);
GL11.glRotatef(180.0F + rotationYaw, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(90 * angle, 1, 0, 0);