mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
suit charger (not the HEV yet)
This commit is contained in:
parent
2387cc13e7
commit
21cb84817e
@ -7,7 +7,9 @@ import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class Charger extends BlockContainer {
|
||||
@ -54,4 +56,16 @@ public class Charger extends BlockContainer {
|
||||
world.setBlockMetadataWithNotify(x, y, z, 4, 2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) {
|
||||
float f = 0.0625F;
|
||||
this.setBlockBounds(5 * f, 0.25F, 5 * f, 11 * f, 0.75F, 11 * f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) {
|
||||
this.setBlockBoundsBasedOnState(world, x, y, z);
|
||||
return AxisAlignedBB.getBoundingBox(x + this.minX, y + this.minY, z + this.minZ, x + this.maxX, y + this.maxY, z + this.maxZ);
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,6 +69,8 @@ import com.hbm.render.item.weapon.*;
|
||||
import com.hbm.render.loader.HmfModelLoader;
|
||||
import com.hbm.render.tileentity.*;
|
||||
import com.hbm.render.util.MissilePart;
|
||||
import com.hbm.render.util.RenderInfoSystem;
|
||||
import com.hbm.render.util.RenderInfoSystem.InfoEntry;
|
||||
import com.hbm.sound.AudioWrapper;
|
||||
import com.hbm.sound.AudioWrapperClient;
|
||||
import com.hbm.sound.nt.ISoundSourceTE;
|
||||
@ -93,11 +95,14 @@ import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
|
||||
public class ClientProxy extends ServerProxy {
|
||||
|
||||
public RenderInfoSystem theInfoSystem = new RenderInfoSystem();
|
||||
|
||||
@Override
|
||||
public void registerRenderInfo() {
|
||||
|
||||
registerClientEventHandler(new ModEventHandlerClient());
|
||||
registerClientEventHandler(new ModEventHandlerRenderer());
|
||||
registerClientEventHandler(theInfoSystem);
|
||||
|
||||
AdvancedModelLoader.registerModelHandler(new HmfModelLoader());
|
||||
ResourceManager.loadAnimatedModels();
|
||||
@ -1623,8 +1628,9 @@ public class ClientProxy extends ServerProxy {
|
||||
|
||||
@Override
|
||||
public void displayTooltip(String msg) {
|
||||
//Minecraft.getMinecraft().ingameGUI.func_110326_a(msg, false);
|
||||
|
||||
Minecraft.getMinecraft().ingameGUI.func_110326_a(msg, false);
|
||||
this.theInfoSystem.push(new InfoEntry(msg, 1000));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -3,6 +3,7 @@ package com.hbm.render.tileentity;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.hbm.main.ResourceManager;
|
||||
import com.hbm.tileentity.machine.TileEntityCharger;
|
||||
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
@ -28,12 +29,12 @@ public class RenderCharger extends TileEntitySpecialRenderer {
|
||||
bindTexture(ResourceManager.charger_tex);
|
||||
ResourceManager.charger.renderPart("Base");
|
||||
|
||||
int time = (int) (System.currentTimeMillis() % 2000);
|
||||
if(time >= 1000)
|
||||
time = 1000 - (time - 1000);
|
||||
TileEntityCharger charger = (TileEntityCharger) tile;
|
||||
|
||||
double extend = Math.min(time, 500) / 500D;
|
||||
double swivel = Math.max(time - 500, 0) / 500D;
|
||||
double time = (charger.lastUsingTicks + (charger.lastUsingTicks - charger.lastUsingTicks) * interp) / (double) charger.delay;
|
||||
|
||||
double extend = Math.min(1, time * 2);
|
||||
double swivel = Math.max(0, (time - 0.5) * 2);
|
||||
|
||||
GL11.glPushMatrix();
|
||||
|
||||
|
||||
144
src/main/java/com/hbm/render/util/RenderInfoSystem.java
Normal file
144
src/main/java/com/hbm/render/util/RenderInfoSystem.java
Normal file
@ -0,0 +1,144 @@
|
||||
package com.hbm.render.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
|
||||
|
||||
public class RenderInfoSystem {
|
||||
|
||||
private static Random rand = new Random();
|
||||
private static HashMap<Integer, InfoEntry> inbox = new HashMap();
|
||||
private static HashMap<Integer, InfoEntry> messages = new HashMap();
|
||||
|
||||
@SubscribeEvent
|
||||
public void clentTick(ClientTickEvent event) {
|
||||
messages.putAll(inbox);
|
||||
inbox.clear();
|
||||
|
||||
List<Integer> keys = new ArrayList(messages.keySet());
|
||||
|
||||
for(int i = 0; i < keys.size(); i++) {
|
||||
Integer key = keys.get(i);
|
||||
InfoEntry entry = messages.get(key);
|
||||
|
||||
if(entry.start + entry.millis < System.currentTimeMillis()) {
|
||||
messages.remove(key);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onOverlayRender(RenderGameOverlayEvent.Pre event) {
|
||||
|
||||
if(event.type != ElementType.CROSSHAIRS)
|
||||
return;
|
||||
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
ScaledResolution resolution = event.resolution;
|
||||
|
||||
int pX = 15; //resolution.getScaledWidth() / 2 + 8;
|
||||
int pZ = 15; //resolution.getScaledHeight() / 2;
|
||||
|
||||
List<InfoEntry> entries = new ArrayList(messages.entrySet());
|
||||
Collections.sort(entries);
|
||||
|
||||
GL11.glPushMatrix();
|
||||
|
||||
int off = 0;
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
for(InfoEntry entry : messages.values()) {
|
||||
|
||||
int elapsed = (int) (now - entry.start);
|
||||
|
||||
int alpha = Math.min(510 * (entry.millis - elapsed) / entry.millis, 255); //smoothly scales down from 510 to 0, then caps at 255
|
||||
int color = entry.color + (alpha << 24 & -0xffffff);
|
||||
mc.fontRenderer.drawString(entry.text, pX, pZ + off, color);
|
||||
|
||||
off += 10;
|
||||
}
|
||||
|
||||
/*mc.fontRenderer.drawString(title, pX + 1, pZ - 9, bgCol);
|
||||
mc.fontRenderer.drawString(title, pX, pZ - 10, titleCol);
|
||||
|
||||
try {
|
||||
for(String line : text) {
|
||||
|
||||
int color = 0xFFFFFF;
|
||||
if(line.startsWith("&[")) {
|
||||
int end = line.lastIndexOf("&]");
|
||||
color = Integer.parseInt(line.substring(2, end));
|
||||
line = line.substring(end + 2);
|
||||
}
|
||||
|
||||
mc.fontRenderer.drawStringWithShadow(line, pX, pZ, color);
|
||||
pZ += 10;
|
||||
}
|
||||
} catch(Exception ex) {
|
||||
mc.fontRenderer.drawStringWithShadow(ex.getClass().getSimpleName(), pX, pZ + 10, 0xff0000);
|
||||
}*/
|
||||
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glColor3f(1F, 1F, 1F);
|
||||
|
||||
GL11.glPopMatrix();
|
||||
Minecraft.getMinecraft().renderEngine.bindTexture(Gui.icons);
|
||||
}
|
||||
|
||||
public static void push(InfoEntry entry) {
|
||||
push(entry, rand.nextInt()); //range is so large, collisions are unlikely and if they do occur, not a big deal
|
||||
}
|
||||
|
||||
public static void push(InfoEntry entry, int id) {
|
||||
inbox.put(id, entry);
|
||||
}
|
||||
|
||||
public static class InfoEntry implements Comparable {
|
||||
|
||||
String text;
|
||||
int color = 0xffffff;
|
||||
long start;
|
||||
int millis;
|
||||
|
||||
public InfoEntry(String text) {
|
||||
this(text, 3000);
|
||||
}
|
||||
|
||||
public InfoEntry(String text, int millis) {
|
||||
this.text = text;
|
||||
this.millis = millis;
|
||||
this.start = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public InfoEntry withColor(int color) {
|
||||
this.color = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
|
||||
if(!(o instanceof InfoEntry)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
InfoEntry other = (InfoEntry) o;
|
||||
|
||||
return this.millis < other.millis ? -1 : this.millis > other.millis ? 1 : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,83 @@
|
||||
package com.hbm.tileentity.machine;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.hbm.tileentity.INBTPacketReceiver;
|
||||
import com.hbm.tileentity.TileEntityLoadedBase;
|
||||
|
||||
import api.hbm.energy.IBatteryItem;
|
||||
import api.hbm.energy.IEnergyUser;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class TileEntityCharger extends TileEntityLoadedBase implements IEnergyUser {
|
||||
public class TileEntityCharger extends TileEntityLoadedBase implements IEnergyUser, INBTPacketReceiver {
|
||||
|
||||
private List<EntityPlayer> players = new ArrayList();
|
||||
private long charge = 0;
|
||||
|
||||
long lastOp = 0;
|
||||
boolean particles = false;
|
||||
|
||||
public int usingTicks;
|
||||
public int lastUsingTicks;
|
||||
public static final int delay = 20;
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata());
|
||||
this.trySubscribe(worldObj, xCoord + dir.offsetX, yCoord, zCoord + dir.offsetZ, dir);
|
||||
|
||||
players = worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5).expand(1, 0.5, 1));
|
||||
|
||||
charge = 0;
|
||||
|
||||
for(EntityPlayer player : players) {
|
||||
|
||||
for(int i = 0; i < 5; i++) {
|
||||
|
||||
ItemStack stack = player.getEquipmentInSlot(i);
|
||||
|
||||
if(stack != null && stack.getItem() instanceof IBatteryItem) {
|
||||
IBatteryItem battery = (IBatteryItem) stack.getItem();
|
||||
charge += Math.min(battery.getMaxCharge() - battery.getCharge(stack), battery.getChargeRate());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setLong("c", charge);
|
||||
data.setBoolean("p", worldObj.getTotalWorldTime() - lastOp < 4);
|
||||
INBTPacketReceiver.networkPack(this, data, 50);
|
||||
}
|
||||
|
||||
lastUsingTicks = usingTicks;
|
||||
|
||||
if(charge > 0 && usingTicks < delay)
|
||||
usingTicks++;
|
||||
if(charge <= 0 && usingTicks > 0)
|
||||
usingTicks--;
|
||||
|
||||
if(particles) {
|
||||
Random rand = worldObj.rand;
|
||||
worldObj.spawnParticle("magicCrit", xCoord + 0.25 + rand.nextDouble() * 0.5, yCoord + rand.nextDouble() * 0.5, zCoord + 0.25 + rand.nextDouble() * 0.5, 0.0, 0.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void networkUnpack(NBTTagCompound nbt) {
|
||||
this.charge = nbt.getLong("c");
|
||||
this.particles = nbt.getBoolean("p");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPower() {
|
||||
@ -13,11 +86,37 @@ public class TileEntityCharger extends TileEntityLoadedBase implements IEnergyUs
|
||||
|
||||
@Override
|
||||
public long getMaxPower() {
|
||||
return 0;
|
||||
return charge;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPower(long power) {
|
||||
public void setPower(long power) { }
|
||||
|
||||
@Override
|
||||
public long transferPower(long power) {
|
||||
|
||||
if(this.usingTicks < delay || power == 0)
|
||||
return power;
|
||||
|
||||
lastOp = worldObj.getTotalWorldTime();
|
||||
|
||||
for(EntityPlayer player : players) {
|
||||
|
||||
for(int i = 0; i < 5; i++) {
|
||||
|
||||
ItemStack stack = player.getEquipmentInSlot(i);
|
||||
|
||||
if(stack != null && stack.getItem() instanceof IBatteryItem) {
|
||||
IBatteryItem battery = (IBatteryItem) stack.getItem();
|
||||
|
||||
long toCharge = Math.min(battery.getMaxCharge() - battery.getCharge(stack), battery.getChargeRate());
|
||||
toCharge = Math.min(toCharge, power);
|
||||
battery.chargeBattery(stack, toCharge);
|
||||
power -= toCharge;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return power;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user