Jump to content

Povstalec

Members
  • Posts

    20
  • Joined

  • Last visited

Everything posted by Povstalec

  1. Alright, so I have a Structure which generates exactly once per dimension (my custom modded Dimensions + Overworld) by having it always generate at the same coordinates. This structure is central to my mod, which is why I always need it to generate. The problem starts when my mod is used along with another mod that adds new biomes to the Overworld. Since those biomes may not always be listed within Forge/Vanilla tags I use to check whether my structure can generate or not, my structure sometimes does not generate. My initial idea was overriding the code that allows the structure to generate if the biome is valid and adding an OR option for when the Dimension is Overworld. However, when looking through the related Structure code, I've been unable to find any way to check what Dimension the Structure may be generating in. And so I would like to ask here. Is there anything I've missed or are there perhaps some other ways to make sure my Structure always generates?
  2. As the title says, AbstractTickableSoundInstance I made can be heard anywhere, not just in a radius around the BlockEntity. I might be blind, but I just can't find any value that would allow me to change that. Looking at other sounds that extend it didn't help me find anything either, so I'm most likely doing someting wrong. Can anyone help me find what it is I'm doing wrong? Sound: https://github.com/Povstalec/StargateJourney/blob/main/src/main/java/net/povstalec/sgjourney/client/sound/sounds/WormholeIdleSound.java BlockEntity that plays the sound: https://github.com/Povstalec/StargateJourney/blob/main/src/main/java/net/povstalec/sgjourney/common/block_entities/stargate/AbstractStargateEntity.java#L661
  3. Oh no, I don't want to do any lerping, I know it's just for client (though I can see why it may have sounded like I do, I should have worded it better). I was just commenting on how baffled I am by the fact that the old values are the same as the new values, since I was expecting them to be different (especially in the case of lerping). That's what I tried to do when I found out the old values and new values are idetical. Then after some more testing, I realized they're identical only on the server. In terms of syncing, I've found ClientboundSetEntityMotionPacket that does the job pretty well.
  4. Alright, so for a second I thought I had a solution when I remembered the old position Entities use for lerping is public public final Vec3 getPosition(float p_20319_) { double d0 = Mth.lerp((double)p_20319_, this.xo, this.getX()); double d1 = Mth.lerp((double)p_20319_, this.yo, this.getY()); double d2 = Mth.lerp((double)p_20319_, this.zo, this.getZ()); return new Vec3(d0, d1, d2); } and while I was able to get the position on server, I found out the old position is identical to the current position (both on client and server), which means if I subtract it from the current position, I still get 0.0, what's up with that? I how can the game lerp motion if the two positions are the same?
  5. I already know how to sync it to the Client from the Server, that's not a problem. But I can't get it to sync from the Client to Server with Entity#hurtMarked, that's the problem. If I try to get the delta movement on Server, the vector looks like this: (0.0, 0.0, 0.0) so saving it and then applying it to the Entity just makes it stop. Are there any other methods Minecraft uses for syncing to Server?
  6. So I've noticed that if I try to get Player's delta movement, it returns some values on Client, but on Server, the vector is just a bunch of zeros. I'm guessing this is because Player movement is mainly handled on Client, but I'd like to ask if there's any way to get Player's movement on Server (for example, if there was a block the Player could pass through only at a certain speed along one axis, or if the block would save Player momentum and then set that Player's momentum again when needed).
  7. So I've come to the conclusion that Packets simply aren't sending the info fast enough and removed the use of packets altogether. Instead I'm just doing the same thing on Client as I am on Server, which does result in a smooth animation, but I can't really control the animation, since most of the stuff the animation depends on is server only. Either way, thanks a lot for your help.
  8. Alright, I see what you mean. But there's a slight problem: I'm not doing any logic with the second renderer. I just made an arbitrary value that is raised by one at the end of each tick and gets sent to the client via a packet, nothing else. Any other ideas?
  9. Alright, so using the other renderer for printing out the values, I got this: Rotation: 16 P-Rotation: 17.39999 Tick: 131 P-Tick: 0.6999946 Rotation: 16 P-Rotation: 16.35999 Tick: 131 P-Tick: 0.17999458 Rotation: 18 P-Rotation: 19.319988 Tick: 132 P-Tick: 0.6599946 Rotation: 18 P-Rotation: 18.159988 Tick: 132 P-Tick: 0.07999456 Rotation: 20 P-Rotation: 21.19999 Tick: 133 P-Tick: 0.59999454 Rotation: 20 P-Rotation: 20.079988 Tick: 133 P-Tick: 0.03999448 Rotation is the progress of the block entity. P-Rotation is progress with partial ticks (multiplied by two) added. Tick is tick. P-Tick is partial tick. I can see a pattern of the partial ticks reaching value 1 before the tick ends, which means they go back down to 0 during the same tick and that causes the animation to stutter. EDIT: And this is how it looks after pausing the game a few times to get a smooth animation: Rotation: 182 P-Rotation: 182.12 Tick: 185 P-Tick: 0.060000777 Rotation: 182 P-Rotation: 182.76 Tick: 185 P-Tick: 0.38000077 Rotation: 182 P-Rotation: 183.44 Tick: 185 P-Tick: 0.72000074 Rotation: 184 P-Rotation: 184.12 Tick: 186 P-Tick: 0.060000777 Rotation: 184 P-Rotation: 184.76 Tick: 186 P-Tick: 0.38000077 Rotation: 184 P-Rotation: 185.44 Tick: 186 P-Tick: 0.72000074 Rotation: 186 P-Rotation: 186.12 Tick: 187 P-Tick: 0.060000777 Rotation: 186 P-Rotation: 186.76 Tick: 187 P-Tick: 0.38000077 Rotation: 186 P-Rotation: 187.44 Tick: 187 P-Tick: 0.72000074 I'm not sure why it prints 3 values when it was only able to print 2 values per tick just a few minutes ago.
  10. Alright, so for the sake of testing, I've made another renderer which adds progress in the render method itself and that animation is perfectly smooth (although the progress obviously doesn't stop when I pause the game). That means the problem really is in syncing. I'll try printing out the height like you suggested, but in the meanwhile, do you know how I could fix this? I'm fairly sure my packets are being sent properly and I can't really think of any other place in the code where desync could happen.
  11. I know it's a value between 0 and 1, that's why I'm multiplying it by four after adding the previous position to get my preffered outcome. As for the Mth#lerp I've essentially copied the code from that and changed it to fit me needs Mth#lerp code: public static float lerp(float partialTick, float progressOld, float progress) { return progressOld + partialTick * (progress - progressOld); } my code: ringHeight = (movingHeight + partialTicks) * 4; I just removed the initial multiplication of partialTicks by (progress - progressOld) because it always changes by 1 pixel anyway. The movingHeight corresponds to progressOld. Then I multiplied everything by 4 to make it go higher. Math#lerp has the same effect, I just removed it from my code so that I don't have to call the method every time. No other reason really. If it works sometimes and sometimes doesn't, I can't be using it completely incorrectly, right? Or is there perhaps something more Math#lerp does other than the lerping math?
  12. Alright, so I have a Block Entity renderer and I want it to have a smooth animation. My current animations work well, other than having a lower framerate, which is obvious. However, when I try interpolating using Partial Ticks, the results vary greatly. Sometimes the animation is perfectly smooth, other times it stutters a lot. From testing I know the varying results are caused by me pausing the game and coming back. When I pause the game, the rendering does indeed stop, but Partial Ticks still do their thing and when I unpause it, Partial Ticks are ahead/behind where they were, which causes the Block Entity animation to start stuttering. How do I get around this issue? Here's my code: (it's basically raising and then lowering five ring models one by one) public class TransportRingsRenderer implements BlockEntityRenderer<TransportRingsEntity> { private static final ResourceLocation TRANSPORT_RINGS_TEXTURE = new ResourceLocation(StargateJourney.MODID, "textures/block/transport_rings.png"); private final ModelPart first_ring; private final ModelPart second_ring; private final ModelPart third_ring; private final ModelPart fourth_ring; private final ModelPart fifth_ring; public TransportRingsRenderer(BlockEntityRendererProvider.Context p_173554_) { ModelPart modelpart = p_173554_.bakeLayer(LayerInit.TRANSPORT_RING_LAYER); this.first_ring = modelpart.getChild("first_ring"); this.second_ring = modelpart.getChild("second_ring"); this.third_ring = modelpart.getChild("third_ring"); this.fourth_ring = modelpart.getChild("fourth_ring"); this.fifth_ring = modelpart.getChild("fifth_ring"); } private float getHeight(int ringNumber, int emptySpace, int transportHeight, int ticks, int progress, float partialTicks) { float ringHeight = 0; int startTicks = 6 * (ringNumber - 1); int movingHeight = progress - 6 * (ringNumber - 1); int staticHeight = transportHeight - 2 * (ringNumber - 1); int stopHeight = transportHeight + 17 - 4 * (5 - ringNumber); if(ticks == progress && progress > startTicks && progress < stopHeight) ringHeight = (movingHeight + partialTicks) * 4; else if(progress >= stopHeight) ringHeight = staticHeight * 4; else if(ticks != progress && progress > startTicks && progress < stopHeight) ringHeight = (movingHeight - partialTicks) * 4; if(emptySpace > 0) return ringHeight; else if(emptySpace < 0) return -ringHeight; return 0; } @Override public void render(TransportRingsEntity rings, float partialTick, PoseStack stack, MultiBufferSource source, int combinedLight, int combinedOverlay) { VertexConsumer vertexconsumer = source.getBuffer(RenderType.entitySolid(TRANSPORT_RINGS_TEXTURE)); // It takes the rings 29 ticks to get into position if there is empty space right above them if(rings.progress > 0) { this.first_ring.y = getHeight(1, rings.emptySpace, rings.transportHeight, rings.ticks, rings.progress, partialTick); this.first_ring.render(stack, vertexconsumer, rings.transportLight, combinedOverlay); } if(rings.progress > 6) { this.second_ring.y = getHeight(2, rings.emptySpace, rings.transportHeight, rings.ticks, rings.progress, partialTick); this.second_ring.render(stack, vertexconsumer, rings.transportLight, combinedOverlay); } if(rings.progress > 12) { this.third_ring.y = getHeight(3, rings.emptySpace, rings.transportHeight, rings.ticks, rings.progress, partialTick); this.third_ring.render(stack, vertexconsumer, rings.transportLight, combinedOverlay); } if(rings.progress > 18) { this.fourth_ring.y = getHeight(4, rings.emptySpace, rings.transportHeight, rings.ticks, rings.progress, partialTick); this.fourth_ring.render(stack, vertexconsumer, rings.transportLight, combinedOverlay); } this.fifth_ring.y = getHeight(5, rings.emptySpace, rings.transportHeight, rings.ticks, rings.progress, partialTick); if(rings.progress <= 24) this.fifth_ring.render(stack, vertexconsumer, combinedLight, combinedOverlay); else this.fifth_ring.render(stack, vertexconsumer, rings.transportLight, combinedOverlay); } }
  13. Alright, thanks, that helped a lot. It gave me the idea to extend the BlockItem class and add some stuff to updateCustomBlockEntityTag(), which now deletes the randomly generated address and replaces it with the one from the BlockItem. It's probably not the best way to go around it, but it does what I want for now. I'll probably come up with something better later down the line.
  14. Block Entity code SavedData code Block code Yeah, I know, I'm making sure it only runs on server, so the problem can't be there.
  15. I've got a BlockEntity, which can save its data to an item when broken(just like a Shulker Box). I use this to generate an "address" - When the BlockEntity is placed in the world for the first time, it will generate a new address and save the address to SavedData. When it is broken, the NBT data is saved to a BlockItem and the address is deleted from SavedData. When it is placed again, this time using the BlockItem that has data from the previous BlockEntity saved, it should copy the data and check if it has the address tag; if it does, it will save the address to SavedData again. The last part used to work for me, but then I changed some things and forgot to make a backup, so it doesn't work properly now. What it does now is: The BlockEntity checks if there is an address tag, but there isn't one, so it generates a new address which it saves to SavedData. The address tag is then copied from the BlockItem immediately after, so when I click on it to see the address, the address is different from what is now saved in SavedData. I'm pretty sure the problem lies in the fact that onLoad() is called before BlockItem NBT data is copied over. I'm using onLoad() to check whether or not it should generate an address and I know the BlockItem NBT data is stored correctly, because: 1. I'm saving more than just the address and everything else works perfectly and 2. the BlockEntity shows the correct address after I place it and click on it. Is there a way to fix/work around this?
  16. Technically, yes, I don't neet to keep the chunk loaded, nor do I need the block entity just to teleport stuff there. But I'm trying to recreate Transport Rings from Stargate, which work by having a platform on each end, that does its own thing. My block entities represent these platforms. Each one takes a different amount of time to get into position animation-wise, so when the first block entity is has already finished its animation, the second entity might still be in the middle of its own animation. Each block entity waits for a certain amount of ticks to change its blockstate at the end of the animation cycle(so that redstone can detect when it's done), so unloading it prematurely/not loading it at all would mean that the blockstate never gets changed and since mysystem works by only allowing block entities to connect to other block entities if they're done animating, the block entity would essentially become inaccesssible until a player loaded it and allowed it to finish its animation. So unless there's a way to do what I want without a loaded chunk, I'd preferably like to keep the loaded chunk. I haven't used Capabilities before, so maybe what you told me can be used to fix my problem without getting rid of the loaded chunk, I dunno. I'll see once I learn a bit more about them. But just in case it's not, any other ways to do it?
  17. Hello, I have a block entity that is using entity.teleportTo(x, y, z); to teleport an entity(Armor Stand in this case) into a chunk that's being kept loaded with ForgeChunkManager.forceChunk(level.getServer().getLevel(Level.OVERWORLD), StargateJourney.MODID, getBlockPos(), level.getChunk(getBlockPos()).getPos().x, level.getChunk(getBlockPos()).getPos().z, true, true); It works well, however, when I teleport the player alongside the entity, the entity doesn't load. It's still there, because if the player leaves to unload the chunk and then returns, the entity appears where it should. I've tried fixing it by not forceloading the chunk and the entity loads without problems, but I actually need to have the chunk loaded, because I have a block entity in said chunk, that is ticking(essentially, it's the second end of a teleporter mechanism). Is there a workaround to load the entity manually or even better, have it never unload in the first place?
×
×
  • Create New...

Important Information

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