Skip to content

Commit

Permalink
Cleanup & Commenting code before updating to 1.17
Browse files Browse the repository at this point in the history
  • Loading branch information
FxMorin committed Jun 10, 2021
1 parent e3049a8 commit d628fdf
Show file tree
Hide file tree
Showing 33 changed files with 157 additions and 81 deletions.
3 changes: 1 addition & 2 deletions src/main/java/carpetfixes/helpers/IDrownedEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import net.minecraft.entity.ai.pathing.EntityNavigation;

public interface IDrownedEntity
{
public interface IDrownedEntity {
EntityNavigation getInitialEntityNavigation();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import net.minecraft.state.property.Property;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -23,9 +22,14 @@ public AbstractRailBlock_invalidUpdateMixin(Settings settings) {
}

@Shadow public abstract Property<RailShape> getShapeProperty();

@Shadow private static boolean shouldDropRail(BlockPos pos, World world, RailShape shape) { return true;}

/**
* The issue here is that the rail updates the other rails near it before
* checking if its in a valid place. This should be the other way round,
* we check if its in a valid place and if its not, then we break the rail
* on if its in a valid place do we update the rails near it.
*/
@Inject(method = "onBlockAdded(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Z)V", at = @At("HEAD"), cancellable = true)
private void updateNeighborsExceptWithBetterDirection(BlockState state, World world, BlockPos pos, BlockState oldState, boolean notify, CallbackInfo ci) {
if (CarpetFixesSettings.railInvalidUpdateOnPushFix) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public AbstractRailBlock_missingUpdateAfterPushMixin(Settings settings) {
@Shadow public abstract Property<RailShape> getShapeProperty();
@Shadow @Final private boolean allowCurves;

/**
* Due to how rails work, if you push them they don't get an update once
* they arrive at there new spot, causing some illegal states that should
* not be happening. We fix this by giving the correct updates.
*/
@Inject(method = "onBlockAdded(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Z)V", at = @At("HEAD"), cancellable = true)
protected void alwaysGiveUpdate(BlockState state, World world, BlockPos pos, BlockState oldState, boolean notify, CallbackInfo ci) {
if (CarpetFixesSettings.railMissingUpdateAfterPushFix) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@ public AbstractRailBlock_missingUpdateOnPushMixin(Settings settings) {
@Shadow public abstract Property<RailShape> getShapeProperty();
@Shadow @Final private boolean allowCurves;

/**
* When pushing rails, we don't update blocks right after turning into a B36
* (Moving_Piston) so some blocks do not realize that they are no longer
* powered or are curved incorrectly. Therefore the fix is to give the
* extra block updates to make sure the rails are updated correctly.
*/
@Inject(method = "onStateReplaced(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Z)V", at = @At("HEAD"))
protected void alwaysGiveUpdate(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved, CallbackInfo ci) {
if (moved && CarpetFixesSettings.railMissingUpdateOnPushFix) {
super.onStateReplaced(state, world, pos, newState, true);
if ((state.get(this.getShapeProperty())).isAscending()) {
world.updateNeighborsAlways(pos.up(), this);
}

if (this.allowCurves) {
world.updateNeighborsAlways(pos, this);
world.updateNeighborsAlways(pos.down(), this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ public class HopperBlock_MissingUpdateMixin extends Block {

public HopperBlock_MissingUpdateMixin(Settings settings) {super(settings);}

/**
* The hopper when placed next to a power source does not give the
* correct block updates, causing some unintended behaviour. We make
* sure to give that correct update here by adding binary 1 to the update.
* Which will add block updates, fixing all the issues.
*/
@ModifyArg(method = "updateEnabled(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"), index = 2)
protected int hopperUpdate(int value) { return CarpetFixesSettings.hopperUpdateFix ? 5 : 4; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ public class SpongeBlock_MissingUpdateMixin extends Block {

public SpongeBlock_MissingUpdateMixin(Settings settings) {super(settings);}

/**
* The sponge when placed next to water does not give the correct block
* updates, causing some unintended behaviour. We make sure to give that
* correct update here by adding binary 1 to the update. Which will add
* block updates, fixing all the issues.
*/
@ModifyArg(method = "update(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"), index = 2)
protected int spongeUpdate(int value) {
return CarpetFixesSettings.spongeUpdateFix ? 3 : 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public class World_blockUpdateOrderMixin {

@Shadow public void updateNeighbor(BlockPos sourcePos, Block sourceBlock, BlockPos neighborPos){}

/**
* This fix is based on the block update order. Vanilla block update order
* is XYZ, resulting in directional behaviour. In this fix we change the
* block update order to XZY, which fixes all directional problems based
* on block updates.
*/
@Inject(method = "updateNeighborsAlways(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/Block;)V", at = @At("HEAD"), cancellable = true)
private void updateNeighborsAlwaysWithBetterDirection(BlockPos pos, Block block, CallbackInfo ci) {
if (CarpetFixesSettings.blockUpdateOrderFix) {
Expand All @@ -31,8 +37,7 @@ private void updateNeighborsAlwaysWithBetterDirection(BlockPos pos, Block block,
private void updateNeighborsExceptWithBetterDirection(BlockPos pos, Block sourceBlock, Direction direction, CallbackInfo ci) {
if (CarpetFixesSettings.blockUpdateOrderFix) {
for(int dirNum = 0; dirNum < 6; ++dirNum) {
Direction dir = CarpetFixesInit.directions[dirNum];
if (direction != dir) {
if (direction != CarpetFixesInit.directions[dirNum]) {
this.updateNeighbor(pos.offset(CarpetFixesInit.directions[dirNum]), sourceBlock, pos);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
@Mixin(Biome.class)
public class Biome_featureOrderMixin {

/**
* Here we inject the lake feature before every other feature. This makes sure
* that vegetation is done after the lakes, so that no lakes replace the blocks
* below grass & other vegetation.
*/
@Inject(
method = "generateFeatureStep(Lnet/minecraft/world/gen/StructureAccessor;Lnet/minecraft/world/gen/chunk/ChunkGenerator;Lnet/minecraft/world/ChunkRegion;JLnet/minecraft/world/gen/ChunkRandom;Lnet/minecraft/util/math/BlockPos;)V",
at = @At(value = "INVOKE", target = "Ljava/util/List;size()I")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

@Mixin(Feature.class)
public class Feature_featureOrderMixin {
/**
* Here we set the lake feature to be set to nothing, so that the injection
* of the lake feature at the beginning is the only lake feature done. I
* wish I could modify the code directly and just add a new group just for
* carvers that are not actually carvers but modify terrain.
*/
@Inject(
method = "register(Ljava/lang/String;Lnet/minecraft/world/gen/feature/Feature;)Lnet/minecraft/world/gen/feature/Feature;",
at = @At("HEAD"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ public class ServerPlayNetworkHandler_vehicleFloatingMixin {
@Shadow private boolean floating;
@Shadow private boolean ridingEntity;

/**
* You can get kicked for flying by mounding an entity after jumping, this is
* because the server does not realize that you mounting an entity means you
* are no longer jumping. So this fix is as simple as telling the server
* that if they are riding an entity, they should not be considered floating
*/
@Inject(method = "onVehicleMove(Lnet/minecraft/network/packet/c2s/play/VehicleMoveC2SPacket;)V", at = @At("RETURN"))
public void IfVehicleMovedPlayerNotFlying(VehicleMoveC2SPacket packet, CallbackInfo ci){
if (CarpetFixesSettings.mountingFlyingTooLongFix && this.ridingEntity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
@Mixin(ServerWorld.class)
public class ServerWorld_spawnChunksMixin {

/**
* If the player list is considered empty, the spawn chunks are no longer
* loaded. The fix is just to make sure that the player list is never
* considered empty.
*/
@Redirect(method= "tick(Ljava/util/function/BooleanSupplier;)V",at=@At(value="INVOKE",target="Ljava/util/List;isEmpty()Z"))
public boolean spawnChunksStayLoaded(List list) {
return !CarpetFixesSettings.spawnChunkEntitiesUnloadingFix && list.isEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,23 @@ public abstract class StringTag_ChunkRegenMixin {

@Mutable @Shadow @Final private String value;

//DataInput.readUTF() is the issue only because DataInput.writeUTF() is writing strings that
//DataInput.readUTF() is unable to read. This crops string during the write so its fine during read

/**
* This fix is crucial for multiple game breaking crashes, exploits, banning
* methods. This bug happens because DataInput.writeUTF() is writing strings
* that DataInput.readUTF() is unable to read. For some reason they do not
* follow the same restrictions. The fix crops the strings during the write
* so its fine during read. Therefore fixing all the issues
*/
@Inject(method = "write(Ljava/io/DataOutput;)V", at = @At("HEAD"))
private void respectReadLimitDuringWrite(DataOutput output, CallbackInfo ci) {
if(CarpetFixesSettings.chunkRegenFix) {
int strlen = this.value.length();
if(strlen > 28501) { //Minimum number that could bypass limit
int utflen = 0;
char c;
/* Mostly same equation used in DataOutputStream */
for (int i = 0; i < strlen; i++) {
c = this.value.charAt(i);
if ((c >= 0x0001) && (c <= 0x007F)) {
utflen++;
} else if (c <= 0x07FF) {
utflen += 2;
} else {
utflen += 3;
}
utflen += ((c >= 0x0001) && (c <= 0x007F)) ? 1 : (c <= 0x07FF) ? 2 : 3;
if (utflen > 65535) {
this.value = this.value.substring(0, i-2);
LOGGER.debug("Trimming Large String ("+strlen+" -> "+this.value.length()+")");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,15 @@ private static void getNoiseAt(SimplexNoiseSampler simplexNoiseSampler, int x, i
int chunkZ = z / 2;
int chunkSectionX = x % 2;
int chunkSectionZ = z % 2;
float noiseShift = -100;
if (MathHelper.abs(x) < 400 && MathHelper.abs(z) < 400) {
noiseShift = 400 - MathHelper.sqrt(x * x + z * z) * 8;
noiseShift = MathHelper.clamp(noiseShift, -100, 80);
}

float noiseShift = (MathHelper.abs(x) < 400 && MathHelper.abs(z) < 400) ? MathHelper.clamp(400 - MathHelper.sqrt(x * x + z * z) * 8, -100, 80) : -100;
for (int islandX = -12; islandX <= 12; ++islandX) {
long areaX = (chunkX + islandX);
for (int islandZ = -12; islandZ <= 12; ++islandZ) {
long areaX = (chunkX + islandX);
long areaZ = (chunkZ + islandZ);
if (areaX * areaX + areaZ * areaZ > 4096L && simplexNoiseSampler.sample(areaX, areaZ) < -0.8999999761581421D) {
float seedX = (chunkSectionX - islandX * 2);
float seedZ = (chunkSectionZ - islandZ * 2);
float compression = 100.0F - MathHelper.sqrt(seedX * seedX + seedZ * seedZ) * ((MathHelper.abs(areaX) * 3439.0F + MathHelper.abs(areaZ) * 147.0F) % 13.0F + 9.0F);
compression = MathHelper.clamp(compression, -100.0F, 80.0F);
noiseShift = Math.max(noiseShift, compression);
noiseShift = Math.max(noiseShift, MathHelper.clamp(100.0F - MathHelper.sqrt(seedX * seedX + seedZ * seedZ) * ((MathHelper.abs(areaX) * 3439.0F + MathHelper.abs(areaZ) * 147.0F) % 13.0F + 9.0F), -100.0F, 80.0F));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(DrownedEntity.class)
public interface DrownedEntity_drownedMemoryLeakAccessor
{
@Accessor
SwimNavigation getWaterNavigation();

@Accessor
MobNavigation getLandNavigation();
public interface DrownedEntity_drownedMemoryLeakAccessor {
@Accessor SwimNavigation getWaterNavigation();
@Accessor MobNavigation getLandNavigation();
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
public class AbstractRailBlock_duplicationMixin {
@Inject(method = "neighborUpdate", require = 1, at = @At(value = "INVOKE", target = "Lnet/minecraft/block/AbstractRailBlock;updateBlockState(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/Block;)V"), cancellable = true)
private void IfRailIsSetCorrectly(BlockState state, World world, BlockPos pos, Block block, BlockPos neighborPos, boolean moved, CallbackInfo ci) {
if (CarpetFixesSettings.railDuplicationFix) {
if (!(world.getBlockState(pos).getBlock() instanceof AbstractRailBlock)) {
ci.cancel();
}
if (CarpetFixesSettings.railDuplicationFix && !(world.getBlockState(pos).getBlock() instanceof AbstractRailBlock)) {
ci.cancel();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public FallingBlockEntity_duplicationMixin(EntityType<?> type, World world) {
super(type, world);
}

/**
* Cancel the entity removal if the entity is already considered dead. This
* prevents duplication of the falling block entity using portals
*/
@Inject(method = "tick()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/FallingBlockEntity;remove()V"), cancellable = true)
private void cancelDupe(CallbackInfo ci) {
if(CarpetFixesSettings.fallingBlockDuplicationFix && !this.isAlive()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@

@Mixin(MobEntity.class)
abstract class MobEntity_portalGeneralItemMixin extends LivingEntity {
protected MobEntity_portalGeneralItemMixin(EntityType<? extends LivingEntity> entityType, World world) {
super(entityType, world);
}
protected MobEntity_portalGeneralItemMixin(EntityType<? extends LivingEntity> entityType, World world) { super(entityType, world); }

/**
* Set all stack counts to 0 when changing dimension. This makes absolutely
* sure that no item can be duped while changing dimension.
*/
@Inject(method= "method_30076()V",at=@At("RETURN"))
protected void stopGeneralItemDupes(CallbackInfo ci) {
if (CarpetFixesSettings.portalGeneralItemDupeFix) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
public class CatEntity$SleepWithOwnerGoal_breakLeashMixin {
@Shadow @Final private CatEntity cat;

/**
* Basically before doing the teleport check if the cat is on a lead
* If so, then teleport it around the lead so that we don't accidentally
* break the lead and risk someone's pet cat escaping
*/
@Redirect(method = "dropMorningGifts()V", at = @At(value="INVOKE",target="Lnet/minecraft/util/math/BlockPos$Mutable;set(Lnet/minecraft/util/math/Vec3i;)Lnet/minecraft/util/math/BlockPos$Mutable;", ordinal=0))
public BlockPos.Mutable SetCorrectly(BlockPos.Mutable mutable, Vec3i pos) {
if (CarpetFixesSettings.catsBreakLeadsDuringGiftFix && this.cat.isLeashed()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

@Mixin(DrownedEntity.class)
public class DrownedEntity_enchantedTridentMixin extends ZombieEntity {
public DrownedEntity_enchantedTridentMixin(EntityType<? extends ZombieEntity> entityType, World world) {
super(entityType, world);
}
public DrownedEntity_enchantedTridentMixin(EntityType<? extends ZombieEntity> entityType, World world) { super(entityType, world); }

@Redirect(method = "attack", at = @At(value = "NEW", target = "net/minecraft/item/ItemStack"))
private ItemStack createItemStack(ItemConvertible item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
@Mixin(EndCrystalEntity.class)
public class EndCrystalEntity_ExplosionChainingMixin {

/**
* Just bypass the isExplosionCheck, I can tell Mojang didn't want that much
* recursion within the explosion which is why its not doing it. Although
* they would need to implement an explosion list of entity ticking of sorts
* which is too much for a fix to do.
*/
@Inject(method = "damage(Lnet/minecraft/entity/damage/DamageSource;F)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/damage/DamageSource;isExplosive()Z"),cancellable = true)
public void isExplosiveBypass(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) {
cir.setReturnValue(CarpetFixesSettings.crystalExplodeOnExplodedFix || source.isExplosive());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public class EndermanEntity$PlaceBlockGoal_updatePlaceMixin {

@Shadow @Final private EndermanEntity enderman;

/**
* Add the onPlaced() condition after the placeBlock which will make sure
* that blocks placed by the enderman will be able to trigger special events
* such as summoning a wither
*/
@Redirect(method= "tick()V",at=@At(value="INVOKE",target="Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
public boolean placeCorrectly(World world, BlockPos pos, BlockState state, int flags){
if (CarpetFixesSettings.endermanDontUpdateOnPlaceFix) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package carpetfixes.mixins.entityFixes;

import net.minecraft.entity.Entity;
import net.minecraft.entity.data.DataTracker;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(Entity.class)
public interface EntityAccessorMixin
{
@Accessor("dataTracker")
DataTracker accessorGetDataTracker();
public interface EntityAccessorMixin {

@Accessor("world")
World accessorGetWorld();
Expand All @@ -24,7 +20,4 @@ public interface EntityAccessorMixin

@Invoker("getZ")
double invokerGetZ();

@Invoker("isSneaking")
boolean invokerIsSneaking();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public class Entity_directionalBlockSlowdownMixin {
@Shadow public float fallDistance;
@Shadow protected Vec3d movementMultiplier;

/**
* A very simple and nice fix, basically if the multiplier is not 0 (default)
* then we know there was a block that set the slowdown before us. So we check
* which block is the slowest and use that for the multiplier. Very simple and nice
*/
@Inject(method = "slowMovement(Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/Vec3d;)V", at = @At("HEAD"), cancellable = true)
public void slowMovement(BlockState state, Vec3d m, CallbackInfo ci) {
if (CarpetFixesSettings.directionalBlockSlowdownFix) {
Expand Down
Loading

0 comments on commit d628fdf

Please sign in to comment.