diff --git a/Common/src/main/java/at/petrak/hexcasting/common/blocks/BlockBurns.java b/Common/src/main/java/at/petrak/hexcasting/common/blocks/BlockBurns.java deleted file mode 100644 index bcbc1c71..00000000 --- a/Common/src/main/java/at/petrak/hexcasting/common/blocks/BlockBurns.java +++ /dev/null @@ -1,33 +0,0 @@ -package at.petrak.hexcasting.common.blocks; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; - -public class BlockBurns extends Block { - private final int flammability; - private final int spreadSpeed; - - public BlockBurns(Properties props, int flammability, int spreadSpeed) { - super(props); - this.flammability = flammability; - this.spreadSpeed = spreadSpeed; - } - - @Override - public boolean isFlammable(BlockState state, BlockGetter level, BlockPos pos, Direction direction) { - return true; - } - - @Override - public int getFlammability(BlockState state, BlockGetter level, BlockPos pos, Direction direction) { - return flammability; - } - - @Override - public int getFireSpreadSpeed(BlockState state, BlockGetter level, BlockPos pos, Direction direction) { - return spreadSpeed; - } -} diff --git a/Common/src/main/java/at/petrak/hexcasting/common/blocks/HexBlocks.java b/Common/src/main/java/at/petrak/hexcasting/common/blocks/HexBlocks.java index 61fc4549..25941c9b 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/blocks/HexBlocks.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/blocks/HexBlocks.java @@ -10,10 +10,9 @@ import at.petrak.hexcasting.common.blocks.circles.directrix.BlockRedstoneDirectr import at.petrak.hexcasting.common.blocks.circles.impetuses.BlockLookingImpetus; import at.petrak.hexcasting.common.blocks.circles.impetuses.BlockRightClickImpetus; import at.petrak.hexcasting.common.blocks.circles.impetuses.BlockStoredPlayerImpetus; -import at.petrak.hexcasting.common.blocks.decoration.BlockAxis; -import at.petrak.hexcasting.common.blocks.decoration.BlockSconce; -import at.petrak.hexcasting.common.blocks.decoration.BlockStrippable; +import at.petrak.hexcasting.common.blocks.decoration.*; import at.petrak.hexcasting.common.items.HexItems; +import at.petrak.hexcasting.xplat.IXplatAbstractions; import com.mojang.datafixers.util.Pair; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.EntityType; @@ -153,14 +152,15 @@ public class HexBlocks { public static final AmethystBlock AMETHYST_TILES = blockItem("amethyst_tiles", new AmethystBlock(BlockBehaviour.Properties.copy(Blocks.AMETHYST_BLOCK))); public static final Block SCROLL_PAPER = blockItem("scroll_paper", - new BlockBurns(papery(MaterialColor.TERRACOTTA_WHITE), 100, 60)); + IXplatAbstractions.INSTANCE.makeFlammable(papery(MaterialColor.TERRACOTTA_WHITE), 100, 60)); public static final Block ANCIENT_SCROLL_PAPER = blockItem("ancient_scroll_paper", - new BlockBurns(papery(MaterialColor.TERRACOTTA_ORANGE), 100, 60)); + IXplatAbstractions.INSTANCE.makeFlammable(papery(MaterialColor.TERRACOTTA_ORANGE), 100, 60)); public static final Block SCROLL_PAPER_LANTERN = blockItem("scroll_paper_lantern", - new BlockBurns(papery(MaterialColor.TERRACOTTA_WHITE).lightLevel($ -> 15), 100, 60)); + IXplatAbstractions.INSTANCE.makeFlammable(papery(MaterialColor.TERRACOTTA_WHITE).lightLevel($ -> 15), 100, 60)); public static final Block ANCIENT_SCROLL_PAPER_LANTERN = blockItem( "ancient_scroll_paper_lantern", - new BlockBurns(papery(MaterialColor.TERRACOTTA_ORANGE).lightLevel($ -> 12), 100, 60)); + IXplatAbstractions.INSTANCE.makeFlammable(papery(MaterialColor.TERRACOTTA_ORANGE).lightLevel($ -> 12), 100, + 60)); public static final BlockSconce SCONCE = blockItem("amethyst_sconce", new BlockSconce(BlockBehaviour.Properties.of(Material.AMETHYST, MaterialColor.COLOR_PURPLE) .sound(SoundType.AMETHYST) @@ -172,28 +172,27 @@ public class HexBlocks { public static final BlockStrippable AKASHIC_LOG = blockItem("akashic_log", new BlockAkashicWood(akashicWoody(), () -> AKASHIC_LOG_STRIPPED)); public static final Block AKASHIC_WOOD_STRIPPED = blockItem("akashic_wood_stripped", - new BlockBurns(akashicWoody(), 5, 5)); + IXplatAbstractions.INSTANCE.makeFlammable(akashicWoody(), 5, 5)); public static final BlockStrippable AKASHIC_WOOD = blockItem("akashic_wood", new BlockStrippable(akashicWoody(), () -> AKASHIC_WOOD_STRIPPED)); public static final Block AKASHIC_PLANKS = blockItem("akashic_planks", - new BlockBurns(akashicWoody(), 20, 5)); + IXplatAbstractions.INSTANCE.makeFlammable(akashicWoody(), 20, 5)); public static final Block AKASHIC_PANEL = blockItem("akashic_panel", - new BlockBurns(akashicWoody(), 20, 5)); + IXplatAbstractions.INSTANCE.makeFlammable(akashicWoody(), 20, 5)); public static final Block AKASHIC_TILE = blockItem("akashic_tile", - new BlockBurns(akashicWoody(), 20, 5)); - // todo: mixin? AT? + IXplatAbstractions.INSTANCE.makeFlammable(akashicWoody(), 20, 5)); public static final DoorBlock AKASHIC_DOOR = blockItem("akashic_door", - new DoorBlock(akashicWoody().noOcclusion())); + new BlockHexDoor(akashicWoody().noOcclusion())); public static final TrapDoorBlock AKASHIC_TRAPDOOR = blockItem("akashic_trapdoor", - new TrapDoorBlock(akashicWoody().noOcclusion())); + new BlockHexTrapdoor(akashicWoody().noOcclusion())); public static final StairBlock AKASHIC_STAIRS = blockItem("akashic_stairs", - new StairBlock(AKASHIC_PLANKS.defaultBlockState(), akashicWoody().noOcclusion())); + new BlockHexStairs(AKASHIC_PLANKS.defaultBlockState(), akashicWoody().noOcclusion())); public static final SlabBlock AKASHIC_SLAB = blockItem("akashic_slab", new SlabBlock(akashicWoody().noOcclusion())); public static final WoodButtonBlock AKASHIC_BUTTON = blockItem("akashic_button", - new WoodButtonBlock(akashicWoody().noOcclusion())); + new BlockHexWoodButton(akashicWoody().noOcclusion())); public static final PressurePlateBlock AKASHIC_PRESSURE_PLATE = blockItem("akashic_pressure_plate", - new PressurePlateBlock(PressurePlateBlock.Sensitivity.EVERYTHING, akashicWoody().noOcclusion())); + new BlockHexPressurePlate(PressurePlateBlock.Sensitivity.EVERYTHING, akashicWoody().noOcclusion())); public static final BlockAkashicLeaves AKASHIC_LEAVES1 = blockItem("akashic_leaves1", new BlockAkashicLeaves(leaves(MaterialColor.COLOR_PURPLE))); public static final BlockAkashicLeaves AKASHIC_LEAVES2 = blockItem("akashic_leaves2", diff --git a/Common/src/main/java/at/petrak/hexcasting/common/blocks/decoration/BlockHexDoor.java b/Common/src/main/java/at/petrak/hexcasting/common/blocks/decoration/BlockHexDoor.java new file mode 100644 index 00000000..355703d0 --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/common/blocks/decoration/BlockHexDoor.java @@ -0,0 +1,9 @@ +package at.petrak.hexcasting.common.blocks.decoration; + +import net.minecraft.world.level.block.DoorBlock; + +public class BlockHexDoor extends DoorBlock { + public BlockHexDoor(Properties $$0) { + super($$0); + } +} diff --git a/Common/src/main/java/at/petrak/hexcasting/common/blocks/decoration/BlockHexPressurePlate.java b/Common/src/main/java/at/petrak/hexcasting/common/blocks/decoration/BlockHexPressurePlate.java new file mode 100644 index 00000000..eabd966c --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/common/blocks/decoration/BlockHexPressurePlate.java @@ -0,0 +1,9 @@ +package at.petrak.hexcasting.common.blocks.decoration; + +import net.minecraft.world.level.block.PressurePlateBlock; + +public class BlockHexPressurePlate extends PressurePlateBlock { + public BlockHexPressurePlate(Sensitivity $$0, Properties $$1) { + super($$0, $$1); + } +} diff --git a/Common/src/main/java/at/petrak/hexcasting/common/blocks/decoration/BlockHexStairs.java b/Common/src/main/java/at/petrak/hexcasting/common/blocks/decoration/BlockHexStairs.java new file mode 100644 index 00000000..8dd541de --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/common/blocks/decoration/BlockHexStairs.java @@ -0,0 +1,10 @@ +package at.petrak.hexcasting.common.blocks.decoration; + +import net.minecraft.world.level.block.StairBlock; +import net.minecraft.world.level.block.state.BlockState; + +public class BlockHexStairs extends StairBlock { + public BlockHexStairs(BlockState $$0, Properties $$1) { + super($$0, $$1); + } +} diff --git a/Common/src/main/java/at/petrak/hexcasting/common/blocks/decoration/BlockHexTrapdoor.java b/Common/src/main/java/at/petrak/hexcasting/common/blocks/decoration/BlockHexTrapdoor.java new file mode 100644 index 00000000..91a5f3e2 --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/common/blocks/decoration/BlockHexTrapdoor.java @@ -0,0 +1,9 @@ +package at.petrak.hexcasting.common.blocks.decoration; + +import net.minecraft.world.level.block.TrapDoorBlock; + +public class BlockHexTrapdoor extends TrapDoorBlock { + public BlockHexTrapdoor(Properties $$0) { + super($$0); + } +} diff --git a/Common/src/main/java/at/petrak/hexcasting/common/blocks/decoration/BlockHexWoodButton.java b/Common/src/main/java/at/petrak/hexcasting/common/blocks/decoration/BlockHexWoodButton.java new file mode 100644 index 00000000..21bc0692 --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/common/blocks/decoration/BlockHexWoodButton.java @@ -0,0 +1,9 @@ +package at.petrak.hexcasting.common.blocks.decoration; + +import net.minecraft.world.level.block.WoodButtonBlock; + +public class BlockHexWoodButton extends WoodButtonBlock { + public BlockHexWoodButton(Properties $$0) { + super($$0); + } +} diff --git a/Common/src/main/java/at/petrak/hexcasting/common/items/HexItems.java b/Common/src/main/java/at/petrak/hexcasting/common/items/HexItems.java index 545a2eb0..628ab526 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/items/HexItems.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/items/HexItems.java @@ -1,21 +1,20 @@ package at.petrak.hexcasting.common.items; -import at.petrak.hexcasting.api.HexAPI; import at.petrak.hexcasting.common.blocks.HexBlocks; import at.petrak.hexcasting.common.items.colorizer.ItemDyeColorizer; import at.petrak.hexcasting.common.items.colorizer.ItemPrideColorizer; import at.petrak.hexcasting.common.items.colorizer.ItemUUIDColorizer; import at.petrak.hexcasting.common.items.magic.*; -import net.minecraft.core.NonNullList; +import at.petrak.hexcasting.xplat.IXplatAbstractions; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.food.FoodProperties; -import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import java.util.EnumMap; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import java.util.function.BiConsumer; @@ -31,31 +30,6 @@ public class HexItems { private static final Map ITEMS = new LinkedHashMap<>(); // preserve insertion order - public static final CreativeModeTab TAB = new CreativeModeTab(HexAPI.MOD_ID) { - @Override - public ItemStack makeIcon() { - return new ItemStack(SPELLBOOK); - } - - @Override - public void fillItemList(NonNullList items) { - super.fillItemList(items); - - var manamounts = new int[]{ - 100_000, - 1_000_000, - 10_000_000, - 100_000_000, - 1_000_000_000, - }; - for (int manamount : manamounts) { - var stack = new ItemStack(BATTERY); - items.add(ItemManaHolder.withMana(stack, manamount, manamount)); - } - } - }; - - public static final Item AMETHYST_DUST = make("amethyst_dust", new Item(props())); public static final Item CHARGED_AMETHYST = make("charged_amethyst", new Item(props())); @@ -109,7 +83,7 @@ public class HexItems { // public static Item.Properties props() { - return new Item.Properties().tab(TAB); + return new Item.Properties().tab(IXplatAbstractions.INSTANCE.getTab()); } public static Item.Properties unstackable() { @@ -127,4 +101,22 @@ public class HexItems { private static T make(String id, T item) { return make(modLoc(id), item); } + + public static ItemStack tabIcon() { + return new ItemStack(SPELLBOOK); + } + + public static void fillTab(List items) { + var manamounts = new int[]{ + 100_000, + 1_000_000, + 10_000_000, + 100_000_000, + 1_000_000_000, + }; + for (int manamount : manamounts) { + var stack = new ItemStack(BATTERY); + items.add(ItemManaHolder.withMana(stack, manamount, manamount)); + } + } } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/lib/HexSounds.java b/Common/src/main/java/at/petrak/hexcasting/common/lib/HexSounds.java index a859f7f0..b06d8622 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/lib/HexSounds.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/lib/HexSounds.java @@ -1,39 +1,50 @@ package at.petrak.hexcasting.common.lib; -import at.petrak.hexcasting.HexMod; +import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvent; -import net.minecraftforge.registries.DeferredRegister; -import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.RegistryObject; -import static at.petrak.hexcasting.common.lib.RegisterHelper.prefix; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.function.BiConsumer; + +import static at.petrak.hexcasting.api.HexAPI.modLoc; public class HexSounds { - public static final DeferredRegister SOUNDS = DeferredRegister.create( - ForgeRegistries.SOUND_EVENTS, - HexMod.MOD_ID); + public static void registerSounds(BiConsumer r) { + for (var e : SOUNDS.entrySet()) { + r.accept(e.getValue(), e.getKey()); + } + } - public static final RegistryObject ADD_LINE = sound("casting.add_line"); - public static final RegistryObject START_PATTERN = sound("casting.start_pattern"); - public static final RegistryObject ADD_PATTERN = sound("casting.add_pattern"); - public static final RegistryObject FAIL_PATTERN = sound("casting.fail_pattern"); - public static final RegistryObject CASTING_AMBIANCE = sound("casting.ambiance"); - public static final RegistryObject ACTUALLY_CAST = sound("casting.cast"); + private static final Map SOUNDS = new LinkedHashMap<>(); - public static final RegistryObject ABACUS = sound("abacus"); - public static final RegistryObject ABACUS_SHAKE = sound("abacus.shake"); + public static final SoundEvent ADD_LINE = sound("casting.add_line"); + public static final SoundEvent START_PATTERN = sound("casting.start_pattern"); + public static final SoundEvent ADD_PATTERN = sound("casting.add_pattern"); + public static final SoundEvent FAIL_PATTERN = sound("casting.fail_pattern"); + public static final SoundEvent CASTING_AMBIANCE = sound("casting.ambiance"); + public static final SoundEvent ACTUALLY_CAST = sound("casting.cast"); - public static final RegistryObject SPELL_CIRCLE_FIND_BLOCK = sound("spellcircle.find_block"); - public static final RegistryObject SPELL_CIRCLE_FAIL = sound("spellcircle.fail"); - public static final RegistryObject SPELL_CIRCLE_CAST = sound("spellcircle.cast"); + public static final SoundEvent ABACUS = sound("abacus"); + public static final SoundEvent ABACUS_SHAKE = sound("abacus.shake"); - public static final RegistryObject SCROLL_DUST = sound("scroll.dust"); - public static final RegistryObject SCROLL_SCRIBBLE = sound("scroll.scribble"); + public static final SoundEvent SPELL_CIRCLE_FIND_BLOCK = sound("spellcircle.find_block"); + public static final SoundEvent SPELL_CIRCLE_FAIL = sound("spellcircle.fail"); + public static final SoundEvent SPELL_CIRCLE_CAST = sound("spellcircle.cast"); - public static final RegistryObject IMPETUS_LOOK_TICK = sound("impetus.fletcher.tick"); - public static final RegistryObject IMPETUS_STOREDPLAYER_DING = sound("impetus.cleric.register"); + public static final SoundEvent SCROLL_DUST = sound("scroll.dust"); + public static final SoundEvent SCROLL_SCRIBBLE = sound("scroll.scribble"); - private static RegistryObject sound(String name) { - return SOUNDS.register(name, () -> new SoundEvent(prefix(name))); + public static final SoundEvent IMPETUS_LOOK_TICK = sound("impetus.fletcher.tick"); + public static final SoundEvent IMPETUS_STOREDPLAYER_DING = sound("impetus.cleric.register"); + + private static SoundEvent sound(String name) { + var id = modLoc(name); + var sound = new SoundEvent(id); + var old = SOUNDS.put(id, sound); + if (old != null) { + throw new IllegalArgumentException("Typo? Duplicate id " + name); + } + return sound; } } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/lib/RegisterHelper.java b/Common/src/main/java/at/petrak/hexcasting/common/lib/RegisterHelper.java deleted file mode 100644 index 8b9ca987..00000000 --- a/Common/src/main/java/at/petrak/hexcasting/common/lib/RegisterHelper.java +++ /dev/null @@ -1,23 +0,0 @@ -package at.petrak.hexcasting.common.lib; - -import at.petrak.hexcasting.HexMod; -import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.registries.IForgeRegistry; -import net.minecraftforge.registries.IForgeRegistryEntry; - -public class RegisterHelper { - // yoinked from botnia - public static > void register(IForgeRegistry reg, ResourceLocation name, - IForgeRegistryEntry thing) { - reg.register(thing.setRegistryName(name)); - } - - public static > void register(IForgeRegistry reg, String name, - IForgeRegistryEntry thing) { - register(reg, prefix(name), thing); - } - - public static ResourceLocation prefix(String path) { - return new ResourceLocation(HexMod.MOD_ID, path); - } -} diff --git a/Common/src/main/java/at/petrak/hexcasting/common/network/MsgNewSpellPatternAck.java b/Common/src/main/java/at/petrak/hexcasting/common/network/MsgNewSpellPatternAck.java index 111b283c..a0ab3366 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/network/MsgNewSpellPatternAck.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/network/MsgNewSpellPatternAck.java @@ -61,7 +61,7 @@ public record MsgNewSpellPatternAck(ControllerInfo info) implements IMessage { var mc = Minecraft.getInstance(); if (self.info().isStackClear()) { // don't pay attention to the screen, so it also stops when we die - mc.getSoundManager().stop(HexSounds.CASTING_AMBIANCE.getId(), null); + mc.getSoundManager().stop(HexSounds.CASTING_AMBIANCE.getLocation(), null); } var screen = Minecraft.getInstance().screen; if (screen instanceof GuiSpellcasting spellGui) { diff --git a/Common/src/main/java/at/petrak/hexcasting/xplat/IXplatAbstractions.java b/Common/src/main/java/at/petrak/hexcasting/xplat/IXplatAbstractions.java index 59499759..90d26065 100644 --- a/Common/src/main/java/at/petrak/hexcasting/xplat/IXplatAbstractions.java +++ b/Common/src/main/java/at/petrak/hexcasting/xplat/IXplatAbstractions.java @@ -8,15 +8,16 @@ import at.petrak.hexcasting.api.spell.casting.CastingHarness; import at.petrak.hexcasting.api.spell.casting.ResolvedPattern; import at.petrak.hexcasting.common.command.PatternResLocArgument; import at.petrak.hexcasting.common.network.IMessage; -import at.petrak.hexcasting.common.network.MsgColorizerUpdateAck; -import at.petrak.hexcasting.common.network.MsgSentinelStatusUpdateAck; import net.minecraft.commands.synchronization.ArgumentTypes; import net.minecraft.commands.synchronization.EmptyArgumentSerializer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.Nullable; @@ -71,13 +72,13 @@ public interface IXplatAbstractions { int getRawColor(FrozenColorizer colorizer, float time, Vec3 position); - default void syncSentinel(ServerPlayer player) { - this.sendPacketToPlayer(player, new MsgSentinelStatusUpdateAck(this.getSentinel(player))); - } + // Blocks - default void syncColorizer(ServerPlayer player) { - this.sendPacketToPlayer(player, new MsgColorizerUpdateAck(this.getColorizer(player))); - } + Block makeFlammable(BlockBehaviour.Properties properties, int flammability, int spreadSpeed); + + // misc + + CreativeModeTab getTab(); default void init() { HexAPI.LOGGER.info("Hello Hexcasting! This is {}!", this.platform()); diff --git a/Common/src/main/resources/assets/hexcasting/lang/en_us.json b/Common/src/main/resources/assets/hexcasting/lang/en_us.json index 63f84adf..0d17440e 100644 --- a/Common/src/main/resources/assets/hexcasting/lang/en_us.json +++ b/Common/src/main/resources/assets/hexcasting/lang/en_us.json @@ -96,6 +96,7 @@ "block.hexcasting.akashic_leaves3": "Citrine Edified Leaves", "itemGroup.hexcasting": "Hexcasting", + "itemGroup.hexcasting.creative_tab": "Hexcasting", "hexcasting.tooltip.spellbook.page": "Selected Page %d/%d", "hexcasting.tooltip.spellbook.page.sealed": "Selected Page %d/%d (%s)", diff --git a/Fabric/src/main/java/at/petrak/hexcasting/FabricHexInitializer.kt b/Fabric/src/main/java/at/petrak/hexcasting/FabricHexInitializer.kt index d6853750..ee21c474 100644 --- a/Fabric/src/main/java/at/petrak/hexcasting/FabricHexInitializer.kt +++ b/Fabric/src/main/java/at/petrak/hexcasting/FabricHexInitializer.kt @@ -1,5 +1,6 @@ import at.petrak.hexcasting.common.blocks.HexBlocks import at.petrak.hexcasting.common.items.HexItems +import at.petrak.hexcasting.common.lib.HexSounds import at.petrak.hexcasting.common.misc.Brainsweeping import at.petrak.hexcasting.fabric.FabricHexConfig import at.petrak.hexcasting.fabric.network.FabricPacketHandler @@ -26,6 +27,7 @@ object FabricHexInitializer : ModInitializer { } fun initRegistries() { + HexSounds.registerSounds(bind(Registry.SOUND_EVENT)) HexBlocks.registerBlocks(bind(Registry.BLOCK)) HexBlocks.registerBlockItems(bind(Registry.ITEM)) HexItems.registerItems(bind(Registry.ITEM)) diff --git a/Fabric/src/main/java/at/petrak/hexcasting/fabric/network/FabricPacketHandler.java b/Fabric/src/main/java/at/petrak/hexcasting/fabric/network/FabricPacketHandler.java index c30978be..43502f5c 100644 --- a/Fabric/src/main/java/at/petrak/hexcasting/fabric/network/FabricPacketHandler.java +++ b/Fabric/src/main/java/at/petrak/hexcasting/fabric/network/FabricPacketHandler.java @@ -29,18 +29,12 @@ public class FabricPacketHandler { makeClientBoundHandler(MsgNewSpellPatternAck::deserialize, MsgNewSpellPatternAck::handle)); ClientPlayNetworking.registerGlobalReceiver( MsgBlinkAck.ID, makeClientBoundHandler(MsgBlinkAck::deserialize, MsgBlinkAck::handle)); - ClientPlayNetworking.registerGlobalReceiver(MsgSentinelStatusUpdateAck.ID, - makeClientBoundHandler(MsgSentinelStatusUpdateAck::deserialize, MsgSentinelStatusUpdateAck::handle)); - ClientPlayNetworking.registerGlobalReceiver(MsgColorizerUpdateAck.ID, - makeClientBoundHandler(MsgColorizerUpdateAck::deserialize, MsgColorizerUpdateAck::handle)); ClientPlayNetworking.registerGlobalReceiver(MsgCastParticleAck.ID, makeClientBoundHandler(MsgCastParticleAck::deserialize, MsgCastParticleAck::handle)); ClientPlayNetworking.registerGlobalReceiver(MsgOpenSpellGuiAck.ID, makeClientBoundHandler(MsgOpenSpellGuiAck::deserialize, MsgOpenSpellGuiAck::handle)); ClientPlayNetworking.registerGlobalReceiver(MsgBeepAck.ID, makeClientBoundHandler(MsgBeepAck::deserialize, MsgBeepAck::handle)); - ClientPlayNetworking.registerGlobalReceiver(MsgBrainsweepAck.ID, - makeClientBoundHandler(MsgBrainsweepAck::deserialize, MsgBrainsweepAck::handle)); ClientPlayNetworking.registerGlobalReceiver(MsgUpdateComparatorVisualsAck.ID, makeClientBoundHandler(MsgUpdateComparatorVisualsAck::deserialize, MsgUpdateComparatorVisualsAck::handle)); } diff --git a/Fabric/src/main/java/at/petrak/hexcasting/fabric/xplat/FabricXplatImpl.java b/Fabric/src/main/java/at/petrak/hexcasting/fabric/xplat/FabricXplatImpl.java index 731f76b8..6094ecd7 100644 --- a/Fabric/src/main/java/at/petrak/hexcasting/fabric/xplat/FabricXplatImpl.java +++ b/Fabric/src/main/java/at/petrak/hexcasting/fabric/xplat/FabricXplatImpl.java @@ -5,23 +5,31 @@ import at.petrak.hexcasting.api.player.FlightAbility; import at.petrak.hexcasting.api.player.Sentinel; import at.petrak.hexcasting.api.spell.casting.CastingHarness; import at.petrak.hexcasting.api.spell.casting.ResolvedPattern; +import at.petrak.hexcasting.common.items.HexItems; import at.petrak.hexcasting.common.network.IMessage; import at.petrak.hexcasting.fabric.cc.HexCardinalComponents; import at.petrak.hexcasting.xplat.IXplatAbstractions; import at.petrak.hexcasting.xplat.Platform; import net.fabricmc.api.EnvType; +import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.fabricmc.fabric.api.registry.FlammableBlockRegistry; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.phys.Vec3; import java.util.List; +import static at.petrak.hexcasting.api.HexAPI.modLoc; + public class FabricXplatImpl implements IXplatAbstractions { @Override public Platform platform() { @@ -132,4 +140,26 @@ public class FabricXplatImpl implements IXplatAbstractions { var cc = HexCardinalComponents.COLORIZER.maybeGet(colorizer.item()); return cc.map(col -> col.color(colorizer.owner(), time, position)).orElse(0xff_ff00dc); } + + @Override + public Block makeFlammable(BlockBehaviour.Properties properties, int flammability, int spreadSpeed) { + var out = new Block(properties); + FlammableBlockRegistry.getDefaultInstance().add(out, flammability, spreadSpeed); + return out; + } + + + private static CreativeModeTab TAB = null; + + @Override + public CreativeModeTab getTab() { + if (TAB == null) { + TAB = FabricItemGroupBuilder.create(modLoc("creative_tab")) + .icon(HexItems::tabIcon) + .appendItems(HexItems::fillTab) + .build(); + } + + return TAB; + } } diff --git a/Forge/src/main/java/at/petrak/hexcasting/ForgeHexInitializer.kt b/Forge/src/main/java/at/petrak/hexcasting/ForgeHexInitializer.kt index 17717468..faa7cc7a 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/ForgeHexInitializer.kt +++ b/Forge/src/main/java/at/petrak/hexcasting/ForgeHexInitializer.kt @@ -6,6 +6,7 @@ import at.petrak.hexcasting.api.advancements.HexAdvancementTriggers import at.petrak.hexcasting.api.mod.HexConfig import at.petrak.hexcasting.common.blocks.HexBlocks import at.petrak.hexcasting.common.items.HexItems +import at.petrak.hexcasting.common.lib.HexSounds import at.petrak.hexcasting.common.misc.Brainsweeping import at.petrak.hexcasting.forge.ForgeHexConfig import at.petrak.hexcasting.forge.cap.CapSyncers @@ -53,6 +54,7 @@ object ForgeHexInitializer { } fun initRegistry() { + bind(ForgeRegistries.SOUND_EVENTS, HexSounds::registerSounds) bind(ForgeRegistries.BLOCKS, HexBlocks::registerBlocks) bind(ForgeRegistries.ITEMS, HexBlocks::registerBlockItems) bind(ForgeRegistries.ITEMS, HexItems::registerItems) diff --git a/Forge/src/main/java/at/petrak/hexcasting/forge/cap/CapSyncers.java b/Forge/src/main/java/at/petrak/hexcasting/forge/cap/CapSyncers.java index 8ffe4b91..0219892b 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/forge/cap/CapSyncers.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/cap/CapSyncers.java @@ -1,5 +1,7 @@ package at.petrak.hexcasting.forge.cap; +import at.petrak.hexcasting.forge.network.MsgColorizerUpdateAck; +import at.petrak.hexcasting.forge.network.MsgSentinelStatusUpdateAck; import at.petrak.hexcasting.xplat.IXplatAbstractions; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; @@ -35,8 +37,8 @@ public class CapSyncers { return; } - IXplatAbstractions.INSTANCE.syncSentinel(player); - IXplatAbstractions.INSTANCE.syncColorizer(player); + syncSentinel(player); + syncColorizer(player); } @SubscribeEvent @@ -45,7 +47,17 @@ public class CapSyncers { return; } - IXplatAbstractions.INSTANCE.syncSentinel(player); - IXplatAbstractions.INSTANCE.syncColorizer(player); + syncSentinel(player); + syncColorizer(player); + } + + public static void syncSentinel(ServerPlayer player) { + IXplatAbstractions.INSTANCE.sendPacketToPlayer(player, + new MsgSentinelStatusUpdateAck(IXplatAbstractions.INSTANCE.getSentinel(player))); + } + + public static void syncColorizer(ServerPlayer player) { + IXplatAbstractions.INSTANCE.sendPacketToPlayer(player, + new MsgColorizerUpdateAck(IXplatAbstractions.INSTANCE.getColorizer(player))); } } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/network/MsgBrainsweepAck.java b/Forge/src/main/java/at/petrak/hexcasting/forge/network/MsgBrainsweepAck.java similarity index 88% rename from Common/src/main/java/at/petrak/hexcasting/common/network/MsgBrainsweepAck.java rename to Forge/src/main/java/at/petrak/hexcasting/forge/network/MsgBrainsweepAck.java index ed5a990f..1ed1f6ff 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/network/MsgBrainsweepAck.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/network/MsgBrainsweepAck.java @@ -1,12 +1,13 @@ -package at.petrak.hexcasting.common.network; +package at.petrak.hexcasting.forge.network; import at.petrak.hexcasting.common.misc.Brainsweeping; +import at.petrak.hexcasting.common.network.IMessage; import io.netty.buffer.ByteBuf; import net.minecraft.client.Minecraft; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.Mob; import static at.petrak.hexcasting.api.HexAPI.modLoc; @@ -44,7 +45,7 @@ public record MsgBrainsweepAck(int target) implements IMessage { var level = Minecraft.getInstance().level; if (level != null) { Entity entity = level.getEntity(msg.target()); - if (entity instanceof LivingEntity living) { + if (entity instanceof Mob living) { Brainsweeping.brainsweep(living); } } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/network/MsgColorizerUpdateAck.java b/Forge/src/main/java/at/petrak/hexcasting/forge/network/MsgColorizerUpdateAck.java similarity index 84% rename from Common/src/main/java/at/petrak/hexcasting/common/network/MsgColorizerUpdateAck.java rename to Forge/src/main/java/at/petrak/hexcasting/forge/network/MsgColorizerUpdateAck.java index 43c4bd9f..1ba69e08 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/network/MsgColorizerUpdateAck.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/network/MsgColorizerUpdateAck.java @@ -1,7 +1,8 @@ -package at.petrak.hexcasting.common.network; +package at.petrak.hexcasting.forge.network; import at.petrak.hexcasting.api.misc.FrozenColorizer; -import at.petrak.hexcasting.api.player.HexPlayerDataHelper; +import at.petrak.hexcasting.common.network.IMessage; +import at.petrak.hexcasting.xplat.IXplatAbstractions; import io.netty.buffer.ByteBuf; import net.minecraft.client.Minecraft; import net.minecraft.network.FriendlyByteBuf; @@ -39,7 +40,7 @@ public record MsgColorizerUpdateAck(FrozenColorizer update) implements IMessage public void run() { var player = Minecraft.getInstance().player; if (player != null) { - HexPlayerDataHelper.setColorizer(player, self.update()); + IXplatAbstractions.INSTANCE.setColorizer(player, self.update()); } } }); diff --git a/Common/src/main/java/at/petrak/hexcasting/common/network/MsgSentinelStatusUpdateAck.java b/Forge/src/main/java/at/petrak/hexcasting/forge/network/MsgSentinelStatusUpdateAck.java similarity index 89% rename from Common/src/main/java/at/petrak/hexcasting/common/network/MsgSentinelStatusUpdateAck.java rename to Forge/src/main/java/at/petrak/hexcasting/forge/network/MsgSentinelStatusUpdateAck.java index 81cf11a8..b492c1c3 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/network/MsgSentinelStatusUpdateAck.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/network/MsgSentinelStatusUpdateAck.java @@ -1,7 +1,8 @@ -package at.petrak.hexcasting.common.network; +package at.petrak.hexcasting.forge.network; -import at.petrak.hexcasting.api.player.HexPlayerDataHelper; import at.petrak.hexcasting.api.player.Sentinel; +import at.petrak.hexcasting.common.network.IMessage; +import at.petrak.hexcasting.xplat.IXplatAbstractions; import io.netty.buffer.ByteBuf; import net.minecraft.client.Minecraft; import net.minecraft.core.Registry; @@ -50,7 +51,7 @@ public record MsgSentinelStatusUpdateAck(Sentinel update) implements IMessage { public void run() { var player = Minecraft.getInstance().player; if (player != null) { - HexPlayerDataHelper.setSentinel(player, self.update()); + IXplatAbstractions.INSTANCE.setSentinel(player, self.update()); } } }); diff --git a/Forge/src/main/java/at/petrak/hexcasting/forge/xplat/ForgeXplatImpl.java b/Forge/src/main/java/at/petrak/hexcasting/forge/xplat/ForgeXplatImpl.java index 7460cce9..02b8351e 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/forge/xplat/ForgeXplatImpl.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/xplat/ForgeXplatImpl.java @@ -1,5 +1,6 @@ package at.petrak.hexcasting.forge.xplat; +import at.petrak.hexcasting.api.HexAPI; import at.petrak.hexcasting.api.addldata.Colorizer; import at.petrak.hexcasting.api.misc.FrozenColorizer; import at.petrak.hexcasting.api.player.FlightAbility; @@ -8,13 +9,17 @@ import at.petrak.hexcasting.api.spell.casting.CastingContext; import at.petrak.hexcasting.api.spell.casting.CastingHarness; import at.petrak.hexcasting.api.spell.casting.ResolvedPattern; import at.petrak.hexcasting.api.utils.HexUtils; +import at.petrak.hexcasting.common.items.HexItems; import at.petrak.hexcasting.common.misc.Brainsweeping; import at.petrak.hexcasting.common.network.IMessage; -import at.petrak.hexcasting.common.network.MsgBrainsweepAck; +import at.petrak.hexcasting.forge.cap.CapSyncers; import at.petrak.hexcasting.forge.cap.HexCapabilities; import at.petrak.hexcasting.forge.network.ForgePacketHandler; +import at.petrak.hexcasting.forge.network.MsgBrainsweepAck; +import at.petrak.hexcasting.forge.xplat.block.BlockBurns; import at.petrak.hexcasting.xplat.IXplatAbstractions; import at.petrak.hexcasting.xplat.Platform; +import net.minecraft.core.NonNullList; import net.minecraft.core.Registry; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; @@ -26,7 +31,10 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.phys.Vec3; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.loading.FMLLoader; @@ -82,7 +90,7 @@ public class ForgeXplatImpl implements IXplatAbstractions { tag.put(TAG_COLOR, colorizer.serialize()); if (player instanceof ServerPlayer serverPlayer) { - this.syncColorizer(serverPlayer); + CapSyncers.syncColorizer(serverPlayer); } } @@ -101,7 +109,7 @@ public class ForgeXplatImpl implements IXplatAbstractions { } if (player instanceof ServerPlayer serverPlayer) { - this.syncSentinel(serverPlayer); + CapSyncers.syncSentinel(serverPlayer); } } @@ -209,6 +217,32 @@ public class ForgeXplatImpl implements IXplatAbstractions { ForgePacketHandler.getNetwork().sendToServer(packet); } + @Override + public Block makeFlammable(BlockBehaviour.Properties properties, int flammability, int spreadSpeed) { + return new BlockBurns(properties, flammability, spreadSpeed); + } + + private static CreativeModeTab TAB = null; + + @Override + public CreativeModeTab getTab() { + if (TAB == null) { + TAB = new CreativeModeTab(HexAPI.MOD_ID) { + @Override + public ItemStack makeIcon() { + return HexItems.tabIcon(); + } + + @Override + public void fillItemList(NonNullList p_40778_) { + super.fillItemList(p_40778_); + HexItems.fillTab(p_40778_); + } + }; + } + + return TAB; + } public static final String TAG_BRAINSWEPT = "hexcasting:brainswept"; public static final String TAG_SENTINEL_EXISTS = "hexcasting:sentinel_exists"; diff --git a/Forge/src/main/java/at/petrak/hexcasting/forge/xplat/block/BlockBurns.java b/Forge/src/main/java/at/petrak/hexcasting/forge/xplat/block/BlockBurns.java new file mode 100644 index 00000000..b96c2620 --- /dev/null +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/xplat/block/BlockBurns.java @@ -0,0 +1,33 @@ +package at.petrak.hexcasting.forge.xplat.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; + +public class BlockBurns extends Block { + private final int flammability; + private final int spreadSpeed; + + public BlockBurns(Properties props, int flammability, int spreadSpeed) { + super(props); + this.flammability = flammability; + this.spreadSpeed = spreadSpeed; + } + + @Override + public boolean isFlammable(BlockState state, BlockGetter level, BlockPos pos, Direction direction) { + return true; + } + + @Override + public int getFlammability(BlockState state, BlockGetter level, BlockPos pos, Direction direction) { + return flammability; + } + + @Override + public int getFireSpreadSpeed(BlockState state, BlockGetter level, BlockPos pos, Direction direction) { + return spreadSpeed; + } +}