added shears harvest any living items...
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package de.jottyfan.minecraft.item;
|
||||
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
@@ -15,6 +16,10 @@ import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.ShearsItem;
|
||||
import net.minecraft.world.level.storage.loot.LootParams;
|
||||
import net.minecraft.world.level.storage.loot.LootTable;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
/**
|
||||
@@ -79,6 +84,20 @@ public class QShears extends ShearsItem {
|
||||
user.level()
|
||||
.addFreshEntity(new ItemEntity(user.level(), pos.x, pos.y, pos.z, new ItemStack(Items.FEATHER, amount)));
|
||||
return InteractionResult.SUCCESS;
|
||||
} else if (user.level() instanceof ServerLevel serverLevel){
|
||||
if (entity.getLootTable().isPresent()) {
|
||||
LootTable lootTable = serverLevel.getServer().reloadableRegistries().getLootTable(entity.getLootTable().get());
|
||||
LootParams lootParams = new LootParams.Builder(serverLevel)
|
||||
.withParameter(LootContextParams.ORIGIN, entity.position())
|
||||
.withParameter(LootContextParams.THIS_ENTITY, entity)
|
||||
.withParameter(LootContextParams.DAMAGE_SOURCE, entity.damageSources().generic())
|
||||
.create(LootContextParamSets.ENTITY);
|
||||
lootTable.getRandomItems(lootParams).forEach(itemStack -> {
|
||||
entity.spawnAtLocation(serverLevel, itemStack);
|
||||
});
|
||||
entity.hurtServer(serverLevel, entity.damageSources().generic(), 0.1f);
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user