Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.12.2] Changing entity hitbox after it has been spawned


red_
 Share

Recommended Posts

Hey folks,

I'm trying to implement a special type of wolf (a direwolf, from the ASOIAF universe) with four different growth stages. First and foremost, these stages change the rendered size of the wolf. I've got this part working already with:

@Override
protected void preRenderCallback(EntityDirewolf entityDirewolf, float b) {
    // the size of a direwolf is influenced by its stage of growth
    // at stage one, a direwolf is the same size as a normal wolf
    // at stage four, a direwolf is twice as large in every dimension
    float modifier = (entityDirewolf.getGrowthStage() / 3f) + (2f / 3f);
    GL11.glScalef(modifier, modifier, modifier);
}

The issue I'm struggling with is scaling the hitbox itself in line with the larger model.

Before I implemented variable stages of growth, I scaled the hitbox in the direwolf's constructor, like so:

public EntityDirewolf(World worldIn) {
    super(worldIn);
    setSize(1.45f, 2.0f);
}

This worked fine. However, I would like to manipulate after the direwolf object has already been instantiated.

From my testing, simply using...

Entity#setSize()

...after the direwolf had been spawned with...

// make a fun cuddly direwolf
EntityDirewolf direwolf = new EntityDirewolf(player.getEntityWorld());
direwolf.setPosition(player.posX, player.posY, player.posZ);
player.getEntityWorld().spawnEntity(direwolf);

...did not do anything.

From my searching on the forums, it seems like newer versions of Forge have a 'recalculateSize()' method that might solve this problem. Unfortunately, I don't think it exists in the older version of Forge I am using, and upgrading isn't possible at this time.

Is there a way to rescale an entity's hitbox on the fly, after said entity has been spawned?

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • MegaMiner is just my playground mod. Here's the entire MegaMinerEvents class. It's just a static event receiver.   package nu.rydin.explodingarrows.common.events; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import nu.rydin.explodingarrows.common.Main; import nu.rydin.explodingarrows.common.enchantments.ModEnchantments; import java.util.LinkedList; @Mod.EventBusSubscriber(modid = Main.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class MegaMinerEvents { private static final class BlockToBreak { private final BlockPos pos; private final Player player; public BlockToBreak(final BlockPos pos, final Player player) { this.pos = pos; this.player = player; } } private static final LinkedList<BlockToBreak> queue = new LinkedList<>(); @SubscribeEvent public static void onBreakBlock(final BlockEvent.BreakEvent e) { final LevelAccessor world = e.getWorld(); if (world.isClientSide()) { return; } for (final Tag t : e.getPlayer().getMainHandItem().getEnchantmentTags()) { final CompoundTag ct = (CompoundTag) t; if (ct.getString("id") .equals(ModEnchantments.MEGA_MINER.get().getRegistryName().toString())) { MegaMinerEvents.mineNeighborhood(e.getPos(), e.getPlayer(), e.getState().getBlock()); } } } @SubscribeEvent public static void onTick(final TickEvent.ServerTickEvent e) { if (MegaMinerEvents.queue.isEmpty()) { return; } final BlockToBreak b = MegaMinerEvents.queue.removeFirst(); final Level world = b.player.level; final BlockState bs = world.getBlockState(b.pos); bs.getBlock().playerDestroy(world, b.player, b.pos, bs, null, b.player.getMainHandItem()); world.removeBlock(b.pos, true); // MegaMinerEvents.mineNeighborhood(b.pos, b.player, bs.getBlock()); System.out.println(MegaMinerEvents.queue.size()); } private static void mineNeighborhood( final BlockPos pos, final Player player, final Block blockType) { final float x0 = pos.getX(); final float y0 = pos.getY(); final float z0 = pos.getZ(); for (float z = z0 - 1.0F; z <= z0 + 1; z += 1.0) { for (float y = y0 - 1.0F; y <= y0 + 1; y += 1.0) { for (float x = x0 - 1.0F; x <= x0 + 1; x += 1.0) { final BlockState b = player.getLevel().getBlockState(pos); if (b.is(blockType)) { MegaMinerEvents.queue.addLast(new BlockToBreak(pos, player)); } } } } } }  
    • i am playing modded and NOT ON A SERVER but everytime i join a world my game crashes and the error message is: Exception in server tick loop  
    • Do you know what OneDrive is? It's a cloud storage service. Do not put your Minecraft server there, as the files will be changing frequently and if conflicts occur, the minecraft server executable will probably just corrupt everything.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.