Jump to content

matthew123

Members
  • Posts

    132
  • Joined

  • Last visited

Everything posted by matthew123

  1. I am using onlyIn to remind myself where this is executed. It doesn't create any issues, does it?
  2. public class MudWallBlockEntity extends Entity { private static final BlockState blockState = ModBlocks.TEMPORARY_DIRT_BLOCK.get().defaultBlockState(); private int height; private OneTimeRunnable finishJutsuOnce; private BlockPos startingBlockPos; private BlockPos endBlockPos; private BlockPos oldPos; private int ticks; public MudWallBlockEntity(EntityType<? extends MudWallBlockEntity> entityType, World level) { super(entityType, level); } @OnlyIn(Dist.CLIENT) public MudWallBlockEntity(EntityType<? extends MudWallBlockEntity> entityType, World level, BlockPos position, int height, OneTimeRunnable releaseJutsu) { super(entityType, level); this.startingBlockPos = position; this.endBlockPos = new BlockPos(startingBlockPos.getX(), height, startingBlockPos.getZ()); this.oldPos = position; this.height = height; this.finishJutsuOnce = releaseJutsu; this.setPos(position.getX(), position.getY(), position.getZ()); this.ticks = 0; } @Override protected void defineSynchedData() { } @Override protected void readAdditionalSaveData(@Nonnull CompoundNBT pCompound) { startingBlockPos = new BlockPos(pCompound.getInt("StartX"), pCompound.getInt("StartY"),pCompound.getInt("StartZ")); endBlockPos = new BlockPos(startingBlockPos.getX(), pCompound.getInt("Height"), startingBlockPos.getZ()); oldPos = new BlockPos(startingBlockPos.getX(), pCompound.getInt("CurrentHeight"), startingBlockPos.getZ()); } @Override protected void addAdditionalSaveData(@Nonnull CompoundNBT pCompound) { pCompound.putInt("StartX", startingBlockPos.getX()); pCompound.putInt("StartY", startingBlockPos.getY()); pCompound.putInt("StartZ", startingBlockPos.getZ()); pCompound.putInt("Height", height); pCompound.putInt("CurrentHeight", oldPos.getY()); } @Nonnull @Override public IPacket<?> getAddEntityPacket() { return new SSpawnObjectPacket(this, Block.getId(this.getBlockState())); } @Override public void tick() { LogManager.getLogger().info("ticks: " + ticks++ + " current " + blockPosition() + " old " + oldPos); if(blockPosition().equals(endBlockPos)){ if(finishJutsuOnce != null){ finishJutsuOnce.execute(); } remove(); return; } if(blockPosition().equals(oldPos.above())){ oldPos = blockPosition(); level.setBlockAndUpdate(blockPosition(), blockState); } setDeltaMovement(0, 0.1, 0); move(MoverType.SELF, getDeltaMovement()); } public BlockState getBlockState() { return blockState; } public BlockPos getStartingBlockPos() { return startingBlockPos; } @Override public boolean canBeCollidedWith() { return false; } @Override protected boolean canAddPassenger(Entity pPassenger) { return false; } @Override public boolean canChangeDimensions() { return false; } }
  3. The entity creates a pillar of blocks. It appears to work fine; the blocks are getting placed. But the entity is not rendering. It should be displaying interpolated movement upwards. Instead, the blocks just appear (so the entity is invisible). public void tick() { LogManager.getLogger().info("ticks: " + ticks++ + " current " + blockPosition() + " old " + oldPos); if(blockPosition().equals(endBlockPos)){ if(releaseJutsuOnce != null){ releaseJutsuOnce.execute(); } remove(); return; } if(blockPosition().equals(oldPos.above())){ oldPos = blockPosition(); level.setBlockAndUpdate(blockPosition(), blockState); } setDeltaMovement(0, 0.1, 0); move(MoverType.SELF, getDeltaMovement()); } Renderer (copied from falling block): public class MudWallBlockEntityRenderer extends EntityRenderer<MudWallBlockEntity> { public MudWallBlockEntityRenderer(EntityRendererManager entityRendererManager) { super(entityRendererManager); this.shadowRadius = 0.5F; } @Override public void render(MudWallBlockEntity entity, float entityYaw, float partialTicks, MatrixStack matrixStack, IRenderTypeBuffer buffer, int packedLight) { BlockState blockstate = entity.getBlockState(); if (blockstate.getRenderShape() == BlockRenderType.MODEL) { World world = entity.getCommandSenderWorld(); if (blockstate != world.getBlockState(entity.blockPosition()) && blockstate.getRenderShape() != BlockRenderType.INVISIBLE) { matrixStack.pushPose(); BlockPos blockpos = new BlockPos(entity.getX(), entity.getBoundingBox().maxY, entity.getZ()); matrixStack.translate(-0.5D, 0.0D, -0.5D); BlockRendererDispatcher blockrendererdispatcher = Minecraft.getInstance().getBlockRenderer(); for (net.minecraft.client.renderer.RenderType type : net.minecraft.client.renderer.RenderType.chunkBufferLayers()) { if (RenderTypeLookup.canRenderInLayer(blockstate, type)) { net.minecraftforge.client.ForgeHooksClient.setRenderLayer(type); blockrendererdispatcher.getModelRenderer().tesselateBlock(world, blockrendererdispatcher.getBlockModel(blockstate), blockstate, blockpos, matrixStack, buffer.getBuffer(type), false, new Random(), blockstate.getSeed(entity.getStartingBlockPos()), OverlayTexture.NO_OVERLAY); } } net.minecraftforge.client.ForgeHooksClient.setRenderLayer(null); matrixStack.popPose(); super.render(entity, entityYaw, partialTicks, matrixStack, buffer, packedLight); } } } @Override public ResourceLocation getTextureLocation(MudWallBlockEntity pEntity) { return AtlasTexture.LOCATION_BLOCKS; } } Registration: RenderingRegistry.registerEntityRenderingHandler(ModEntities.MUD_WALL_BLOCK_ENTITY.get(), MudWallBlockEntityRenderer::new);
  4. Then what do I do? My entity just animates a block model going up then places it. Is there another way to do it? P.S the server places that block independently without syncing it.
  5. I have an entity which used only on the clients. I theorize that this is the reason my tick() method is not getting called. Is there any way to manually schedule it for ticking? The entity is spawned into the world via addFreshEntity on ClientWorld. It moves to a certain position then places a block there and removes itself.
  6. I have another issue. Let me explain my use of the entity. The server is spawning that entity, that just goes upwards. When it reaches the position of the block above, it deletes itself. At that time, the entity will place a block there. This entity is spawned only on the client, using a packet. Multiple may be spawned at a time. I haven't made the entity place the blocks yet, because I ran into an issue. My game bugs out randomly, when spawning these entities. My modded overlay disappears, my placer stops moving and oscillates back and forth, and I can't do anything. public class MudWallBlockEntity extends Entity { private BlockPos startingBlockPos; private BlockState blockState; private int ticks; public MudWallBlockEntity(EntityType<? extends MudWallBlockEntity> entityType, World level){ super(entityType, level); } public MudWallBlockEntity(EntityType<? extends MudWallBlockEntity> entityType, World level, BlockPos position, BlockState block){ super(entityType, level); this.startingBlockPos = position; this.blockState = block; this.setPos(position.getX(), position.getY(), position.getZ()); this.ticks = 0; } @Override protected void defineSynchedData() { } @Override protected void readAdditionalSaveData(@Nonnull CompoundNBT pCompound) { } @Override protected void addAdditionalSaveData(@Nonnull CompoundNBT pCompound) { } @Override public IPacket<?> getAddEntityPacket() { LogManager.getLogger().error("THE GAME CRASHED BECAUSE THE /SUMMON COMMAND WAS USED TO SUMMON MudWallBlockEntity!"); return null; } @Override public void tick() { if(ticks++ == 0){ // the entity was placed into the world. } LogManager.getLogger().info("ticks: " + ticks); if(blockPosition().getY() >= startingBlockPos.getY()){ remove(); return; } setDeltaMovement(0, 0.05, 0); move(MoverType.SELF, getDeltaMovement()); } public BlockState getBlockState() { return blockState; } public BlockPos getStartingBlockPos(){ return startingBlockPos; } @Override public boolean canBeCollidedWith() { return false; } @Override protected boolean canAddPassenger(Entity pPassenger) { return false; } @Override public boolean canChangeDimensions() { return false; } } public class MudWallBlockEntityRenderer extends EntityRenderer<MudWallBlockEntity> { public MudWallBlockEntityRenderer(EntityRendererManager entityRendererManager) { super(entityRendererManager); this.shadowRadius = 0.5F; } @Override public void render(MudWallBlockEntity entity, float entityYaw, float partialTicks, MatrixStack matrixStack, IRenderTypeBuffer buffer, int packedLight) { BlockState blockstate = entity.getBlockState(); if (blockstate.getRenderShape() == BlockRenderType.MODEL) { World world = entity.getCommandSenderWorld(); if (blockstate != world.getBlockState(entity.blockPosition()) && blockstate.getRenderShape() != BlockRenderType.INVISIBLE) { matrixStack.pushPose(); BlockPos blockpos = new BlockPos(entity.getX(), entity.getBoundingBox().maxY, entity.getZ()); matrixStack.translate(-0.5D, 0.0D, -0.5D); BlockRendererDispatcher blockrendererdispatcher = Minecraft.getInstance().getBlockRenderer(); for (net.minecraft.client.renderer.RenderType type : net.minecraft.client.renderer.RenderType.chunkBufferLayers()) { if (RenderTypeLookup.canRenderInLayer(blockstate, type)) { net.minecraftforge.client.ForgeHooksClient.setRenderLayer(type); blockrendererdispatcher.getModelRenderer().tesselateBlock(world, blockrendererdispatcher.getBlockModel(blockstate), blockstate, blockpos, matrixStack,buffer.getBuffer(type), false, new Random(), blockstate.getSeed(entity.getStartingBlockPos()), OverlayTexture.NO_OVERLAY); } } net.minecraftforge.client.ForgeHooksClient.setRenderLayer(null); matrixStack.popPose(); super.render(entity, entityYaw, partialTicks, matrixStack, buffer, packedLight); } } } @Override public ResourceLocation getTextureLocation(MudWallBlockEntity pEntity) { return AtlasTexture.LOCATION_BLOCKS; } } Spawning code: public static void handlePacket(ServerSpawnMudWallEntityPacket message, Supplier<NetworkEvent.Context> ctx) { PlayerEntity player = (PlayerEntity) Minecraft.getInstance().cameraEntity; ClientWorld level = (ClientWorld) (player.getCommandSenderWorld()); for(Tuple<BlockPos, UUID> spawnData : message.getSpawnList()){ BlockPos blockPos = spawnData.getFirst(); UUID uuid = spawnData.getSecond(); MudWallBlockEntity entity = new MudWallBlockEntity( ModEntities.MUD_WALL_BLOCK_ENTITY.get(), level, blockPos, ModBlocks.TEMPORARY_DIRT_BLOCK.get().defaultBlockState()); entity.setPacketCoordinates(blockPos.getX(), blockPos.getY(), blockPos.getZ()); entity.moveTo(blockPos, 0f, 0f); entity.setUUID(uuid); level.putNonPlayerEntity(entities++, entity); } } The UUID is just UUID.getRandom. "entities" is an integer. The value printed in the entity tick is one tick (so the method ran once before doing entity.remove()) Here is what happens: https://streamable.com/mc98kl
  7. seriously, why don't you analyze the darn code? just look for float fields.
  8. Then analyze the vanilla code and find the right names!!!
  9. Thanks, but I had already solved it.
  10. You should read the documentation from mcforge.readthedocs.io. "On RenderPlayerEvent.Pre" is exactly what is sounds like : on that event, do as instructed above. "I even know java, c++ and python" irrelevant. Programming is not necessarily about how many languages you've learned, but how well you can use one of them. Just being familiar with an OOP language would have made it possible to study the vanilla code. I'll tell you again. On RenderPlayerEvent.Pre set the visible field on the rightArm model to false, and in post, set it to true, then set it's x, y, z position and rotation values (look at how vanilla does it). Then call the render method passing in the matrix from the event object. Also see how vanilla does it. This example is not very good for practical purposes, but I hope is enough to satisfy the stack overflow trend: @SubscribeEvent public void renderPlayerPre(RenderPlayerEvent.Pre event) { event.getRenderer().getModel().rightArm.visible = false; } @SubscribeEvent public void renderPlayerPost(RenderPlayerEvent.Post event) { PlayerEntity player = event.getPlayer(); PlayerModel<AbstractClientPlayerEntity> model = event.getRenderer().getModel(); ModelRenderer rightArm = model.rightArm; rightArm.visible = true; // rotation point rightArm.x = -MathHelper.cos((float) Math.toRadians(player.yRot)) * 5.0F; rightArm.y = 20; rightArm.z = -MathHelper.sin((float) Math.toRadians(player.yRot)) * 5.0F; // rotation rightArm.xRot = (float) Math.toRadians(42); rightArm.yRot = (float) -Math.toRadians(player.yBodyRot); rightArm.render( event.getMatrixStack(), event.getBuffers().getBuffer(RenderType.entitySolid(((AbstractClientPlayerEntity)player).getSkinTextureLocation())), Minecraft.getInstance().getEntityRenderDispatcher().getPackedLightCoords(player, 1f), OverlayTexture.NO_OVERLAY); }
  11. I myself learned modding a couple weeks ago and did not have any trouble following the suggestion from dieseben07 which was: "cancel the event and do the rendering yourself". If you want to get anywhere with modding, you need to learn it properly. On PlayerRenderEvent.pre, take the arm model, and set the visible field to false. In RenderPlayerEvent.post, set the field to true, then adjust the x, y, z fields of the arm model (the rotation points). Y is either 20 or 17.5 if crouching (i believe). Use some trigonometry to calculate the rest from the player's rotations. Then you have the xRot, ... fields which you can modify. You might need some math for that too. After you're done modifying the pose, call render for the arm model. It takes the matrix stack from the event, a vertex builder, ... you can see an example of using this from the vanilla rendering code. I actually learned how to do this by studying vanilla code. You should too! All the code you need is there.
  12. check if your event is getting fired, first (and you must be in 3rd person on singleplayer for it to work). second, modifying those values doesn't do anything. It is already rendered (in post) or the values will be overwritten for rendering (in pre). You need to cancel the rendering and do it yourself. I do it with the field model#visible = false in pre, then in post, set it to true, then modify the rotation points and angles, then render it using the render method that takes the buffer, vertex builder, ... it would be much easier to use rightArmPose = ... in PRE.
  13. I am not sure I follow. How would I make the block "fall" or "rise"?
  14. I would like to render a texture over the player's head (specifically, the eyes). How would I do that?
  15. That worked, thanks.
  16. Then, how would I go about rotating / animating things in the player model?
  17. Also does not work.
  18. Huh. Now that i think about it, the POST event is AFTER the thing was rendered. So I may need to do it in PRE, right?
  19. event.getRenderer().getModel().rightArm.yRot = 50f; event.getRenderer().getModel().rightArm.xRot = 50f; I also need to render two hands in first person. Is it possible to somehow copy the matrix from the stack then add it on top after rotation to emulate a second hand?
  20. I will just be tweaking the Euler angle until i get it right.
  21. I will implement the hand animation using RenderHandEvent. How do I work with these quaternions?
  22. By going into third person The arm did not rotate. But I also want the pose in first person to change.
  23. Well, it is not working anyway. I want to modify the player's arm rotation (the model rotations in general). How would I do that? I also want to do it for all players that are tracking.
  24. Oh, I get it. On singleplayer, it does not render the player model. Thus, theoretically, it should work when I go into 3rd person?
  25. Is that event only for remote players? I want to modify my player.
×
×
  • Create New...

Important Information

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