Jump to content

That_Martin_Guy

Members
  • Posts

    197
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by That_Martin_Guy

  1. Great idea! Don't know why I couldn't figure that out myself. I will post the result when I'm done. storage = new EnergyStorage(Integer.MIN_VALUE); in the constructor. If it gets called when I re-enter the world it will reset the storage variable, won't it?
  2. The best way I could figure out on my own was to implement storage like this public TileEntityLamp() { storage = new EnergyStorage(Integer.MIN_VALUE); PLAYER_ENTRY_LIST.setAccessible(true); } and change update to this public void update() { if (worldObj.getBlockState(this.pos).getBlock() instanceof BlockLamp) { BlockLamp lamp = (BlockLamp) worldObj.getBlockState(pos).getBlock(); if(lifetime == 0) lifetime = lamp.maxLifetime; if(storage.getMaxEnergyStored() == Integer.MIN_VALUE) storage = new EnergyStorage(lamp.capacity); if (!worldObj.isRemote) { EnergyLevel energyLevel = EnergyLevel.getEnergyLevel(storage.getEnergyStored(), storage.getMaxEnergyStored()); storage.modifyEnergyStored(-lamp.loss); if (EnergyLevel.getEnergyLevel(storage.getEnergyStored(), storage.getMaxEnergyStored()) != energyLevel) { switch (EnergyLevel.getEnergyLevel(storage.getEnergyStored(), storage.getMaxEnergyStored())) { case EMPTY: break; case LOW: lifetime -= 1 * lamp.lowEnergyMultiplier; break; case MEDIUM: lifetime -= 1 * lamp.mediumEnergyMultiplier; break; case HIGH: lifetime -= 1 * lamp.highEnergyMultiplier; break; } try { List<EntityPlayerMP> playerList = (List<EntityPlayerMP>) PLAYER_ENTRY_LIST.get(((WorldServer) worldObj).getPlayerChunkMap().getEntry(worldObj.getChunkFromBlockCoords(pos).xPosition, worldObj.getChunkFromBlockCoords(pos).zPosition)); LampEnergyMessage message = new LampEnergyMessage(storage.getEnergyStored(), pos); for (EntityPlayerMP player : playerList) { BrightenUp.network.sendTo(message, player); } } catch (IllegalAccessException e) { e.printStackTrace(); } worldObj.checkLight(pos); worldObj.notifyBlockUpdate(pos, worldObj.getBlockState(pos), worldObj.getBlockState(pos), 3); this.markDirty(); } } } } . This would not work in normal code since it resets every time you log in, but it was the closest solution I could find. Even after this, though, it has the exact same problem as before. Doesn't update when recieving power. When the creative energy cell is broken it stays unlit, then goes to medium, then low, then empty.
  3. I saw a request on the minecraft forum were someone wanted to have a prompt before he exists the game, whether by pressing the "exit" button in the main menu or pressing the X in the top left of the window. I thought to myself this would either be really hard or really easy to create depending on if there was some sort of event that was fired in these conditions. The closest thing I could find on google was a person wondering if there was any event that was fired in this condition, since he wanted to close some libraries before exiting (link to it here).
  4. This version of the TE results in this crash whenever I join a world with a lamp in it or place a new one down.
  5. I would personally find it useful if it was possible to have events fire when certain actions happened to the minecraft window. Examples of this would be Window closed (X button) Window maximized/resized Window minimized Main menu exit button pressed . A problem with this would potentially be making it cross compatible with mac/linux, although I'm not sure how much power forge has in this category.
  6. How would I then get the proper BlockLamp object? Checking if the block at the TE's position is an instance of BlockLamp crashes the game in my tests. I added this and this to my classes to log this exact thing. It seems it does update its lighting when its at an energy level of MEDIUM, LOW or EMPTY, but not otherwise. Here is an excerpt from the resulting log with some of my own comments.
  7. Done EDIT: I will be gone for a few hours, potentially the entire day. Stay tuned.
  8. I tried sending the actual energy stored in the TE through the network, but it didn't change much from previous tests.
  9. I'm aware of this. The problem is that I'm not sure what I want it to do. There is no EnergyLevel field, so I can't set that property somehow. I also thought that getEnergyLevel was how I was supposed to set it, since it could be called on both sides, but I guess I'm wrong.
  10. worldObj.notifyBlockUpdate(pos, worldObj.getBlockState(pos), worldObj.getBlockState(pos), 3); in TileEntityLamp#update? Or is this not how you update blocks? Also, after applying the changes diesieben suggested the block doesn't update its lighting at all, unless by normal means (placing/breaking blocks for example). My github has been updated once again. EDIT: I also feel the LampEnergyMessage is a bit unnecessary at this point, since I can call TileEntityLamp#getEnergyLevel on both sides. I'm not really using the message properly, currently. Not really sure how to set it since the old energyLevel field has been removed.
  11. You can definitely tell I was tired when programming this because... Oh god it's horrible. Let's just go through the list shall we? Fully agree. State removed, replaced all the blockstate related methods with this change in getLightValue: public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos) { if(world.getTileEntity(pos) instanceof TileEntityLamp) { TileEntityLamp lamp = (TileEntityLamp) world.getTileEntity(pos); switch(lamp.getEnergyLevel()) { case LOW: return getBaseLightValue(); case MEDIUM: return getBaseLightValue() * 2; case HIGH: return getBaseLightValue() * 5; } System.out.println(lamp.getEnergyLevel()); } return 0; } and LampEnergyMessage#Handler#onMessage to public IMessage onMessage(LampEnergyMessage message, MessageContext ctx) { FMLCommonHandler.instance().getWorldThread(ctx.getClientHandler()).addScheduledTask(() -> { final World world = Minecraft.getMinecraft().theWorld; assert world != null; if(world.getTileEntity(message.pos) instanceof TileEntityLamp) { TileEntityLamp lamp = (TileEntityLamp) world.getTileEntity(message.pos); lamp.setEnergyLevel(EnergyLevel.valueOf(message.energyLevel.toUpperCase())); world.checkLight(message.pos); System.out.println("Message sent as " + message.energyLevel.toUpperCase()); } }); return null; } . TileEntityLamp#getEnergyLevel and setEnergyLevel are the simplest getters and setters you can get and not really worth posting. Thank you for the heads up! Completely missed that I didn't ever change energyLevel. TileEntityLamp#update has been changed to public void update() { if(!worldObj.isRemote) { if (worldObj.getBlockState(this.pos).getBlock() instanceof BlockLamp) { EnergyLevel previousLevel = EnergyLevel.getEnergyLevel(storage.getEnergyStored(), storage.getMaxEnergyStored()); storage.modifyEnergyStored(-loss); if (EnergyLevel.getEnergyLevel(storage.getEnergyStored(), storage.getMaxEnergyStored()) != previousLevel) { switch (EnergyLevel.getEnergyLevel(storage.getEnergyStored(), storage.getMaxEnergyStored())) { case EMPTY: energyLevel = EMPTY; break; case LOW: this.lifetime -= 1 * lowEnergyMultiplier; energyLevel = LOW; break; case MEDIUM: this.lifetime -= 1 * mediumEnergyMultiplier; energyLevel = MEDIUM; break; case HIGH: this.lifetime -= 1 * highEnergyMultiplier; energyLevel = HIGH; break; } try { List<EntityPlayerMP> playerList = (List<EntityPlayerMP>) PLAYER_ENTRY_LIST.get(worldObj.getMinecraftServer().worldServerForDimension(worldObj.provider.getDimension()).getPlayerChunkMap().getEntry(worldObj.getChunkFromBlockCoords(pos).xPosition, worldObj.getChunkFromBlockCoords(pos).zPosition)); LampEnergyMessage message = new LampEnergyMessage(energyLevel.toString(), pos); for(EntityPlayerMP player : playerList) { BrightenUp.network.sendTo(message, player); } } //Hang with me on this one catch (IllegalAccessException e) { e.printStackTrace(); } worldObj.checkLight(pos); worldObj.notifyBlockUpdate(pos, worldObj.getBlockState(pos), worldObj.getBlockState(pos), 3); this.markDirty(); } } } } I honestly thought not including the access type in the declaration made it private. TIL. Any fields that could be are now final. I make duplicate values in both my block and TE because I don't know any other way to transfer its properties from the block to the TE (other than setting up setters in a similar way to vanilla minecraft, but IMO that makes the code way too unorganized for my taste). Don't really know a simpler to do this. The best way to get a MinecraftServer (that I've heard of) is with a World object. I didn't see any other way to call get a WorldServer without MinecraftServer other than worldServerForDimension, although I might be wrong on this. World#provider#getDimension was the only way I found were you could get a dimension ID, but again, I might be wrong. 'Cause I didn't find any other way to transfer enums through the network, so I figured using toString and valueOf was the second best option. I keep it as a simple print since I might re-design my code a lot, and it is just easier to keep it like this in case I need to move or remove it. Will definitely improve it once the lamp light works properly. However, even after all of these changes, I still cannot get the lamp's lighting to work. It doesn't update when a creative energy cell is next to it, only when it would normally update (block next to it destroyed, placed etc). When it is empty it does update, however, and turns off completely. Not when it is HIGH, MEDIUM or LOW, though.
  12. I feel like I'm getting close, but I still have a problem. The lighting doesn't update properly (only seems to send network messages when un-charging) and every time the energy level changes the lamp turns on for a split second, then immediatly turns off. Some changes to the code are a new IProperty called PropertyEnum in the block class for the energy level, EnergyLevel is now in a seperate class (thatmartinguy.brightenup.energy.EnergyLevel) and the LampEnergyMessage now requires a string (to be converted into an enum) and a pos instead of an int and a pos. Github
  13. Still puzzled trying to figure out how to get List<EntityPlayerMP> from the Field. I have updated my github to the most up to date version, but it crashes with this log.
  14. Never heard of reflection before, so I looked it up. I tried to find something related to getting a private List with a non-generic type, but I didn't find anything. I'm completely lost here. I tried Class<?> playerEntry = worldObj.getMinecraftServer().worldServerForDimension(worldObj.provider.getDimension()).getPlayerChunkMap().getEntry(worldObj.getChunkFromBlockCoords(pos).xPosition, worldObj.getChunkFromBlockCoords(pos).zPosition).getClass(); try { Field players = playerEntry.getDeclaredField("players"); List<EntityPlayerMP> playerList = players.getDeclaringClass().cast(List<EntityPlayerMP>()); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } , but IDEA gives me "Expression expected" under // this here // | | // \/ \/ List<EntityPlayerMP> playerList = players.getDeclaringClass().cast(List<EntityPlayerMP>()); .
  15. Doesn't seem to be possible to convert it like this, unless I'm doing something wrong. I got the method you mentioned this way instead: worldObj.getMinecraftServer().worldServerForDimension(worldObj.provider.getDimension()).getPlayerChunkMap().getEntry(worldObj.getChunkFromBlockCoords(pos).xPosition, worldObj.getChunkFromBlockCoords(pos).zPosition) . The problem is that I can't add .players to the end of this line. Further digging reveals that the only players field in PlayerChunkMapEntry is a private final List<EntityPlayerMP>. How do I access this field? Woops! Mistake on my part. Don't know when I moved it, but it's only supposed to be called if the energy value actually changed.
  16. I don't really understand what to do at this point. I tried adding creating a message for sending the energy level to the client and basing the blocks energy level off of that, but the block updates are wonky and it can be at full brightness when empty. Any ideas? Refer to my github if you want to look at my code.
  17. Bingo! The client is always at LOW, no matter how much energy the server has. To fix this I encased the contents of update in if(!worldObj.isRemote) and getLightValue in if(FMLCommonHandler.instance().getSide().isServer()) . The problem is that now the block doesn't have lighting at all. Does this mean that the light is checked on the client while the energy level is checked on the server? Big bummer if this is the case.
  18. I added @Override public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos) { if(world.getTileEntity(pos) instanceof TileEntityLamp) { TileEntityLamp tileEntity = (TileEntityLamp) world.getTileEntity(pos); TileEntityLamp.EnergyLevel energyLevel = tileEntity.getEnergyLevel(); switch(energyLevel) { case LOW: return getBaseLightValue(); case MEDIUM: return getBaseLightValue() * 3; case HIGH: return getBaseLightValue() * 5; default: return 0; } } return 0; } to my block and changed the tile entity's update method to @Override public void update() { if (this.worldObj.getBlockState(this.pos).getBlock() instanceof BlockLamp) { EnergyLevel previousLevel = this.getEnergyLevel(); System.out.println(this.getEnergyPercentage()); storage.modifyEnergyStored(-loss); if (this.getEnergyLevel() != previousLevel) { switch (this.getEnergyLevel()) { case LOW: this.lifetime -= 1 * lowEnergyMultiplier; break; case MEDIUM: this.lifetime -= 1 * mediumEnergyMultiplier; break; case HIGH: this.lifetime -= 1 * highEnergyMultiplier; break; } this.worldObj.checkLight(pos); } this.markDirty(); } } . Still has very similar behavior.
  19. My lamp has a tile entity that updates its lighting depending on how much power it holds. The lighting doesn't update properly, though. When I place the lamp it is at full brightness, if it's power level reduces it goes a tad bit darker, but not mutch. It never completely goes black. When I break the block the lighting doesn't update and lingers until I restart the world. What am I doing wrong? BlockLamp public class BlockLamp extends Block implements ITileEntityProvider { int capacity; int loss; float lifetime; float lowEnergyMultiplier; float mediumEnergyMultiplier; float highEnergyMultiplier; public BlockLamp(Material material, String name, float lightLevel, float lifetime, int capacity, int loss) { this(material, name, lightLevel, lifetime, capacity, loss, 1, 2, 3); } public BlockLamp(Material material, String name, float lightLevel , float lifetime, int capacity, int loss, float lowEnergyMultiplier, float mediumEnergyMultiplier, float highEnergyMultiplier) { super(material); this.setUnlocalizedName(name); this.setRegistryName(name); this.setCreativeTab(BrightenUp.tabBrightenUp); this.setLightLevel(lightLevel); this.loss = loss; this.capacity = capacity; this.lifetime = lifetime; this.lowEnergyMultiplier = lowEnergyMultiplier; this.mediumEnergyMultiplier = mediumEnergyMultiplier; this.highEnergyMultiplier = highEnergyMultiplier; } @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileEntityLamp(capacity, loss, lifetime, lowEnergyMultiplier, mediumEnergyMultiplier, highEnergyMultiplier); } @Override public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { if(worldIn.getTileEntity(pos) instanceof TileEntityLamp) { worldIn.removeTileEntity(pos); } } public float getBaseLightValue() { return this.lightValue; } } TileEntityLamp public class TileEntityLamp extends TileEntity implements ITickable, IEnergyReceiver { EnergyStorage storage; int loss; float lifetime; float lowEnergyMultiplier; float mediumEnergyMultiplier; float highEnergyMultiplier; public TileEntityLamp(int capacity, int loss, float lifetime, float lowEnergyMultiplier, float mediumEnergyMultiplier, float highEnergyMultiplier) { storage = new EnergyStorage(capacity); this.loss = loss; this.lifetime = lifetime; this.lowEnergyMultiplier = lowEnergyMultiplier; this.mediumEnergyMultiplier = mediumEnergyMultiplier; this.highEnergyMultiplier = highEnergyMultiplier; } @Override public void update() { if (this.worldObj.getBlockState(this.pos).getBlock() instanceof BlockLamp) { BlockLamp lamp = (BlockLamp) this.worldObj.getBlockState(pos).getBlock(); EnergyLevel previousLevel = this.getEnergyLevel(); System.out.println(this.getEnergyPercentage()); storage.modifyEnergyStored(-loss); if (this.getEnergyLevel() != previousLevel) { switch (this.getEnergyLevel()) { case EMPTY: lamp.setLightLevel(0); break; case LOW: this.lifetime -= 1 * lowEnergyMultiplier; lamp.setLightLevel(lamp.getBaseLightValue()); break; case MEDIUM: this.lifetime -= 1 * mediumEnergyMultiplier; lamp.setLightLevel(lamp.getBaseLightValue() * 3); break; case HIGH: this.lifetime -= 1 * highEnergyMultiplier; lamp.setLightLevel(lamp.getBaseLightValue() * 5); break; } this.worldObj.notifyBlockUpdate(pos, this.worldObj.getBlockState(pos), this.worldObj.getBlockState(pos), 3); } this.markDirty(); } this.worldObj.checkLightFor(EnumSkyBlock.BLOCK, pos); } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); storage.writeToNBT(compound); compound.setFloat("lifetime", lifetime); return compound; } @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); storage.readFromNBT(compound); lifetime = compound.getFloat("lifetime"); } @Override public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate) { return storage.receiveEnergy(maxReceive, simulate); } @Override public int getEnergyStored(EnumFacing from) { return storage.getEnergyStored(); } @Override public int getMaxEnergyStored(EnumFacing from) { return storage.getMaxEnergyStored(); } @Override public boolean canConnectEnergy(EnumFacing from) { return from == EnumFacing.DOWN || from == EnumFacing.UP; } private float getEnergyPercentage() { return (storage.getEnergyStored() * 100) / storage.getMaxEnergyStored(); } public EnergyLevel getEnergyLevel() { if(this.getEnergyPercentage() <= 40) { return EnergyLevel.LOW; } else if(this.getEnergyPercentage() > 40 && this.getEnergyPercentage() < 60) { return EnergyLevel.MEDIUM; } else if(this.getEnergyPercentage() <= 0) { return EnergyLevel.EMPTY; } else { return EnergyLevel.HIGH; } } public enum EnergyLevel { EMPTY, LOW, MEDIUM, HIGH } } I have also tried having the block handle the update, but that had a similar result. Any ideas?
  20. So I simply cloned the 1.10.2 branch (since that is the version I'm working on) and moved the src folders to my project. However, I get a ton of errors in IDEA (mostly related to IDEA not recognizing it should compile for java 1.8). If I try to use gradlew runClient with the dependencies in build.gradle it tells me this: > Could not find mezz.jei:jei_1.10.2:3.14.7.416. Searched in the following locations: http://files.minecraftforge.net/maven/mezz/jei/jei_1.10.2/3.14.7.416/jei_1.10.2-3.14.7.416.pom http://files.minecraftforge.net/maven/mezz/jei/jei_1.10.2/3.14.7.416/jei_1.10.2-3.14.7.416.jar https://repo1.maven.org/maven2/mezz/jei/jei_1.10.2/3.14.7.416/jei_1.10.2-3.14.7.416.pom https://repo1.maven.org/maven2/mezz/jei/jei_1.10.2/3.14.7.416/jei_1.10.2-3.14.7.416.jar https://libraries.minecraft.net/mezz/jei/jei_1.10.2/3.14.7.416/jei_1.10.2-3.14.7.416.pom https://libraries.minecraft.net/mezz/jei/jei_1.10.2/3.14.7.416/jei_1.10.2-3.14.7.416.jar https://jitpack.io/mezz/jei/jei_1.10.2/3.14.7.416/jei_1.10.2-3.14.7.416.pom https://jitpack.io/mezz/jei/jei_1.10.2/3.14.7.416/jei_1.10.2-3.14.7.416.jar file:/C:/Users/Axel/.gradle/caches/minecraft/deobfedDeps/mezz/jei/jei_1.10.2/3.14.7.416/jei_1.10.2-3.14.7.416.pom file:/C:/Users/Axel/.gradle/caches/minecraft/deobfedDeps/mezz/jei/jei_1.10.2/3.14.7.416/jei_1.10.2-3.14.7.416.jar file:/D:/Java Projects/Minecraft Mods/Brighten Up/.gradle/minecraft/jei_1.10.2-3.14.7.416.jar file:/D:/Java Projects/Minecraft Mods/Brighten Up/.gradle/minecraft/jei_1.10.2.jar . If I remove the dependencies from build.gradle the output still gives a ton of errors, mostly it telling me not to use code only available in java 1.7+. What did I do wrong?
  21. I did find an existing version of CoFH-Core on there, but when I ran gradlew dependencies it showed testRuntime - Runtime dependencies for source set 'test'. +--- com.github.CoFH:CoFHCore:a19dbc5eea | \--- mezz.jei:jei_1.11.2:4.5.0.+ FAILED Is this an error on CoFH's part? I don't think 4.5.0.+ is a valid version of JEI (I might be wrong though). Also, I tried adding my own version of JEI, also via jitpack, but JEI doesn't show up in game, and no new files are created in my project directory. Is this intended? Do I still need a jar for viewing the CoFH's source code in my IDE?
  22. A mod I want to create requires CoFH core, and I see no source download for this. Therefore I go onto their github and try and add the clone command found there to my build.gradle dependencies { compile 'https://github.com/CoFH/CoFHCore.git' } (The code isn't actually all on one line, the formatter was just not happy with me copy pasting it.) I run "gradlew setupDecompWorkspace --refresh-dependencies", followed by gradlew dependencies, but it says lines like testRuntime - Runtime dependencies for source set 'test'. \--- https://github.com/CoFH/CoFHCore.git: FAILED . So instead I use compile 'scm:git:git://github.com/CoFH/CoFHCore.git' which I found in their build.gradle, but it provides a similar result. What am I doing wrong?
  23. Is this also how it works outside a dev environment?
  24. I noticed that both the client and server files (like options.txt, server.properties, resourcepacks etc) are in the "run" directory. This makes me wonder how it loads and handles config files when you have both a client and server open at the same time (via "gradlew runClient" and "gradlew runServer" for example). I made a boolean config value and a command that prints that value, and it turns out that if I change the value via the GUI in the client but don't change it in actual file the command will post different results. Could someone explain how it manages to keep track of both at the same time?
  25. A very simple mod that creates the teleportXP gamerule. When this gamerule is active it will teleport any XP orb to the closest player. This will increase performance when you accidentally leave your XP farm running while building, hunting etc. Currently working on making a config file were you can disable the gamerule requirement and making the mod prioritize non-creative players. Downloads Changelog
×
×
  • Create New...

Important Information

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