Posted December 31, 20168 yr Hey there! I have a overlay here that overlays the amount of RF the tile that your looking at has : However, It doesnt seem to update with the TE until a relog... Here is the overlay event: @SubscribeEvent public void onGameOverlay(RenderGameOverlayEvent.Post event){ if(event.getType() == RenderGameOverlayEvent.ElementType.ALL && Minecraft.getMinecraft().currentScreen == null){ Minecraft minecraft = Minecraft.getMinecraft(); EntityPlayer player = minecraft.player; RayTraceResult posHit = minecraft.objectMouseOver; FontRenderer font = minecraft.fontRendererObj; ItemStack stack = player.getHeldItemMainhand(); if(StackUtil.isValid(stack)){ if(stack.getItem() instanceof IHudDisplay){ ((IHudDisplay)stack.getItem()).displayHud(minecraft, player, stack, posHit, event.getResolution()); } } if(posHit != null && posHit.getBlockPos() != null){ Block blockHit = minecraft.world.getBlockState(posHit.getBlockPos()).getBlock(); TileEntity tileHit = minecraft.world.getTileEntity(posHit.getBlockPos()); if(blockHit instanceof IHudDisplay){ ((IHudDisplay)blockHit).displayHud(minecraft, player, stack, posHit, event.getResolution()); } if(tileHit instanceof TileEntityBase){ TileEntityBase base = (TileEntityBase)tileHit; if(base.isRedstoneToggle()){ String strg = "Activation Mode: "+ TextFormatting.DARK_RED+(base.isPulseMode ? "Pulse" : "Deactivation")+TextFormatting.RESET; font.drawStringWithShadow(strg, event.getResolution().getScaledWidth()/2+5, event.getResolution().getScaledHeight()/2+5, StringUtil.DECIMAL_COLOR_WHITE); String expl; if(StackUtil.isValid(stack) && stack.getItem() == InitItems.itemJAWrench){ expl = TextFormatting.GREEN+"Right-Click to adjust!"; } else{ expl = TextFormatting.GRAY.toString()+TextFormatting.ITALIC+"Hold a " + TextFormatting.BLUE + "Wrench " + TextFormatting.GRAY + " to Adjust"; } font.drawStringWithShadow(expl, event.getResolution().getScaledWidth()/2+5, event.getResolution().getScaledHeight()/2+15, StringUtil.DECIMAL_COLOR_WHITE); } } if(tileHit instanceof IEnergyDisplay){ IEnergyDisplay display = (IEnergyDisplay)tileHit; if(!display.needsHoldShift() || player.isSneaking()){ if(energyDisplay == null){ energyDisplay = new EnergyDisplay(0, 0, null); } energyDisplay.setData(2, event.getResolution().getScaledHeight()-96, display.getEnergyStorage(), true, true); GlStateManager.pushMatrix(); GlStateManager.color(1F, 1F, 1F, 1F); energyDisplay.draw(); GlStateManager.popMatrix(); } } } } } This If is here the overlay is handled: if(tileHit instanceof IEnergyDisplay){ IEnergyDisplay display = (IEnergyDisplay)tileHit; if(!display.needsHoldShift() || player.isSneaking()){ if(energyDisplay == null){ energyDisplay = new EnergyDisplay(0, 0, null); } energyDisplay.setData(2, event.getResolution().getScaledHeight()-96, display.getEnergyStorage(), true, true); GlStateManager.pushMatrix(); GlStateManager.color(1F, 1F, 1F, 1F); energyDisplay.draw(); GlStateManager.popMatrix(); } } Here is the energy display class: @SideOnly(Side.CLIENT) public class EnergyDisplay extends Gui { private CustomEnergyStorage rfReference; private int x; private int y; private boolean outline; private boolean drawTextNextTo; public EnergyDisplay(int x, int y, CustomEnergyStorage rfReference, boolean outline, boolean drawTextNextTo){ this.setData(x, y, rfReference, outline, drawTextNextTo); } public EnergyDisplay(int x, int y, CustomEnergyStorage rfReference){ this(x, y, rfReference, false, false); } public void setData(int x, int y, CustomEnergyStorage rfReference, boolean outline, boolean drawTextNextTo){ this.x = x; this.y = y; this.rfReference = rfReference; this.outline = outline; this.drawTextNextTo = drawTextNextTo; } public void draw(){ Minecraft mc = Minecraft.getMinecraft(); mc.getTextureManager().bindTexture(ResourceUtil.GUI_INVENTORY_LOCATION); int barX = this.x; int barY = this.y; if(this.outline){ this.drawTexturedModalRect(this.x, this.y, 52, 163, 26, 93); barX += 4; barY += 4; } this.drawTexturedModalRect(barX, barY, 18, 171, 18, 85); if(this.rfReference.getEnergyStored() > 0){ int i = this.rfReference.getEnergyStored()*83/this.rfReference.getMaxEnergyStored(); GlStateManager.color(255/255F, 0/255F, 0/255F); this.drawTexturedModalRect(barX+1, barY+84-i, 36, 172, 16, i); GlStateManager.color(1F, 1F, 1F); } if(this.drawTextNextTo){ this.drawString(mc.fontRendererObj, this.getOverlayText(), barX+25, barY+78, StringUtil.DECIMAL_COLOR_WHITE); } } public void drawOverlay(int mouseX, int mouseY){ if(this.isMouseOver(mouseX, mouseY)){ Minecraft mc = Minecraft.getMinecraft(); List<String> text = new ArrayList<String>(); text.add(this.getOverlayText()); GuiUtils.drawHoveringText(text, mouseX, mouseY, mc.displayWidth, mc.displayHeight, -1, mc.fontRendererObj); } } private boolean isMouseOver(int mouseX, int mouseY){ return mouseX >= this.x && mouseY >= this.y && mouseX < this.x+(this.outline ? 26 : 18) && mouseY < this.y+(this.outline ? 93 : 85); } private String getOverlayText(){ NumberFormat format = NumberFormat.getInstance(); return format.format(this.rfReference.getEnergyStored())+"/"+format.format(this.rfReference.getMaxEnergyStored())+" Redstone Flux"; } } The IEnergyDisplay: public interface IEnergyDisplay{ @SideOnly(Side.CLIENT) CustomEnergyStorage getEnergyStorage(); @SideOnly(Side.CLIENT) boolean needsHoldShift(); } and the TE: public class TileEntityGeothermicPump extends TileEntityBase implements ISharingEnergyHandler, IEnergyDisplay { public final CustomEnergyStorage storage = new CustomEnergyStorage(250000, 0, 50); public static final int PRODUCE = 35; public static final int PROBE_USE = 10; private BlockPos blockToBreak; private BlockPos blockToPlace; public static int DEATH_TICK = 10; public boolean isBroke = false; public boolean isRunning = false; private int tick; private int deathTick; public EntityPlayer player; public UUID uuid; public TileEntityGeothermicPump() { super("geothermicPump"); } @Override public void updateEntity() { super.updateEntity(); if(!world.isRemote) { if (player != null) { deathTick++; tick++; System.out.println(storage.getEnergyStored()); if (tick >= 5) { digDown(); tick = 0; } deathTicking(); }else if(uuid != null){ this.player = getPlayerFromUUID(uuid); } if(uuid == null & player != null) { setUuid(player.getUniqueID()); } if(player == null && uuid == null) { ModUtil.LOGGER.warn("No player or UUID was saved! You must replace the Geothermic Pump @ x: " + pos.getX() + " y: " + pos.getY() + " z: " + pos.getZ()); } } } public void digDown() { if(!isRunning) { if (blockToBreak == null || (blockToBreak.getX() == 0 && blockToBreak.getY() == 0 && blockToBreak.getZ() == 0)) { blockToBreak = new BlockPos(this.getPos().getX(), this.getPos().getY() - 1, this.getPos().getZ()); } else { IBlockState block = world.getBlockState(blockToBreak); if (block.getBlock() == Blocks.AIR) { blockToBreak = blockToBreak.down(); } else if(block.getBlock() instanceof BlockContainer){ TileEntity te = world.getTileEntity(blockToBreak); handleTEBreaking(te, this.getPos()); }else { world.destroyBlock(blockToBreak, false); renderStaticEffect(EnumParticleTypes.END_ROD, blockToBreak.getX(), blockToBreak.getY(), blockToBreak.getZ()); } if (blockToBreak.getY() < 0) { isRunning = true; } } }else { //place scaffolding code } } public void placeDestroyedBlocks(){ if(blockToPlace == null || (blockToPlace.getX() == 0 && blockToPlace.getY() == 0 && blockToPlace.getZ() == 0)){ //Both of these ifs are here due to blockpos being 'dumb' blockToPlace = new BlockPos(this.getPos().getX(), this.getPos().getY() - 1, this.getPos().getZ()); }else { if (tick >= 5) { IBlockState block = world.getBlockState(blockToPlace); if (block.getBlock() == Blocks.AIR) { //for now, b/c no scaffolding code has been implemented. world.setBlockState(blockToPlace, Blocks.STONE.getDefaultState()); } else { blockToPlace = blockToPlace.down(); } } } } public void deathTicking() { if(isRunning) { if (deathTick >= 100) { DEATH_TICK--; deathTick = 0; } if (DEATH_TICK <= 0) { placeDestroyedBlocks(); isBroke = true; } storage.receiveEnergyInternal(PRODUCE, false); renderLaserToEndPoint(this.getPos().getX(), -15, this.getPos().getZ()); } } public void handleTEBreaking(TileEntity tileEntity, BlockPos basePos) { if(tileEntity != null) { BlockPos posToSend = new BlockPos(basePos.getX(), basePos.getY()+1, basePos.getZ()); IBlockState blockOccupy = this.world.getBlockState(posToSend); if(blockOccupy.getBlock() instanceof BlockAir) { renderEffect(EnumParticleTypes.PORTAL, blockToBreak.getX(), blockToBreak.getY(), blockToBreak.getZ(), posToSend.getX(), posToSend.getY(), posToSend.getZ()); renderStaticEffect(EnumParticleTypes.END_ROD, blockToBreak.getX(), blockToBreak.getY(), blockToBreak.getZ()); }else { posToSend.add(0, 1, 0); return; } } } public void renderStaticEffect(EnumParticleTypes type, double startX, double startY, double startZ) { ((WorldServer)this.world).spawnParticle(type, false, startX, startY, startZ, 2, 0, 0, 0, 0.1D); } public void renderEffect(EnumParticleTypes type, double startX, double startY, double startZ, double endX, double endY, double endZ) { this.world.spawnParticle(type, startX, startY, startZ, endX, endY, endZ); } public void renderLaserToEndPoint(int endX, int endY, int endZ) { ResourceUtil.spawnLaserWithTimeServer(this.world, this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), endX, endY, endZ, ResourceUtil.getRGBFromFloatValue(getPlayer().world.getTotalWorldTime()%256), 10, 120, 0.1F, 0.8F); } @Override public void writeSyncableNBT(NBTTagCompound compound, NBTType type) { super.writeSyncableNBT(compound, type); this.storage.writeToNBT(compound); if(type != NBTType.SAVE_BLOCK) { if(blockToBreak != null) { compound.setInteger("PosXBreak", blockToBreak.getX()); compound.setInteger("PosYBreak", blockToBreak.getY()); compound.setInteger("PosZBreak", blockToBreak.getZ()); } if(uuid != null) { compound.setUniqueId("UUID", uuid); } compound.setBoolean("IsRunning", isRunning); compound.setBoolean("IsBroken", isBroke); } } @Override public void readSyncableNBT(NBTTagCompound compound, NBTType type) { super.readSyncableNBT(compound, type); this.storage.readFromNBT(compound); if(type != NBTType.SAVE_BLOCK) { this.setUuid(compound.getUniqueId("UUID")); this.isRunning = compound.getBoolean("IsRunning"); this.isBroke = compound.getBoolean("IsBroken"); } } public void setUuid(UUID uuid) { this.uuid = uuid; } public EntityPlayer getPlayerFromUUID(UUID uuid) { return world.getPlayerEntityByUUID(uuid); } public EntityPlayer getPlayer() { return player; } public void setPlayer(EntityPlayer player) { this.player = player; } @Override public CustomEnergyStorage getEnergyStorage(){ return this.storage; } @Override public boolean needsHoldShift(){ return false; } @Override public int getEnergyToSplitShare(){ return this.storage.getEnergyStored(); } @Override public boolean doesShareEnergy(){ return true; } @Override public EnumFacing[] getEnergyShareSides(){ return EnumFacing.values(); } @Override public boolean canShareTo(TileEntity tile){ return true; } @Override public IEnergyStorage getEnergyStorage(EnumFacing facing){ return this.storage; } public boolean isRunning() { return isRunning; } public void setRunning(boolean running) { isRunning = running; } } Thanks! EDIT: TileEntityBase: public abstract class TileEntityBase extends TileEntity implements ITickable{ public final String name; public boolean isRedstonePowered; public boolean isPulseMode; public boolean stopFromDropping; protected int ticksElapsed; protected TileEntity[] tilesAround = new TileEntity[6]; protected boolean hasSavedDataOnChangeOrWorldStart; public TileEntityBase(String name){ this.name = name; } public static void init() { ModUtil.LOGGER.info("Registering TileEntities..."); register(TileEntityConstructor.class); register(TileEntityGeothermicPump.class); register(TileEntityItemBuffer.class); } private static void register(Class<? extends TileEntityBase> tileClass){ try{ String name = ModUtil.MOD_ID+":"+tileClass.newInstance().name; GameRegistry.registerTileEntity(tileClass, name); } catch(Exception e){ ModUtil.LOGGER.fatal("Registering a TileEntity failed!", e); } } @Override public final NBTTagCompound writeToNBT(NBTTagCompound compound){ this.writeSyncableNBT(compound, NBTType.SAVE_TILE); return compound; } @Override public final void readFromNBT(NBTTagCompound compound){ this.readSyncableNBT(compound, NBTType.SAVE_TILE); } @Override public final SPacketUpdateTileEntity getUpdatePacket(){ NBTTagCompound compound = new NBTTagCompound(); this.writeSyncableNBT(compound, NBTType.SYNC); return new SPacketUpdateTileEntity(this.pos, -1, compound); } @Override public final void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt){ this.readSyncableNBT(pkt.getNbtCompound(), NBTType.SYNC); } @Override public final NBTTagCompound getUpdateTag(){ NBTTagCompound compound = new NBTTagCompound(); this.writeSyncableNBT(compound, NBTType.SYNC); return compound; } @Override public final void handleUpdateTag(NBTTagCompound compound){ this.readSyncableNBT(compound, NBTType.SYNC); } public final void sendUpdate(){ if(this.world != null && !this.world.isRemote){ NBTTagCompound compound = new NBTTagCompound(); this.writeSyncableNBT(compound, NBTType.SYNC); NBTTagCompound data = new NBTTagCompound(); data.setTag("Data", compound); data.setInteger("X", this.pos.getX()); data.setInteger("Y", this.pos.getY()); data.setInteger("Z", this.pos.getZ()); PacketHandler.theNetwork.sendToAllAround(new PacketServerToClient(data, PacketHandler.TILE_ENTITY_HANDLER), new NetworkRegistry.TargetPoint(this.world.provider.getDimension(), this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), 64)); } } public void writeSyncableNBT(NBTTagCompound compound, NBTType type){ if(type != NBTType.SAVE_BLOCK){ super.writeToNBT(compound); } if(type == NBTType.SAVE_TILE){ compound.setBoolean("Redstone", this.isRedstonePowered); compound.setInteger("TicksElapsed", this.ticksElapsed); compound.setBoolean("StopDrop", this.stopFromDropping); } if(this.isRedstoneToggle() && (type != NBTType.SAVE_BLOCK || this.isPulseMode)){ compound.setBoolean("IsPulseMode", this.isPulseMode); } } public void readSyncableNBT(NBTTagCompound compound, NBTType type){ if(type != NBTType.SAVE_BLOCK){ super.readFromNBT(compound); } if(type == NBTType.SAVE_TILE){ this.isRedstonePowered = compound.getBoolean("Redstone"); this.ticksElapsed = compound.getInteger("TicksElapsed"); this.stopFromDropping = compound.getBoolean("StopDrop"); } if(this.isRedstoneToggle()){ this.isPulseMode = compound.getBoolean("IsPulseMode"); } } @Override public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState){ return !oldState.getBlock().isAssociatedBlock(newState.getBlock()); } public String getDisplayedName(){ return StringUtil.localize("container."+ModUtil.MOD_ID+"."+this.name+".name"); } @Override public ITextComponent getDisplayName(){ return new TextComponentString(this.getDisplayedName()); } /** * !WORLD.ISREMOTE */ @Override public final void update(){ this.updateEntity(); } public int getComparatorStrength(){ return 0; } public void updateEntity(){ this.ticksElapsed++; if(!this.world.isRemote){ if(this instanceof ISharingEnergyHandler){ ISharingEnergyHandler provider = (ISharingEnergyHandler)this; if(provider.doesShareEnergy()){ int total = provider.getEnergyToSplitShare(); if(total > 0){ EnumFacing[] sides = provider.getEnergyShareSides(); int amount = total/sides.length; if(amount <= 0){ amount = total; } for(EnumFacing side : sides){ TileEntity tile = this.tilesAround[side.ordinal()]; if(tile != null && provider.canShareTo(tile)){ WorldUtil.doEnergyInteraction(this, tile, side, amount); } } } } } if(this instanceof ISharingFluidHandler){ ISharingFluidHandler handler = (ISharingFluidHandler)this; if(handler.doesShareFluid()){ int total = handler.getMaxFluidAmountToSplitShare(); if(total > 0){ EnumFacing[] sides = handler.getFluidShareSides(); int amount = total/sides.length; if(amount <= 0){ amount = total; } for(EnumFacing side : sides){ TileEntity tile = this.tilesAround[side.ordinal()]; if(tile != null){ WorldUtil.doFluidInteraction(this, tile, side, amount); } } } } } if(!this.hasSavedDataOnChangeOrWorldStart){ if(this.shouldSaveDataOnChangeOrWorldStart()){ this.saveDataOnChangeOrWorldStart(); } this.hasSavedDataOnChangeOrWorldStart = true; } } } public void saveDataOnChangeOrWorldStart(){ for(EnumFacing side : EnumFacing.values()){ this.tilesAround[side.ordinal()] = this.world.getTileEntity(this.pos.offset(side)); } } public boolean shouldSaveDataOnChangeOrWorldStart(){ return this instanceof ISharingEnergyHandler || this instanceof ISharingFluidHandler; } public void setRedstonePowered(boolean powered){ this.isRedstonePowered = powered; this.markDirty(); } public boolean canPlayerUse(EntityPlayer player){ return player.getDistanceSq(this.getPos().getX()+0.5D, this.pos.getY()+0.5D, this.pos.getZ()+0.5D) <= 64 && !this.isInvalid() && this.world.getTileEntity(this.pos) == this; } protected boolean sendUpdateWithInterval(){ if(this.ticksElapsed% ConfigIntValues.TILE_ENTITY_UPDATE_INTERVAL.getValue() == 0){ this.sendUpdate(); return true; } else{ return false; } } @Override public boolean hasCapability(Capability<?> capability, EnumFacing facing){ return this.getCapability(capability, facing) != null; } @Override public <T> T getCapability(Capability<T> capability, EnumFacing facing){ if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY){ IItemHandler handler = this.getItemHandler(facing); if(handler != null){ return (T)handler; } } else if(capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY){ IFluidHandler tank = this.getFluidHandler(facing); if(tank != null){ return (T)tank; } } else if(capability == CapabilityEnergy.ENERGY){ IEnergyStorage storage = this.getEnergyStorage(facing); if(storage != null){ return (T)storage; } } return super.getCapability(capability, facing); } public IFluidHandler getFluidHandler(EnumFacing facing){ return null; } public IEnergyStorage getEnergyStorage(EnumFacing facing){ return null; } public IItemHandler getItemHandler(EnumFacing facing){ return null; } public boolean isRedstoneToggle(){ return false; } public void activateOnPulse(){ } public boolean respondsToPulses(){ return this.isRedstoneToggle() && this.isPulseMode; } public enum NBTType{ SAVE_TILE, SYNC, SAVE_BLOCK } } Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
December 31, 20168 yr You also need to post TileEntityBase Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
December 31, 20168 yr Author Okay edited.. Also github for anybody that prefers that: https://github.com/LambdaXV/PlentifulUtilities Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
December 31, 20168 yr Okay edited.. Also github for anybody that prefers that: https://github.com/LambdaXV/PlentifulUtilities Is your sendUpdate method getting called? And you should just put your github in your signature. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
December 31, 20168 yr Is your sendUpdate method getting called? And you should just put your github in your signature. It's called from sendUpdateWithInterval which is, itself, not called. So no. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
December 31, 20168 yr Is your sendUpdate method getting called? And you should just put your github in your signature. It's called from sendUpdateWithInterval which is, itself, not called. So no. I didn't think it was VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
December 31, 20168 yr Author Thanks guys. That seemed to work.. Derp that I missed that Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.