Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
package net.modfest.fireblanket.mixin.entity_ticking;

import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.storage.ReadView;
import net.minecraft.storage.WriteView;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.border.WorldBorder;
import net.modfest.fireblanket.mixinsupport.ImmmovableLivingEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(LivingEntity.class)
public abstract class MixinLivingEntity extends Entity implements ImmmovableLivingEntity {
@Shadow
public abstract void kill(ServerWorld world);

private boolean fireblanket$movementless = false;

public MixinLivingEntity(EntityType<?> type, World world) {
Expand Down Expand Up @@ -43,4 +51,25 @@ public MixinLivingEntity(EntityType<?> type, World world) {
public void setNoMovement(boolean noMovement) {
this.fireblanket$movementless = noMovement;
}

@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/border/WorldBorder;getDamagePerBlock()D"), method = "baseTick")
private void doNotLeaveTheWorldBorderPlease(CallbackInfo ci, @Local ServerWorld serverWorld) {
this.kill(serverWorld);
this.setVelocity(Vec3d.ZERO);
this.scheduleVelocityUpdate();
}

@Inject(at = @At("RETURN"), method = "tick")
private void doNotGoTooFarPlease(CallbackInfo ci) {
WorldBorder border = getWorld().getWorldBorder();
double maxOutOfBoundsDistance = 64;

int topY = getWorld().getHeight() - getWorld().getBottomY();
double x = MathHelper.clamp(this.getX(), border.getBoundWest() - maxOutOfBoundsDistance, border.getBoundEast() + maxOutOfBoundsDistance);
double y = MathHelper.clamp(this.getY(), getWorld().getBottomY() - maxOutOfBoundsDistance, topY + maxOutOfBoundsDistance * 100);
double z = MathHelper.clamp(this.getZ(), border.getBoundNorth() - maxOutOfBoundsDistance, border.getBoundSouth() + maxOutOfBoundsDistance);
if (x != this.getX() || y != this.getY() || z != this.getZ()) {
this.setPosition(x, y, z);
}
}
}
Loading