Jump to content

Jetug

Members
  • Posts

    32
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Jetug

  1. I found it. It's the IForgeEntity#getStepHeight()
  2. I have a rideable LivingEntity and when I ride on it near a block it automatically climbs on it. How to disable it? Here is my travel method: @Override public void travel(@NotNull Vec3 travelVector) { if (!isAlive()) return; if (isVehicle() && hasPassenger()) { var entity = getControllingPassenger(); if(entity == null) return; setRotationMatchingPassenger(entity); if (isControlledByLocalInstance()) super.travel(new Vec3(entity.xxa, travelVector.y, entity.zza)); else setDeltaMovement(Vec3.ZERO); } else { super.travel(travelVector); } }
  3. Thanks! It worked
  4. From finishUsingItem() in my item class public ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity entity) { if (entity instanceof Player player) setAddMaxHealth(player, -10) return super.finishUsingItem(stack, level, entity); } The code works fine only when the value is positive
  5. I'm modifying the player's max health attribute but it only updates when the player gets damage private static void addMaxHealth(Player player, double value) { player.getAttribute(Attributes.MAX_HEALTH) .addPermanentModifier(new AttributeModifier("health", value, AttributeModifier.Operation.ADDITION)); }
  6. Because I am working on a feature related to username and if I could change it testing would be much easier
  7. I tried to write mcUsername=somename in gradle.properties but it didn't work
  8. Turns out it was much easier @OnlyIn(Dist.CLIENT) @SubscribeEvent() public static void onRenderHand(RenderArmEvent event) { if(handRenderer == null) handRenderer = new CustomHandRenderer(); var poseStack = new PoseStack(); poseStack.translate(0.5, -0.5, -0.6); handRenderer.render( null, poseStack, event.getMultiBufferSource(), event.getPackedLight()); event.setCanceled(true); } https://i.imgur.com/tHo5mqo.png
  9. I wrote this code and my hand model renders but doesn't follow camera rotation(https://imgur.com/1pgyxUl). I took the PoseStack installation code from GameRenderer#renderLeve. @OnlyIn(Dist.CLIENT) @SubscribeEvent() public static void onRenderHand(RenderArmEvent event) { if(handRenderer == null) handRenderer = new CustomHandRenderer(); var minecraft = Minecraft.getInstance(); var camera = minecraft.gameRenderer.getMainCamera(); var poseStack = new PoseStack(); poseStack.mulPose(Vector3f.XP.rotationDegrees(camera.getXRot())); poseStack.mulPose(Vector3f.YP.rotationDegrees(camera.getYRot() + 180.0F)); applyItemArmTransform(poseStack, HumanoidArm.RIGHT, 1); handRenderer.render( null, poseStack, event.getMultiBufferSource(), event.getPackedLight()); event.setCanceled(true); } For rendering I use GeckoLib
  10. I want to make a custom first person hand model. Can anyone tell me how can I do this or give me examples of open source mods that have done this
  11. Never heard of mixin before, very cool tool, rewrote everything with mixin and it works. Thanks.
  12. I needed to rewrite the GameRenderer#pick() method so I wrote my own GameRenderer class and set an instance of it to Minecraft#gameRenderer with reflection: @Mod.EventBusSubscriber(modid = Global.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) public final class SetupEvents { @SubscribeEvent() public static void onRegisterRenderers(EntityRenderersEvent.RegisterRenderers event){ try { var minecraft = Minecraft.getInstance(); var gameRenderer = new ModGameRenderer(minecraft, minecraft.getResourceManager() ,minecraft.renderBuffers()); Field field = minecraft.getClass().getDeclaredField("gameRenderer"); field.setAccessible(true); field.set(minecraft, gameRenderer); } catch (Exception e) { e.printStackTrace(); } } } And when I run the mod in the IDE my pick() method works but when I build the mod and run it through the minecraft launcher it doesn't. Maybe it's because of the GeckoLib library that I use in my project?
  13. I want to get the skin of a certain player. I tried to get it with AbstractClientPlayer#getSkinTextureLocation but it returns the default Steve or Alex skin and it looks like it only works with offline players
  14. Maybe harder but i already did it :) Anyway thank you, I corrected the method and now it works public static NativeImage getNativeImage(BufferedImage img) { NativeImage nativeImage = new NativeImage(img.getWidth(), img.getHeight(), true); for (int x = 0; x < img.getWidth(); x++) { for (int y = 0; y < img.getHeight(); y++) { int clr = img.getRGB(x, y); int alpha = (clr & 0xff000000) >> 24; int red = (clr & 0x00ff0000) >> 16; int green = (clr & 0x0000ff00) >> 8; int blue = clr & 0x000000ff; int rgb = alpha; rgb = (rgb << 8) + blue; rgb = (rgb << 8) + green; rgb = (rgb << 8) + red; nativeImage.setPixelRGBA(x, y, rgb); } } return nativeImage; }
  15. I decided that it would be easier to do this with the resizing of the player texture and wrote this code while waiting for an answer: @Override public void render(PoseStack matrixStackIn, MultiBufferSource bufferIn, int packedLightIn, PowerArmorEntity entity, float limbSwing, float limbSwingAmount, float parti if(!entity.isInvisible() && entity.isVehicle() && entity.getControllingPassenger() instanceof AbstractClientPlayer clientPlayer ) { var texture = getHeadResourceLocation(clientPlayer, entity); if (texture == null) return; var cameo = RenderType.armorCutoutNoCull(texture); int overlay = OverlayTexture.NO_OVERLAY; matrixStackIn.pushPose(); matrixStackIn.scale(1.0f, 1.0f, 1.0f); matrixStackIn.translate(0.0d, 0.0d, 0.0d); this.getRenderer().render( getEntityModel().getModel(POWER_ARMOR_MODEL_LOCATION), entity, partialTicks, cameo, matrixStackIn, bufferIn, bufferIn.getBuffer(cameo), packedLightIn, overlay, 1f, 1f, 1f, 1f); matrixStackIn.popPose(); } } @Nullable private ResourceLocation getHeadResourceLocation(AbstractClientPlayer clientPlayer, PowerArmorEntity entity) { var tag = clientPlayer.getUUID().toString(); if (playerTextures.containsKey(tag)) { return playerTextures.get(tag); } else { var playerHead = getPlayerHead(clientPlayer); var entityTextureRL = entityRenderer.getTextureLocation(entity); var entityTexture = resourceToBufferedImage(entityTextureRL); if (playerHead == null || entityTexture == null) return null; playerHead = extendImage(playerHead, entityTexture.getWidth(), entityTexture.getHeight()); var nativeImage = getNativeImage(playerHead); var dynamicTexture = new DynamicTexture(nativeImage); var finalTextureLocation = new ResourceLocation(Global.MOD_ID, tag); Minecraft.getInstance().getTextureManager().register(finalTextureLocation, dynamicTexture); playerTextures.put(tag, finalTextureLocation); return finalTextureLocation; } } And it actually worked, but Steve looks like he's turned into a vampire I think the problem is in this method: public static NativeImage getNativeImage(BufferedImage img) { NativeImage nativeImage = new NativeImage(img.getWidth(), img.getHeight(), true); for (int x = 0; x < img.getWidth(); x++) { for (int y = 0; y < img.getHeight(); y++) { var color = img.getRGB(x, y); nativeImage.setPixelRGBA(x, y, color); } } return nativeImage; } Full code: https://github.com/Jetug/PowerArmorMod/blob/1.18/src/main/java/com/jetug/power_armor_mod/client/render/layers/PlayerHeadLayer.java
  16. I understood the logic, but I don't know how to implement it. I'm new to minecraft modding
  17. I have an entity and I want its head to have the texture of the player's head. I wrote my layer class like this: public class PlayerHeadLayer extends GeoLayerRenderer<PowerArmorEntity> { public PlayerHeadLayer(IGeoRenderer<PowerArmorEntity> entityRenderer) { super(entityRenderer); } @Override public void render(PoseStack matrixStackIn, MultiBufferSource bufferIn, int packedLightIn, PowerArmorEntity entity, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch) { if(!entity.isInvisible() && entity.isVehicle() && entity.getControllingPassenger() instanceof AbstractClientPlayer clientPlayer ) { var texture = clientPlayer.getSkinTextureLocation(); int overlay = OverlayTexture.NO_OVERLAY; var cameo = RenderType.armorCutoutNoCull(texture); matrixStackIn.pushPose(); matrixStackIn.scale(1.0f, 1.0f, 1.0f); matrixStackIn.translate(0.0d, 0.0d, 0.0d); this.getRenderer().render( this.getEntityModel().getModel(POWER_ARMOR_MODEL_LOCATION), entity, partialTicks, cameo, matrixStackIn, bufferIn, bufferIn.getBuffer(cameo), packedLightIn, overlay, 1f, 1f, 1f, 1f); matrixStackIn.popPose(); } } } But the player texture scale is too big Texture of my entity:
  18. I have an entity with a SimpleContainer and whet i try to get an item from it it returns an air block
  19. What in minecraft code is responsible for rendering hands in first person? I want to write my own hand renderer.
  20. I somehow figured out what the code doing, and now it works. Thank you private static EntityHitResult getEntityHitResult(Entity cameraEntity, Vec3 eyePosition, Vec3 pickVector, AABB box, Predicate<Entity> filter, double pickRange) { Level level = cameraEntity.level; double _pickRange = pickRange; Entity entity = null; Vec3 vec3 = null; var player = Minecraft.getInstance().player; for(Entity levelEntity : level.getEntities(cameraEntity, box, filter)) { if(levelEntity instanceof PowerArmorEntity && player != null && player.getVehicle() == levelEntity) continue; AABB aabb = levelEntity.getBoundingBox().inflate(levelEntity.getPickRadius()); Optional<Vec3> optional = aabb.clip(eyePosition, pickVector); if (aabb.contains(eyePosition)) { if (_pickRange >= 0.0D) { entity = levelEntity; vec3 = optional.orElse(eyePosition); _pickRange = 0.0D; } } else if (optional.isPresent()) { Vec3 optionalVector = optional.get(); double distance = eyePosition.distanceToSqr(optionalVector); if (distance < _pickRange || _pickRange == 0.0D) { if (levelEntity.getRootVehicle() == cameraEntity.getRootVehicle() && !levelEntity.canRiderInteract()) { if (_pickRange == 0.0D) { entity = levelEntity; vec3 = optionalVector; } } else { entity = levelEntity; vec3 = optionalVector; _pickRange = distance; } } } } return entity == null ? null : new EntityHitResult(entity, vec3); }
  21. Yes, it looks like getEntityHitResult is what I needed, but I have no idea what the code in this method does, I tried to rewrite the code like this: private static EntityHitResult getEntityHitResult(Entity cameraEntity, Vec3 eyePosition, Vec3 vector2, AABB box, Predicate<Entity> filter, double pickRange) { Level level = cameraEntity.level; double _pickRange = pickRange; Entity entity = null; Vec3 vec3 = null; for(Entity levelEntity : level.getEntities(cameraEntity, box, filter)) { AABB aabb = levelEntity.getBoundingBox().inflate(levelEntity.getPickRadius()); Optional<Vec3> optional = aabb.clip(eyePosition, vector2); if (aabb.contains(eyePosition)) { if (_pickRange >= 0.0D) { entity = levelEntity; vec3 = optional.orElse(eyePosition); _pickRange = 0.0D; } } else if (optional.isPresent()) { Vec3 optionalVector = optional.get(); double distance = eyePosition.distanceToSqr(optionalVector); if (distance < _pickRange || _pickRange == 0.0D) { if (levelEntity.getRootVehicle() == cameraEntity.getRootVehicle() && !levelEntity.canRiderInteract()) { if (_pickRange == 0.0D) { entity = levelEntity; vec3 = optionalVector; } } else { entity = levelEntity; vec3 = optionalVector; _pickRange = distance; } } } } //my code if(entity instanceof PowerArmorEntity && entity.getControllingPassenger() == Minecraft.getInstance().player) return new EntityHitResult(entity, vector2); else return entity == null ? null : new EntityHitResult(entity, vec3); } as a result, when I'm in armor, I can't hit mobs at all, but at least I can hit blocks
  22. Do you know what method in the minecraft code is responsible for determining the player's target to hit or pick? Like when I ride a horse and break a block through its hitbox how does the game understand that it should break the block and not hit the horse?
  23. Thanks but it doesn't work for me because I want to make my armor work like power armor in Fallout 4, so it has to be an entity
  24. I have an armor that is a mountable entity and when I sit in it and try to hit something I hit the hitbox of my entity. How to make my entity ignore my hits?
  25. I want to set custom hand model and animation for it
×
×
  • Create New...

Important Information

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