Skip to content

Commit

Permalink
Update to 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
Rektroth committed Jul 4, 2024
1 parent 4702bf1 commit 1f48a5b
Show file tree
Hide file tree
Showing 17 changed files with 221 additions and 317 deletions.
103 changes: 53 additions & 50 deletions README.md

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.6
yarn_mappings=1.20.6+build.1
loader_version=0.15.10
minecraft_version=1.21
yarn_mappings=1.21+build.7
loader_version=0.15.11

# Mod Properties
mod_version=0.11.4
mod_version=0.12.0
maven_group=io.github.rektroth
archives_base_name=whiteout

# Dependencies
fabric_version=0.97.8+1.20.6
lithium_version=mc1.20.6-0.12.3
fabric_version=0.100.4+1.21
lithium_version=mc1.21-0.12.7
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,37 @@

package io.github.rektroth.whiteout.mixin.breakingpermablocks;

import com.google.common.collect.Sets;
import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
import io.github.rektroth.whiteout.util.BlockUtil;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.minecraft.block.BlockState;
import net.minecraft.enchantment.ProtectionEnchantment;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.TntEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.FluidState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.event.GameEvent;
import net.minecraft.world.explosion.Explosion;
import net.minecraft.world.explosion.ExplosionBehavior;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.*;

@Mixin(Explosion.class)
public class ExplosionMixin {
@Final
@Shadow
private ObjectArrayList<BlockPos> affectedBlocks;

@Final
@Shadow
private Map<PlayerEntity, Vec3d> affectedPlayers;

@Final
@Shadow
private ExplosionBehavior behavior;

@Final
@Shadow
private DamageSource damageSource;

@Final
@Shadow
private Entity entity;

@Final
@Shadow
private float power;
Expand All @@ -76,139 +59,73 @@ public class ExplosionMixin {
private double z;

/**
* Collects the blocks and damages the entities in the explosion radius.
* @author Rektroth
* @reason Mixins are not capable of inserting "continue" into loops.
* I'm too new to mixins to figure out anything other than overwriting the entire thing.
* The `continue` that is needed is marked.
* If someone comes up with a better way to do this, I would prefer it.
* Skips the existing loop.
* @param prevValue boilerplate
*/
@Overwrite
public void collectBlocksAndDamageEntities() {
this.world.emitGameEvent(this.entity, GameEvent.EXPLODE, new Vec3d(this.x, this.y, this.z));
Set<BlockPos> set = Sets.newHashSet();

int k;
int l;
for(int j = 0; j < 16; ++j) {
for(k = 0; k < 16; ++k) {
for(l = 0; l < 16; ++l) {
if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) {
double d = ((float)j / 15.0F * 2.0F - 1.0F);
double e = ((float)k / 15.0F * 2.0F - 1.0F);
double f = ((float)l / 15.0F * 2.0F - 1.0F);
double g = Math.sqrt(d * d + e * e + f * f);
d /= g;
e /= g;
f /= g;
float h = this.power * (0.7F + this.world.random.nextFloat() * 0.6F);
double m = this.x;
double n = this.y;
double o = this.z;

for (float p = 0.3F; h > 0.0F; h -= 0.22500001F) {
BlockPos blockPos = BlockPos.ofFloored(m, n, o);
BlockState blockState = this.world.getBlockState(blockPos);

/*
THIS IS THE CONTINUE THAT PAPER INSERTS
*/
if (BlockUtil.isDestroyable(blockState.getBlock())) {
continue;
}
/*
THIS IS THE CONTINUE THAT PAPER INSERTS
*/

FluidState fluidState = this.world.getFluidState(blockPos);

if (!this.world.isInBuildLimit(blockPos)) {
break;
}

Optional<Float> optional = this.behavior.getBlastResistance((Explosion)(Object)this, this.world, blockPos, blockState, fluidState);
if (optional.isPresent()) {
h -= (optional.get() + 0.3F) * 0.3F;
}

if (h > 0.0F && this.behavior.canDestroyBlock((Explosion)(Object)this, this.world, blockPos, blockState, h)) {
set.add(blockPos);
}

m += d * 0.30000001192092896;
n += e * 0.30000001192092896;
o += f * 0.30000001192092896;
}
}
}
@ModifyConstant(constant = @Constant(floatValue = 0.0F, ordinal = 0), method = "collectBlocksAndDamageEntities")
private float skipLoop(float prevValue) {
return Float.MAX_VALUE;
}

/**
* yadayada
* @param ci boilerplate
* @param set he set of positions of blocks destroyed.
* @param d d
* @param e e
* @param f f
*/
@Inject(
at = @At(
target = "Lnet/minecraft/util/math/random/Random;nextFloat()F",
value = "INVOKE_ASSIGN"
),
method = "collectBlocksAndDamageEntities"
)
private void newLoop(
CallbackInfo ci,
@Local LocalRef<Set<BlockPos>> set,
@Local(ordinal = 0) double d,
@Local(ordinal = 1) double e,
@Local(ordinal = 2) double f
) {
Set<BlockPos> newSet = set.get();

// these 4 already exist in the base class as local variables,
// but Fabric claims it can't find them - so I must redefine them here
float h = this.power * (0.7F + this.world.random.nextFloat() * 0.6F);
double m = this.x;
double n = this.y;
double o = this.z;

for (float p = 0.3F; h > 0.0F; h -= 0.22500001F) {
BlockPos blockPos = BlockPos.ofFloored(m, n, o);
BlockState blockState = this.world.getBlockState(blockPos);

if (BlockUtil.isDestroyable(blockState.getBlock())) {
continue;
}
}

this.affectedBlocks.addAll(set);
float q = this.power * 2.0F;
k = MathHelper.floor(this.x - (double)q - 1.0);
l = MathHelper.floor(this.x + (double)q + 1.0);
int r = MathHelper.floor(this.y - (double)q - 1.0);
int s = MathHelper.floor(this.y + (double)q + 1.0);
int t = MathHelper.floor(this.z - (double)q - 1.0);
int u = MathHelper.floor(this.z + (double)q + 1.0);
List<Entity> list = this.world.getOtherEntities(this.entity, new Box(k, r, t, l, s, u));
Vec3d vec3d = new Vec3d(this.x, this.y, this.z);
Iterator<Entity> var34 = list.iterator();

while(true) {
Entity entity;
double w;
double x;
double y;
double v;
double z;
do {
do {
do {
if (!var34.hasNext()) {
return;
}

entity = var34.next();
} while(entity.isImmuneToExplosion((Explosion)(Object)this));

v = Math.sqrt(entity.squaredDistanceTo(vec3d)) / (double)q;
} while(!(v <= 1.0));

w = entity.getX() - this.x;
x = (entity instanceof TntEntity ? entity.getY() : entity.getEyeY()) - this.y;
y = entity.getZ() - this.z;
z = Math.sqrt(w * w + x * x + y * y);
} while(z == 0.0);

w /= z;
x /= z;
y /= z;
if (this.behavior.shouldDamage((Explosion)(Object)this, entity)) {
entity.damage(this.damageSource, this.behavior.calculateDamage((Explosion)(Object)this, entity));
FluidState fluidState = this.world.getFluidState(blockPos);

if (!this.world.isInBuildLimit(blockPos)) {
break;
}

double aa = (1.0 - v) * (double)Explosion.getExposure(vec3d, entity) * (double)this.behavior.getKnockbackModifier(entity);
double ab;
if (entity instanceof LivingEntity livingEntity) {
ab = ProtectionEnchantment.transformExplosionKnockback(livingEntity, aa);
} else {
ab = aa;
Optional<Float> optional = this.behavior.getBlastResistance((Explosion) (Object) this, this.world, blockPos, blockState, fluidState);

if (optional.isPresent()) {
h -= (optional.get() + 0.3F) * 0.3F;
}

w *= ab;
x *= ab;
y *= ab;
Vec3d vec3d2 = new Vec3d(w, x, y);
entity.setVelocity(entity.getVelocity().add(vec3d2));
if (entity instanceof PlayerEntity playerEntity) {
if (!playerEntity.isSpectator() && (!playerEntity.isCreative() || !playerEntity.getAbilities().flying)) {
this.affectedPlayers.put(playerEntity, vec3d2);
}
if (h > 0.0F && this.behavior.canDestroyBlock((Explosion) (Object) this, this.world, blockPos, blockState, h)) {
newSet.add(blockPos);
set.set(newSet);
}

entity.onExplodedBy(this.entity);
m += d * 0.30000001192092896;
n += e * 0.30000001192092896;
o += f * 0.30000001192092896;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.PortalForcer;
import net.minecraft.world.dimension.PortalForcer;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,32 @@
* Patch for MC-123450
*
* Authored for CraftBukkit/Spigot by Phoenix616 <[email protected]> on November 5, 2022.
* Ported to Fabric by Rektroth <[email protected]> on April 26, 2024.
* Ported to Fabric by Rektroth <[email protected]> on April 27, 2024.
*/

package io.github.rektroth.whiteout.mixin.mc123450;

import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.MapIdComponent;
import net.minecraft.entity.decoration.ItemFrameEntity;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
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.Redirect;

@Mixin(ItemFrameEntity.class)
public abstract class ItemFrameEntityMixin {
/**
* Sets the map ID to the ID of the map in the player's item stack rather than the already removed map,
* so that the map ID is not null when it tries to remove the green marker.
* @param stack The item stack.
* @param ci boilerplate
* @param mapIdComponent The map ID.
* Redirects checking if the item frame is empty to check both that and if the item frame was updated,
* so that the item frame only plays a sound when updated.
* @param value The item stack.
* @param update Whether the item frame was updated.
* @return True if the item frame should play its place sound, false otherwise.
*/
@Inject(
at = @At(
target = "Lnet/minecraft/entity/decoration/ItemFrameEntity;getMapId()Lnet/minecraft/component/type/MapIdComponent;",
value = "INVOKE_ASSIGN"),
method = "removeFromFrame"
@Redirect(
at = @At(target = "Lnet/minecraft/item/ItemStack;isEmpty()Z", value = "INVOKE", ordinal = 1),
method = "setHeldItemStack(Lnet/minecraft/item/ItemStack;Z)V"
)
private void getMapIdFromItem(ItemStack stack, CallbackInfo ci, @Local LocalRef<MapIdComponent> mapIdComponent) {
mapIdComponent.set(stack.get(DataComponentTypes.MAP_ID));
private boolean shouldPlaySound(ItemStack value, @Local(argsOnly = true) boolean update) {
return !(!value.isEmpty() && update);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,40 @@
* Patch for MC-123848
*
* Authored for CraftBukkit/Spigot by Jake Potrebic <[email protected]> on July 11, 2022.
* Ported to Fabric by Rektroth <[email protected]> on April 27, 2024.
* Ported to Fabric by Rektroth <[email protected]> on April 25, 2024.
*/

package io.github.rektroth.whiteout.mixin.mc123848;

import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.decoration.AbstractDecorationEntity;
import net.minecraft.entity.decoration.ItemFrameEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(ItemFrameEntity.class)
public abstract class ItemFrameEntityMixin {
public abstract class ItemFrameEntityMixin extends AbstractDecorationEntity {
/**
* Redirects checking if the item frame is empty to check both that and if the item frame was updated,
* so that the item frame only plays a sound when updated.
* @param value The item stack.
* @param update Whether the item frame was updated.
* @return True if the item frame should play its place sound, false otherwise.
* boilerplate
* @param entityType boilerplate
* @param world boilerplate
*/
@Redirect(
at = @At(target = "Lnet/minecraft/item/ItemStack;isEmpty()Z", value = "INVOKE", ordinal = 1),
method = "setHeldItemStack(Lnet/minecraft/item/ItemStack;Z)V"
)
private boolean shouldPlaySound(ItemStack value, @Local(argsOnly = true) boolean update) {
return !(!value.isEmpty() && update);
protected ItemFrameEntityMixin(EntityType<? extends AbstractDecorationEntity> entityType, World world) {
super(entityType, world);
}

/**
* Overrides the parent method to drop the item stack as an entity *below* the item frame when facing down.
* @param stack The item stack.
* @return The item entity to drop.
*/
@Nullable
@Override
public ItemEntity dropStack(ItemStack stack) {
return this.dropStack(stack, getMovementDirection().equals(Direction.DOWN) ? -0.6F : 0.0F);
}
}
Loading

0 comments on commit 1f48a5b

Please sign in to comment.