Jump to content

Arrows Do No Damage


Lumby

Recommended Posts

I have a block that shoots an arrow every time it is activated by right click whilst holding cobblestone. The arrows it spawn, however, bounce off of any entity it hits. Any idea what might cause this, and possible fixes? Thanks!

 

Code:

   public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float side, float hitX, float hitY)
    {
    	
    	if(playerIn.getHeldItemMainhand().getItem().equals(Item.getItemFromBlock(Blocks.COBBLESTONE))) {
    		if(facing == ((EnumFacing)state.getValue(FACING))) {
    			return true;
    		}
			if(rechargeTimer == 0) {
				if(worldIn.isRemote) {
					EntityTippedArrow entityarrow;
	        		if(((EnumFacing)state.getValue(FACING)).getIndex() ==2){
	        			entityarrow = new EntityTippedArrow(worldIn, (double)pos.getX()+0.5, ((double)pos.getY()+0.9), (double)pos.getZ()-0.1);
	        		}else if(((EnumFacing)state.getValue(FACING)).getIndex() ==3) {
	        			entityarrow = new EntityTippedArrow(worldIn, (double)pos.getX()+0.5, ((double)pos.getY()+0.9), (double)pos.getZ()+1.1);
	        		}else if(((EnumFacing)state.getValue(FACING)).getIndex() ==4) {
	        			entityarrow = new EntityTippedArrow(worldIn, (double)pos.getX()-0.1, ((double)pos.getY()+0.9), (double)pos.getZ()+0.5);
	        		}else {
	        			entityarrow = new EntityTippedArrow(worldIn, (double)pos.getX()+1.1, ((double)pos.getY()+0.9), (double)pos.getZ()+0.5);
	        		}
	        		
	        		entityarrow.setPotionEffect(new ItemStack(Items.ARROW));
				float f = -MathHelper.sin(playerIn.rotationYaw * 0.017453292F) * MathHelper.cos(playerIn.rotationPitch * 0.017453292F);
				float f1 = -MathHelper.sin(playerIn.rotationPitch * 0.017453292F);
				float f2 = MathHelper.cos(playerIn.rotationYaw * 0.017453292F) * MathHelper.cos(playerIn.rotationPitch * 0.017453292F);
	        		entityarrow.setIsCritical(true);
	        		entityarrow.setDamage(30.0);
	        		entityarrow.setKnockbackStrength(1);
	        		entityarrow.shoot((double)f, (double)f1+0.05, (double)f2, 3.0F, 1.0F);
	        		worldIn.spawnEntity(entityarrow);
	        		
	            		this.rechargeTimer =1;

			}
        		if(!playerIn.capabilities.isCreativeMode) {
        			playerIn.getActiveItemStack().shrink(1);
            		}
                
        		worldIn.playSound(playerIn, pos, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 0.5F, 0.4F / (0.2F + 0.8F));
        	}
			worldIn.scheduleUpdate(pos, this, 10);
	}
    	
    	
    	return true;
    }

 

Edited by Lumby
Link to comment
Share on other sites

13 minutes ago, Lumby said:

if(worldIn.isRemote) {

This would be your issue. You are only spawning your arrow on the client. You need to do the opposite.

 

Also you can't do this

13 minutes ago, Lumby said:

if(rechargeTimer == 0) {

Blocks are singletons thus every block in the world that shares this class shares all the variables of that class. You must use a TileEntity if you want to store the data per-block.

  • Thanks 1
Link to comment
Share on other sites

Thank you so much for your help! Sorry I'm still new to modding so don't really have a clear idea which things should be on server or client. 

1 hour ago, V0idWa1k3r said:

Blocks are singletons thus every block in the world that shares this class shares all the variables of that class. You must use a TileEntity if you want to store the data per-block.

Regarding this, I've made some adjustments to my block class and created a new TileEntity to store the cooldown. Essentially, that cooldown is to prevent spamming the shots and give the block a steady rate of fire. At first it worked fine, but occasionally when I tried to load the world it gives an exception and crashes:

Quote

A TileEntity type com.crumbletheundead.blocks.machines.Trebuchet.TileEntityTrebuchet has throw an exception trying to write state. It will not persist. Report this to the mod author

java.lang.RuntimeException: class com.crumbletheundead.blocks.machines.Trebuchet.TileEntityTrebuchet is missing a mapping! This is a bug!

Any ideas what this might be?

 

This is my updated block class:

public class TrebuchetBlock extends BlockBase implements ITileEntityProvider{

	public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
	
	public TrebuchetBlock(String name, Material material) {
		super(name, material);
		setSoundType(SoundType.STONE);
		setHardness(18.0F);
		setResistance(18.0F);
		setHarvestLevel("pickaxe",3);
		setCreativeTab(CreativeTabs.REDSTONE);
		
        
	}
	
    public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand){
        if (!worldIn.isRemote){
        	if(worldIn.getTileEntity(pos) instanceof TileEntityTrebuchet) {
        		((TileEntityTrebuchet)worldIn.getTileEntity(pos)).setCooldown(0);
        	}
        }
    }
	
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float side, float hitX, float hitY){
    	
    	if(playerIn.getHeldItemMainhand().getItem().equals(Item.getItemFromBlock(Blocks.COBBLESTONE))) {
    		if(facing == ((EnumFacing)state.getValue(FACING))) {
    			return true;
    		}
			if((worldIn.getTileEntity(pos)) instanceof TileEntityTrebuchet) {
				if(((TileEntityTrebuchet)worldIn.getTileEntity(pos)).getCooldown()==0) {
					if(!worldIn.isRemote) {
						EntityTippedArrow entityarrow;
		        		if(((EnumFacing)state.getValue(FACING)).getIndex() ==2){
		        			entityarrow = new EntityTippedArrow(worldIn, (double)pos.getX()+0.5, ((double)pos.getY()+0.9), (double)pos.getZ()-0.2);
		        		}else if(((EnumFacing)state.getValue(FACING)).getIndex() ==3) {
		        			entityarrow = new EntityTippedArrow(worldIn, (double)pos.getX()+0.5, ((double)pos.getY()+0.9), (double)pos.getZ()+1.2);
		        		}else if(((EnumFacing)state.getValue(FACING)).getIndex() ==4) {
		        			entityarrow = new EntityTippedArrow(worldIn, (double)pos.getX()-0.2, ((double)pos.getY()+0.9), (double)pos.getZ()+0.5);
		        		}else{
		        			entityarrow = new EntityTippedArrow(worldIn, (double)pos.getX()+1.2, ((double)pos.getY()+0.9), (double)pos.getZ()+0.5);
		        		}
		        		
		        		entityarrow.setPotionEffect(new ItemStack(Items.ARROW));
		        		float f = -MathHelper.sin(playerIn.rotationYaw * 0.017453292F) * MathHelper.cos(playerIn.rotationPitch * 0.017453292F);
		        		float f1 = -MathHelper.sin(playerIn.rotationPitch * 0.017453292F);
		        		float f2 = MathHelper.cos(playerIn.rotationYaw * 0.017453292F) * MathHelper.cos(playerIn.rotationPitch * 0.017453292F);
		        		entityarrow.setIsCritical(true);
		        		entityarrow.setDamage(30.0);
		        		entityarrow.setKnockbackStrength(1);
		        		entityarrow.shoot((double)f, (double)f1+0.05, (double)f2, 3.0F, 1.0F);
		        		worldIn.spawnEntity(entityarrow);
		        		
		        		((TileEntityTrebuchet)worldIn.getTileEntity(pos)).setCooldown(1);
				}
	        		if(!playerIn.capabilities.isCreativeMode) {
	        			playerIn.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND).shrink(1);
	        		}
	        		worldIn.playSound(playerIn, pos, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 0.5F, 0.4F / (0.2F + 0.8F));
			}
				

        		
			}
			worldIn.scheduleUpdate(pos, this, 60);
			
		}
    	
    	
    	return true;
    }
    
    
	
    protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, new IProperty[] {FACING});
    }

    public IBlockState withRotation(IBlockState state, Rotation rot)
    {
        return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
    }
    
    public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
    {
        return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
    }
    
    public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
    {
        return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
    }
    
    public int getMetaFromState(IBlockState state)
    {
        int i = 0;
        i = i | ((EnumFacing)state.getValue(FACING)).getHorizontalIndex();
        return i;
    }
    
    public IBlockState getStateFromMeta(int meta)
    {
        return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
    }

    public TileEntity createNewTileEntity(World worldIn, int meta)
    {
    	TileEntityTrebuchet tileEntityTrebuchet = new TileEntityTrebuchet();
        
        return tileEntityTrebuchet;
    }
    
    @Override
    public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
    {

		if(stack.hasDisplayName())
		{
			TileEntity tileentity = worldIn.getTileEntity(pos);
			
			if(tileentity instanceof TileEntityTrebuchet){
				((TileEntityTrebuchet)tileentity).setCustomName(stack.getDisplayName());
				((TileEntityTrebuchet)tileentity).setCooldown(0);
			}	
		}
    }


}

 

And TileEntity Class:

public class TileEntityTrebuchet extends TileEntity{
	private String customName;
	public int cooldown;
	
	public boolean hasCustomName() 
	{
		return this.customName != null && !this.customName.isEmpty();
	}
	
	public void setCustomName(String customName) 
	{
		this.customName = customName;
	}
	
	@Override
	public void readFromNBT(NBTTagCompound compound)
	{
		super.readFromNBT(compound);
		if (compound.hasKey("cooldown")) {
			cooldown = compound.getInteger("cooldown");
		}
		
		if(compound.hasKey("CustomName", 8)) {
			this.customName = compound.getString("CustomName");
		}
	}
	
	@Override
	public NBTTagCompound writeToNBT(NBTTagCompound compound) 
	{
		super.writeToNBT(compound);
		compound.setInteger("cooldown", cooldown);
		
		
		if(compound.hasKey("CustomName", 8)) {
			compound.setString("CustomName", this.customName);
		}
		
		return compound;
	}
	
	public int getCooldown() {
		return this.cooldown;
	}
	public void setCooldown(int cd) {
		this.cooldown= cd;
	}
	
	public boolean isUsableByPlayer(EntityPlayer player) 
	{
		return this.world.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
	}
}

 

Edited by Lumby
Link to comment
Share on other sites

Thanks for the suggestion! I've registered the tileEntity and added the necessary methods and annotations as you mentioned. The world no longer crashes, but no tileEntities are created every time I place a block. Any idea what might cause this?

 

Block class:


public class TrebuchetBlock extends BlockBase {

	public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
	
	public TrebuchetBlock(String name, Material material) {
		super(name, material);
		setSoundType(SoundType.STONE);
		setHardness(18.0F);
		setResistance(18.0F);
		setHarvestLevel("pickaxe",3);
		setCreativeTab(CreativeTabs.REDSTONE);
		
        
	}
	
    public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand){
        if (!worldIn.isRemote){
        	if(worldIn.getTileEntity(pos) instanceof TileEntityTrebuchet) {
        		((TileEntityTrebuchet)worldIn.getTileEntity(pos)).setCooldown(0);
        	}
        }
    }
	
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float side, float hitX, float hitY){
    	
    	if(playerIn.getHeldItemMainhand().getItem().equals(Item.getItemFromBlock(Blocks.COBBLESTONE))) {
			if((worldIn.getTileEntity(pos)) instanceof TileEntityTrebuchet) {
				worldIn.playSound(playerIn, pos, SoundEvents.BLOCK_CHEST_OPEN, SoundCategory.BLOCKS, 0.5F, 0.4F / (0.2F + 0.8F));
				if(((TileEntityTrebuchet)worldIn.getTileEntity(pos)).getCooldown()<=0) {
					if(!worldIn.isRemote) {
						EntityTippedArrow entityarrow;
		        		if(((EnumFacing)state.getValue(FACING)).getIndex() ==2){
		        			entityarrow = new EntityTippedArrow(worldIn, (double)pos.getX()+0.5, ((double)pos.getY()+0.9), (double)pos.getZ()-0.2);
		        		}else if(((EnumFacing)state.getValue(FACING)).getIndex() ==3) {
		        			entityarrow = new EntityTippedArrow(worldIn, (double)pos.getX()+0.5, ((double)pos.getY()+0.9), (double)pos.getZ()+1.2);
		        		}else if(((EnumFacing)state.getValue(FACING)).getIndex() ==4) {
		        			entityarrow = new EntityTippedArrow(worldIn, (double)pos.getX()-0.2, ((double)pos.getY()+0.9), (double)pos.getZ()+0.5);
		        		}else{
		        			entityarrow = new EntityTippedArrow(worldIn, (double)pos.getX()+1.2, ((double)pos.getY()+0.9), (double)pos.getZ()+0.5);
		        		}
		        		
		        		entityarrow.setPotionEffect(new ItemStack(Items.ARROW));
		        		float f = -MathHelper.sin(playerIn.rotationYaw * 0.017453292F) * MathHelper.cos(playerIn.rotationPitch * 0.017453292F);
		        		float f1 = -MathHelper.sin(playerIn.rotationPitch * 0.017453292F);
		        		float f2 = MathHelper.cos(playerIn.rotationYaw * 0.017453292F) * MathHelper.cos(playerIn.rotationPitch * 0.017453292F);
		        		entityarrow.setIsCritical(true);
		        		entityarrow.setDamage(30.0);
		        		entityarrow.setKnockbackStrength(1);
		        		entityarrow.shoot((double)f, (double)f1+0.05, (double)f2, 3.0F, 1.0F);
		        		worldIn.spawnEntity(entityarrow);
		        		
		        		((TileEntityTrebuchet)worldIn.getTileEntity(pos)).setCooldown(1);
					}
	        		if(!playerIn.capabilities.isCreativeMode) {
	        			playerIn.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND).shrink(1);
	        		}
	        		worldIn.playSound(playerIn, pos, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 0.5F, 0.4F / (0.2F + 0.8F));
				}	
			}
			worldIn.scheduleUpdate(pos, this, 60);
			
		}
    	
    	
    	return true;
    }
    
    
	
    protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, new IProperty[] {FACING});
    }

    public IBlockState withRotation(IBlockState state, Rotation rot)
    {
        return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
    }
    
    public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
    {
        return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
    }
    
    public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
    {
        return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
    }
    
    public int getMetaFromState(IBlockState state)
    {
        int i = 0;
        i = i | ((EnumFacing)state.getValue(FACING)).getHorizontalIndex();
        return i;
    }
    
    public IBlockState getStateFromMeta(int meta)
    {
        return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
    }

    
    @Override
    public TileEntity createTileEntity(World world, IBlockState state) {
    	TileEntityTrebuchet tileEntityTrebuchet = new TileEntityTrebuchet();
        
        return tileEntityTrebuchet;
 
    }
    
    @Override
    public boolean hasTileEntity() {
    	return true;
    }
    
    @Override
    public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
    {

		if(stack.hasDisplayName())
		{
			TileEntity tileentity = worldIn.getTileEntity(pos);
			
			if(tileentity instanceof TileEntityTrebuchet){
				((TileEntityTrebuchet)tileentity).setCustomName(stack.getDisplayName());
				((TileEntityTrebuchet)tileentity).setCooldown(0);
			}	
		}
    }


}

 

TileEntity class:


public class TileEntityTrebuchet extends TileEntity{
	private String customName;
	private int cooldown;
	
	public TileEntityTrebuchet() {
		this.cooldown = 0;
	}
	
	public boolean hasCustomName() 
	{
		return this.customName != null && !this.customName.isEmpty();
	}
	
	public void setCustomName(String customName) 
	{
		this.customName = customName;
	}
	
	@Override
	public void readFromNBT(NBTTagCompound compound)
	{
		super.readFromNBT(compound);
		if (compound.hasKey("cooldown")) {
			cooldown = compound.getInteger("cooldown");
		}
		
		if(compound.hasKey("CustomName", 8)) {
			this.customName = compound.getString("CustomName");
		}
	}
	
	@Override
	public NBTTagCompound writeToNBT(NBTTagCompound compound) 
	{
		super.writeToNBT(compound);
		if(compound.hasKey("cooldown")) {
			compound.setInteger("cooldown", cooldown);
		}
		
		
		if(compound.hasKey("CustomName", 8)) {
			compound.setString("CustomName", this.customName);
		}
		
		return compound;
	}
	
	public int getCooldown() {
		return this.cooldown;
	}
	public void setCooldown(int cd) {
		this.cooldown= cd;
	}
	public void shrinkCooldown() {
		this.cooldown--;
	}
	
}

 

This is my preInit() method:

	@EventHandler()
	public static void PreInit(FMLPreInitializationEvent event) {
		RegistryHandler.preInitRegistries();

	}

 

preInitRegistries() in my RegistryHandler class:

	public static void preInitRegistries() {
		TileEntityHandler.registerTileEntities();
		Main.network = NetworkRegistry.INSTANCE.newSimpleChannel(Reference.MOD_ID);
		RegistryHandler.registerPackets(Main.network);
		
	}

 

TileEntityHandler class:



public class TileEntityHandler {

	public static void registerTileEntities() {
		GameRegistry.registerTileEntity(TileEntityTrebuchet.class, new ResourceLocation(Reference.MOD_ID + ":trebuchet"));
	}
	
}

 

Edited by Lumby
Link to comment
Share on other sites

 

@Override
	public NBTTagCompound writeToNBT(NBTTagCompound compound) 
	{
		super.writeToNBT(compound);
		compound.setInteger("cooldown", cooldown);
		
		
		if(compound.hasKey("CustomName", 8)) {
			compound.setString("CustomName", this.customName);
		}
		
		return compound;
	}

This

16 hours ago, Lumby said:

if(compound.hasKey("CustomName", 8))

will never be true.

 

This

public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand){
        if (!worldIn.isRemote){
        	if(worldIn.getTileEntity(pos) instanceof TileEntityTrebuchet) {
        		((TileEntityTrebuchet)worldIn.getTileEntity(pos)).setCooldown(0);
        	}
        }
    }

doesn't do what you think it does. It fires each tick, sure... for one random block in all of loaded chunks. Implement ITickable in your TileEntity and do the stuff with the cooldown there.

 

What makes you think no tile entity is created? Have you placed a breakpoing in any of your methods that get the tile entity and inspected the TE local?

  • Thanks 1
Link to comment
Share on other sites

6 minutes ago, V0idWa1k3r said:

Have you placed a breakpoing in any of your methods that get the tile entity and inspected the TE local?

Sorry I don't quite get what this means, I'm assuming you're asking if I put any tests? 

17 minutes ago, Lumby said:

if((worldIn.getTileEntity(pos)) instanceof TileEntityTrebuchet) {

I tested that the cobblestone if statement fired by having a SoundEvent fire right after it, and it did fire. The above if statement comes right after that cobblestone if statement. I then put the same SoundEvent to fire right after the above if statement, but it never did. I then went into MCEdit to check for TileEntities, and none showed up (other modded tileEntities of mine, however, did show up in MCEdit). 

Edited by Lumby
Link to comment
Share on other sites

1 hour ago, Lumby said:

Got it, I'll keep at it for another while bswefore bothering you guys again with the repository. Nonetheless, thank you all very much for the effort. 

 

2 hours ago, Lumby said:

public boolean hasTileEntity() {

This is why your TE is not appearing, this method needs to have a IBlockState parameter.

  • Thanks 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

11 minutes ago, Animefan8888 said:

This is why your TE is not appearing, this method needs to have a IBlockState parameter.

And this is why you should always @Override

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

53 minutes ago, V0idWa1k3r said:

In the code the OP posted he has one though

He is just using a deprecated version. Which is his issue as far as I can tell.

*Digs into what the non-state method signature is. Ah, it does look like that, and not part of ITileEntityProvider.*

My mistake

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

1 hour ago, Animefan8888 said:

This is why your TE is not appearing, this method needs to have a IBlockState parameter.

1 hour ago, V0idWa1k3r said:

He is just using a deprecated version. Which is his issue as far as I can tell.

That worked like a charm, thanks for the help!

Edited by Lumby
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I'm using Modrinth as a launcher for a forge modpack on 1.20.1, and can't diagnose the issue on the crash log myself. Have tried repairing the Minecraft instillation as well as removing a few mods that have been problematic for me in the past to no avail. Crash log is below, if any further information is necessary let me know. Thank you! https://paste.ee/p/k6xnS
    • Hey folks. I am working on a custom "Mecha" entity (extended from LivingEntity) that the player builds up from blocks that should get modular stats depending on the used blocks. e.g. depending on what will be used for the legs, the entity will have a different jump strength. However, something unexpected is happening when trying to override a few of LivingEntity's functions and using my new own "Mecha" specific fields: instead of their actual instance-specific value, the default value is used (0f for a float, null for an object...) This is especially strange as when executing with the same entity from a point in the code specific to the mecha entity, the correct value is used. Here are some code snippets to better illustrate what I mean: /* The main Mecha class, cut down for brevity */ public class Mecha extends LivingEntity { protected float jumpMultiplier; //somewhere later during the code when spawning the entity, jumpMultiplier is set to something like 1.5f //changing the access to public didn't help @Override //Overridden from LivingEntity, this function is only used in the jumpFromGround() function, used in the aiStep() function, used in the LivingEntity tick() function protected float getJumpPower() { //something is wrong with this function //for some reason I can't correctly access the fields and methods from the instanciated entity when I am in one of those overridden protected functions. this is very annoying LogUtils.getLogger().info(String.valueOf(this.jumpMultiplier))) //will print 0f return this.jumpMultiplier * super.getJumpPower(); } //The code above does not operate properly. Written as is, the entity will not jump, and adding debug logs shows that when executing the code, the value of this.jumpMultiplier is 0f //in contrast, it will be the correct value when done here: @Override public void tick() { super.tick(); //inherited LivingEntity logic //Custom logic LogUtils.getLogger().info(String.valueOf(this.jumpMultiplier))) //will print 1.5f } } My actual code is slightly different, as the jumpMuliplier is stored in another object (so I am calling "this.legModule.getJumpPower()" instead of the float), but even using a simple float exactly like in the code above didn't help. When running my usual code, the object I try to use is found to be null instead, leading to a crash from a nullPointerException. Here is the stacktrace of said crash: The full code can be viewed here. I have found a workaround in the case of jump strength, but have already found the same problem for another parameter I want to do, and I do not understand why the code is behaving as such, and I would very much like to be able to override those methods as intended - they seemed to work just fine like that for vanilla mobs... Any clues as to what may be happening here?
    • Please delete post. Had not noticed the newest edition for 1.20.6 which resolves the issue.
    • https://paste.ee/p/GTgAV Here's my debug log, I'm on 1.18.2 with forge 40.2.4 and I just want to get it to work!! I cant find any mod names in the error part and I would like some help from the pros!! I have 203 mods at the moment.
  • Topics

×
×
  • Create New...

Important Information

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