71 lines
2.1 KiB
Java
71 lines
2.1 KiB
Java
package com.thebrokenrail.reliccraft.mixin;
|
|
|
|
import com.thebrokenrail.reliccraft.block.TeleportationRestrictorBlock;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.nbt.CompoundTag;
|
|
import org.spongepowered.asm.mixin.Mixin;
|
|
import org.spongepowered.asm.mixin.Shadow;
|
|
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 abstract class MixinEntity implements TeleportationRestrictorBlock.TeleportingEntity {
|
|
@Shadow
|
|
protected boolean inNetherPortal;
|
|
|
|
@Unique
|
|
protected byte teleportCooldown = 2;
|
|
|
|
@Override
|
|
public void resetTeleportCooldown() {
|
|
teleportCooldown = 4;
|
|
}
|
|
|
|
@Override
|
|
public void setTeleportCooldown(byte teleportCooldown) {
|
|
this.teleportCooldown = teleportCooldown;
|
|
}
|
|
|
|
@Inject(at = @At("HEAD"), method = "tick")
|
|
public void tick(CallbackInfo info) {
|
|
updateNetherPortal();
|
|
if (teleportCooldown > 0) {
|
|
teleportCooldown--;
|
|
}
|
|
}
|
|
|
|
@Unique
|
|
private void updateNetherPortal() {
|
|
if (cannotTeleport()) {
|
|
inNetherPortal = false;
|
|
}
|
|
}
|
|
|
|
@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;
|
|
}
|
|
|
|
@Inject(at = @At("HEAD"), method = "toTag")
|
|
public void toTag(CompoundTag tag, CallbackInfoReturnable<CompoundTag> info) {
|
|
tag.putByte("RelicCraftTeleportCooldown", teleportCooldown);
|
|
}
|
|
|
|
@Inject(at = @At("HEAD"), method = "fromTag")
|
|
public void fromTag(CompoundTag tag, CallbackInfo info) {
|
|
teleportCooldown = tag.getByte("RelicCraftTeleportCooldown");
|
|
updateNetherPortal();
|
|
}
|
|
}
|