Jump to content

Lambda

Members
  • Posts

    486
  • Joined

  • Last visited

Everything posted by Lambda

  1. So I should jsut use the WorldSavedData, I already have one storing a few things.. Also the ChunkPos thing... How should I get each chunk and assign a default value to them?
  2. Well yeah, but how would I create a 'World' capability.. what differences vs. player capabilities, etc.
  3. Hey there! So I'm in need of storing a capability that keeps track of an integer inside each chunk.. Is there a way I can store a capability in each of those chunks?
  4. Thanks guys. That seemed to work.. Derp that I missed that
  5. Okay edited.. Also github for anybody that prefers that: https://github.com/LambdaXV/PlentifulUtilities
  6. 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: Thanks! EDIT: TileEntityBase:
  7. Okay! Its updated now!
  8. Yeah here: https://github.com/LambdaXV/PlentifulUtilities/tree/master/src/main/java/com/lambda/plentifulutilities
  9. Okay! That worked! Thanks!
  10. So just store a private BlockPos?
  11. Oops. Could you show what you mean, either with a video or a gif? Here:
  12. Compared to my TEs, you should probably use capabilities instead of getField/setField. I don't know if it will fix your problems, but its 'good' to do it anyways.
  13. Okay adding this: || (blockToBreak.getY() == 0 && blockToBreak.getZ() == 0 && blockToBreak.getZ() == 0)) to the if statement checking null, however, all the TE dig in the same place still..
  14. Yep, for some reason the blockpos is at 0,0,0 then goes down one every tick I tell it to dig.. only relogging many times fixes it.
  15. How would I check that it is instantiated/created.
  16. Well one thing I just noticed is the fact that it returns ones if the item on top is valid, so my method of this: if (StackUtil.containsSets(itemStackList, recipe.input, true) >= recipe.input.size()) { Wont work due to the method return: 1 1 1 1 depending on how many items are on top, ex: 3 items = 3 ones, etc. So I'm stuck again
  17. Yeah it should be.. Its not throwing a mapping error... and yes, I have it saved now, but still doesn't work
  18. Could you show your TileEntityBase and IEnergyDisplay? I highly that its something to do with these classes, but: 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 } } IEnergyDisplay: public interface IEnergyDisplay{ @SideOnly(Side.CLIENT) CustomEnergyStorage getEnergyStorage(); @SideOnly(Side.CLIENT) boolean needsHoldShift(); } CustomEnergyStorage just extends MCForge's EnergyStorage.
  19. Yes, that has nothing to do with the function of the blocks breaking, this basically opens a 'portal' to a void and creates energy from it.. reason why i need the blocks to break.. the isRunning boolean is so it knows that it has it the void.
  20. Update Function. with !world.isRemote. Edit: here is the entire class: public class TileEntityGeothermicPump extends TileEntityBase implements IEnergyDisplay { public final CustomEnergyStorage storage = new CustomEnergyStorage(250000, 0, 50); public static final int PRODUCE = 35; public static final int PROBE_USE = 10; private static BlockPos blockToBreak; public static int DEATH_TICK = 10; public boolean isBroke = false; public boolean isRunning = false; private int tick; private int deathTick; public TileEntityGeothermicPump() { super("geothermicPump"); } @Override public void updateEntity() { super.updateEntity(); if(!world.isRemote) { deathTick++; tick++; System.out.println(tick); if(tick >= 25) { digDown(); tick=0; } //deathTicking(); } } public void digDown() { if(blockToBreak == null) { 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 { world.destroyBlock(blockToBreak, false); renderStaticEffect(EnumParticleTypes.END_ROD, blockToBreak.getX(), blockToBreak.getY(), blockToBreak.getZ()); } if (blockToBreak.getY() < 0) { isRunning = true; } } } public void deathTicking() { if(isRunning) { if (deathTick >= 100) { DEATH_TICK--; deathTick = 0; } if (DEATH_TICK <= 0) { //placeDestroyedBlocks(this.getPos().getY()); isBroke = true; } } } 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 BlockContainer) { tileEntity.setPos(posToSend); 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); } //todo replace bedrock with last two blocks public void placeDestroyedBlocks(){ //todo REWRITE! WAS BREAKING! } @Override public CustomEnergyStorage getEnergyStorage() { return storage; } @Override public boolean needsHoldShift() { return false; } public boolean isRunning() { return isRunning; } public void setRunning(boolean running) { isRunning = running; } }
  21. Well, now it still kinda messes with the positions, I have to relog 3-4 times before it works, then all the blocks mine at the same position... here is the code: public void digDown() { if(blockToBreak == null) { 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 { world.destroyBlock(blockToBreak, false); renderStaticEffect(EnumParticleTypes.END_ROD, blockToBreak.getX(), blockToBreak.getY(), blockToBreak.getZ()); } if (blockToBreak.getY() < 0) { isRunning = true; } } }
  22. Well, sorry for making this over complicated for myself and you guys.. got it working now
  23. Yeah just realized that! Yes this is inside a TE.. Yeah but storing a local variable, BlockPos posToBreak = new BlockPos(this.getPos().getX(), this.getPos().getY()-1, this.getPos().getZ()); with the method in the last post, always seems to return: [18:16:59] [server thread/INFO]: [sTDOUT]: BlockPos{x=-280, y=63, z=234} [18:16:59] [server thread/INFO]: [sTDOUT]: BlockPos{x=-280, y=63, z=234}
  24. Well, trying to store a local vairble: BlockPos posToBreak = new BlockPos(this.getPos().getX(), this.getPos().getY()-1, this.getPos().getZ()); within the method: public void digDown() { BlockPos posToBreak = new BlockPos(this.getPos().getX(), this.getPos().getY()-1, this.getPos().getZ()); IBlockState block = world.getBlockState(posToBreak); if(block.getBlock() == Blocks.AIR) { posToBreak = posToBreak.add(0,-1,0); }else if(!(block instanceof TileEntity)) { world.destroyBlock(posToBreak, false); }else { handleTEBreaking((TileEntity) block, this.getPos()); } } Will make posToBreak = posToBreak.add(0,-1,0); redundant, because it never actually changes anything.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.