Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////////Item class//////////////////////
- public class EntityStorageItem extends Item {
- public EntityStorageItem(Properties pProperties) {
- super(pProperties);
- }
- public InteractionResult useOn(UseOnContext pContext) {
- ItemStack is = pContext.getItemInHand();
- CompoundTag tag = is.getTagElement("stored_entity");
- BlockPos pos = pContext.getClickedPos();
- if(tag != null){
- Entity entity1 = EntityType.create(tag, pContext.getLevel()).get(); // method 1
- pContext.getLevel().addFreshEntity(entity1); // method 2
- entity1.moveTo(pContext.getPlayer().position());
- Entity entity = EntityType.loadEntityRecursive(tag, pContext.getLevel(), (p_138828_) -> {
- p_138828_.moveTo(pos.getX(), pos.getY(), pos.getZ(), p_138828_.getYRot(), p_138828_.getXRot());
- return p_138828_;
- }); // method 3 from SummonCommand
- }
- return InteractionResult.PASS;
- }
- }
- ////////////////////////Entity class (partial)/////////////////////////
- public class ExampleEntity extends Animal {
- @Override
- public InteractionResult mobInteract(Player pPlayer, InteractionHand pHand){
- ItemStack items = pPlayer.getItemInHand(pHand);
- Item item = items.getItem();
- if(item instanceof EntityStorageItem && pPlayer.isCrouching()){
- CompoundTag tag = new CompoundTag();
- this.save(tag);
- items.addTagElement("stored_entity",tag);
- //this.discard();
- }
- return super.mobInteract(pPlayer, pHand);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment