Search in sources :

Example 11 with IMixinEntity

use of org.spongepowered.common.interfaces.entity.IMixinEntity in project SpongeCommon by SpongePowered.

the class MixinEntityAIRunAroundLikeCrazy method updateTask.

/**
 * @author rexbut - December 16th, 2016
 *
 * @reason - adjusted to support {@link DismountTypes}
 */
@Overwrite
public void updateTask() {
    if (this.horseHost.getRNG().nextInt(50) == 0) {
        Entity entity = this.horseHost.getPassengers().get(0);
        if (entity == null) {
            return;
        }
        if (entity instanceof EntityPlayer) {
            int i = this.horseHost.getTemper();
            int j = this.horseHost.getMaxTemper();
            if (j > 0 && this.horseHost.getRNG().nextInt(j) < i) {
                this.horseHost.setTamedBy((EntityPlayer) entity);
                this.horseHost.world.setEntityState(this.horseHost, (byte) 7);
                return;
            }
            this.horseHost.increaseTemper(5);
        }
        // this.horseHost.removePassengers(); // Vanilla
        if (((IMixinEntity) this.horseHost).removePassengers(DismountTypes.DERAIL)) {
            // Sponge end
            this.horseHost.makeMad();
            this.horseHost.world.setEntityState(this.horseHost, (byte) 6);
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 12 with IMixinEntity

use of org.spongepowered.common.interfaces.entity.IMixinEntity in project SpongeCommon by SpongePowered.

the class MixinEntityAITasks method removeTask.

/**
 * @author Zidane - November 30th, 2015
 * @reason Integrate Sponge events into the AI task removal.
 *
 * @param aiBase
 */
@SuppressWarnings({ "rawtypes" })
@Overwrite
public void removeTask(EntityAIBase aiBase) {
    final Iterator iterator = this.taskEntries.iterator();
    while (iterator.hasNext()) {
        final EntityAITasks.EntityAITaskEntry entityaitaskentry = (EntityAITasks.EntityAITaskEntry) iterator.next();
        final EntityAIBase otherAiBase = entityaitaskentry.action;
        // Sponge start
        if (otherAiBase.equals(aiBase)) {
            AITaskEvent.Remove event = null;
            if (ShouldFire.AI_TASK_EVENT_REMOVE && this.owner != null && !((IMixinEntity) this.owner).isInConstructPhase()) {
                event = SpongeEventFactory.createAITaskEventRemove(Sponge.getCauseStackManager().getCurrentCause(), (Goal) this, (Agent) this.owner, (AITask) otherAiBase, entityaitaskentry.priority);
                SpongeImpl.postEvent(event);
            }
            if (event == null || !event.isCancelled()) {
                if (entityaitaskentry.using) {
                    entityaitaskentry.using = false;
                    otherAiBase.resetTask();
                    this.executingTaskEntries.remove(entityaitaskentry);
                }
                iterator.remove();
                return;
            }
        }
    // Sponge end
    }
}
Also used : Agent(org.spongepowered.api.entity.living.Agent) AITaskEvent(org.spongepowered.api.event.entity.ai.AITaskEvent) Goal(org.spongepowered.api.entity.ai.Goal) IMixinEntityAIBase(org.spongepowered.common.interfaces.ai.IMixinEntityAIBase) EntityAIBase(net.minecraft.entity.ai.EntityAIBase) Iterator(java.util.Iterator) EntityAITasks(net.minecraft.entity.ai.EntityAITasks) IMixinEntityAITasks(org.spongepowered.common.interfaces.ai.IMixinEntityAITasks) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) AITask(org.spongepowered.api.entity.ai.task.AITask) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 13 with IMixinEntity

use of org.spongepowered.common.interfaces.entity.IMixinEntity in project SpongeCommon by SpongePowered.

the class IMixinCustomDataHolder method removeCustomFromNbt.

default void removeCustomFromNbt(DataManipulator<?, ?> manipulator) {
    if (this instanceof IMixinEntity) {
        final NBTTagCompound spongeData = ((IMixinEntity) this).getSpongeData();
        if (spongeData.hasKey(NbtDataUtil.CUSTOM_MANIPULATOR_TAG_LIST, NbtDataUtil.TAG_LIST)) {
            final NBTTagList tagList = spongeData.getTagList(NbtDataUtil.CUSTOM_MANIPULATOR_TAG_LIST, NbtDataUtil.TAG_COMPOUND);
            if (!tagList.hasNoTags()) {
                for (int i = 0; i < tagList.tagCount(); i++) {
                    final NBTTagCompound tag = tagList.getCompoundTagAt(i);
                    final String dataClass = tag.getString("DataClass");
                    if (dataClass.equalsIgnoreCase(manipulator.getClass().getName())) {
                        tagList.removeTag(i);
                        break;
                    }
                }
            }
        }
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity)

Example 14 with IMixinEntity

use of org.spongepowered.common.interfaces.entity.IMixinEntity in project SpongeCommon by SpongePowered.

the class MixinEntityPlayerMP method onClonePlayer.

@Inject(method = "copyFrom", at = @At("HEAD"))
public void onClonePlayer(EntityPlayerMP oldPlayer, boolean respawnFromEnd, CallbackInfo ci) {
    // Copy over sponge data from the old player.
    // Allows plugins to specify data that persists after players respawn.
    IMixinEntity oldEntity = (IMixinEntity) oldPlayer;
    NBTTagCompound old = oldEntity.getEntityData();
    if (old.hasKey(NbtDataUtil.SPONGE_DATA)) {
        this.getEntityData().setTag(NbtDataUtil.SPONGE_DATA, old.getCompoundTag(NbtDataUtil.SPONGE_DATA));
        this.readFromNbt(this.getSpongeData());
    }
    // Copy overworld spawn pos
    ((IMixinEntityPlayer) this).setOverworldSpawnPoint(SpongeImplHooks.getBedLocation(oldPlayer, 0));
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) IMixinEntityPlayer(org.spongepowered.common.interfaces.entity.player.IMixinEntityPlayer) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 15 with IMixinEntity

use of org.spongepowered.common.interfaces.entity.IMixinEntity in project SpongeForge by SpongePowered.

the class SpongeEventHooks method onChunkWatchEvent.

@SubscribeEvent
public void onChunkWatchEvent(ChunkWatchEvent event) {
    IMixinEntity spongeEntity = (IMixinEntity) event.getPlayer();
    if (spongeEntity.isTeleporting()) {
        spongeEntity.getTeleportVehicle().getPassengers().add(event.getPlayer());
        spongeEntity.setTeleportVehicle(null);
        spongeEntity.setIsTeleporting(false);
    }
}
Also used : IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

IMixinEntity (org.spongepowered.common.interfaces.entity.IMixinEntity)30 World (org.spongepowered.api.world.World)10 Entity (net.minecraft.entity.Entity)7 EntityPlayer (net.minecraft.entity.player.EntityPlayer)7 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)7 Vector3d (com.flowpowered.math.vector.Vector3d)6 User (org.spongepowered.api.entity.living.player.User)6 IMixinChunk (org.spongepowered.common.interfaces.IMixinChunk)6 ArrayList (java.util.ArrayList)5 BlockPos (net.minecraft.util.math.BlockPos)5 WorldServer (net.minecraft.world.WorldServer)5 Overwrite (org.spongepowered.asm.mixin.Overwrite)5 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 Nullable (javax.annotation.Nullable)3 ItemStack (net.minecraft.item.ItemStack)3 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)3 Entity (org.spongepowered.api.entity.Entity)3 Player (org.spongepowered.api.entity.living.player.Player)3 CauseStackManager (org.spongepowered.api.event.CauseStackManager)3