Jump to content

[1.10.2] Set tool strength based on player's dimension


HenryRichard

Recommended Posts

I'm trying to make some tools that work better in The End. Currently I'm doing this:

    public float getStrVsBlock(ItemStack stack, IBlockState state)
    {
        float strength = super.getStrVsBlock(stack, state);
        //TODO: make this not client only
        if(Minecraft.getMinecraft().thePlayer.dimension == 1) {
        	strength *= 8;
        }
        
        return strength;
    }
    
    /**
     * ItemStack sensitive version of getItemAttributeModifiers
     */
    public Multimap<String, AttributeModifier> getAttributeModifiers(EntityEquipmentSlot slot, ItemStack stack)
    {
    	Multimap<String, AttributeModifier> multimap = HashMultimap.<String, AttributeModifier>create();
        
        double atk = (double)this.attackDamage;
        //TODO: make this not client only
        try {
        if(Minecraft.getMinecraft() != null && Minecraft.getMinecraft().thePlayer != null && Minecraft.getMinecraft().thePlayer.dimension == 1) {
        	atk *= 4;
        }
        } finally {
        	
        }

        if (slot == EntityEquipmentSlot.MAINHAND)
        {
            multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getAttributeUnlocalizedName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", atk, 0));
            multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getAttributeUnlocalizedName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Weapon modifier", -2.4000000953674316D, 0));
        }

        return multimap;
    }

However, since Minecraft is a client-only class, this will crash a server. I don't know of a way I can get a player from an ItemStack, IBlockState, or EntityEquipmentSlot. I could potentially use NBT data that gets set when the tool is equipped, but that seems messy and a little hacky and I'd rather not do it if there's a better way. Any ideas?

I'll put something here when I have something of value I need to put at the end of every post. For now it's this mostly pointless text.

Link to comment
Share on other sites

That solves half of it, though I now need to make the sword deal quadruple damage. I'm trying to use this:

@SubscribeEvent
public void enditeLivingAttackEvent(LivingAttackEvent e) {
	System.out.println("enditeLivingAttackEvent!");
	if(e.getEntity() != null && e.getEntity().dimension == 1 && e.getSource().getSourceOfDamage() instanceof EntityLiving) {
		System.out.println("entity isn't null, is in end, and was attacked by EntityLiving!");
		EntityLiving attacker = (EntityLiving) e.getSource().getSourceOfDamage();
		if(attacker.getHeldItem(EnumHand.MAIN_HAND) != null && attacker.getHeldItem(EnumHand.MAIN_HAND).getItem() == EWOTItems.enditeSword) {
			System.out.println("IT'S SUPER EFFECTIVE!");
			e.getEntityLiving().attackEntityFrom(DamageSource.generic, e.getAmount() * 3);
		}
	}
}

But it's not working. If possible I'd like to use something similar to the code in my first post so that the tooltip showing the attack damage updates, though I'd understand if that wasn't possible without making a coremod (which sounds like a bad idea).

I'll put something here when I have something of value I need to put at the end of every post. For now it's this mostly pointless text.

Link to comment
Share on other sites

Is the code being executed? Are you in the end when testing?

As for tooltips, you can use

ItemTooltipEvent

to change the tooltip of any item.

I'll look into messing with the tooltip in a bit.

It is executing - "enditeLivingAttackEvent!" is printed every time something takes damage (sometimes several times - no idea what's causing that), but it never progresses past that. I've tested it both in and out of The End and it doesn't do anything out of the ordinary either way.

I'll put something here when I have something of value I need to put at the end of every post. For now it's this mostly pointless text.

Link to comment
Share on other sites

Alright - I discovered e.getSource().getSourceOfDamage() instanceof EntityLiving is returning false. Now the question is what can I do about that? Is there a different event I should be using?

I'll put something here when I have something of value I need to put at the end of every post. For now it's this mostly pointless text.

Link to comment
Share on other sites

I'm the stupid one - I didn't even check EntityPlayer!

 

It's kinda working now - the main problem is that it's now making endermen teleport, as well as the more minor problem of not technically having the attack come from the attacker. I'm pretty sure it's because I'm attacking as DamageSource.generic, so that may have to change. There doesn't seem to be any way to set LivingAttackEvent.amount, so I'm not really sure what to do from here.

 

BTW Here's the current code:

@SubscribeEvent
public void enditeLivingAttackEvent(LivingAttackEvent e) {
if(e.getEntity().dimension == 1 && e.getSource().getSourceOfDamage() instanceof EntityLivingBase) {
	EntityLivingBase attacker = (EntityLivingBase) e.getSource().getSourceOfDamage();
	if(attacker.getHeldItem(EnumHand.MAIN_HAND) != null && attacker.getHeldItem(EnumHand.MAIN_HAND).getItem() == EWOTItems.enditeSword) {
		//Not sure what to do here
	}
}
}

I'll put something here when I have something of value I need to put at the end of every post. For now it's this mostly pointless text.

Link to comment
Share on other sites

It's working perfectly now - thanks so much!

Here's my finished code for everything, in case someone in the future want to do a similar thing:

@SubscribeEvent
public void enditeBreakSpeedEvent(PlayerEvent.BreakSpeed e) {
	if(e.getEntityPlayer().getHeldItem(EnumHand.MAIN_HAND) != null && e.getEntityPlayer().getHeldItem(EnumHand.MAIN_HAND).getItem() instanceof IEndTool && e.getEntityPlayer().dimension == 1) {
		e.setNewSpeed(e.getOriginalSpeed() * ;
	}
}

@SubscribeEvent
public void enditeLivingHurtEvent(LivingHurtEvent e) {
	if(e.getEntity().dimension == 1 && e.getSource().getEntity() instanceof EntityLivingBase) {
		EntityLivingBase attacker = (EntityLivingBase) e.getSource().getEntity();
		if(attacker.getHeldItem(EnumHand.MAIN_HAND) != null && attacker.getHeldItem(EnumHand.MAIN_HAND).getItem() == EWOTItems.enditeSword) {
			e.setAmount(e.getAmount() * 4);
		}
	}
}

I'll put something here when I have something of value I need to put at the end of every post. For now it's this mostly pointless text.

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



×
×
  • Create New...

Important Information

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