Skip to content

Commit

Permalink
Added TE White/Blacklist
Browse files Browse the repository at this point in the history
Now triggers onBlockPlacedBy()
Fixed SecurityCraft bug
  • Loading branch information
Theta-Dev committed Dec 6, 2020
1 parent a10a10e commit e4b3421
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 13 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,20 @@ SHIFT+Right clicking empty space opens the option screen of your wand.

- Look at your statisics to see how many blocks you have placed using your wand

- **1.16+ only:** The Infinity Wand won't burn in lava just like netherite gear.
- **1.16+ only:** The Infinity Wand won't burn in lava just like netherite gear.

## Contributions and #Hacktoberfest
As #Hacktoberfest now requires repo owners to opt in, I added the tag to this repository.

I'd really appreciate translations. Currently ConstructionWand only has English and German, so if you speak any other language you can help translate the mod and add a new language file under `src/main/resources/assets/constructionwand/lang/`.

## TileEntity Blacklist
Some modded TileEntitys can cause issues when placed using a wand. They may turn into invisible and unremovable ghost blocks,
become unbreakable or cause other unwanted effects.

That's why I've included a Black/Whitelist system
for TileEntities in CW Version 1.7. Chisels&Bits blocks are blacklisted by default. There are probably a few other tile entities
from other mods out there which may cause issues as well. If you find some of them you can tell me by creating
an issue, commenting on Curse or editing the default blacklist yourself
(it is located at https://github.com/Theta-Dev/ConstructionWand/blob/1.16.2/src/main/java/thetadev/constructionwand/basics/ConfigServer.java#L28)
and making a PR.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ mcp_mappings=20200723-1.16.1
botania=1.16-398

version_major=1
version_minor=6
version_minor=7
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ public class ConfigClient
public static final ForgeConfigSpec.BooleanValue SHIFTCTRL_GUI;

static {
BUILDER.comment("This is the Client config for ConstructionWand.",
"If you're not familiar with Forge's new split client/server config, let me explain:",
"Client config is stored in the /config folder and only contains client specific settings like graphics and keybinds.",
"Mod behavior is configured in the Server config, which is world-specific and thus located",
"in the /saves/myworld/serverconfig folder. If you want to change the serverconfig for all",
"new worlds, copy the config files in the /defaultconfigs folder.");

BUILDER.push("keys");
BUILDER.comment("Press SHIFT+CTRL instead of SHIFT for changing wand mode/direction lock");
SHIFTCTRL_MODE = BUILDER.define("ShiftCtrl", false);
Expand Down
20 changes: 19 additions & 1 deletion src/main/java/thetadev/constructionwand/basics/ConfigServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemTier;
import net.minecraftforge.common.ForgeConfigSpec;
import thetadev.constructionwand.items.ItemWand;
import thetadev.constructionwand.items.ModItems;

import java.util.Arrays;
Expand All @@ -24,6 +23,10 @@ public class ConfigServer
"minecraft:dirt;minecraft:grass_block;minecraft:coarse_dirt;minecraft:podzol;minecraft:mycelium;minecraft:farmland;minecraft:grass_path"
};

public static final ForgeConfigSpec.BooleanValue TE_WHITELIST;
public static final ForgeConfigSpec.ConfigValue<List<?>> TE_LIST;
private static final String[] TE_LIST_DEFAULT = {"chiselsandbits"};

private static final HashMap<Item, WandProperties> wandProperties = new HashMap<>();

public static WandProperties getWandProperties(Item wand) {
Expand Down Expand Up @@ -73,6 +76,13 @@ public int getAngel() {
}

static {
BUILDER.comment("This is the Server config for ConstructionWand.",
"If you're not familiar with Forge's new split client/server config, let me explain:",
"Client config is stored in the /config folder and only contains client specific settings like graphics and keybinds.",
"Mod behavior is configured in the Server config, which is world-specific and thus located",
"in the /saves/myworld/serverconfig folder. If you want to change the serverconfig for all",
"new worlds, copy the config files in the /defaultconfigs folder.");

new WandProperties(BUILDER, ModItems.WAND_STONE, ItemTier.STONE.getMaxUses(), 9, 0);
new WandProperties(BUILDER, ModItems.WAND_IRON, ItemTier.IRON.getMaxUses(), 27, 1);
new WandProperties(BUILDER, ModItems.WAND_DIAMOND, ItemTier.DIAMOND.getMaxUses(), 128, 4);
Expand All @@ -90,6 +100,14 @@ public int getAngel() {
BUILDER.comment("Blocks to treat equally when in Similar mode. Enter block IDs seperated by ;");
SIMILAR_BLOCKS = BUILDER.defineList("SimilarBlocks", Arrays.asList(SIMILAR_BLOCKS_DEFAULT), obj -> true);
BUILDER.pop();

BUILDER.push("tileentity");
BUILDER.comment("White/Blacklist for Tile Entities. Allow/Prevent blocks with TEs from being placed by wand.",
"You can either add block ids like minecraft:chest or mod ids like minecraft");
TE_LIST = BUILDER.defineList("TEList", Arrays.asList(TE_LIST_DEFAULT), obj -> true);
BUILDER.comment("If set to TRUE, treat TEList as a whitelist, otherwise blacklist");
TE_WHITELIST = BUILDER.define("TEWhitelist", false);
BUILDER.pop();
}

public static final ForgeConfigSpec SPEC = BUILDER.build();
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/thetadev/constructionwand/basics/WandUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package thetadev.constructionwand.basics;

import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
Expand Down Expand Up @@ -72,4 +73,19 @@ public static List<ItemStack> getFullInv(PlayerEntity player) {
public static int maxRange(BlockPos p1, BlockPos p2) {
return Math.max(Math.abs(p1.getX() - p2.getX()), Math.abs(p1.getZ() - p2.getZ()));
}

public static boolean isTEAllowed(BlockState state) {
if(!state.hasTileEntity()) return true;

ResourceLocation name = state.getBlock().getRegistryName();
if(name == null) return false;

String fullId = name.toString();
String modId = name.getNamespace();

boolean inList = ConfigServer.TE_LIST.get().contains(fullId) || ConfigServer.TE_LIST.get().contains(modId);
boolean isWhitelist = ConfigServer.TE_WHITELIST.get();

return isWhitelist == inList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import thetadev.constructionwand.ConstructionWand;
import thetadev.constructionwand.basics.*;
import thetadev.constructionwand.basics.ConfigClient;
import thetadev.constructionwand.basics.WandUtil;
import thetadev.constructionwand.basics.option.WandOptions;
import thetadev.constructionwand.items.ItemWand;
import thetadev.constructionwand.network.PacketQueryUndo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.IItemTier;
import net.minecraft.item.Item;
import net.minecraft.item.Item.Properties;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.tags.ItemTags;
import net.minecraft.util.ResourceLocation;
import thetadev.constructionwand.basics.ConfigServer;

public class ItemWandBasic extends ItemWand
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package thetadev.constructionwand.items;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import thetadev.constructionwand.basics.ConfigServer;

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/thetadev/constructionwand/items/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.IForgeRegistryEntry;
import thetadev.constructionwand.basics.ConfigServer;
import thetadev.constructionwand.ConstructionWand;

@Mod.EventBusSubscriber(modid = ConstructionWand.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/thetadev/constructionwand/job/WandJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ protected PlaceSnapshot getPlaceSnapshot(BlockPos pos, BlockState supportingBloc
blockState = Block.getValidBlockForPosition(blockState, world, pos);
if(blockState.getBlock() == Blocks.AIR || !blockState.isValidPosition(world, pos)) continue;

// Forbidden Tile Entity?
if(!WandUtil.isTEAllowed(blockState)) continue;

// No entities colliding?
VoxelShape shape = blockState.getCollisionShape(world, pos);
if(!shape.isEmpty()) {
Expand Down Expand Up @@ -303,6 +306,9 @@ private boolean placeBlock(PlaceSnapshot placeSnapshot) {
return false;
}

// Call OnBlockPlaced method
placeBlock.getBlock().onBlockPlacedBy(world, blockPos, placeBlock, player, new ItemStack(placeSnapshot.item));

// Update stats
player.addStat(Stats.ITEM_USED.get(placeSnapshot.item));
player.addStat(ModStats.USE_WAND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import thetadev.constructionwand.ConstructionWand;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set;
import java.util.function.Supplier;

Expand Down

0 comments on commit e4b3421

Please sign in to comment.