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);
}
}
}
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
}
}
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;
}
}
}
}
}
}
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));
}
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);
}
}
Aggregations