add ignoredEntities config and modid support for ignoredBlocks and ignoredEntities

This commit is contained in:
Flemmli97 2021-07-20 23:12:56 +02:00
parent 44a4767612
commit 73d944799c
6 changed files with 27 additions and 3 deletions

View File

@ -3,6 +3,7 @@ package io.github.flemmli97.flan;
import me.shedaniel.architectury.annotations.ExpectPlatform;
import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.item.Item;
@ -30,6 +31,11 @@ public class CrossPlatformStuff {
throw new AssertionError();
}
@ExpectPlatform
public static SimpleRegistryWrapper<EntityType<?>> registryEntities() {
throw new AssertionError();
}
@ExpectPlatform
public static boolean isInventoryTile(BlockEntity blockEntity) {
throw new AssertionError();

View File

@ -35,7 +35,9 @@ public class Config {
public int defaultClaimDepth = 10;
public boolean lenientBlockEntityCheck;
public List<String> ignoredBlocks = new ArrayList<>();
public List<String> ignoredEntityTypes = new ArrayList<>();
public List<String> ignoredEntityTypes = Lists.newArrayList(
"corpse:corpse"
);
public List<String> blockEntityTagIgnore = Lists.newArrayList(
"IsDeathChest", //vanilla death chest
"gunpowder.owner" //gunpowder

View File

@ -120,7 +120,8 @@ public class BlockInteractEvents {
}
public static boolean alwaysAllowBlock(Identifier id, BlockEntity blockEntity) {
return ConfigHandler.config.ignoredBlocks.contains(id.toString())
return ConfigHandler.config.ignoredBlocks.contains(id.getNamespace())
|| ConfigHandler.config.ignoredBlocks.contains(id.toString())
|| (blockEntity != null
&& ConfigHandler.config.blockEntityTagIgnore.stream().anyMatch(blockEntity.toTag(new CompoundTag())::contains));
}

View File

@ -1,5 +1,6 @@
package io.github.flemmli97.flan.event;
import io.github.flemmli97.flan.CrossPlatformStuff;
import io.github.flemmli97.flan.api.data.IPermissionContainer;
import io.github.flemmli97.flan.api.permission.ClaimPermission;
import io.github.flemmli97.flan.api.permission.ObjectToPermissionMap;
@ -43,6 +44,7 @@ import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.EntityHitResult;
@ -105,7 +107,10 @@ public class EntityInteractEvents {
}
public static boolean canInteract(Entity entity) {
return entity.getScoreboardTags().stream().anyMatch(ConfigHandler.config.entityTagIgnore::contains);
Identifier id = CrossPlatformStuff.registryEntities().getIDFrom(entity.getType());
return ConfigHandler.config.ignoredEntityTypes.contains(id.getNamespace())
|| ConfigHandler.config.ignoredEntityTypes.contains(id.toString())
|| entity.getScoreboardTags().stream().anyMatch(ConfigHandler.config.entityTagIgnore::contains);
}
public static boolean projectileHit(ProjectileEntity proj, HitResult res) {

View File

@ -6,6 +6,7 @@ import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.block.Block;
import net.minecraft.block.InventoryProvider;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.Item;
@ -40,6 +41,10 @@ public class CrossPlatformStuffImpl {
return new FabricRegistryWrapper<>(Registry.ITEM);
}
public static SimpleRegistryWrapper<EntityType<?>> registryEntities() {
return new FabricRegistryWrapper<>(Registry.ENTITY_TYPE);
}
public static boolean isInventoryTile(BlockEntity blockEntity) {
return blockEntity instanceof Inventory || blockEntity instanceof InventoryProvider;
}

View File

@ -5,6 +5,7 @@ import io.github.flemmli97.flan.SimpleRegistryWrapper;
import net.minecraft.block.Block;
import net.minecraft.block.InventoryProvider;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.Item;
@ -32,6 +33,10 @@ public class CrossPlatformStuffImpl {
return new ForgeRegistryWrapper<>(ForgeRegistries.ITEMS);
}
public static SimpleRegistryWrapper<EntityType<?>> registryEntities() {
return new ForgeRegistryWrapper<>(ForgeRegistries.ENTITIES);
}
public static boolean isInventoryTile(BlockEntity blockEntity) {
return blockEntity instanceof Inventory || blockEntity instanceof InventoryProvider || blockEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).isPresent();
}