mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-28 07:55:41 +00:00
Added plumbing for handling XP.
This commit is contained in:
1 parent
59ff369d05
commit
143a003b89
10 files changed
+219
-33
No files matched your search
@@ -91,6 +91,8 @@ public final class IconEIO {
|
||||
public static final IconEIO MINUS_BUT = new IconEIO(129, 246, 10, 10);
|
||||
|
||||
public static final IconEIO SOUND = new IconEIO(209, 172, 22, 22);
|
||||
|
||||
public static final IconEIO XP = new IconEIO(235, 60, 22, 22);
|
||||
|
||||
private static final int TEX_SIZE = 256;
|
||||
private static final double PIX_SIZE = 1d / TEX_SIZE;
|
||||
|
||||
@@ -31,6 +31,8 @@ public class BlockKillerJoe extends AbstractMachineBlock<TileKillerJoe> {
|
||||
public static BlockKillerJoe create() {
|
||||
PacketHandler.INSTANCE.registerMessage(PacketNutrientLevel.class, PacketNutrientLevel.class, PacketHandler.nextID(), Side.CLIENT);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketSwing.class, PacketSwing.class, PacketHandler.nextID(), Side.CLIENT);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketExperianceTotal.class, PacketExperianceTotal.class, PacketHandler.nextID(), Side.CLIENT);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketUseXP.class, PacketUseXP.class, PacketHandler.nextID(), Side.SERVER);
|
||||
BlockKillerJoe res = new BlockKillerJoe();
|
||||
res.init();
|
||||
return res;
|
||||
|
||||
@@ -14,7 +14,7 @@ public class ContainerKillerJoe extends AbstractMachineContainer {
|
||||
|
||||
@Override
|
||||
protected void addMachineSlots(InventoryPlayer playerInv) {
|
||||
addSlotToContainer(new Slot(tileEntity, 0, 80, 35) {
|
||||
addSlotToContainer(new Slot(tileEntity, 0, 80, 25) {
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack itemStack) {
|
||||
return tileEntity.isItemValidForSlot(0, itemStack);
|
||||
|
||||
@@ -3,17 +3,23 @@ package crazypants.enderio.machine.killera;
|
||||
import java.awt.Color;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import crazypants.enderio.fluid.Fluids;
|
||||
import crazypants.enderio.gui.IconButtonEIO;
|
||||
import crazypants.enderio.gui.IconEIO;
|
||||
import crazypants.enderio.machine.GuiMachineBase;
|
||||
import crazypants.enderio.machine.IoMode;
|
||||
import crazypants.enderio.machine.PacketRedstoneMode;
|
||||
import crazypants.enderio.machine.generator.zombie.ContainerZombieGenerator;
|
||||
import crazypants.enderio.machine.generator.zombie.TileZombieGenerator;
|
||||
import crazypants.enderio.machine.power.PowerDisplayUtil;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.gui.GuiToolTip;
|
||||
import crazypants.render.ColorUtil;
|
||||
import crazypants.render.RenderUtil;
|
||||
@@ -21,13 +27,17 @@ import crazypants.util.Lang;
|
||||
|
||||
public class GuiKillerJoe extends GuiMachineBase {
|
||||
|
||||
private static final int XP_ID = 3489;
|
||||
|
||||
private TileKillerJoe joe;
|
||||
|
||||
private IconButtonEIO xpB;
|
||||
|
||||
public GuiKillerJoe(InventoryPlayer inventory, TileKillerJoe tileEntity) {
|
||||
super(tileEntity, new ContainerKillerJoe(inventory, tileEntity));
|
||||
joe = tileEntity;
|
||||
|
||||
addToolTip(new GuiToolTip(new Rectangle(35, 21, 15, 47), "") {
|
||||
addToolTip(new GuiToolTip(new Rectangle(18, 11, 15, 47), "") {
|
||||
|
||||
@Override
|
||||
protected void updateText() {
|
||||
@@ -39,6 +49,23 @@ public class GuiKillerJoe extends GuiMachineBase {
|
||||
|
||||
});
|
||||
|
||||
xpB = new IconButtonEIO(this, XP_ID, 128, 56, IconEIO.XP);
|
||||
xpB.setToolTip(Lang.localize("killerJoe.giveXp.tooltip"));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
xpB.onGuiInit();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton b) {
|
||||
super.actionPerformed(b);
|
||||
if(b.id == XP_ID) {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketUseXP(joe));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,8 +83,8 @@ public class GuiKillerJoe extends GuiMachineBase {
|
||||
super.renderSlotHighlights(mode);
|
||||
|
||||
if(mode == IoMode.PULL || mode == IoMode.PUSH_PULL) {
|
||||
int x = 33;
|
||||
int y = 19;
|
||||
int x = 16;
|
||||
int y = 9;
|
||||
int w = 15 + 4;
|
||||
int h = 47 + 4;
|
||||
renderSlotHighlight(PULL_COLOR,x,y,w,h);
|
||||
@@ -73,13 +100,21 @@ public class GuiKillerJoe extends GuiMachineBase {
|
||||
int sy = (height - ySize) / 2;
|
||||
drawTexturedModalRect(sx, sy, 0, 0, xSize, ySize);
|
||||
|
||||
int x = guiLeft + 35;
|
||||
int y = guiTop + 21;
|
||||
int x = guiLeft + 18;
|
||||
int y = guiTop + 11;
|
||||
if(joe.fuelTank.getFluidAmount() > 0) {
|
||||
RenderUtil.renderGuiTank(joe.fuelTank.getFluid(), joe.fuelTank.getCapacity(), joe.fuelTank.getFluidAmount(), x, y, zLevel, 15, 47);
|
||||
}
|
||||
|
||||
|
||||
String s = joe.experienceLevel + "";
|
||||
drawCenteredString(Minecraft.getMinecraft().fontRenderer, s, sx + xSize/2, sy + 50, 8453920);
|
||||
|
||||
RenderUtil.bindTexture("enderio:textures/gui/killerJoe.png");
|
||||
GL11.glColor3f(1, 1, 1);
|
||||
int xpScaled = joe.getXpBarScaled(63);
|
||||
drawTexturedModalRect(sx + 56, sy + 62, 192, 0, xpScaled, 3);
|
||||
|
||||
|
||||
super.drawGuiContainerBackgroundLayer(par1, par2, par3);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package crazypants.enderio.machine.killera;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.network.MessageTileEntity;
|
||||
import crazypants.enderio.network.NetworkUtil;
|
||||
|
||||
public class PacketExperianceTotal extends MessageTileEntity<TileKillerJoe> implements IMessageHandler<PacketExperianceTotal, IMessage> {
|
||||
|
||||
private int level;
|
||||
private float exp;
|
||||
|
||||
public PacketExperianceTotal() {
|
||||
}
|
||||
|
||||
public PacketExperianceTotal(TileKillerJoe tile) {
|
||||
super(tile);
|
||||
level = tile.experienceLevel;
|
||||
exp = tile.experience;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
super.toBytes(buf);
|
||||
buf.writeInt(level);
|
||||
buf.writeFloat(exp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
super.fromBytes(buf);
|
||||
level = buf.readInt();
|
||||
exp = buf.readFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketExperianceTotal message, MessageContext ctx) {
|
||||
EntityPlayer player = EnderIO.proxy.getClientPlayer();
|
||||
TileKillerJoe tile = message.getTileEntity(player.worldObj);
|
||||
if (tile != null) {
|
||||
tile.experienceLevel = message.level;
|
||||
tile.experience = message.exp;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package crazypants.enderio.machine.killera;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.network.MessageTileEntity;
|
||||
|
||||
public class PacketUseXP extends MessageTileEntity<TileKillerJoe> implements IMessageHandler<PacketUseXP, IMessage> {
|
||||
|
||||
public PacketUseXP() {
|
||||
}
|
||||
|
||||
public PacketUseXP(TileKillerJoe tile) {
|
||||
super(tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketUseXP message, MessageContext ctx) {
|
||||
EntityPlayer player = ctx.getServerHandler().playerEntity;
|
||||
TileKillerJoe tile = message.getTileEntity(player.worldObj);
|
||||
if (tile != null) {
|
||||
tile.givePlayerXp(player);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import net.minecraft.entity.IEntityMultiPart;
|
||||
import net.minecraft.entity.SharedMonsterAttributes;
|
||||
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
||||
import net.minecraft.entity.boss.EntityDragonPart;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -70,6 +71,14 @@ public class TileKillerJoe extends AbstractMachineEntity implements IFluidHandle
|
||||
|
||||
private float prevSwingProgress;
|
||||
|
||||
int experienceLevel;
|
||||
|
||||
float experience;
|
||||
|
||||
private boolean xpDirty;
|
||||
|
||||
private int experienceTotal;
|
||||
|
||||
public TileKillerJoe() {
|
||||
super(new SlotDefinition(1, 0, 0));
|
||||
powerHandler = PowerHandlerUtil.createHandler(new BasicCapacitor(0, 0), this, Type.MACHINE);
|
||||
@@ -106,6 +115,12 @@ public class TileKillerJoe extends AbstractMachineEntity implements IFluidHandle
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
updateArmSwingProgress();
|
||||
super.updateEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean processTasks(boolean redstoneCheckPassed) {
|
||||
|
||||
@@ -117,10 +132,16 @@ public class TileKillerJoe extends AbstractMachineEntity implements IFluidHandle
|
||||
return false;
|
||||
}
|
||||
|
||||
//addExperience(1);
|
||||
|
||||
if(tanksDirty) {
|
||||
PacketHandler.sendToAllAround(new PacketNutrientLevel(this), this);
|
||||
tanksDirty = false;
|
||||
}
|
||||
if(xpDirty) {
|
||||
PacketHandler.sendToAllAround(new PacketExperianceTotal(this), this);
|
||||
xpDirty = false;
|
||||
}
|
||||
|
||||
if(fuelTank.getFluidAmount() < fuelTank.getCapacity() * 0.7f) {
|
||||
return false;
|
||||
@@ -149,46 +170,79 @@ public class TileKillerJoe extends AbstractMachineEntity implements IFluidHandle
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
updateArmSwingProgress();
|
||||
super.updateEntity();
|
||||
|
||||
//------------------------------- XP
|
||||
|
||||
public void addExperience(int xpToAdd) {
|
||||
int j = Integer.MAX_VALUE - this.experienceTotal;
|
||||
if (xpToAdd > j) {
|
||||
xpToAdd = j;
|
||||
}
|
||||
|
||||
experience += (float) xpToAdd / (float) getXpBarCapacity();
|
||||
experienceTotal += xpToAdd;
|
||||
for (; experience >= 1.0F; experience /= (float) getXpBarCapacity()) {
|
||||
experience = (experience - 1.0F) * (float) getXpBarCapacity();
|
||||
experienceLevel++;
|
||||
}
|
||||
xpDirty = true;
|
||||
}
|
||||
|
||||
void swingWeapon() {
|
||||
private int getXpBarCapacity(int level) {
|
||||
return level >= 30 ? 62 + (level - 30) * 7 : (level >= 15 ? 17 + (level - 15) * 3 : 17);
|
||||
}
|
||||
|
||||
private int getXpBarCapacity() {
|
||||
return getXpBarCapacity(experienceLevel);
|
||||
}
|
||||
|
||||
public int getXpBarScaled(int scale) {
|
||||
int result = (int) (experience * scale);
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
public void givePlayerXp(EntityPlayer player) {
|
||||
int takeXp = Math.min(getXpBarCapacity(), experienceTotal);
|
||||
player.addExperience(takeXp);
|
||||
|
||||
int newXp = experienceTotal - takeXp;
|
||||
experience = 0;
|
||||
experienceLevel = 0;
|
||||
experienceTotal = 0;
|
||||
addExperience(newXp);
|
||||
|
||||
}
|
||||
|
||||
//------------------------------- Weapon stuffs
|
||||
|
||||
void swingWeapon() {
|
||||
if(getStackInSlot(0) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
if(!isSwingInProgress || swingProgressInt >= getArmSwingAnimationEnd() / 2 || swingProgressInt < 0) {
|
||||
swingProgressInt = -1;
|
||||
isSwingInProgress = true;
|
||||
if(worldObj instanceof WorldServer) {
|
||||
System.out.println("TileKillerJoe.swingWeapon: sending packet");
|
||||
PacketHandler.sendToAllAround(new PacketSwing(this), this);
|
||||
} else {
|
||||
System.out.println("TileKillerJoe.swingWeapon: Swing start on client");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
float getSwingProgress(float p_70678_1_) {
|
||||
float f1 = swingProgress - prevSwingProgress;
|
||||
float f1 = swingProgress - prevSwingProgress;
|
||||
|
||||
if (f1 < 0.0F) {
|
||||
++f1;
|
||||
}
|
||||
if(f1 < 0.0F) {
|
||||
++f1;
|
||||
}
|
||||
|
||||
return prevSwingProgress + f1 * p_70678_1_;
|
||||
return prevSwingProgress + f1 * p_70678_1_;
|
||||
}
|
||||
|
||||
private void updateArmSwingProgress() {
|
||||
|
||||
//TODO:
|
||||
|
||||
prevSwingProgress = swingProgress;
|
||||
|
||||
|
||||
int i = getArmSwingAnimationEnd();
|
||||
if(isSwingInProgress) {
|
||||
++swingProgressInt;
|
||||
@@ -206,11 +260,6 @@ public class TileKillerJoe extends AbstractMachineEntity implements IFluidHandle
|
||||
return 6;
|
||||
}
|
||||
|
||||
private void useNutrient() {
|
||||
fuelTank.drain(Config.killerJoeNutrientUsePerAttackMb, true);
|
||||
tanksDirty = true;
|
||||
}
|
||||
|
||||
private float getEnchantmentDamage(EntityLivingBase ent) {
|
||||
ItemStack weaponStack = getStackInSlot(0);
|
||||
if(weaponStack == null) {
|
||||
@@ -291,6 +340,8 @@ public class TileKillerJoe extends AbstractMachineEntity implements IFluidHandle
|
||||
return killBounds;
|
||||
}
|
||||
|
||||
//------------------------------- Power
|
||||
|
||||
public PowerReceiver getPowerReceiver(ForgeDirection side) {
|
||||
return null;
|
||||
}
|
||||
@@ -299,7 +350,12 @@ public class TileKillerJoe extends AbstractMachineEntity implements IFluidHandle
|
||||
return false;
|
||||
}
|
||||
|
||||
// Fluid Stuff
|
||||
//------------------------------- Fluid Stuff
|
||||
|
||||
private void useNutrient() {
|
||||
fuelTank.drain(Config.killerJoeNutrientUsePerAttackMb, true);
|
||||
tanksDirty = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean doPull(ForgeDirection dir) {
|
||||
@@ -368,6 +424,8 @@ public class TileKillerJoe extends AbstractMachineEntity implements IFluidHandle
|
||||
return false;
|
||||
}
|
||||
|
||||
//------------------------------- Save / Load
|
||||
|
||||
@Override
|
||||
public void readCommon(NBTTagCompound nbtRoot) {
|
||||
super.readCommon(nbtRoot);
|
||||
@@ -382,6 +440,9 @@ public class TileKillerJoe extends AbstractMachineEntity implements IFluidHandle
|
||||
fuelTank.setFluid(null);
|
||||
}
|
||||
|
||||
experienceLevel = nbtRoot.getInteger("experienceLevel");
|
||||
experienceTotal = nbtRoot.getInteger("experienceTotal");
|
||||
experience = nbtRoot.getFloat("experience");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -392,6 +453,11 @@ public class TileKillerJoe extends AbstractMachineEntity implements IFluidHandle
|
||||
fuelTank.writeToNBT(tankRoot);
|
||||
nbtRoot.setTag("fuelTank", tankRoot);
|
||||
}
|
||||
|
||||
nbtRoot.setInteger("experienceLevel", experienceLevel);
|
||||
nbtRoot.setInteger("experienceTotal", experienceTotal);
|
||||
nbtRoot.setFloat("experience", experience);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user