Jump to content

Mod for taming doesnt work.


Darwino43

Recommended Posts

This is for advanced Minecraft Java mod makers. So i have this script: 

import net.minecraft.entity.monster.SkeletonEntity;
import net.minecraft.item.Items;
import net.minecraft.item.EnchantedGoldenAppleItem;
import net.minecraft.item.ItemStack;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Hand;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

public class Example {
    @SubscribeEvent
    public void tameSkeleton(PlayerInteractEvent.EntityInteract event) {
        if (event.getTarget() instanceof SkeletonEntity) {
            SkeletonEntity skeleton = (SkeletonEntity) event.getTarget();
            ItemStack itemstack = event.getPlayer().getHeldItem(event.getHand());
            if (skeleton.isTamed()) {
                return;
            } else if (itemstack.getItem() instanceof EnchantedGoldenAppleItem) {
                if (!event.getPlayer().abilities.isCreativeMode) {
                    itemstack.shrink(1);
                }
                if (!skeleton.world.isRemote) {
                    skeleton.setTamedBy(event.getPlayer());
                    skeleton.world.setEntityState(skeleton, (byte)7);
                }
                return;
            }
        }
    }
    @SubscribeEvent
    public void skeletonDefendPlayer(LivingAttackEvent event) {
        if (event.getEntity() instanceof PlayerEntity) {
            PlayerEntity player = (PlayerEntity) event.getEntity();
            if (player.getAttackingEntity() instanceof SkeletonEntity) {
                SkeletonEntity skeleton = (SkeletonEntity) player.getAttackingEntity();
                if (skeleton.isTamed()) {
                    event.setCanceled(true);
                    skeleton.setAttackTarget(event.getSource().getTrueSource());
                }
            }
        }
    }
}
 

and it should make skeleton posible to tame. Apps that im using to create mods doesnt show any errors so why it doesnt work?

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.