Skip to content

Commit

Permalink
Fix shulker boxes not being properly excluded from the mod's features
Browse files Browse the repository at this point in the history
  • Loading branch information
ArkoSammy12 committed Aug 1, 2024
1 parent 0655f03 commit 11403d5
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ loader_version=0.15.11
fabric_version=0.100.7+1.21

# Mod Properties
mod_version=1.2.0-1.21+
mod_version=1.2.1-1.21+
maven_group=xd.arkosammy
archives_base_name=creeper-healing

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import xd.arkosammy.creeperhealing.ExplosionManagerRegistrar;
import xd.arkosammy.creeperhealing.util.EmptyWorld;
import xd.arkosammy.creeperhealing.util.ExcludedBlocks;
import xd.arkosammy.creeperhealing.util.ExplosionContext;
import xd.arkosammy.creeperhealing.util.ExplosionUtils;
import xd.arkosammy.creeperhealing.explosions.ducks.ExplosionAccessor;
Expand Down Expand Up @@ -79,18 +80,34 @@ private void onExplosion(boolean particles, CallbackInfo ci){
ExplosionUtils.DROP_CONTAINER_INVENTORY_ITEMS.set(true);
this.indirectlyAffectedPositions.removeIf(pos -> {
BlockState oldState = this.affectedStatesAndBlockEntities.get(pos).getLeft();
// Hardcoded exception, place before all other logic
if (ExcludedBlocks.isExcluded(oldState)) {
return true;
}
BlockState newState = this.world.getBlockState(pos);
return newState.equals(oldState);
return Objects.equals(oldState, newState);
});

List<BlockPos> vanillaAffectedPositions = new ArrayList<>();
for (BlockPos pos : this.getAffectedBlocks()) {
// Hardcoded exception, place before all other logic
BlockState state = this.affectedStatesAndBlockEntities.get(pos).getLeft();
if (ExcludedBlocks.isExcluded(state)) {
continue;
}
vanillaAffectedPositions.add(pos);
}
Map<BlockPos, Pair<BlockState, BlockEntity>> filteredSavedStatesAndBlockEntities = new HashMap<>();
for (Map.Entry<BlockPos, Pair<BlockState, BlockEntity>> entry : this.affectedStatesAndBlockEntities.entrySet()) {
BlockPos entryPos = entry.getKey();
if (this.getAffectedBlocks().contains(entryPos) || this.indirectlyAffectedPositions.contains(entryPos)) {
if (vanillaAffectedPositions.contains(entryPos) || this.indirectlyAffectedPositions.contains(entryPos)) {
filteredSavedStatesAndBlockEntities.put(entry.getKey(), entry.getValue());
}
}


ExplosionContext explosionContext = new ExplosionContext(
new ArrayList<>(this.getAffectedBlocks()),
vanillaAffectedPositions,
new ArrayList<>(this.indirectlyAffectedPositions),
filteredSavedStatesAndBlockEntities,
this.world,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public abstract class FallingBlockMixin {
private boolean onBlockAttemptedFall(boolean original, BlockState blockState){
// Hardcoded Exception. Place before all other logic
if(ExcludedBlocks.isExcluded(blockState)){
ExplosionUtils.FALLING_BLOCK_SCHEDULE_TICK.set(true);
return original;
}
boolean canFall = original && ExplosionUtils.FALLING_BLOCK_SCHEDULE_TICK.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private void onBlockStateSet(BlockPos pos, BlockState state, int flags, int maxU
private void preventItemsFromDroppingOnExplosionsIfNeeded(BlockState instance, WorldAccess worldAccess, BlockPos blockPos, int flags, int maxUpdateDepth, Operation<Void> original, @Share("isBlockAtPosExcluded") LocalBooleanRef isBlockAtPosExcluded) {
// Hardcoded exception. Place before all other logic
if(isBlockAtPosExcluded.get()) {
original.call(instance, worldAccess, blockPos, flags, maxUpdateDepth);
return;
}
int newFlags = ExplosionUtils.DROP_BLOCK_ITEMS.get() ? flags : flags | Block.SKIP_DROPS;
Expand Down
38 changes: 31 additions & 7 deletions src/main/java/xd/arkosammy/creeperhealing/util/ExcludedBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.registry.tag.TagKey;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;

Expand All @@ -12,20 +15,41 @@
* or because they are not meant to be healed.
*/
public enum ExcludedBlocks {
SHULKER_BOX(Blocks.SHULKER_BOX);
SHULKER_BOX(Blocks.SHULKER_BOX, BlockTags.SHULKER_BOXES);

private final Block blockInstance;

public static boolean isExcluded(Block block) {
return Arrays.stream(ExcludedBlocks.values()).anyMatch(excludedBlock -> excludedBlock.blockInstance.equals(block));
@Nullable
private final TagKey<Block> blockTag;

public static boolean isExcluded(@Nullable Block block) {
if (block == null) {
return false;
}
return Arrays.stream(ExcludedBlocks.values()).anyMatch(excludedBlock -> {
if (block.getDefaultState().isOf(excludedBlock.blockInstance)) {
return true;
}
TagKey<Block> blockTag = excludedBlock.blockTag;
return blockTag != null && block.getDefaultState().isIn(blockTag);
});
}

public static boolean isExcluded(BlockState state) {
return Arrays.stream(ExcludedBlocks.values()).anyMatch(excludedBlock -> state.isOf(excludedBlock.blockInstance));
public static boolean isExcluded(@Nullable BlockState state) {
if (state == null) {
return false;
}
return Arrays.stream(ExcludedBlocks.values()).anyMatch(excludedBlock -> {
if (state.isOf(excludedBlock.blockInstance)) {
return true;
}
TagKey<Block> blockTag = excludedBlock.blockTag;
return blockTag != null && state.isIn(blockTag);
});
}

ExcludedBlocks(Block blockInstance){
ExcludedBlocks(Block blockInstance, @Nullable TagKey<Block> blockTag) {
this.blockInstance = blockInstance;
this.blockTag = blockTag;
}

}

0 comments on commit 11403d5

Please sign in to comment.