forked from Moulberry/AxiomPaperPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add disallowed-blocks, log-large-block-buffer-changes and block-buffe…
…r-rate-limit config options
- Loading branch information
Showing
12 changed files
with
433 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package com.moulberry.axiom; | ||
|
||
import com.mojang.brigadier.StringReader; | ||
import com.mojang.datafixers.util.Either; | ||
import com.moulberry.axiom.buffer.BlockBuffer; | ||
import net.minecraft.commands.arguments.blocks.BlockPredicateArgument; | ||
import net.minecraft.commands.arguments.blocks.BlockStateParser; | ||
import net.minecraft.core.IdMapper; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.nbt.NbtUtils; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.Blocks; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.block.state.properties.Property; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Predicate; | ||
|
||
public class DisallowedBlocks { | ||
|
||
public static IdMapper<BlockState> createAllowedBlockRegistry(List<String> disallowedBlocks) { | ||
List<Predicate<BlockState>> disallowedPredicates = new ArrayList<>(); | ||
|
||
for (String disallowedBlock : disallowedBlocks) { | ||
try { | ||
var parsed = BlockStateParser.parseForTesting(BuiltInRegistries.BLOCK.asLookup(), new StringReader(disallowedBlock), false); | ||
|
||
parsed.left().ifPresent(result -> { | ||
disallowedPredicates.add(blockState -> { | ||
if (!blockState.is(result.blockState().getBlock())) { | ||
return false; | ||
} else { | ||
for (Property<?> property : result.properties().keySet()) { | ||
if (blockState.getValue(property) != result.blockState().getValue(property)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
}); | ||
}); | ||
|
||
parsed.right().ifPresent(result -> { | ||
disallowedPredicates.add(blockState -> { | ||
if (!blockState.is(result.tag())) { | ||
return false; | ||
} else { | ||
for(Map.Entry<String, String> entry : result.vagueProperties().entrySet()) { | ||
Property<?> property = blockState.getBlock().getStateDefinition().getProperty(entry.getKey()); | ||
if (property == null) { | ||
return false; | ||
} | ||
|
||
Comparable<?> comparable = property.getValue(entry.getValue()).orElse(null); | ||
if (comparable == null) { | ||
return false; | ||
} | ||
|
||
if (blockState.getValue(property) != comparable) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
}); | ||
}); | ||
} catch (Exception ignored) {} | ||
} | ||
|
||
IdMapper<BlockState> allowedBlockRegistry = new IdMapper<>(); | ||
|
||
// Create allowedBlockRegistry | ||
blocks: | ||
for (BlockState blockState : Block.BLOCK_STATE_REGISTRY) { | ||
for (Predicate<BlockState> disallowedPredicate : disallowedPredicates) { | ||
if (disallowedPredicate.test(blockState)) { | ||
allowedBlockRegistry.add(BlockBuffer.EMPTY_STATE); | ||
continue blocks; | ||
} | ||
} | ||
|
||
allowedBlockRegistry.add(blockState); | ||
} | ||
allowedBlockRegistry.addMapping(BlockBuffer.EMPTY_STATE, Block.BLOCK_STATE_REGISTRY.getId(BlockBuffer.EMPTY_STATE)); | ||
return allowedBlockRegistry; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.