Skip to content

Commit

Permalink
removed spawn chunks size rule. Hack for network stuff - may stay. 24…
Browse files Browse the repository at this point in the history
…w03a
  • Loading branch information
gnembon committed Jan 18, 2024
1 parent 4aec811 commit d524df5
Show file tree
Hide file tree
Showing 25 changed files with 116 additions and 194 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check https://fabricmc.net/develop/
minecraft_version=23w51b
loader_version=0.15.3
minecraft_version=24w03a
loader_version=0.15.6
jsr305_version=3.0.2
fabric_version=0.91.1+1.20.3

Expand Down
32 changes: 0 additions & 32 deletions src/main/java/carpet/CarpetSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import carpet.utils.Translations;
import carpet.utils.CommandHelper;
import carpet.utils.Messenger;
import carpet.utils.SpawnChunks;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.core.registries.Registries;
Expand Down Expand Up @@ -770,37 +769,6 @@ private static class SimulationDistanceValidator extends Validator<Integer>
)
public static int simulationDistance = 0;

public static class ChangeSpawnChunksValidator extends Validator<Integer> {
@Override public Integer validate(CommandSourceStack source, CarpetRule<Integer> currentRule, Integer newValue, String string) {
if (source == null) return newValue;
if (newValue < 0 || newValue > 32)
{
Messenger.m(source, "r spawn chunk size has to be between 0 and 32");
return null;
}
if (currentRule.value().intValue() == newValue.intValue())
{
//must been some startup thing
return newValue;
}
ServerLevel currentOverworld = source.getServer().overworld();
if (currentOverworld != null)
{
SpawnChunks.changeSpawnSize(currentOverworld, newValue);
}
return newValue;
}
}
@Rule(
desc = "Changes size of spawn chunks",
extra = {"Defines new radius", "setting it to 0 - disables spawn chunks"},
category = CREATIVE,
strict = false,
options = {"0", "11"},
validate = ChangeSpawnChunksValidator.class
)
public static int spawnChunksSize = MinecraftServer.START_CHUNK_RADIUS;

public enum RenewableCoralMode {
FALSE,
EXPANDED,
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/carpet/helpers/BlockRotator.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ else if (block instanceof PistonBaseBlock)
}
else if (block instanceof SlabBlock)
{
if (((SlabBlock) block).useShapeForLightOcclusion(state))
if (state.getValue(SlabBlock.TYPE) != SlabType.DOUBLE)
{
newState = state.setValue(SlabBlock.TYPE, state.getValue(SlabBlock.TYPE) == SlabType.TOP ? SlabType.BOTTOM : SlabType.TOP);
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/carpet/helpers/CarpetTaintedList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package carpet.helpers;

import java.util.ArrayList;
import java.util.List;

public class CarpetTaintedList<E> extends ArrayList<E>
{
public CarpetTaintedList(final List<E> list)
{
super(list);
}
}
2 changes: 1 addition & 1 deletion src/main/java/carpet/helpers/OptimizedExplosion.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public static void doExplosionB(Explosion e, boolean spawnParticles)
// explosionSound incremented till disabling the explosion particles and sound
if (explosionSound < 100 || explosionSound % 100 == 0)
{
world.playSound(null, posX, posY, posZ, SoundEvents.GENERIC_EXPLODE, SoundSource.BLOCKS, 4.0F,
world.playSound(null, posX, posY, posZ, SoundEvents.GENERIC_EXPLODE.value(), SoundSource.BLOCKS, 4.0F,
(1.0F + (world.random.nextFloat() - world.random.nextFloat()) * 0.2F) * 0.7F);

if (spawnParticles)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/carpet/helpers/RedstoneWireTurbo.java
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ private void breadthFirstWalk(final Level worldIn) {
// call BlockStateBase#neighborChanged directly. This change mostly
// restores old behavior, at the cost of bypassing the
// max-chained-neighbor-updates server property.
worldIn.getBlockState(upd.self).neighborChanged(worldIn, upd.self, wire, upd.parent, false);
worldIn.getBlockState(upd.self).handleNeighborChanged(worldIn, upd.self, wire, upd.parent, false);
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package carpet.mixins;

import carpet.helpers.CarpetTaintedList;
import carpet.network.CarpetClient;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
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.CallbackInfoReturnable;

import java.util.List;

@Mixin(CustomPacketPayload.class)
public interface CustomPacketPayload_networkStuffMixin
{
@Inject(method = "codec(Lnet/minecraft/network/protocol/common/custom/CustomPacketPayload$FallbackProvider;Ljava/util/List;)Lnet/minecraft/network/codec/StreamCodec;", at = @At("HEAD"), cancellable = true)
private static <B extends FriendlyByteBuf> void onCodec(final CustomPacketPayload.FallbackProvider<B> fallbackProvider, final List<CustomPacketPayload.TypeAndCodec<? super B, ?>> list, final CallbackInfoReturnable<StreamCodec<B, CustomPacketPayload>> cir)
{
// this is stupid hack to make sure carpet payloads are always registered
// that might collide with other mods that do the same thing
// so we may need to adjust this in the future
if (!(list instanceof CarpetTaintedList))
{
List<CustomPacketPayload.TypeAndCodec<? super B, ?>> extendedList = new CarpetTaintedList<>(list);
extendedList.add(new CustomPacketPayload.TypeAndCodec<>(CarpetClient.CarpetPayload.TYPE, CarpetClient.CarpetPayload.STREAM_CODEC));
cir.setReturnValue(CustomPacketPayload.codec(fallbackProvider, extendedList));
}
}
}
6 changes: 3 additions & 3 deletions src/main/java/carpet/mixins/Explosion_optimizedTntMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import carpet.logging.LoggerRegistry;
import carpet.logging.logHelpers.ExplosionLogHelper;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.minecraft.core.Holder;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.monster.breeze.Breeze;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -81,9 +81,9 @@ private BlockState noBlockCalcsWithNoBLockDamage(Level world, BlockPos pos)
return world.getBlockState(pos);
}

@Inject(method = "<init>(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/damagesource/DamageSource;Lnet/minecraft/world/level/ExplosionDamageCalculator;DDDFZLnet/minecraft/world/level/Explosion$BlockInteraction;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/sounds/SoundEvent;)V",
@Inject(method = "<init>(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/damagesource/DamageSource;Lnet/minecraft/world/level/ExplosionDamageCalculator;DDDFZLnet/minecraft/world/level/Explosion$BlockInteraction;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/core/Holder;)V",
at = @At(value = "RETURN"))
private void onExplosionCreated(Level world, Entity entity, DamageSource damageSource, ExplosionDamageCalculator explosionBehavior, double x, double y, double z, float power, boolean createFire, Explosion.BlockInteraction destructionType, ParticleOptions particleOptions, ParticleOptions particleOptions2, SoundEvent soundEvent, CallbackInfo ci)
private void onExplosionCreated(Level world, Entity entity, DamageSource damageSource, ExplosionDamageCalculator explosionBehavior, double x, double y, double z, float power, boolean createFire, Explosion.BlockInteraction destructionType, ParticleOptions particleOptions, ParticleOptions particleOptions2, Holder soundEvent, CallbackInfo ci)
{
if (LoggerRegistry.__explosions && ! world.isClientSide)
{
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/carpet/mixins/Explosion_scarpetEventMixin.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package carpet.mixins;

import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.minecraft.core.Holder;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.sounds.SoundEvent;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
Expand Down Expand Up @@ -45,9 +45,9 @@ public abstract class Explosion_scarpetEventMixin

private List<Entity> affectedEntities;

@Inject(method = "<init>(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/damagesource/DamageSource;Lnet/minecraft/world/level/ExplosionDamageCalculator;DDDFZLnet/minecraft/world/level/Explosion$BlockInteraction;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/sounds/SoundEvent;)V",
@Inject(method = "<init>(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/damagesource/DamageSource;Lnet/minecraft/world/level/ExplosionDamageCalculator;DDDFZLnet/minecraft/world/level/Explosion$BlockInteraction;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/core/Holder;)V",
at = @At(value = "RETURN"))
private void onExplosionCreated(Level world, Entity entity, DamageSource damageSource, ExplosionDamageCalculator explosionBehavior, double x, double y, double z, float power, boolean createFire, Explosion.BlockInteraction destructionType, ParticleOptions particleOptions, ParticleOptions particleOptions2, SoundEvent soundEvent, CallbackInfo ci)
private void onExplosionCreated(Level world, Entity entity, DamageSource damageSource, ExplosionDamageCalculator explosionBehavior, double x, double y, double z, float power, boolean createFire, Explosion.BlockInteraction destructionType, ParticleOptions particleOptions, ParticleOptions particleOptions2, Holder soundEvent, CallbackInfo ci)
{
if (EXPLOSION_OUTCOME.isNeeded() && !world.isClientSide())
{
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/carpet/mixins/MinecraftServer_coreMixin.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package carpet.mixins;

import carpet.CarpetServer;
import carpet.CarpetSettings;
import carpet.utils.CarpetProfiler;
import carpet.utils.SpawnChunks;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.progress.ChunkProgressListener;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand Down Expand Up @@ -61,11 +58,4 @@ private void serverDoneClosed(CallbackInfo ci)

@Shadow
public abstract ServerLevel overworld();

@Inject(method = "prepareLevels", at = @At("RETURN"))
private void afterSpawnCreated(ChunkProgressListener worldGenerationProgressListener, CallbackInfo ci)
{
if (CarpetSettings.spawnChunksSize != 11)
SpawnChunks.changeSpawnSize(overworld(), CarpetSettings.spawnChunksSize);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected PickaxeItem_missingToolsMixin(float attackDamage, float attackSpeed, T

@Override
public float getDestroySpeed(ItemStack stack, BlockState state) {
if (CarpetSettings.missingTools && state.getBlock().getSoundType(state) == SoundType.GLASS)
if (CarpetSettings.missingTools && state.getSoundType() == SoundType.GLASS)
{
return speed;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/carpet/mixins/ServerLevel_scarpetMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private Explosion.BlockInteraction getCMDestroyType(final GameRules.Key<GameRule
}

@Inject(method = "explode", at = @At("HEAD"))
private void handleExplosion(/*@Nullable*/ Entity entity, /*@Nullable*/ DamageSource damageSource, /*@Nullable*/ ExplosionDamageCalculator explosionBehavior, double d, double e, double f, float g, boolean bl, ExplosionInteraction explosionInteraction, ParticleOptions particleOptions, ParticleOptions particleOptions2, SoundEvent soundEvent, CallbackInfoReturnable<Explosion> cir)
private void handleExplosion(/*@Nullable*/ Entity entity, /*@Nullable*/ DamageSource damageSource, /*@Nullable*/ ExplosionDamageCalculator explosionBehavior, double d, double e, double f, float g, boolean bl, ExplosionInteraction explosionInteraction, ParticleOptions particleOptions, ParticleOptions particleOptions2, Holder<SoundEvent> soundEvent, CallbackInfoReturnable<Explosion> cir)
{
if (EXPLOSION.isNeeded()) {
Explosion.BlockInteraction var10000 = switch (explosionInteraction) {
Expand Down
17 changes: 0 additions & 17 deletions src/main/java/carpet/mixins/ServerLevel_spawnChunksMixin.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
package carpet.mixins;

import carpet.CarpetSettings;
import com.mojang.authlib.GameProfile;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
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.callback.CallbackInfoReturnable;

@Mixin(value = ServerPlayer.class)
public abstract class ServerPlayerGameMode_antiCheatMixin extends Player
@Mixin(value = Player.class)
public abstract class ServerPlayerGameMode_antiCheatMixin extends LivingEntity
{
public ServerPlayerGameMode_antiCheatMixin(final Level level, final BlockPos blockPos, final float f, final GameProfile gameProfile)
@Shadow public abstract double entityInteractionRange();

@Shadow public abstract double blockInteractionRange();

protected ServerPlayerGameMode_antiCheatMixin(final EntityType<? extends LivingEntity> entityType, final Level level)
{
super(level, blockPos, f, gameProfile);
super(entityType, level);
}

@Inject(method = "canInteractWithBlock", at = @At("HEAD"), cancellable = true)
private void canInteractLongRangeBlock(BlockPos pos, CallbackInfoReturnable<Boolean> cir)
private void canInteractLongRangeBlock(BlockPos pos, double d, CallbackInfoReturnable<Boolean> cir)
{
double maxRange = blockInteractionRange() + 1.0;
double maxRange = blockInteractionRange() + d;
maxRange = maxRange * maxRange;
if (CarpetSettings.antiCheatDisabled && maxRange < 1024 && getEyePosition().distanceToSqr(Vec3.atCenterOf(pos)) < 1024) cir.setReturnValue(true);
}

@Inject(method = "canInteractWithEntity", at = @At("HEAD"), cancellable = true)
private void canInteractLongRangeEntity(AABB aabb, CallbackInfoReturnable<Boolean> cir)
@Inject(method = "canInteractWithEntity(Lnet/minecraft/world/phys/AABB;D)Z", at = @At("HEAD"), cancellable = true)
private void canInteractLongRangeEntity(AABB aabb, double d, CallbackInfoReturnable<Boolean> cir)
{
double maxRange = entityInteractionRange() + 1.0;
double maxRange = entityInteractionRange() + d;
maxRange = maxRange * maxRange;
if (CarpetSettings.antiCheatDisabled && maxRange < 1024 && aabb.distanceToSqr(getEyePosition()) < 1024) cir.setReturnValue(true);
}
Expand Down

This file was deleted.

11 changes: 7 additions & 4 deletions src/main/java/carpet/network/CarpetClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,31 @@
import net.minecraft.nbt.Tag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;

public class CarpetClient
{
public record CarpetPayload(CompoundTag data) implements CustomPacketPayload
{
public static final StreamCodec<FriendlyByteBuf, CarpetPayload> STREAM_CODEC = CustomPacketPayload.codec(CarpetPayload::write, CarpetPayload::new);

public static final Type<CarpetPayload> TYPE = new CustomPacketPayload.Type<>(CARPET_CHANNEL);

public CarpetPayload(FriendlyByteBuf input)
{
this(input.readNbt());
}

@Override
public void write(FriendlyByteBuf output)
{
output.writeNbt(data);
}

@Override
public ResourceLocation id()
@Override public Type<CarpetPayload> type()
{
return CARPET_CHANNEL;
return TYPE;
}
}

Expand Down
Loading

0 comments on commit d524df5

Please sign in to comment.