From d7aaa4f06f3fefacf0cd7ffdaa8e388a29ec8cd7 Mon Sep 17 00:00:00 2001 From: Justin Parsell Date: Sat, 27 Nov 2021 03:07:09 -0500 Subject: [PATCH] Config update & introduction of flammable tag --- .../java/me/parsell/wireddust/WiredDust.java | 8 +++---- .../me/parsell/wireddust/WiredDustConfig.java | 13 ++++------ .../common/WDBlazePowderWireBlock.java | 2 +- .../common/WDGunpowderWireBlock.java | 24 +++++++++++-------- .../wireddust/core/WiredDustBlocks.java | 10 +------- .../wireddust/core/WiredDustGamerules.java | 13 ++++++---- .../wireddust/core/WiredDustItems.java | 18 +++++++------- .../parsell/wireddust/core/WiredDustTags.java | 20 ++++++++++++++++ .../gunpowder_wire_flammable_blocks.json | 8 +++++++ 9 files changed, 70 insertions(+), 46 deletions(-) create mode 100644 src/main/java/me/parsell/wireddust/core/WiredDustTags.java create mode 100644 src/main/resources/data/glowstonewire/tags/blocks/gunpowder_wire_flammable_blocks.json diff --git a/src/main/java/me/parsell/wireddust/WiredDust.java b/src/main/java/me/parsell/wireddust/WiredDust.java index 56245db..3a4f31e 100644 --- a/src/main/java/me/parsell/wireddust/WiredDust.java +++ b/src/main/java/me/parsell/wireddust/WiredDust.java @@ -1,14 +1,12 @@ package me.parsell.wireddust; import me.parsell.wireddust.core.WiredDustBlocks; +import me.parsell.wireddust.core.WiredDustGamerules; import me.parsell.wireddust.core.WiredDustItems; +import me.parsell.wireddust.core.WiredDustTags; import me.shedaniel.autoconfig.AutoConfig; import me.shedaniel.autoconfig.serializer.GsonConfigSerializer; import net.fabricmc.api.ModInitializer; -import net.fabricmc.fabric.api.event.player.UseBlockCallback; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.util.ActionResult; public class WiredDust implements ModInitializer { public static final String MODID = "wireddust"; @@ -21,6 +19,8 @@ public class WiredDust implements ModInitializer { WiredDustBlocks.init(); WiredDustItems.init(); + WiredDustGamerules.init(); + WiredDustTags.init(); // Make sure player is not in spectator mode diff --git a/src/main/java/me/parsell/wireddust/WiredDustConfig.java b/src/main/java/me/parsell/wireddust/WiredDustConfig.java index c2e206c..06402cd 100644 --- a/src/main/java/me/parsell/wireddust/WiredDustConfig.java +++ b/src/main/java/me/parsell/wireddust/WiredDustConfig.java @@ -5,18 +5,15 @@ import me.shedaniel.autoconfig.annotation.Config; @Config(name = "WiredDust") public class WiredDustConfig implements ConfigData{ - public boolean useVanillaItems = true; - public boolean addSugarWire = true; public boolean addGlowstoneWire = true; public boolean addBlazePowderWire = true; - //public boolean doBlazePowderDamage = true; // GR + public boolean GR_DO_BLAZE_POWDER_WIRE_DAMAGE_DEFAULT = true; public boolean addGunpowderWire = true; - public boolean gunpowderWireIgnitesExtremelyFlammableBlocks = true; //GR: Campfire, leaves - public boolean gunpowderWireIgnitesFlammableBlocks = false; //GR: wool, hay - //public boolean gunpowderWireIgnitesTNT = true; //GR: tnt duh - - //TODO Consider gamerules for additional functionality instead of mod config + public boolean GR_GUNPOWDER_WIRE_IGNITES_TNT_DEFAULT = true; + public boolean GR_GUNPOWDER_WIRE_LIGHTS_CAMPFIRES_DEFAULT = true; + public boolean GR_GUNPOWDER_WIRE_IGNITES_BLOCKS = true; + } diff --git a/src/main/java/me/parsell/wireddust/common/WDBlazePowderWireBlock.java b/src/main/java/me/parsell/wireddust/common/WDBlazePowderWireBlock.java index a713909..ebd9eda 100644 --- a/src/main/java/me/parsell/wireddust/common/WDBlazePowderWireBlock.java +++ b/src/main/java/me/parsell/wireddust/common/WDBlazePowderWireBlock.java @@ -43,7 +43,7 @@ public class WDBlazePowderWireBlock extends WDWireBlock{ // determine what particle I should show ParticleEffect blaze_powder_particle = ParticleTypes.FLAME; - if(world.getBiomeAccess().getBiome(pos).getDownfall() > 0.0F) + if(world.getBiomeAccess().getBiome(pos).getDownfall() > 0.0F) // Todo: this isn't correct blaze_powder_particle = ParticleTypes.SMOKE; world.addParticle(blaze_powder_particle, pos.getX() + x_rand, pos.getY() + 0.1D, pos.getZ() + z_rand, 0.0, 0.0, 0.0); diff --git a/src/main/java/me/parsell/wireddust/common/WDGunpowderWireBlock.java b/src/main/java/me/parsell/wireddust/common/WDGunpowderWireBlock.java index df3b51f..33b593e 100644 --- a/src/main/java/me/parsell/wireddust/common/WDGunpowderWireBlock.java +++ b/src/main/java/me/parsell/wireddust/common/WDGunpowderWireBlock.java @@ -4,6 +4,7 @@ import java.util.Iterator; import java.util.Random; import me.parsell.wireddust.core.WiredDustGamerules; +import me.parsell.wireddust.core.WiredDustTags; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.block.Block; @@ -26,6 +27,7 @@ import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction.Axis; +import net.minecraft.world.GameRules; import net.minecraft.world.World; import net.minecraft.world.WorldAccess; @@ -102,12 +104,13 @@ public class WDGunpowderWireBlock extends WDWireBlock{ public void light(World world, BlockPos pos, BlockState state){ world.setBlockState(pos, state.with(LIT, true)); - scheduleTick(world, pos); + System.out.println(WiredDustTags.GUNPOWDER_IGNITABLE_BLOCKS.toString()); + scheduleTick(world, pos, 55); } - public void scheduleTick(WorldAccess world, BlockPos pos) { + public void scheduleTick(WorldAccess world, BlockPos pos, int length) { if (!world.isClient() && !world.getBlockTickScheduler().isScheduled(pos, this)) { - world.getBlockTickScheduler().schedule(pos, this, 60); + world.getBlockTickScheduler().schedule(pos, this, length); } } @@ -119,26 +122,27 @@ public class WDGunpowderWireBlock extends WDWireBlock{ @Override public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { if(!state.get(BURNT)) { - Iterator dirItr = Direction.Type.HORIZONTAL.iterator(); + Iterator dirItr = Direction.Type.HORIZONTAL.iterator(); //TODO: Maybe allow down/up direction? while(dirItr.hasNext()) { Direction dir = dirItr.next(); BlockPos offsetPos = pos.offset(dir); BlockState offsetBlockState = world.getBlockState(offsetPos); + GameRules worldGameRules = world.getGameRules(); if(state.get(super.DIRECTION_TO_WIRE_CONNECTION.get(dir)).isConnected()) if(offsetBlockState.isOf(this)) - light(world, offsetPos, offsetBlockState); - else if(offsetBlockState.isOf(Blocks.TNT) && world.getGameRules().getBoolean(WiredDustGamerules.GUNPOWDER_WIRE_IGNITES_TNT)) { + light(world, offsetPos, offsetBlockState); // TODO: get up/down + else if(offsetBlockState.isOf(Blocks.TNT) && worldGameRules.getBoolean(WiredDustGamerules.GUNPOWDER_WIRE_IGNITES_TNT)) { TntBlock.primeTnt(world, offsetPos); world.setBlockState(offsetPos, Blocks.AIR.getDefaultState()); - } else if(offsetBlockState.isOf(Blocks.CAMPFIRE) && !offsetBlockState.get(CampfireBlock.LIT)) + } else if(offsetBlockState.isOf(Blocks.CAMPFIRE) && !offsetBlockState.get(CampfireBlock.LIT) && worldGameRules.getBoolean(WiredDustGamerules.GUNPOWDER_WIRE_LIGHTS_CAMPFIRES)) world.setBlockState(offsetPos, offsetBlockState.with(CampfireBlock.LIT, true)); - else if(false) // TODO: make flammable blocks array - ; + else if(WiredDustTags.GUNPOWDER_IGNITABLE_BLOCKS.contains(offsetBlockState.getBlock()) && world.getBlockState(offsetPos.up()).isAir() && worldGameRules.getBoolean(WiredDustGamerules.GUNPOWDER_WIRE_IGNITES_BLOCKS)) + System.out.println("True"); // TODO: FIX THIS } world.setBlockState(pos, state.with(BURNT, true)); - scheduleTick(world, pos); + scheduleTick(world, pos, 65); } else { world.setBlockState(pos, Blocks.AIR.getDefaultState()); } diff --git a/src/main/java/me/parsell/wireddust/core/WiredDustBlocks.java b/src/main/java/me/parsell/wireddust/core/WiredDustBlocks.java index 321b13f..77d210a 100644 --- a/src/main/java/me/parsell/wireddust/core/WiredDustBlocks.java +++ b/src/main/java/me/parsell/wireddust/core/WiredDustBlocks.java @@ -1,8 +1,5 @@ package me.parsell.wireddust.core; -import java.util.HashMap; -import java.util.Map; - import me.parsell.wireddust.WiredDust; import me.parsell.wireddust.common.WDBlazePowderWireBlock; import me.parsell.wireddust.common.WDGunpowderWireBlock; @@ -10,14 +7,10 @@ import me.parsell.wireddust.common.WDWireBlock; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.minecraft.block.Block; import net.minecraft.block.Material; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; public class WiredDustBlocks { - public static Map WDITEM_TO_BLOCK = new HashMap(); - public static final Block GLOWSTONE_WIRE = new WDWireBlock(FabricBlockSettings.of(Material.SUPPORTED).breakInstantly().noCollision().luminance(9)); public static final Block GUNPOWDER_WIRE = new WDGunpowderWireBlock(FabricBlockSettings.of(Material.SUPPORTED).breakInstantly().noCollision()); public static final Block BLAZE_POWDER_WIRE = new WDBlazePowderWireBlock(FabricBlockSettings.of(Material.SUPPORTED).breakInstantly().noCollision().luminance(2)); @@ -29,7 +22,6 @@ public class WiredDustBlocks { Registry.register(Registry.BLOCK, new Identifier(WiredDust.MODID, "blaze_powder_wire"), BLAZE_POWDER_WIRE); Registry.register(Registry.BLOCK, new Identifier(WiredDust.MODID, "sugar_wire"), SUGAR_WIRE); - WDITEM_TO_BLOCK.put(new ItemStack(Items.GLOWSTONE_DUST), GLOWSTONE_WIRE); - WDITEM_TO_BLOCK.put(new ItemStack(Items.SUGAR), SUGAR_WIRE); + } } diff --git a/src/main/java/me/parsell/wireddust/core/WiredDustGamerules.java b/src/main/java/me/parsell/wireddust/core/WiredDustGamerules.java index 3980eaa..4d15b71 100644 --- a/src/main/java/me/parsell/wireddust/core/WiredDustGamerules.java +++ b/src/main/java/me/parsell/wireddust/core/WiredDustGamerules.java @@ -1,5 +1,6 @@ package me.parsell.wireddust.core; +import me.parsell.wireddust.WiredDust; import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory; import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry; import net.minecraft.world.GameRules; @@ -8,13 +9,17 @@ import net.minecraft.world.GameRules.Category; public class WiredDustGamerules { public static final GameRules.Key DO_BLAZE_POWDER_WIRE_DAMAGE; public static final GameRules.Key GUNPOWDER_WIRE_IGNITES_TNT; + public static final GameRules.Key GUNPOWDER_WIRE_LIGHTS_CAMPFIRES; + public static final GameRules.Key GUNPOWDER_WIRE_IGNITES_BLOCKS; - public void init(){ - // placeabo, just ensures that static gets ran here + public static void init(){ + // placeabo, just ensures that these get registered } static { - DO_BLAZE_POWDER_WIRE_DAMAGE = GameRuleRegistry.register("doBlazePowderWireDamage", Category.MISC, GameRuleFactory.createBooleanRule(true)); - GUNPOWDER_WIRE_IGNITES_TNT = GameRuleRegistry.register("gunpowderWireIgnitesTNT", Category.MISC, GameRuleFactory.createBooleanRule(true)); + DO_BLAZE_POWDER_WIRE_DAMAGE = GameRuleRegistry.register("doBlazePowderWireDamage", Category.MISC, GameRuleFactory.createBooleanRule(WiredDust.CONFIG.GR_DO_BLAZE_POWDER_WIRE_DAMAGE_DEFAULT)); + GUNPOWDER_WIRE_IGNITES_TNT = GameRuleRegistry.register("gunpowderWireIgnitesTNT", Category.MISC, GameRuleFactory.createBooleanRule(WiredDust.CONFIG.GR_GUNPOWDER_WIRE_IGNITES_TNT_DEFAULT)); + GUNPOWDER_WIRE_LIGHTS_CAMPFIRES = GameRuleRegistry.register("gunpowderWireLightsCampfire", Category.MISC, GameRuleFactory.createBooleanRule(WiredDust.CONFIG.GR_GUNPOWDER_WIRE_LIGHTS_CAMPFIRES_DEFAULT)); + GUNPOWDER_WIRE_IGNITES_BLOCKS = GameRuleRegistry.register("gunpowderWireIgnitesBlocks", Category.MISC, GameRuleFactory.createBooleanRule(WiredDust.CONFIG.GR_GUNPOWDER_WIRE_IGNITES_BLOCKS)); } } diff --git a/src/main/java/me/parsell/wireddust/core/WiredDustItems.java b/src/main/java/me/parsell/wireddust/core/WiredDustItems.java index 3335a12..0c78d56 100644 --- a/src/main/java/me/parsell/wireddust/core/WiredDustItems.java +++ b/src/main/java/me/parsell/wireddust/core/WiredDustItems.java @@ -13,15 +13,13 @@ import net.minecraft.util.registry.RegistryKey; public class WiredDustItems { public static void init(){ - if(WiredDust.CONFIG.useVanillaItems) { - if(WiredDust.CONFIG.addGlowstoneWire) - Registry.ITEM.set(Registry.ITEM.getRawId(Items.GLOWSTONE_DUST), RegistryKey.of(Registry.ITEM.getKey(), new Identifier("glowstone_dust")), new BlockItem(WiredDustBlocks.GLOWSTONE_WIRE, new FabricItemSettings().group(ItemGroup.MATERIALS)), Lifecycle.stable()); - if(WiredDust.CONFIG.addBlazePowderWire) - Registry.ITEM.set(Registry.ITEM.getRawId(Items.BLAZE_POWDER), RegistryKey.of(Registry.ITEM.getKey(), new Identifier("blaze_powder")), new BlockItem(WiredDustBlocks.BLAZE_POWDER_WIRE, new FabricItemSettings().group(ItemGroup.BREWING)), Lifecycle.stable()); - if(WiredDust.CONFIG.addGunpowderWire) - Registry.ITEM.set(Registry.ITEM.getRawId(Items.GUNPOWDER), RegistryKey.of(Registry.ITEM.getKey(), new Identifier("gunpowder")), new BlockItem(WiredDustBlocks.GUNPOWDER_WIRE, new FabricItemSettings().group(ItemGroup.MATERIALS)), Lifecycle.stable()); - if(WiredDust.CONFIG.addSugarWire) - Registry.ITEM.set(Registry.ITEM.getRawId(Items.SUGAR), RegistryKey.of(Registry.ITEM.getKey(), new Identifier("sugar")), new BlockItem(WiredDustBlocks.SUGAR_WIRE, new FabricItemSettings().group(ItemGroup.MATERIALS)), Lifecycle.stable()); - } + if(WiredDust.CONFIG.addGlowstoneWire) + Registry.ITEM.set(Registry.ITEM.getRawId(Items.GLOWSTONE_DUST), RegistryKey.of(Registry.ITEM.getKey(), new Identifier("glowstone_dust")), new BlockItem(WiredDustBlocks.GLOWSTONE_WIRE, new FabricItemSettings().group(ItemGroup.MATERIALS)), Lifecycle.stable()); + if(WiredDust.CONFIG.addBlazePowderWire) + Registry.ITEM.set(Registry.ITEM.getRawId(Items.BLAZE_POWDER), RegistryKey.of(Registry.ITEM.getKey(), new Identifier("blaze_powder")), new BlockItem(WiredDustBlocks.BLAZE_POWDER_WIRE, new FabricItemSettings().group(ItemGroup.BREWING)), Lifecycle.stable()); + if(WiredDust.CONFIG.addGunpowderWire) + Registry.ITEM.set(Registry.ITEM.getRawId(Items.GUNPOWDER), RegistryKey.of(Registry.ITEM.getKey(), new Identifier("gunpowder")), new BlockItem(WiredDustBlocks.GUNPOWDER_WIRE, new FabricItemSettings().group(ItemGroup.MATERIALS)), Lifecycle.stable()); + if(WiredDust.CONFIG.addSugarWire) + Registry.ITEM.set(Registry.ITEM.getRawId(Items.SUGAR), RegistryKey.of(Registry.ITEM.getKey(), new Identifier("sugar")), new BlockItem(WiredDustBlocks.SUGAR_WIRE, new FabricItemSettings().group(ItemGroup.MATERIALS)), Lifecycle.stable()); } } diff --git a/src/main/java/me/parsell/wireddust/core/WiredDustTags.java b/src/main/java/me/parsell/wireddust/core/WiredDustTags.java new file mode 100644 index 0000000..22db3c9 --- /dev/null +++ b/src/main/java/me/parsell/wireddust/core/WiredDustTags.java @@ -0,0 +1,20 @@ +package me.parsell.wireddust.core; + +import net.minecraft.block.Block; +import net.minecraft.tag.Tag; +import net.minecraft.util.Identifier; +import me.parsell.wireddust.WiredDust; +import net.fabricmc.fabric.api.tag.TagRegistry; + +public class WiredDustTags { + public static final Tag GUNPOWDER_IGNITABLE_BLOCKS; + + public static void init(){ + //empty + } + + static { + GUNPOWDER_IGNITABLE_BLOCKS = TagRegistry.block(new Identifier(WiredDust.MODID, "gunpowder_ignitable_blocks")); // TODO: FIX + } + +} diff --git a/src/main/resources/data/glowstonewire/tags/blocks/gunpowder_wire_flammable_blocks.json b/src/main/resources/data/glowstonewire/tags/blocks/gunpowder_wire_flammable_blocks.json new file mode 100644 index 0000000..fdf8bad --- /dev/null +++ b/src/main/resources/data/glowstonewire/tags/blocks/gunpowder_wire_flammable_blocks.json @@ -0,0 +1,8 @@ +{ + "replace": false, + "values": [ + "#minecraft:leaves", + "#minecraft:wool", + "minecraft:hay_block" + ] +} \ No newline at end of file