Entity cooldown map
This commit is contained in:
parent
62c9c622a4
commit
251c5750ee
1 changed files with 15 additions and 5 deletions
|
@ -1,5 +1,7 @@
|
||||||
package ru.betterend.mixin.common;
|
package ru.betterend.mixin.common;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
@ -8,6 +10,8 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EntityType;
|
import net.minecraft.entity.EntityType;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
|
@ -19,9 +23,8 @@ import ru.betterend.interfaces.TeleportingEntity;
|
||||||
|
|
||||||
@Mixin(Entity.class)
|
@Mixin(Entity.class)
|
||||||
public abstract class EntityMixin implements TeleportingEntity {
|
public abstract class EntityMixin implements TeleportingEntity {
|
||||||
|
private static final Map<Entity, Long> COOLDOWN = Maps.newHashMap();
|
||||||
private BlockPos beExitPos;
|
private BlockPos beExitPos;
|
||||||
private long beCooldown;
|
|
||||||
|
|
||||||
@Shadow
|
@Shadow
|
||||||
public float yaw;
|
public float yaw;
|
||||||
|
@ -81,6 +84,7 @@ public abstract class EntityMixin implements TeleportingEntity {
|
||||||
@Inject(method = "getTeleportTarget", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "getTeleportTarget", at = @At("HEAD"), cancellable = true)
|
||||||
protected void be_getTeleportTarget(ServerWorld destination, CallbackInfoReturnable<TeleportTarget> info) {
|
protected void be_getTeleportTarget(ServerWorld destination, CallbackInfoReturnable<TeleportTarget> info) {
|
||||||
if (beExitPos != null) {
|
if (beExitPos != null) {
|
||||||
|
COOLDOWN.remove(beGetSelf());
|
||||||
info.setReturnValue(new TeleportTarget(new Vec3d(beExitPos.getX() + 0.5D, beExitPos.getY(), beExitPos.getZ() + 0.5D), getVelocity(), yaw, pitch));
|
info.setReturnValue(new TeleportTarget(new Vec3d(beExitPos.getX() + 0.5D, beExitPos.getY(), beExitPos.getZ() + 0.5D), getVelocity(), yaw, pitch));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,18 +92,20 @@ public abstract class EntityMixin implements TeleportingEntity {
|
||||||
@Inject(method = "baseTick", at = @At("TAIL"))
|
@Inject(method = "baseTick", at = @At("TAIL"))
|
||||||
public void be_baseTick(CallbackInfo info) {
|
public void be_baseTick(CallbackInfo info) {
|
||||||
if (hasCooldown()) {
|
if (hasCooldown()) {
|
||||||
this.beCooldown--;
|
Entity key = beGetSelf();
|
||||||
|
long value = COOLDOWN.getOrDefault(key, 0L) - 1;
|
||||||
|
COOLDOWN.put(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long beGetCooldown() {
|
public long beGetCooldown() {
|
||||||
return this.beCooldown;
|
return COOLDOWN.getOrDefault(beGetSelf(), 0L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beSetCooldown(long time) {
|
public void beSetCooldown(long time) {
|
||||||
this.beCooldown = time;
|
COOLDOWN.put(beGetSelf(), time);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -111,4 +117,8 @@ public abstract class EntityMixin implements TeleportingEntity {
|
||||||
public BlockPos beGetExitPos() {
|
public BlockPos beGetExitPos() {
|
||||||
return this.beExitPos;
|
return this.beExitPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Entity beGetSelf() {
|
||||||
|
return (Entity) (Object) this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue