*now* it's compiling, at least on forge

This commit is contained in:
gamma-delta 2022-11-04 17:31:18 +01:00
parent 24d8390ec9
commit d148552a81
23 changed files with 183 additions and 188 deletions

View file

@ -1,11 +0,0 @@
package at.petrak.hexcasting.client;
import at.petrak.hexcasting.client.gui.PatternTooltipGreeble;
import at.petrak.hexcasting.xplat.IClientXplatAbstractions;
// https://github.com/VazkiiMods/Quark/blob/ace90bfcc26db4c50a179f026134e2577987c2b1/src/main/java/vazkii/quark/content/client/module/ImprovedTooltipsModule.java
public class HexTooltips {
public static void init() {
IClientXplatAbstractions.INSTANCE.registerIdentityTooltipMapping(PatternTooltipGreeble.class);
}
}

View file

@ -88,8 +88,6 @@ public class RegisterClientStuff {
registerWandOverrides(HexItems.STAFF_ACACIA);
registerWandOverrides(HexItems.STAFF_EDIFIED);
HexTooltips.init();
x.setRenderLayer(HexBlocks.CONJURED_LIGHT, RenderType.cutout());
x.setRenderLayer(HexBlocks.CONJURED_BLOCK, RenderType.cutout());
x.setRenderLayer(HexBlocks.EDIFIED_DOOR, RenderType.cutout());

View file

@ -3,6 +3,7 @@ package at.petrak.hexcasting.client.gui;
import at.petrak.hexcasting.api.spell.math.HexPattern;
import at.petrak.hexcasting.client.ClientTickCounter;
import at.petrak.hexcasting.client.RenderLib;
import at.petrak.hexcasting.common.misc.PatternTooltip;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
@ -14,13 +15,14 @@ import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.inventory.tooltip.TooltipComponent;
import net.minecraft.world.phys.Vec2;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.stream.Collectors;
// https://github.com/VazkiiMods/Quark/blob/master/src/main/java/vazkii/quark/content/client/tooltip/MapTooltips.java
// https://github.com/VazkiiMods/Botania/blob/95bd2d3fbc857b7c102687554e1d1b112f8af436/Xplat/src/main/java/vazkii/botania/client/gui/ManaBarTooltipComponent.java
// yoink
public class PatternTooltipGreeble implements ClientTooltipComponent, TooltipComponent {
public class PatternTooltipComponent implements ClientTooltipComponent {
public static final ResourceLocation PRISTINE_BG = new ResourceLocation(
"hexcasting:textures/gui/scroll.png");
public static final ResourceLocation ANCIENT_BG = new ResourceLocation(
@ -36,9 +38,9 @@ public class PatternTooltipGreeble implements ClientTooltipComponent, TooltipCom
private final float scale;
private final ResourceLocation background;
public PatternTooltipGreeble(HexPattern pattern, ResourceLocation background) {
this.pattern = pattern;
this.background = background;
public PatternTooltipComponent(PatternTooltip tt) {
this.pattern = tt.pattern();
this.background = tt.background();
var pair = RenderLib.getCenteredPattern(pattern, SIZE, SIZE, 8f);
this.scale = pair.getFirst();
@ -47,6 +49,14 @@ public class PatternTooltipGreeble implements ClientTooltipComponent, TooltipCom
this.pathfinderDots = dots.stream().distinct().collect(Collectors.toList());
}
@Nullable
public static ClientTooltipComponent tryConvert(TooltipComponent cmp) {
if (cmp instanceof PatternTooltip ptt) {
return new PatternTooltipComponent(ptt);
}
return null;
}
@Override
public void renderImage(Font font, int mouseX, int mouseY, PoseStack ps, ItemRenderer pItemRenderer,
int pBlitOffset) {

View file

@ -5,9 +5,10 @@ import at.petrak.hexcasting.api.spell.iota.Iota;
import at.petrak.hexcasting.api.spell.iota.PatternIota;
import at.petrak.hexcasting.api.spell.math.HexPattern;
import at.petrak.hexcasting.api.utils.NBTHelper;
import at.petrak.hexcasting.client.gui.PatternTooltipGreeble;
import at.petrak.hexcasting.client.gui.PatternTooltipComponent;
import at.petrak.hexcasting.common.entities.EntityWallScroll;
import at.petrak.hexcasting.common.lib.HexIotaTypes;
import at.petrak.hexcasting.common.misc.PatternTooltip;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
@ -120,7 +121,7 @@ public class ItemScroll extends Item implements IotaHolderItem {
var ancientId = NBTHelper.getString(pStack, TAG_OP_ID);
if (ancientId != null) {
return Component.translatable(descID + ".of",
Component.translatable( "hexcasting.spell." + ResourceLocation.tryParse(ancientId)));
Component.translatable("hexcasting.spell." + ResourceLocation.tryParse(ancientId)));
} else if (NBTHelper.hasCompound(pStack, TAG_PATTERN)) {
return Component.translatable(descID);
} else {
@ -135,10 +136,10 @@ public class ItemScroll extends Item implements IotaHolderItem {
var compound = NBTHelper.getCompound(stack, ItemScroll.TAG_PATTERN);
if (compound != null) {
var pattern = HexPattern.fromNBT(compound);
return Optional.of(new PatternTooltipGreeble(
return Optional.of(new PatternTooltip(
pattern,
NBTHelper.hasString(stack,
ItemScroll.TAG_OP_ID) ? PatternTooltipGreeble.ANCIENT_BG : PatternTooltipGreeble.PRISTINE_BG));
ItemScroll.TAG_OP_ID) ? PatternTooltipComponent.ANCIENT_BG : PatternTooltipComponent.PRISTINE_BG));
}
return Optional.empty();

View file

@ -7,9 +7,10 @@ import at.petrak.hexcasting.api.spell.iota.Iota;
import at.petrak.hexcasting.api.spell.iota.PatternIota;
import at.petrak.hexcasting.api.spell.math.HexPattern;
import at.petrak.hexcasting.api.utils.NBTHelper;
import at.petrak.hexcasting.client.gui.PatternTooltipGreeble;
import at.petrak.hexcasting.client.gui.PatternTooltipComponent;
import at.petrak.hexcasting.common.blocks.circles.BlockEntitySlate;
import at.petrak.hexcasting.common.lib.HexIotaTypes;
import at.petrak.hexcasting.common.misc.PatternTooltip;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
@ -112,9 +113,7 @@ public class ItemSlate extends BlockItem implements IotaHolderItem {
var patTag = bet.getCompound(BlockEntitySlate.TAG_PATTERN);
if (!patTag.isEmpty()) {
var pattern = HexPattern.fromNBT(patTag);
return Optional.of(new PatternTooltipGreeble(
pattern,
PatternTooltipGreeble.SLATE_BG));
return Optional.of(new PatternTooltip(pattern, PatternTooltipComponent.SLATE_BG));
}
}
return Optional.empty();

View file

@ -19,7 +19,7 @@ public class HexLootHandler {
public static final ResourceLocation TABLE_INJECT_AMETHYST_CLUSTER = modLoc("inject/amethyst_cluster");
public static void lootLoad(ResourceLocation id, Consumer<LootPool.Builder> addPool) {
public static void lootLoad(ResourceLocation id, Consumer<LootPool> addPool) {
if (id.equals(Blocks.AMETHYST_CLUSTER.getLootTable())) {
addPool.accept(getInjectPool(TABLE_INJECT_AMETHYST_CLUSTER));
} else {
@ -31,10 +31,11 @@ public class HexLootHandler {
}
}
public static LootPool.Builder getInjectPool(ResourceLocation entry) {
public static LootPool getInjectPool(ResourceLocation entry) {
return LootPool.lootPool()
.add(getInjectEntry(entry, 1))
.setBonusRolls(UniformGenerator.between(0, 1));
.setBonusRolls(UniformGenerator.between(0, 1))
.build();
}
private static LootPoolEntryContainer.Builder<?> getInjectEntry(ResourceLocation table, int weight) {

View file

@ -0,0 +1,11 @@
package at.petrak.hexcasting.common.misc;
import at.petrak.hexcasting.api.spell.math.HexPattern;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.inventory.tooltip.TooltipComponent;
/**
* Used for displaying patterns on the tooltips for scrolls and slates.
*/
public record PatternTooltip(HexPattern pattern, ResourceLocation background) implements TooltipComponent {
}

View file

@ -2,7 +2,6 @@ package at.petrak.hexcasting.xplat;
import at.petrak.hexcasting.api.HexAPI;
import at.petrak.hexcasting.common.network.IMessage;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
import net.minecraft.client.particle.ParticleProvider;
import net.minecraft.client.particle.SpriteSet;
import net.minecraft.client.renderer.RenderType;
@ -14,7 +13,6 @@ import net.minecraft.core.particles.ParticleType;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.inventory.tooltip.TooltipComponent;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
@ -32,8 +30,6 @@ public interface IClientXplatAbstractions {
<T extends ParticleOptions> void registerParticleType(ParticleType<T> type,
Function<SpriteSet, ParticleProvider<T>> factory);
<T extends ClientTooltipComponent & TooltipComponent> void registerIdentityTooltipMapping(Class<T> clazz);
void registerItemProperty(Item item, ResourceLocation id, ItemPropertyFunction func);
// On Forge, these are already exposed; on Farbc we do a mixin

View file

@ -131,11 +131,18 @@ public interface IXplatAbstractions {
boolean isCorrectTierForDrops(Tier tier, BlockState bs);
ResourceLocation getID(Block block);
// These don't need to be xplat anymore, but it does save refactoring if they're still defined here
default ResourceLocation getID(Block block) {
return Registry.BLOCK.getKey(block);
}
ResourceLocation getID(Item item);
default ResourceLocation getID(Item item) {
return Registry.ITEM.getKey(item);
}
ResourceLocation getID(VillagerProfession profession);
default ResourceLocation getID(VillagerProfession profession) {
return Registry.VILLAGER_PROFESSION.getKey(profession);
}
Ingredient getUnsealedIngredient(ItemStack stack);

View file

@ -4,14 +4,12 @@ import at.petrak.hexcasting.client.ClientTickCounter
import at.petrak.hexcasting.client.HexAdditionalRenderers
import at.petrak.hexcasting.client.RegisterClientStuff
import at.petrak.hexcasting.client.ShiftScrollListener
import at.petrak.hexcasting.client.gui.PatternTooltipComponent
import at.petrak.hexcasting.fabric.event.MouseScrollCallback
import at.petrak.hexcasting.fabric.network.FabricPacketHandler
import net.fabricmc.api.ClientModInitializer
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents
import net.fabricmc.fabric.api.client.rendering.v1.BlockEntityRendererRegistry
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents
import net.fabricmc.fabric.api.client.rendering.v1.*
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider
import net.minecraft.world.level.block.entity.BlockEntity
import net.minecraft.world.level.block.entity.BlockEntityType
@ -36,6 +34,7 @@ object FabricHexClientInitializer : ClientModInitializer {
ClientTickCounter.clientTickEnd()
ShiftScrollListener.clientTickEnd()
}
TooltipComponentCallback.EVENT.register(PatternTooltipComponent::tryConvert)
MouseScrollCallback.EVENT.register(ShiftScrollListener::onScrollInGameplay)

View file

@ -27,7 +27,7 @@ public class PatternRendererEMI implements EmiRenderable {
public PatternRendererEMI(ResourceLocation pattern, int w, int h) {
var entry = PatternRegistry.lookupPattern(pattern);
this.strokeOrder = !entry.isPerWorld();
var data = PatternDrawingUtil.loadPatterns(List.of(new Pair<>(entry.getPrototype(), HexCoord.getOrigin())));
var data = PatternDrawingUtil.loadPatterns(List.of(new Pair<>(entry.prototype(), HexCoord.getOrigin())));
this.patterns = data.patterns();
this.pathfinderDots = data.pathfinderDots();
this.width = w;

View file

@ -20,7 +20,8 @@ archivesBaseName = getArtifactID("forge")
// Adds KFF as dependency and Kotlin libs to the runtime classpath
// If you already know how to add the Kotlin plugin to Gradle, this is the only line you need for KFF
apply from: 'https://raw.githubusercontent.com/thedarkcolour/KotlinForForge/site/thedarkcolour/kotlinforforge/gradle/kff-3.3.2.gradle'
apply from: "https://raw.githubusercontent.com/thedarkcolour/KotlinForForge/site/thedarkcolour/kotlinforforge/gradle/kff-" +
"${kotlinForForgeVersion}.gradle"
minecraft {
mappings channel: 'official', version: minecraftVersion

View file

@ -1 +1,3 @@
forgeVersion=43.1.47
forgeVersion=43.1.1
kotlinForForgeVersion=3.7.1

View file

@ -0,0 +1,19 @@
package at.petrak.hexcasting.forge;
import at.petrak.hexcasting.api.HexAPI;
import at.petrak.hexcasting.common.command.PatternResLocArgument;
import net.minecraft.commands.synchronization.ArgumentTypeInfo;
import net.minecraft.commands.synchronization.SingletonArgumentInfo;
import net.minecraft.core.Registry;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.RegistryObject;
// ArgumentTypeInfos.java
public class ForgeHexArgumentTypeRegistry {
public static final DeferredRegister<ArgumentTypeInfo<?, ?>> ARGUMENT_TYPES = DeferredRegister.create(
Registry.COMMAND_ARGUMENT_TYPE_REGISTRY, HexAPI.MOD_ID);
public static final RegistryObject<ArgumentTypeInfo<PatternResLocArgument, ?>> PATTERN_RESLOC = ARGUMENT_TYPES.register(
"pattern", () ->
SingletonArgumentInfo.contextFree(PatternResLocArgument::id));
}

View file

@ -4,7 +4,9 @@ import at.petrak.hexcasting.client.ClientTickCounter;
import at.petrak.hexcasting.client.HexAdditionalRenderers;
import at.petrak.hexcasting.client.RegisterClientStuff;
import at.petrak.hexcasting.client.ShiftScrollListener;
import at.petrak.hexcasting.client.gui.PatternTooltipComponent;
import at.petrak.hexcasting.client.shader.HexShaders;
import at.petrak.hexcasting.common.misc.PatternTooltip;
import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.color.item.ItemColors;
import net.minecraftforge.client.event.*;
@ -34,15 +36,16 @@ public class ForgeHexClientInitializer {
var evBus = MinecraftForge.EVENT_BUS;
evBus.addListener((RenderLevelLastEvent e) ->
HexAdditionalRenderers.overlayLevel(e.getPoseStack(), e.getPartialTick()));
evBus.addListener((RenderGameOverlayEvent.Post e) -> {
if (e.getType() == RenderGameOverlayEvent.ElementType.ALL) {
HexAdditionalRenderers.overlayGui(e.getMatrixStack(), e.getPartialTicks());
evBus.addListener((RenderLevelStageEvent e) -> {
if (e.getStage().equals(RenderLevelStageEvent.Stage.AFTER_PARTICLES)) {
HexAdditionalRenderers.overlayLevel(e.getPoseStack(), e.getPartialTick());
}
});
evBus.addListener((RenderGuiEvent.Post e) -> {
HexAdditionalRenderers.overlayGui(e.getPoseStack(), e.getPartialTick());
});
evBus.addListener((TickEvent.RenderTickEvent e) -> {
if (e.phase == TickEvent.Phase.START) {
@ -57,7 +60,7 @@ public class ForgeHexClientInitializer {
}
});
evBus.addListener((InputEvent.MouseScrollEvent e) -> {
evBus.addListener((InputEvent.MouseScrollingEvent e) -> {
var cancel = ShiftScrollListener.onScrollInGameplay(e.getScrollDelta());
e.setCanceled(cancel);
});
@ -69,7 +72,7 @@ public class ForgeHexClientInitializer {
}
@SubscribeEvent(priority = EventPriority.LOWEST)
public static void registerParticles(ParticleFactoryRegisterEvent evt) {
public static void registerParticles(RegisterParticleProvidersEvent evt) {
RegisterClientStuff.registerParticles();
}
@ -77,4 +80,9 @@ public class ForgeHexClientInitializer {
public static void registerRenderers(EntityRenderersEvent.RegisterRenderers evt) {
RegisterClientStuff.registerBlockEntityRenderers(evt::registerBlockEntityRenderer);
}
}
@SubscribeEvent
public static void registerTooltipComponents(RegisterClientTooltipComponentFactoriesEvent evt) {
evt.register(PatternTooltip.class, PatternTooltipComponent::new);
}
}

View file

@ -9,7 +9,6 @@ import at.petrak.hexcasting.common.blocks.behavior.HexComposting;
import at.petrak.hexcasting.common.blocks.behavior.HexStrippables;
import at.petrak.hexcasting.common.casting.RegisterPatterns;
import at.petrak.hexcasting.common.casting.operators.spells.great.OpFlight;
import at.petrak.hexcasting.common.command.PatternResLocArgument;
import at.petrak.hexcasting.common.entities.HexEntities;
import at.petrak.hexcasting.common.items.ItemJewelerHammer;
import at.petrak.hexcasting.common.lib.*;
@ -25,15 +24,13 @@ import at.petrak.hexcasting.forge.network.MsgBrainsweepAck;
import at.petrak.hexcasting.forge.recipe.ForgeUnsealedIngredient;
import at.petrak.hexcasting.interop.HexInterop;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
import net.minecraft.commands.synchronization.ArgumentTypes;
import net.minecraft.commands.synchronization.EmptyArgumentSerializer;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
@ -43,13 +40,12 @@ import net.minecraftforge.common.ToolActions;
import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.event.LootTableLoadEvent;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.living.LivingConversionEvent;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.level.BlockEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
@ -57,9 +53,7 @@ import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
import net.minecraftforge.network.PacketDistributor;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.registries.IForgeRegistryEntry;
import net.minecraftforge.registries.RegisterEvent;
import thedarkcolour.kotlinforforge.KotlinModLoadingContext;
import java.util.function.BiConsumer;
@ -89,36 +83,33 @@ public class ForgeHexInitializer {
}
private static void initRegistry() {
bind(ForgeRegistries.SOUND_EVENTS, HexSounds::registerSounds);
bind(ForgeRegistries.BLOCKS, HexBlocks::registerBlocks);
bind(ForgeRegistries.ITEMS, HexBlocks::registerBlockItems);
bind(ForgeRegistries.BLOCK_ENTITIES, HexBlockEntities::registerTiles);
bind(ForgeRegistries.ITEMS, HexItems::registerItems);
bind(Registry.SOUND_EVENT_REGISTRY, HexSounds::registerSounds);
bind(Registry.BLOCK_REGISTRY, HexBlocks::registerBlocks);
bind(Registry.ITEM_REGISTRY, HexBlocks::registerBlockItems);
bind(Registry.BLOCK_ENTITY_TYPE_REGISTRY, HexBlockEntities::registerTiles);
bind(Registry.ITEM_REGISTRY, HexItems::registerItems);
bind(ForgeRegistries.RECIPE_SERIALIZERS, HexRecipeSerializers::registerSerializers);
bind(Registry.RECIPE_SERIALIZER_REGISTRY, HexRecipeSerializers::registerSerializers);
bind(ForgeRegistries.ENTITIES, HexEntities::registerEntities);
bind(Registry.ENTITY_TYPE_REGISTRY, HexEntities::registerEntities);
bind(ForgeRegistries.PARTICLE_TYPES, HexParticles::registerParticles);
bind(Registry.PARTICLE_TYPE_REGISTRY, HexParticles::registerParticles);
ForgeHexArgumentTypeRegistry.ARGUMENT_TYPES.register(getModEventBus());
HexIotaTypes.registerTypes();
ArgumentTypes.register(HexAPI.MOD_ID + ":pattern", PatternResLocArgument.class,
new EmptyArgumentSerializer<>(PatternResLocArgument::id));
HexAdvancementTriggers.registerTriggers();
}
// https://github.com/VazkiiMods/Botania/blob/1.18.x/Forge/src/main/java/vazkii/botania/forge/ForgeCommonInitializer.java
private static <T extends IForgeRegistryEntry<T>> void bind(IForgeRegistry<T> registry,
private static <T> void bind(ResourceKey<Registry<T>> registry,
Consumer<BiConsumer<T, ResourceLocation>> source) {
getModEventBus().addGenericListener(registry.getRegistrySuperType(),
(RegistryEvent.Register<T> event) -> {
IForgeRegistry<T> forgeRegistry = event.getRegistry();
source.accept((t, rl) -> {
t.setRegistryName(rl);
forgeRegistry.register(t);
});
});
getModEventBus().addListener((RegisterEvent event) -> {
if (registry.equals(event.getRegistryKey())) {
source.accept((t, rl) -> event.register(registry, rl, () -> t));
}
});
}
private static void initListeners() {
@ -138,12 +129,14 @@ public class ForgeHexInitializer {
}));
// We have to do these at some point when the registries are still open
modBus.addGenericListener(Item.class, (RegistryEvent<Item> evt) -> {
HexRecipeSerializers.registerTypes();
CraftingHelper.register(modLoc("unsealed"), ForgeUnsealedIngredient.Serializer.INSTANCE);
HexStatistics.register();
HexLootFunctions.registerSerializers((lift, id) ->
Registry.register(Registry.LOOT_FUNCTION_TYPE, id, lift));
modBus.addListener((RegisterEvent evt) -> {
if (evt.getRegistryKey().equals(Registry.ITEM_REGISTRY)) {
HexRecipeSerializers.registerTypes();
CraftingHelper.register(modLoc("unsealed"), ForgeUnsealedIngredient.Serializer.INSTANCE);
HexStatistics.register();
HexLootFunctions.registerSerializers((lift, id) ->
Registry.register(Registry.LOOT_FUNCTION_TYPE, id, lift));
}
});
modBus.addListener((FMLLoadCompleteEvent evt) ->
@ -151,21 +144,21 @@ public class ForgeHexInitializer {
evBus.addListener((PlayerInteractEvent.EntityInteract evt) -> {
var res = Brainsweeping.tradeWithVillager(
evt.getPlayer(), evt.getWorld(), evt.getHand(), evt.getTarget(), null);
evt.getEntity(), evt.getLevel(), evt.getHand(), evt.getTarget(), null);
if (res.consumesAction()) {
evt.setCanceled(true);
evt.setCancellationResult(res);
}
});
evBus.addListener((LivingConversionEvent.Post evt) ->
Brainsweeping.copyBrainsweepFromVillager(evt.getEntityLiving(), evt.getOutcome()));
Brainsweeping.copyBrainsweepFromVillager(evt.getEntity(), evt.getOutcome()));
evBus.addListener((LivingEvent.LivingUpdateEvent evt) -> {
OpFlight.INSTANCE.tickDownFlight(evt.getEntityLiving());
evBus.addListener((LivingEvent.LivingTickEvent evt) -> {
OpFlight.INSTANCE.tickDownFlight(evt.getEntity());
});
evBus.addListener((TickEvent.WorldTickEvent evt) -> {
if (evt.phase == TickEvent.Phase.END && evt.world instanceof ServerLevel world) {
evBus.addListener((TickEvent.LevelTickEvent evt) -> {
if (evt.phase == TickEvent.Phase.END && evt.level instanceof ServerLevel world) {
PlayerPositionRecorder.updateAllPlayers(world);
}
});
@ -173,7 +166,7 @@ public class ForgeHexInitializer {
evBus.addListener((RegisterCommandsEvent evt) -> HexCommands.register(evt.getDispatcher()));
evBus.addListener((PlayerEvent.BreakSpeed evt) ->
evt.setCanceled(ItemJewelerHammer.shouldFailToBreak(evt.getPlayer(), evt.getState(), evt.getPos())));
evt.setCanceled(ItemJewelerHammer.shouldFailToBreak(evt.getEntity(), evt.getState(), evt.getPos())));
evBus.addListener((LootTableLoadEvent evt) -> HexLootHandler.lootLoad(
evt.getName(),
@ -184,7 +177,7 @@ public class ForgeHexInitializer {
// On Fabric this should be auto-synced
evBus.addListener((PlayerEvent.StartTracking evt) -> {
Entity target = evt.getTarget();
if (evt.getPlayer() instanceof ServerPlayer serverPlayer &&
if (evt.getTarget() instanceof ServerPlayer serverPlayer &&
target instanceof Mob mob && IXplatAbstractions.INSTANCE.isBrainswept(mob)) {
ForgePacketHandler.getNetwork()
.send(PacketDistributor.PLAYER.with(() -> serverPlayer), MsgBrainsweepAck.of(mob));

View file

@ -11,7 +11,7 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
public class CapSyncers {
@SubscribeEvent
public static void copyDataOnDeath(PlayerEvent.Clone evt) {
var eitherSidePlayer = evt.getPlayer();
var eitherSidePlayer = evt.getEntity();
// this apparently defines it in outside scope. the more you know.
if (!(eitherSidePlayer instanceof ServerPlayer player)) {
return;
@ -33,7 +33,7 @@ public class CapSyncers {
@SubscribeEvent
public static void syncDataOnLogin(PlayerEvent.PlayerLoggedInEvent evt) {
if (!(evt.getPlayer() instanceof ServerPlayer player)) {
if (!(evt.getEntity() instanceof ServerPlayer player)) {
return;
}
@ -43,7 +43,7 @@ public class CapSyncers {
@SubscribeEvent
public static void syncDataOnRejoin(PlayerEvent.PlayerRespawnEvent evt) {
if (!(evt.getPlayer() instanceof ServerPlayer player)) {
if (!(evt.getEntity() instanceof ServerPlayer player)) {
return;
}

View file

@ -16,8 +16,8 @@ import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraftforge.common.Tags;
import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.data.event.GatherDataEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.forge.event.lifecycle.GatherDataEvent;
import java.util.EnumMap;
import java.util.stream.Stream;
@ -38,13 +38,10 @@ public class HexForgeDataGenerators {
DataGenerator gen = ev.getGenerator();
ExistingFileHelper efh = ev.getExistingFileHelper();
if (ev.includeClient()) {
gen.addProvider(new HexItemModels(gen, efh));
gen.addProvider(new HexBlockStatesAndModels(gen, efh));
}
if (ev.includeServer()) {
gen.addProvider(PaucalForgeDatagenWrappers.addEFHToAdvancements(new HexAdvancements(gen), efh));
}
gen.addProvider(ev.includeClient(), new HexItemModels(gen, efh));
gen.addProvider(ev.includeClient(), new HexBlockStatesAndModels(gen, efh));
gen.addProvider(ev.includeServer(),
PaucalForgeDatagenWrappers.addEFHToAdvancements(new HexAdvancements(gen), efh));
}
private static void configureForgeDatagen(GatherDataEvent ev) {
@ -52,18 +49,16 @@ public class HexForgeDataGenerators {
DataGenerator gen = ev.getGenerator();
ExistingFileHelper efh = ev.getExistingFileHelper();
if (ev.includeServer()) {
gen.addProvider(new HexLootTables(gen));
gen.addProvider(new HexplatRecipes(gen, INGREDIENTS));
gen.addProvider(ev.includeServer(), new HexLootTables(gen));
gen.addProvider(ev.includeServer(), new HexplatRecipes(gen, INGREDIENTS));
var xtags = IXplatAbstractions.INSTANCE.tags();
var blockTagProvider = PaucalForgeDatagenWrappers.addEFHToTagProvider(
new HexBlockTagProvider(gen, xtags), efh);
gen.addProvider(blockTagProvider);
var itemTagProvider = PaucalForgeDatagenWrappers.addEFHToTagProvider(
new HexItemTagProvider(gen, blockTagProvider, IXplatAbstractions.INSTANCE.tags()), efh);
gen.addProvider(itemTagProvider);
}
var xtags = IXplatAbstractions.INSTANCE.tags();
var blockTagProvider = PaucalForgeDatagenWrappers.addEFHToTagProvider(
new HexBlockTagProvider(gen, xtags), efh);
gen.addProvider(ev.includeServer(), blockTagProvider);
var itemTagProvider = PaucalForgeDatagenWrappers.addEFHToTagProvider(
new HexItemTagProvider(gen, blockTagProvider, IXplatAbstractions.INSTANCE.tags()), efh);
gen.addProvider(ev.includeServer(), itemTagProvider);
}
private static IXplatIngredients INGREDIENTS = new IXplatIngredients() {

View file

@ -11,11 +11,12 @@ import at.petrak.hexcasting.common.items.magic.ItemPackagedHex;
import at.petrak.hexcasting.common.lib.HexBlocks;
import at.petrak.hexcasting.common.lib.HexItems;
import at.petrak.paucal.api.forge.datagen.PaucalItemModelProvider;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.core.Registry;
import net.minecraft.data.DataGenerator;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.Item;
import net.minecraftforge.client.model.generators.ModelBuilder;
import net.minecraftforge.client.model.generators.ModelFile;
import net.minecraftforge.common.data.ExistingFileHelper;
@ -36,10 +37,10 @@ public class HexItemModels extends PaucalItemModelProvider {
simpleItem(HexItems.CREATIVE_UNLOCKER);
simpleItem(HexItems.LORE_FRAGMENT);
singleTexture(HexBlocks.CONJURED_BLOCK.getRegistryName().getPath(),
singleTexture(Registry.BLOCK.getKey(HexBlocks.CONJURED_BLOCK).getPath(),
new ResourceLocation("item/generated"),
"layer0", new ResourceLocation("item/amethyst_shard"));
singleTexture(HexBlocks.CONJURED_LIGHT.getRegistryName().getPath(),
singleTexture(Registry.BLOCK.getKey(HexBlocks.CONJURED_LIGHT).getPath(),
new ResourceLocation("item/generated"),
"layer0", new ResourceLocation("item/amethyst_shard"));
@ -53,9 +54,9 @@ public class HexItemModels extends PaucalItemModelProvider {
buildScroll(HexItems.SCROLL_LARGE, "large");
simpleItem(HexItems.SCRYING_LENS);
getBuilder(HexItems.SCRYING_LENS.getRegistryName().getPath())
getBuilder(Registry.ITEM.getKey(HexItems.SCRYING_LENS).getPath())
.transforms()
.transform(ModelBuilder.Perspective.HEAD)
.transform(ItemTransforms.TransformType.HEAD)
.rotation(0f, 0f, 0f)
.translation(-2.5f, 0f, -8f)
.scale(0.4f);
@ -94,7 +95,7 @@ public class HexItemModels extends PaucalItemModelProvider {
"layer0", modLoc("item/phial/" + name));
float fillProp = (float) fill / maxFill;
getBuilder(HexItems.BATTERY.getRegistryName().getPath()).override()
getBuilder(Registry.ITEM.getKey(HexItems.BATTERY).getPath()).override()
.predicate(ItemMediaBattery.MANA_PREDICATE, fillProp)
.predicate(ItemMediaBattery.MAX_MANA_PREDICATE, size)
.model(new ModelFile.UncheckedModelFile(modLoc("item/" + name)))
@ -103,21 +104,21 @@ public class HexItemModels extends PaucalItemModelProvider {
}
for (var dye : DyeColor.values()) {
singleTexture(HexItems.DYE_COLORIZERS.get(dye).getRegistryName().getPath(),
singleTexture(Registry.ITEM.getKey(HexItems.DYE_COLORIZERS.get(dye)).getPath(),
new ResourceLocation("item/generated"),
"layer0", modLoc("item/colorizer/dye_" + dye.getName()));
}
for (var type : ItemPrideColorizer.Type.values()) {
singleTexture(HexItems.PRIDE_COLORIZERS.get(type).getRegistryName().getPath(),
singleTexture(Registry.ITEM.getKey(HexItems.PRIDE_COLORIZERS.get(type)).getPath(),
new ResourceLocation("item/generated"),
"layer0", modLoc("item/colorizer/pride_" + type.getName()));
}
singleTexture(HexItems.UUID_COLORIZER.getRegistryName().getPath(), new ResourceLocation("item/generated"),
singleTexture(Registry.ITEM.getKey(HexItems.UUID_COLORIZER).getPath(), new ResourceLocation("item/generated"),
"layer0", modLoc("item/colorizer/uuid"));
simpleItem(modLoc("slate_blank"));
simpleItem(modLoc("slate_written"));
getBuilder(HexItems.SLATE.getRegistryName().getPath()).override()
getBuilder(Registry.ITEM.getKey(HexItems.SLATE).getPath()).override()
.predicate(ItemSlate.WRITTEN_PRED, 0)
.model(new ModelFile.UncheckedModelFile(modLoc("item/slate_blank")))
.end()
@ -126,32 +127,32 @@ public class HexItemModels extends PaucalItemModelProvider {
.model(new ModelFile.UncheckedModelFile(modLoc("item/slate_written")))
.end();
getBuilder(HexBlocks.AKASHIC_RECORD.getRegistryName().getPath()).parent(
getBuilder(Registry.BLOCK.getKey(HexBlocks.AKASHIC_RECORD).getPath()).parent(
new ModelFile.UncheckedModelFile(modLoc("block/akashic_record")));
simpleItem(modLoc("edified_door"));
getBuilder(HexBlocks.EDIFIED_TRAPDOOR.getRegistryName().getPath()).parent(
getBuilder(Registry.BLOCK.getKey(HexBlocks.EDIFIED_TRAPDOOR).getPath()).parent(
new ModelFile.UncheckedModelFile(modLoc("block/edified_trapdoor_bottom")));
getBuilder(HexBlocks.EDIFIED_LOG.getRegistryName().getPath()).parent(
getBuilder(Registry.BLOCK.getKey(HexBlocks.EDIFIED_LOG).getPath()).parent(
new ModelFile.UncheckedModelFile(modLoc("block/edified_log")));
getBuilder(HexBlocks.STRIPPED_EDIFIED_LOG.getRegistryName().getPath()).parent(
getBuilder(Registry.BLOCK.getKey(HexBlocks.STRIPPED_EDIFIED_LOG).getPath()).parent(
new ModelFile.UncheckedModelFile(modLoc("block/stripped_edified_log")));
getBuilder(HexBlocks.EDIFIED_WOOD.getRegistryName().getPath()).parent(
getBuilder(Registry.BLOCK.getKey(HexBlocks.EDIFIED_WOOD).getPath()).parent(
new ModelFile.UncheckedModelFile(modLoc("block/edified_wood")));
getBuilder(HexBlocks.STRIPPED_EDIFIED_WOOD.getRegistryName().getPath()).parent(
getBuilder(Registry.BLOCK.getKey(HexBlocks.STRIPPED_EDIFIED_WOOD).getPath()).parent(
new ModelFile.UncheckedModelFile(modLoc("block/stripped_edified_wood")));
getBuilder(HexBlocks.EDIFIED_STAIRS.getRegistryName().getPath()).parent(
getBuilder(Registry.BLOCK.getKey(HexBlocks.EDIFIED_STAIRS).getPath()).parent(
new ModelFile.UncheckedModelFile(modLoc("block/edified_stairs")));
getBuilder(HexBlocks.EDIFIED_SLAB.getRegistryName().getPath()).parent(
getBuilder(Registry.BLOCK.getKey(HexBlocks.EDIFIED_SLAB).getPath()).parent(
new ModelFile.UncheckedModelFile(modLoc("block/edified_slab")));
getBuilder(HexBlocks.EDIFIED_BUTTON.getRegistryName().getPath()).parent(
getBuilder(Registry.BLOCK.getKey(HexBlocks.EDIFIED_BUTTON).getPath()).parent(
new ModelFile.UncheckedModelFile(new ResourceLocation("block/button_inventory")))
.texture("texture", modLoc("block/edified_planks"));
getBuilder(HexBlocks.EDIFIED_PRESSURE_PLATE.getRegistryName().getPath())
getBuilder(Registry.BLOCK.getKey(HexBlocks.EDIFIED_PRESSURE_PLATE).getPath())
.parent(new ModelFile.UncheckedModelFile(modLoc("block/edified_pressure_plate")));
}
private void buildSealableIotaHolder(Item item, String stub) {
var name = item.getRegistryName().getPath();
var name = Registry.ITEM.getKey(item).getPath();
var plain = singleTexture(name, new ResourceLocation("item/generated"),
"layer0", modLoc("item/" + stub));
var unsealed = withExistingParent(name + "_filled", new ResourceLocation("item/generated"))
@ -170,7 +171,7 @@ public class HexItemModels extends PaucalItemModelProvider {
}
private void buildScroll(Item item, String size) {
getBuilder(item.getRegistryName().getPath())
getBuilder(Registry.ITEM.getKey(item).getPath())
.override()
.predicate(ItemScroll.ANCIENT_PREDICATE, 0f)
.model(new ModelFile.UncheckedModelFile(modLoc("item/scroll_pristine_" + size))).end()
@ -180,9 +181,9 @@ public class HexItemModels extends PaucalItemModelProvider {
}
private void buildStaff(Item item, String name) {
singleTexture(item.getRegistryName().getPath(), new ResourceLocation("item/handheld_rod"),
singleTexture(Registry.ITEM.getKey(item).getPath(), new ResourceLocation("item/handheld_rod"),
"layer0", modLoc("item/staves/" + name));
getBuilder(item.getRegistryName().getPath())
getBuilder(Registry.ITEM.getKey(item).getPath())
.override()
.predicate(ItemStaff.FUNNY_LEVEL_PREDICATE, 0)
.model(new ModelFile.UncheckedModelFile(modLoc("item/" + name + "_staff")))
@ -198,7 +199,7 @@ public class HexItemModels extends PaucalItemModelProvider {
private void buildPackagedSpell(Item item, String name) {
simpleItem(modLoc(name));
simpleItem(modLoc(name + "_filled"));
getBuilder(item.getRegistryName().getPath())
getBuilder(Registry.ITEM.getKey(item).getPath())
.override()
.predicate(ItemPackagedHex.HAS_PATTERNS_PRED, -0.01f)
.model(new ModelFile.UncheckedModelFile(modLoc("item/" + name)))

View file

@ -41,7 +41,7 @@ public class BrainsweepRecipeCategory implements IRecipeCategory<BrainsweepRecip
ResourceLocation location = modLoc("textures/gui/brainsweep_jei.png");
background = guiHelper.drawableBuilder(location, 0, 0, 118, 86).setTextureSize(128, 128).build();
var brainsweep = modLoc("brainsweep");
localizedName = Component.translatable( "hexcasting.spell." + brainsweep);
localizedName = Component.translatable("hexcasting.spell." + brainsweep);
icon = new PatternDrawable(brainsweep, 16, 16);
}
@ -103,18 +103,4 @@ public class BrainsweepRecipeCategory implements IRecipeCategory<BrainsweepRecip
RecipeType<BrainsweepRecipe> getRecipeType() {
return HexJEIPlugin.BRAINSWEEPING;
}
@Override
@SuppressWarnings("removal")
public @NotNull
ResourceLocation getUid() {
return UID;
}
@Override
@SuppressWarnings("removal")
public @NotNull
Class<? extends BrainsweepRecipe> getRecipeClass() {
return BrainsweepRecipe.class;
}
}

View file

@ -8,13 +8,14 @@ import at.petrak.hexcasting.common.lib.HexIotaTypes;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.minecraft.core.Registry;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraftforge.common.crafting.AbstractIngredient;
import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.common.crafting.IIngredientSerializer;
import net.minecraftforge.common.crafting.NBTIngredient;
import net.minecraftforge.common.crafting.PartialNBTIngredient;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
@ -68,8 +69,9 @@ public class ForgeUnsealedIngredient extends AbstractIngredient {
@Override
public @NotNull JsonElement toJson() {
JsonObject json = new JsonObject();
json.addProperty("type", Objects.toString(CraftingHelper.getID(NBTIngredient.Serializer.INSTANCE)));
json.addProperty("item", Objects.toString(stack.getItem().getRegistryName()));
// TODO: should this be Partial or Strict
json.addProperty("type", Objects.toString(CraftingHelper.getID(PartialNBTIngredient.Serializer.INSTANCE)));
json.addProperty("item", Objects.toString(Registry.ITEM.getKey(stack.getItem())));
return json;
}

View file

@ -4,7 +4,6 @@ import at.petrak.hexcasting.common.network.IMessage;
import at.petrak.hexcasting.forge.network.ForgePacketHandler;
import at.petrak.hexcasting.xplat.IClientXplatAbstractions;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
import net.minecraft.client.particle.ParticleProvider;
import net.minecraft.client.particle.SpriteSet;
import net.minecraft.client.renderer.ItemBlockRenderTypes;
@ -19,10 +18,8 @@ import net.minecraft.core.particles.ParticleType;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.inventory.tooltip.TooltipComponent;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.client.MinecraftForgeClient;
import java.util.function.Function;
@ -49,11 +46,6 @@ public class ForgeClientXplatImpl implements IClientXplatAbstractions {
Minecraft.getInstance().particleEngine.register(type, factory::apply);
}
@Override
public <T extends ClientTooltipComponent & TooltipComponent> void registerIdentityTooltipMapping(Class<T> clazz) {
MinecraftForgeClient.registerTooltipComponentFactory(clazz, Function.identity());
}
@Override
public void registerItemProperty(Item item, ResourceLocation id, ItemPropertyFunction func) {
ItemProperties.register(item, id, func);

View file

@ -47,7 +47,6 @@ import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.npc.Villager;
import net.minecraft.world.entity.npc.VillagerProfession;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
@ -66,9 +65,9 @@ import net.minecraft.world.phys.Vec3;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.*;
import net.minecraftforge.common.loot.CanToolPerformAction;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fluids.FluidAttributes;
import net.minecraftforge.event.level.BlockEvent;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidType;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fml.ModContainer;
@ -315,26 +314,11 @@ public class ForgeXplatImpl implements IXplatAbstractions {
public boolean tryPlaceFluid(Level level, InteractionHand hand, BlockPos pos, ItemStack stack, Fluid fluid) {
Optional<IFluidHandler> handler = FluidUtil.getFluidHandler(level, pos, Direction.UP).resolve();
if (handler.isPresent() &&
FluidUtil.tryEmptyContainer(stack, handler.get(), FluidAttributes.BUCKET_VOLUME, null, true).isSuccess()) {
FluidUtil.tryEmptyContainer(stack, handler.get(), FluidType.BUCKET_VOLUME, null, true).isSuccess()) {
return true;
}
return FluidUtil.tryPlaceFluid(null, level, hand, pos, stack, new FluidStack(
fluid, FluidAttributes.BUCKET_VOLUME)).isSuccess();
}
@Override
public ResourceLocation getID(Block block) {
return block.getRegistryName();
}
@Override
public ResourceLocation getID(Item item) {
return item.getRegistryName();
}
@Override
public ResourceLocation getID(VillagerProfession profession) {
return profession.getRegistryName();
fluid, FluidType.BUCKET_VOLUME)).isSuccess();
}
@Override
@ -428,7 +412,8 @@ public class ForgeXplatImpl implements IXplatAbstractions {
public boolean isPlacingAllowed(Level world, BlockPos pos, ItemStack blockStack, Player player) {
ItemStack cached = player.getMainHandItem();
player.setItemInHand(InteractionHand.MAIN_HAND, blockStack.copy());
var evt = ForgeHooks.onRightClickBlock(player, InteractionHand.MAIN_HAND, pos, new BlockHitResult(Vec3.atCenterOf(pos), Direction.DOWN, pos, true));
var evt = ForgeHooks.onRightClickBlock(player, InteractionHand.MAIN_HAND, pos,
new BlockHitResult(Vec3.atCenterOf(pos), Direction.DOWN, pos, true));
player.setItemInHand(InteractionHand.MAIN_HAND, cached);
return !evt.isCanceled();
}