Jump to content

[1.10.2] Thorns like behavior


Egietje

Recommended Posts

Hello

I want to make armor that if you wear the whole set you 'become' a hedgehog

With that I mean if you collide with another entity it will damage the other entity and damages the armor sort of like thorns

But how do I detect of the player that wears the set is collided with another entity and how do I damage the other entity and the armor?

Link to comment
Share on other sites

To detect if they are wearing the armor use onArmorTick and check if the players armor slots are of the armor Item. And I don't think there is a collision event so i would issue a pull request on forges github. Other thatn that you could use PlayerTickEvent and manually check if the player collides with another player.

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

So I would do something like:

@Override
public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) {
	if(player.getItemStackFromSlot(EntityEquipmentSlot.HEAD) != null && player.getItemStackFromSlot(EntityEquipmentSlot.HEAD).getItem().equals(KokkieItems.EGEL_HELMET)) {
		if(player.getItemStackFromSlot(EntityEquipmentSlot.CHEST) != null && player.getItemStackFromSlot(EntityEquipmentSlot.CHEST).getItem().equals(KokkieItems.EGEL_CHESTPLATE)) {
			if(player.getItemStackFromSlot(EntityEquipmentSlot.LEGS) != null && player.getItemStackFromSlot(EntityEquipmentSlot.LEGS).getItem().equals(KokkieItems.EGEL_LEGGINGS)) {
				if(player.getItemStackFromSlot(EntityEquipmentSlot.FEET) != null && player.getItemStackFromSlot(EntityEquipmentSlot.FEET).getItem().equals(KokkieItems.EGEL_BOOTS)) {
					Entity entityInAABB = (Entity) world.getEntitiesWithinAABB(player.getClass(), player.getEntityBoundingBox());
					//Hurt entityInAABB
				}
			}
		}
	}
}

Link to comment
Share on other sites

The if statements are to check if the player is wearing all of the armor pieces of the set

How should I otherwise do that?

 

How can I hurt an entity?

With one if statement &&'s to use more than one boolean value. Also world.getEntitiesWithinAABB(...) should return a List<Entity> not a single Entity also instead of player.getClass() use EntityLivingBase.class.

 

*Edit Also to damage an entity living.attackEntityFromDamageSource(...)

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

If you want you can tidy it up by putting these conditions in a function that returns a boolean, where it returns false whenever any of the armor pieces isn't present. That won't make much of a change, however.

 

As for the hurting, check if the entity is instance of

EntityLivingBase

(super class for all entities with health even players) then use

EntityLivingBase#attackEntityFrom

with DamageSource being

DamageSource.causePlayerDamage(player)

Link to comment
Share on other sites

So it would be like this:

for(List<EntityLivingBase> entityInAABB = entitiesInAABB;entityInAABB.listIterator().hasNext();entityInAABB.listIterator().next()) {

					}

Not quite, you don't need to use iterator for a list at least if you are not removing anything. Instead a simple for loop would work.

The one you have down there will not work mainly because you don't create a variable for the next iteration. Though if you ever need to use an iterator look at some vanilla examples one off the top of my head would be FurnaceRecipes#getSmeltingResult(...).

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

No, I was f*cking around, but this works, right?

for (int i = 0; i < entitiesInAABB.size(); i++) {
						EntityLivingBase entityInAABB = entitiesInAABB.get(i);
						//Hurt entityInAABB
					}

Lol, yeah that will work.

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

Yeah but make sure that when you call getEntitiesWithinAABB(...) pass EntityLivingBase.class not Entity, because anything lower in the hierarchy is not damageable like that.

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

Guest
This topic is now closed to further replies.


×
×
  • Create New...

Important Information

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