Skip to content

Commit

Permalink
misc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AViewFromTheTop committed Mar 1, 2025
1 parent d64f390 commit ec72618
Show file tree
Hide file tree
Showing 27 changed files with 136 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public void tick(@NotNull BlockState state, @NotNull ServerLevel level, @NotNull
@Override
public void onLand(@NotNull Level level, @NotNull BlockPos pos, @NotNull BlockState state, @NotNull BlockState replaceableState, @NotNull FallingBlockEntity fallingBlock) {
if (!level.isClientSide) {
level.setBlock(pos, replaceableState, UPDATE_ALL);
level.setBlockAndUpdate(pos, replaceableState);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ protected void neighborChanged(BlockState blockState, @NotNull Level level, Bloc
newState = newState.setValue(GEYSER_STAGE, GeyserStage.ERUPTING);
}
}
level.setBlock(blockPos, newState, UPDATE_ALL);
level.setBlockAndUpdate(blockPos, newState);
}
}
}
Expand Down Expand Up @@ -187,7 +187,7 @@ public static GeyserType getGeyserTypeForPos(@NotNull LevelAccessor level, @NotN
public void tick(@NotNull BlockState state, @NotNull ServerLevel level, @NotNull BlockPos pos, @NotNull RandomSource random) {
GeyserType geyserType = getGeyserTypeForPos(level, state, pos);
if (geyserType != state.getValue(GEYSER_TYPE)) {
level.setBlock(pos, state.setValue(GEYSER_TYPE, geyserType), UPDATE_ALL);
level.setBlockAndUpdate(pos, state.setValue(GEYSER_TYPE, geyserType));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public HangingTendrilBlock(@NotNull Properties settings) {
}

public static void deactivate(@NotNull Level level, @NotNull BlockPos pos, @NotNull BlockState state, RandomSource random) {
level.setBlock(pos, state.setValue(PHASE, SculkSensorPhase.INACTIVE).setValue(POWER, 0), UPDATE_ALL);
level.setBlockAndUpdate(pos, state.setValue(PHASE, SculkSensorPhase.INACTIVE).setValue(POWER, 0));
if (!state.getValue(WATERLOGGED)) {
level.playSound(null, pos, WWSounds.BLOCK_HANGING_TENDRIL_CLICKING_STOP, SoundSource.BLOCKS, 1F, random.nextFloat() * 0.2F + 0.8F);
}
Expand Down Expand Up @@ -233,7 +233,7 @@ public void activate(
int power,
int frequency
) {
level.setBlock(pos, state.setValue(PHASE, SculkSensorPhase.ACTIVE).setValue(POWER, power), UPDATE_ALL);
level.setBlockAndUpdate(pos, state.setValue(PHASE, SculkSensorPhase.ACTIVE).setValue(POWER, power));
boolean tendrilsCarryEvents = WWBlockConfig.get().sculk.tendrilsCarryEvents;
SculkSensorBlock.updateNeighbours(level, pos, state);
SculkSensorBlock.tryResonateVibration(tendrilsCarryEvents ? entity : null, level, pos, frequency);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

import com.google.common.annotations.VisibleForTesting;
import com.mojang.serialization.MapCodec;
import java.util.Iterator;
import java.util.Optional;
import java.util.function.BiPredicate;
import java.util.function.Predicate;
import net.frozenblock.wilderwild.block.entity.IcicleBlockEntity;
import net.frozenblock.wilderwild.block.impl.SnowloggingUtils;
import net.frozenblock.wilderwild.registry.WWBlockEntityTypes;
Expand Down Expand Up @@ -69,10 +73,6 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Iterator;
import java.util.Optional;
import java.util.function.BiPredicate;
import java.util.function.Predicate;

public class IcicleBlock extends BaseEntityBlock implements Fallable, SimpleWaterloggedBlock {
public static final MapCodec<IcicleBlock> CODEC = simpleCodec(IcicleBlock::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static boolean canScorch(@NotNull BlockState state) {
public static void scorch(@NotNull BlockState state, @NotNull Level level, @NotNull BlockPos pos) {
state = stateWithoutDusting(state);
if (canScorch(state)) {
level.setBlock(pos, SCORCH_MAP.get(state), UPDATE_ALL);
level.setBlockAndUpdate(pos, SCORCH_MAP.get(state));
level.gameEvent(null, GameEvent.BLOCK_CHANGE, pos);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,14 @@ public BlockState playerWillDestroy(@NotNull Level level, @NotNull BlockPos pos,
}

@Override
public void playerDestroy(@NotNull Level level, @NotNull Player player, @NotNull BlockPos pos, @NotNull BlockState state, @Nullable BlockEntity blockEntity, @NotNull ItemStack stack) {
public void playerDestroy(
@NotNull Level level,
@NotNull Player player,
@NotNull BlockPos pos,
@NotNull BlockState state,
@Nullable BlockEntity blockEntity,
@NotNull ItemStack stack
) {
if (SnowloggingUtils.isSnowlogged(state)) {
BlockState snowEquivalent = SnowloggingUtils.getSnowEquivalent(state);
if (player.hasCorrectToolForDrops(snowEquivalent)) {
Expand Down Expand Up @@ -300,13 +307,13 @@ public BlockState setAgeOnBothHalves(@NotNull BlockState state, @NotNull Level l

public void removeTopHalfIfYoung(@NotNull BlockState state, @NotNull Level level, @NotNull BlockPos pos) {
if (state.is(this) && !isLower(state) && !isFullyGrown(state)) {
level.setBlock(pos, level.getFluidState(pos).createLegacyBlock(), UPDATE_ALL);
level.setBlockAndUpdate(pos, level.getFluidState(pos).createLegacyBlock());
return;
}
BlockPos movedPos = pos.above();
BlockState secondState = level.getBlockState(movedPos);
if (secondState.is(this) && !isLower(secondState) && !isFullyGrown(secondState)) {
level.setBlock(movedPos, level.getFluidState(movedPos).createLegacyBlock(), UPDATE_ALL);
level.setBlockAndUpdate(movedPos, level.getFluidState(movedPos).createLegacyBlock());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.LevelEvent;
import net.minecraft.world.level.block.SupportType;
import net.minecraft.world.level.block.entity.BlockEntity;
Expand Down Expand Up @@ -336,7 +335,7 @@ public void setDormant(Level level, BlockPos pos, BlockState state, RandomSource
}

public void setStageAndCooldown(@NotNull Level level, BlockPos pos, @NotNull BlockState state, GeyserStage geyserStage, RandomSource random) {
level.setBlock(pos, state.setValue(GeyserBlock.GEYSER_STAGE, geyserStage), Block.UPDATE_ALL);
level.setBlockAndUpdate(pos, state.setValue(GeyserBlock.GEYSER_STAGE, geyserStage));
if (geyserStage == GeyserStage.ACTIVE) {
this.ticksUntilNextEvent = random.nextInt(MIN_ACTIVE_TICKS, MAX_ACTIVE_TICKS);
} else if (geyserStage != GeyserStage.ERUPTING) { // Eruption duration is set in serverTick to work with Redstone properly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.jetbrains.annotations.NotNull;

public class ScorchedBlockEntity extends BlockEntity {
private static final int RESET_DELAY = 40;
private int brushCount;
private long brushCountResetsAtTick;
private long coolDownEndsAtTick;
Expand All @@ -39,7 +40,7 @@ public ScorchedBlockEntity(@NotNull BlockPos blockPos, @NotNull BlockState block
}

public boolean brush(long l) {
this.brushCountResetsAtTick = l + 40L;
this.brushCountResetsAtTick = l + RESET_DELAY;
if (l < this.coolDownEndsAtTick || !(this.level instanceof ServerLevel)) {
return false;
}
Expand All @@ -49,20 +50,18 @@ public boolean brush(long l) {
this.brushingCompleted();
return true;
}
this.level.scheduleTick(this.getBlockPos(), this.getBlockState().getBlock(), 40);
int j = this.getCompletionState();
if (i != j) {
this.level.scheduleTick(this.getBlockPos(), this.getBlockState().getBlock(), RESET_DELAY);
int completionState = this.getCompletionState();
if (i != completionState) {
BlockState blockState = this.getBlockState();
BlockState blockState2 = blockState.setValue(BlockStateProperties.DUSTED, j);
this.level.setBlock(this.getBlockPos(), blockState2, 3);
BlockState blockState2 = blockState.setValue(BlockStateProperties.DUSTED, completionState);
this.level.setBlockAndUpdate(this.getBlockPos(), blockState2);
}
return false;
}

private void brushingCompleted() {
if (this.level == null || this.level.getServer() == null) {
return;
}
if (this.level == null || this.level.getServer() == null) return;
this.level.levelEvent(LevelEvent.PARTICLES_AND_SOUND_BRUSH_BLOCK_COMPLETE, this.worldPosition, Block.getId(this.getBlockState()));
ScorchedBlock.hydrate(this.getBlockState(), this.level, this.worldPosition);
this.brushCount = 0;
Expand All @@ -79,7 +78,7 @@ public void checkReset() {
this.brushCount = Math.max(0, this.brushCount - 2);
int j = this.getCompletionState();
if (i != j) {
this.level.setBlock(this.getBlockPos(), this.getBlockState().setValue(BlockStateProperties.DUSTED, j), Block.UPDATE_ALL);
this.level.setBlockAndUpdate(this.getBlockPos(), this.getBlockState().setValue(BlockStateProperties.DUSTED, j));
}
this.brushCountResetsAtTick = this.level.getGameTime() + 4L;
}
Expand All @@ -92,17 +91,10 @@ public void checkReset() {
}

private int getCompletionState() {
if (this.brushCount == 0) {
return 0;
}
if (this.brushCount < 3) {
return 1;
}
if (this.brushCount < 6) {
return 2;
}
if (this.brushCount == 0) return 0;
if (this.brushCount < 3) return 1;
if (this.brushCount < 6) return 2;
return 3;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public static void onRandomTick(BlockState state, ServerLevel level, BlockPos po
if (isSnowlogged(state)) {
if (level.getBrightness(LightLayer.BLOCK, pos) > 11) {
Block.dropResources(getSnowEquivalent(state), level, pos);
level.setBlock(pos, state.setValue(SNOW_LAYERS, 0), Block.UPDATE_ALL);
level.setBlockAndUpdate(pos, state.setValue(SNOW_LAYERS, 0));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package net.frozenblock.wilderwild.block.impl;

import com.google.common.collect.ImmutableMap;
import java.util.Map;
import net.frozenblock.wilderwild.registry.WWBlocks;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.WorldGenLevel;
Expand All @@ -27,7 +28,6 @@
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import java.util.Map;

public class SnowyBlockUtils {
public static final Map<Block, Block> SNOWY_BLOCK_MAP = ImmutableMap.<Block, Block>builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,16 @@
import net.minecraft.world.item.Items;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.DoublePlantBlock;
import net.minecraft.world.level.block.SlabBlock;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
import net.minecraft.world.level.block.state.properties.SlabType;
import net.minecraft.world.level.storage.loot.IntRange;
import net.minecraft.world.level.storage.loot.LootPool;
import net.minecraft.world.level.storage.loot.LootTable;
import net.minecraft.world.level.storage.loot.entries.LootItem;
import net.minecraft.world.level.storage.loot.functions.ApplyBonusCount;
import net.minecraft.world.level.storage.loot.functions.CopyBlockState;
import net.minecraft.world.level.storage.loot.functions.CopyComponentsFunction;
import net.minecraft.world.level.storage.loot.functions.LimitCount;
import net.minecraft.world.level.storage.loot.functions.SetItemCountFunction;
import net.minecraft.world.level.storage.loot.predicates.BonusLevelTableCondition;
import net.minecraft.world.level.storage.loot.predicates.ExplosionCondition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import net.minecraft.data.models.model.TexturedModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.properties.AttachFace;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private static boolean attemptPlace(Ostrich entity, @NotNull Level level, Block
BlockState belowState = level.getBlockState(belowPos);
if (blockState.isAir() && belowState.isFaceSturdy(level, belowPos, Direction.UP)) {
BlockState placementState = block.defaultBlockState();
level.setBlock(placePos, placementState, Block.UPDATE_ALL);
level.setBlockAndUpdate(placePos, placementState);
level.gameEvent(GameEvent.BLOCK_PLACE, placePos, GameEvent.Context.of(entity, placementState));
level.playSound(null, entity, WWSounds.ENTITY_OSTRICH_LAY_EGG, SoundSource.BLOCKS, 1F, 1F);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private static boolean attemptPlace(Penguin entity, @NotNull Level level, Block
BlockState belowState = level.getBlockState(belowPos);
if (blockState.isAir() && belowState.isFaceSturdy(level, belowPos, Direction.UP)) {
BlockState placementState = block.defaultBlockState();
level.setBlock(placePos, placementState, Block.UPDATE_ALL);
level.setBlockAndUpdate(placePos, placementState);
level.gameEvent(GameEvent.BLOCK_PLACE, placePos, GameEvent.Context.of(entity, placementState));
level.playSound(null, entity, entity.isLinux() ? WWSounds.ENTITY_LINUX_LAY_EGG : WWSounds.ENTITY_PENGUIN_LAY_EGG, SoundSource.BLOCKS, 1F, 1F);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
import net.frozenblock.wilderwild.registry.WWMemoryModuleTypes;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Unit;
import net.minecraft.world.entity.ai.Brain;
import net.minecraft.world.entity.ai.behavior.Behavior;
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
import net.minecraft.world.entity.ai.memory.MemoryStatus;
import org.jetbrains.annotations.NotNull;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -87,16 +86,17 @@ private void spawnFireRandomlyAround(Level level, RandomSource random, BlockPos
blockPos = poses.next();
BlockPos blockPos2 = blockPos.below();
BlockState blockState = level.getBlockState(blockPos);
if (!set.contains(blockPos) && blockState.canBeReplaced() && blockState.getFluidState().isEmpty() && level.getBlockState(blockPos2).isFaceSturdy(level, blockPos2, Direction.UP)) {
if (!set.contains(blockPos)
&& blockState.canBeReplaced()
&& blockState.getFluidState().isEmpty()
&& level.getBlockState(blockPos2).isFaceSturdy(level, blockPos2, Direction.UP)
) {
set.add(blockPos.immutable());
if (set.size() >= i) {
break;
}
if (set.size() >= i) break;
}
}

poses = set.iterator();

while (poses.hasNext()) {
blockPos = poses.next();
BlockState fireState;
Expand All @@ -106,7 +106,7 @@ private void spawnFireRandomlyAround(Level level, RandomSource random, BlockPos
fireState = Blocks.FIRE.defaultBlockState();
}
if (fireState.canSurvive(level, blockPos)) {
level.setBlock(blockPos, fireState, Block.UPDATE_ALL);
level.setBlockAndUpdate(blockPos, fireState);
WWScorchingFirePlacePacket.sendToAll(serverLevel, blockPos);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayerGameMode;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -47,10 +46,10 @@ public class ServerPlayerGameModeMixin {
@Local(ordinal = 1) BlockState destroyedState
) {
if (SnowloggingUtils.isSnowlogged(destroyedState)) {
instance.setBlock(pos, destroyedState.setValue(SnowloggingUtils.SNOW_LAYERS, 0), Block.UPDATE_ALL);
instance.setBlockAndUpdate(pos, destroyedState.setValue(SnowloggingUtils.SNOW_LAYERS, 0));
return true;
} else if (destroyedState.getBlock() instanceof MesogleaBlock) {
instance.setBlock(pos, Blocks.AIR.defaultBlockState(), Block.UPDATE_ALL);
instance.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
return true;
}
return original.call(instance, pos, b);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,11 @@
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.frozenblock.wilderwild.registry.WWBlocks;
import net.frozenblock.wilderwild.registry.WWGameEvents;
import net.minecraft.core.Holder;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.level.pathfinder.WalkNodeEvaluator;
import net.minecraft.world.phys.Vec3;
import org.objectweb.asm.Opcodes;
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.Slice;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private SculkSensorBlockEntityMixin(BlockEntityType<?> type, BlockPos pos, Block
this.wilderWild$setPrevActive(nbt.getBoolean("prevActive"));

Direction facing = Direction.byName(nbt.getString("facing"));
this.wilderWild$setFacing(Objects.requireNonNullElse(facing, Direction.SOUTH));
this.wilderWild$setFacing(Objects.requireNonNullElse(facing, Direction.NORTH));
}

@Inject(method = "saveAdditional", at = @At("TAIL"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public void init() {
Blocks.DIRT,
(blockState, serverLevel, blockPos, randomSource) -> {
if (DripstoneDripApi.getDripstoneFluid(serverLevel, blockPos) == Fluids.WATER) {
serverLevel.setBlock(blockPos, Blocks.MUD.defaultBlockState(), Block.UPDATE_ALL);
serverLevel.setBlockAndUpdate(blockPos, Blocks.MUD.defaultBlockState());
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.frozenblock.wilderwild.WWConstants;
import net.frozenblock.wilderwild.worldgen.biome.AridForest;
import net.frozenblock.wilderwild.worldgen.biome.AridSavanna;
import net.frozenblock.wilderwild.worldgen.biome.AutumnalPlains;
import net.frozenblock.wilderwild.worldgen.biome.BirchJungle;
import net.frozenblock.wilderwild.worldgen.biome.BirchTaiga;
import net.frozenblock.wilderwild.worldgen.biome.CypressWetlands;
Expand All @@ -46,7 +47,6 @@
import net.frozenblock.wilderwild.worldgen.biome.SparseBirchJungle;
import net.frozenblock.wilderwild.worldgen.biome.SparseForest;
import net.frozenblock.wilderwild.worldgen.biome.TemperateRainforest;
import net.frozenblock.wilderwild.worldgen.biome.AutumnalPlains;
import net.frozenblock.wilderwild.worldgen.biome.WarmBeach;
import net.frozenblock.wilderwild.worldgen.biome.WarmRiver;
import net.minecraft.data.worldgen.BootstrapContext;
Expand Down
Loading

0 comments on commit ec72618

Please sign in to comment.