42 lines
1.2 KiB
Java
42 lines
1.2 KiB
Java
package com.thebrokenrail.reliccraft.mixin;
|
|
|
|
import com.thebrokenrail.reliccraft.block.TeleportationRestrictorBlock;
|
|
import net.minecraft.entity.Entity;
|
|
import org.spongepowered.asm.mixin.Mixin;
|
|
import org.spongepowered.asm.mixin.Unique;
|
|
import org.spongepowered.asm.mixin.injection.At;
|
|
import org.spongepowered.asm.mixin.injection.Inject;
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
|
|
@SuppressWarnings("unused")
|
|
@Mixin(Entity.class)
|
|
public class MixinEntity implements TeleportationRestrictorBlock.TeleportingEntity {
|
|
@Unique
|
|
private int teleportCooldown = 0;
|
|
|
|
@Override
|
|
public void resetTeleportCooldown() {
|
|
teleportCooldown = 4;
|
|
}
|
|
|
|
@Inject(at = @At("HEAD"), method = "tick")
|
|
public void tick(CallbackInfo info) {
|
|
if (teleportCooldown > 0) {
|
|
teleportCooldown--;
|
|
}
|
|
}
|
|
|
|
@Inject(at = @At("HEAD"), method = "canUsePortals", cancellable = true)
|
|
public void canUsePortals(CallbackInfoReturnable<Boolean> info) {
|
|
if (cannotTeleport()) {
|
|
info.setReturnValue(false);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean cannotTeleport() {
|
|
return teleportCooldown > 0;
|
|
}
|
|
}
|