diff --git a/common/src/main/java/io/github/foundationgames/automobility/Automobility.java b/common/src/main/java/io/github/foundationgames/automobility/Automobility.java index 484b926..3602335 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/Automobility.java +++ b/common/src/main/java/io/github/foundationgames/automobility/Automobility.java @@ -3,6 +3,7 @@ import io.github.foundationgames.automobility.block.AutomobilityBlocks; import io.github.foundationgames.automobility.entity.AutomobilityEntities; import io.github.foundationgames.automobility.item.AutomobilityItems; +import io.github.foundationgames.automobility.item.DynamicCreativeItem; import io.github.foundationgames.automobility.particle.AutomobilityParticles; import io.github.foundationgames.automobility.platform.Platform; import io.github.foundationgames.automobility.recipe.AutoMechanicTableRecipe; @@ -15,28 +16,34 @@ import io.github.foundationgames.automobility.util.InitlessConstants; import io.github.foundationgames.automobility.util.RegistryQueue; import io.github.foundationgames.automobility.util.network.CommonPackets; -import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Block; +import java.util.ArrayList; +import java.util.List; + public class Automobility { public static final String MOD_ID = InitlessConstants.AUTOMOBILITY; - public static final CreativeModeTab GROUP = Platform.get().creativeTab(rl("automobility"), AUtils::createGroupIcon); - public static final CreativeModeTab PREFABS = Platform.get().creativeTab(rl("automobility_prefabs"), AUtils::createPrefabsIcon); + public static ItemGroup GROUP = new ItemGroup(rl("automobility")); + public static ItemGroup PREFABS = new ItemGroup(rl("automobility_prefabs")); - public static final TagKey SLOPES = TagKey.create(Registry.BLOCK_REGISTRY, rl("slopes")); - public static final TagKey STEEP_SLOPES = TagKey.create(Registry.BLOCK_REGISTRY, rl("steep_slopes")); - public static final TagKey NON_STEEP_SLOPES = TagKey.create(Registry.BLOCK_REGISTRY, rl("non_steep_slopes")); - public static final TagKey STICKY_SLOPES = TagKey.create(Registry.BLOCK_REGISTRY, rl("sticky_slopes")); + public static final TagKey SLOPES = TagKey.create(Registries.BLOCK, rl("slopes")); + public static final TagKey STEEP_SLOPES = TagKey.create(Registries.BLOCK, rl("steep_slopes")); + public static final TagKey NON_STEEP_SLOPES = TagKey.create(Registries.BLOCK, rl("non_steep_slopes")); + public static final TagKey STICKY_SLOPES = TagKey.create(Registries.BLOCK, rl("sticky_slopes")); public static final Eventual> AUTO_MECHANIC_SCREEN = - RegistryQueue.register(Registry.MENU, Automobility.rl("auto_mechanic_table"), () -> Platform.get().menuType(AutoMechanicTableScreenHandler::new)); + RegistryQueue.register(BuiltInRegistries.MENU, Automobility.rl("auto_mechanic_table"), () -> Platform.get().menuType(AutoMechanicTableScreenHandler::new)); public static final Eventual> SINGLE_SLOT_SCREEN = - RegistryQueue.register(Registry.MENU, Automobility.rl("single_slot"), () -> Platform.get().menuType(SingleSlotScreenHandler::new)); + RegistryQueue.register(BuiltInRegistries.MENU, Automobility.rl("single_slot"), () -> Platform.get().menuType(SingleSlotScreenHandler::new)); public static void init() { AutomobilitySounds.init(); @@ -50,11 +57,39 @@ public static void init() { } public static void initOther() { - RegistryQueue.register(Registry.RECIPE_TYPE, AutoMechanicTableRecipe.ID, () -> AutoMechanicTableRecipe.TYPE); - RegistryQueue.register(Registry.RECIPE_SERIALIZER, AutoMechanicTableRecipe.ID, () -> AutoMechanicTableRecipeSerializer.INSTANCE); + RegistryQueue.register(BuiltInRegistries.RECIPE_TYPE, AutoMechanicTableRecipe.ID, () -> AutoMechanicTableRecipe.TYPE); + RegistryQueue.register(BuiltInRegistries.RECIPE_SERIALIZER, AutoMechanicTableRecipe.ID, () -> AutoMechanicTableRecipeSerializer.INSTANCE); + RegistryQueue.register(BuiltInRegistries.CREATIVE_MODE_TAB, GROUP.rl, () -> Platform.get().creativeTab(GROUP.rl, AUtils::createGroupIcon, GROUP)); + RegistryQueue.register(BuiltInRegistries.CREATIVE_MODE_TAB, PREFABS.rl, () -> Platform.get().creativeTab(PREFABS.rl, AUtils::createPrefabsIcon, PREFABS)); } public static ResourceLocation rl(String path) { return new ResourceLocation(MOD_ID, path); } + + public static void addToItemGroup(ItemGroup group, Eventual itemPromise) { + group.list.add((Eventual) itemPromise); + } + + public static class ItemGroup implements CreativeModeTab.DisplayItemsGenerator { + private final List> list = new ArrayList<>(); + private final ResourceLocation rl; + + private ItemGroup(ResourceLocation rl) { + this.rl = rl; + } + + @Override + public void accept(CreativeModeTab.ItemDisplayParameters params, CreativeModeTab.Output output) { + list.forEach(i -> { + if (i.require() instanceof DynamicCreativeItem dynamic) { + var array = new ArrayList(); + dynamic.fillItemCategory(array); + array.forEach(output::accept); + } else { + output.accept(i.require()); + } + }); + } + } } diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/BaseAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/BaseAttachment.java index fe9c091..f8ea43b 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/BaseAttachment.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/BaseAttachment.java @@ -25,7 +25,7 @@ public final AutomobileEntity automobile() { } protected final Level world() { - return this.automobile.level; + return this.automobile.level(); } public abstract Vec3 pos(); diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/AutomobileRenderer.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/AutomobileRenderer.java index 7ac8b3a..3afa984 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/AutomobileRenderer.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/AutomobileRenderer.java @@ -2,7 +2,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; -import com.mojang.math.Vector3f; +import com.mojang.math.Axis; import io.github.foundationgames.automobility.automobile.AutomobileEngine; import io.github.foundationgames.automobility.automobile.WheelBase; import io.github.foundationgames.automobility.automobile.render.attachment.front.FrontAttachmentRenderModel; @@ -27,8 +27,8 @@ public static void render( pose.pushPose(); - pose.mulPose(Vector3f.ZP.rotationDegrees(180)); - pose.mulPose(Vector3f.YP.rotationDegrees(automobile.getAutomobileYaw(tickDelta) + 180)); + pose.mulPose(Axis.ZP.rotationDegrees(180)); + pose.mulPose(Axis.YP.rotationDegrees(automobile.getAutomobileYaw(tickDelta) + 180)); float chassisRaise = wheels.model().radius() / 16; float bounce = automobile.getSuspensionBounce(tickDelta) * 0.048f; @@ -57,7 +57,7 @@ public static void render( float eBack = frame.model().enginePosBack() / 16; float eUp = frame.model().enginePosUp() / 16; pose.translate(0, -eUp, eBack); - pose.mulPose(Vector3f.YP.rotationDegrees(180)); + pose.mulPose(Axis.YP.rotationDegrees(180)); if (!engine.isEmpty() && engineModel != null) { engineModel.renderToBuffer(pose, buffers.getBuffer(engineModel.renderType(engineTexture)), light, overlay, 1, 1, 1, 1); if (engineModel instanceof BaseModel base) { @@ -81,8 +81,8 @@ public static void render( pose.pushPose(); pose.translate(exhaust.x() / 16, -exhaust.y() / 16, exhaust.z() / 16); - pose.mulPose(Vector3f.YP.rotationDegrees(exhaust.yaw())); - pose.mulPose(Vector3f.XP.rotationDegrees(exhaust.pitch())); + pose.mulPose(Axis.YP.rotationDegrees(exhaust.yaw())); + pose.mulPose(Axis.XP.rotationDegrees(exhaust.pitch())); exhaustFumesModel.renderToBuffer(pose, exhaustBuffer, light, overlay, 1, 1, 1, 1); pose.popPose(); @@ -95,7 +95,7 @@ public static void render( if (!rearAtt.isEmpty()) { pose.pushPose(); pose.translate(0, chassisRaise, frame.model().rearAttachmentPos() / 16); - pose.mulPose(Vector3f.YN.rotationDegrees(automobile.getAutomobileYaw(tickDelta) - automobile.getRearAttachmentYaw(tickDelta))); + pose.mulPose(Axis.YN.rotationDegrees(automobile.getAutomobileYaw(tickDelta) - automobile.getRearAttachmentYaw(tickDelta))); pose.translate(0, 0, rearAtt.model().pivotDistPx() / 16); if (rearAttachmentModel instanceof RearAttachmentRenderModel rm) { @@ -146,12 +146,12 @@ public static void render( pose.translate(pos.right() / 16, wheelRadius / 16, -pos.forward() / 16); - if (pos.end() == WheelBase.WheelEnd.FRONT) pose.mulPose(Vector3f.YP.rotationDegrees(automobile.getSteering(tickDelta) * 27)); + if (pos.end() == WheelBase.WheelEnd.FRONT) pose.mulPose(Axis.YP.rotationDegrees(automobile.getSteering(tickDelta) * 27)); pose.translate(0, -chassisRaise, 0); - pose.mulPose(Vector3f.XP.rotationDegrees(wheelAngle)); + pose.mulPose(Axis.XP.rotationDegrees(wheelAngle)); pose.scale(scale, scale, scale); - pose.mulPose(Vector3f.YP.rotationDegrees(180 + pos.yaw())); + pose.mulPose(Axis.YP.rotationDegrees(180 + pos.yaw())); wheelModel.renderToBuffer(pose, wheelBuffer, light, overlay, 1, 1, 1, 1); if (wheelModel instanceof BaseModel base) { diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/RenderableAutomobile.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/RenderableAutomobile.java index 541f109..d14debb 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/RenderableAutomobile.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/RenderableAutomobile.java @@ -1,6 +1,5 @@ package io.github.foundationgames.automobility.automobile.render; -import com.mojang.math.Vector3f; import io.github.foundationgames.automobility.automobile.AutomobileEngine; import io.github.foundationgames.automobility.automobile.AutomobileFrame; import io.github.foundationgames.automobility.automobile.AutomobileWheel; @@ -9,6 +8,7 @@ import io.github.foundationgames.automobility.automobile.attachment.front.FrontAttachment; import io.github.foundationgames.automobility.automobile.attachment.rear.RearAttachment; import org.jetbrains.annotations.Nullable; +import org.joml.Vector3f; public interface RenderableAutomobile { AutomobileFrame getFrame(); diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/CopperEngineModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/CopperEngineModel.java index 509f1da..f8a467f 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/CopperEngineModel.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/CopperEngineModel.java @@ -1,7 +1,7 @@ package io.github.foundationgames.automobility.automobile.render.engine; import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.math.Vector3f; +import com.mojang.math.Axis; import io.github.foundationgames.automobility.Automobility; import io.github.foundationgames.automobility.automobile.render.BaseModel; import net.minecraft.client.model.geom.ModelLayerLocation; @@ -17,6 +17,6 @@ public CopperEngineModel(EntityRendererProvider.Context ctx) { @Override protected void prepare(PoseStack matrices) { - matrices.mulPose(Vector3f.YP.rotationDegrees(180)); + matrices.mulPose(Axis.YP.rotationDegrees(180)); } } diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/CreativeEngineModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/CreativeEngineModel.java index 1b5fad0..2731977 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/CreativeEngineModel.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/CreativeEngineModel.java @@ -1,7 +1,7 @@ package io.github.foundationgames.automobility.automobile.render.engine; import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.math.Vector3f; +import com.mojang.math.Axis; import io.github.foundationgames.automobility.Automobility; import io.github.foundationgames.automobility.automobile.render.BaseModel; import net.minecraft.client.model.geom.ModelLayerLocation; @@ -17,6 +17,6 @@ public CreativeEngineModel(EntityRendererProvider.Context ctx) { @Override protected void prepare(PoseStack matrices) { - matrices.mulPose(Vector3f.YP.rotationDegrees(180)); + matrices.mulPose(Axis.YP.rotationDegrees(180)); } } diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/CARRFrameModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/CARRFrameModel.java index f7698b0..cfd81c1 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/CARRFrameModel.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/CARRFrameModel.java @@ -1,7 +1,7 @@ package io.github.foundationgames.automobility.automobile.render.frame; import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.math.Vector3f; +import com.mojang.math.Axis; import io.github.foundationgames.automobility.Automobility; import io.github.foundationgames.automobility.automobile.render.BaseModel; import net.minecraft.client.model.geom.ModelLayerLocation; @@ -17,6 +17,6 @@ public CARRFrameModel(EntityRendererProvider.Context ctx) { @Override protected void prepare(PoseStack matrices) { - matrices.mulPose(Vector3f.YP.rotationDegrees(-90)); + matrices.mulPose(Axis.YP.rotationDegrees(-90)); } } diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/StandardFrameModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/StandardFrameModel.java index 175aa10..363dd4f 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/StandardFrameModel.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/StandardFrameModel.java @@ -1,7 +1,7 @@ package io.github.foundationgames.automobility.automobile.render.frame; import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.math.Vector3f; +import com.mojang.math.Axis; import io.github.foundationgames.automobility.Automobility; import io.github.foundationgames.automobility.automobile.render.BaseModel; import net.minecraft.client.model.geom.ModelLayerLocation; @@ -17,6 +17,6 @@ public StandardFrameModel(EntityRendererProvider.Context ctx) { @Override protected void prepare(PoseStack matrices) { - matrices.mulPose(Vector3f.YP.rotationDegrees(-90)); + matrices.mulPose(Axis.YP.rotationDegrees(-90)); } } diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/item/ItemRenderableAutomobile.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/item/ItemRenderableAutomobile.java index e8f0676..e78f9f7 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/item/ItemRenderableAutomobile.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/item/ItemRenderableAutomobile.java @@ -1,6 +1,5 @@ package io.github.foundationgames.automobility.automobile.render.item; -import com.mojang.math.Vector3f; import io.github.foundationgames.automobility.automobile.AutomobileData; import io.github.foundationgames.automobility.automobile.AutomobileEngine; import io.github.foundationgames.automobility.automobile.AutomobileFrame; @@ -9,6 +8,7 @@ import io.github.foundationgames.automobility.automobile.attachment.rear.RearAttachment; import io.github.foundationgames.automobility.automobile.render.RenderableAutomobile; import org.jetbrains.annotations.Nullable; +import org.joml.Vector3f; public class ItemRenderableAutomobile implements RenderableAutomobile { private final AutomobileData reader; diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/OffRoadWheelModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/OffRoadWheelModel.java index febc2cd..3040b6f 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/OffRoadWheelModel.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/OffRoadWheelModel.java @@ -1,7 +1,7 @@ package io.github.foundationgames.automobility.automobile.render.wheel; import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.math.Vector3f; +import com.mojang.math.Axis; import io.github.foundationgames.automobility.Automobility; import io.github.foundationgames.automobility.automobile.render.BaseModel; import net.minecraft.client.model.geom.ModelLayerLocation; @@ -17,6 +17,6 @@ public OffRoadWheelModel(EntityRendererProvider.Context ctx) { @Override protected void prepare(PoseStack matrices) { - matrices.mulPose(Vector3f.YP.rotationDegrees(-90)); + matrices.mulPose(Axis.YP.rotationDegrees(-90)); } } diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/StandardWheelModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/StandardWheelModel.java index db9f875..1e79ebe 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/StandardWheelModel.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/StandardWheelModel.java @@ -1,7 +1,7 @@ package io.github.foundationgames.automobility.automobile.render.wheel; import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.math.Vector3f; +import com.mojang.math.Axis; import io.github.foundationgames.automobility.Automobility; import io.github.foundationgames.automobility.automobile.render.BaseModel; import net.minecraft.client.model.geom.ModelLayerLocation; @@ -17,6 +17,6 @@ public StandardWheelModel(EntityRendererProvider.Context ctx) { @Override protected void prepare(PoseStack matrices) { - matrices.mulPose(Vector3f.YP.rotationDegrees(-90)); + matrices.mulPose(Axis.YP.rotationDegrees(-90)); } } diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/AutomobilityBlocks.java b/common/src/main/java/io/github/foundationgames/automobility/block/AutomobilityBlocks.java index 274f5fe..9d71925 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/block/AutomobilityBlocks.java +++ b/common/src/main/java/io/github/foundationgames/automobility/block/AutomobilityBlocks.java @@ -11,7 +11,7 @@ import io.github.foundationgames.automobility.util.Eventual; import io.github.foundationgames.automobility.util.RegistryQueue; import net.minecraft.ChatFormatting; -import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.chat.Component; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.CreativeModeTab; @@ -21,7 +21,6 @@ import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockBehaviour; -import net.minecraft.world.level.material.Material; import java.util.function.Function; import java.util.function.Supplier; @@ -30,44 +29,52 @@ public enum AutomobilityBlocks {; public static final Eventual AUTO_MECHANIC_TABLE = register("auto_mechanic_table", () -> new AutoMechanicTableBlock(BlockBehaviour.Properties.copy(Blocks.COPPER_BLOCK)), Automobility.GROUP); public static final Eventual AUTOMOBILE_ASSEMBLER = register("automobile_assembler", () -> new AutomobileAssemblerBlock(BlockBehaviour.Properties.copy(Blocks.ANVIL)), Automobility.GROUP); - public static final Eventual SLOPE = register("slope", () -> new SlopeBlock(BlockBehaviour.Properties.copy(Blocks.IRON_BLOCK), false), b -> new SlopeBlockItem(b, new Item.Properties().tab(Automobility.GROUP))); - public static final Eventual STEEP_SLOPE = register("steep_slope", () -> new SteepSlopeBlock(BlockBehaviour.Properties.copy(Blocks.IRON_BLOCK), false), b -> new SteepSlopeBlockItem(b, new Item.Properties().tab(Automobility.GROUP))); + public static final Eventual SLOPE = register("slope", () -> new SlopeBlock(BlockBehaviour.Properties.copy(Blocks.IRON_BLOCK), false), b -> new SlopeBlockItem(b, new Item.Properties()), Automobility.GROUP); + public static final Eventual STEEP_SLOPE = register("steep_slope", () -> new SteepSlopeBlock(BlockBehaviour.Properties.copy(Blocks.IRON_BLOCK), false), b -> new SteepSlopeBlockItem(b, new Item.Properties()), Automobility.GROUP); public static final Eventual SLOPE_WITH_DASH_PANEL = register("slope_with_dash_panel", () -> new SlopeWithDashPanelBlock(BlockBehaviour.Properties.copy(Blocks.IRON_BLOCK) .lightLevel(s -> s.getValue(DashPanelBlock.POWERED) ? 0 : 1).emissiveRendering((s, l, p) -> !s.getValue(DashPanelBlock.POWERED)))); public static final Eventual STEEP_SLOPE_WITH_DASH_PANEL = register("steep_slope_with_dash_panel", () -> new SteepSlopeWithDashPanelBlock(BlockBehaviour.Properties.copy(Blocks.IRON_BLOCK) .lightLevel(s -> s.getValue(DashPanelBlock.POWERED) ? 0 : 1).emissiveRendering((s, l, p) -> !s.getValue(DashPanelBlock.POWERED)))); public static final Eventual DASH_PANEL = register("dash_panel", () -> new DashPanelBlock(BlockBehaviour.Properties.copy(Blocks.IRON_BLOCK) - .lightLevel(s -> s.getValue(DashPanelBlock.POWERED) ? 0 : 1).emissiveRendering((s, l, p) -> !s.getValue(DashPanelBlock.POWERED)).noCollission()), b -> new DashPanelItem(b, new Item.Properties().tab(Automobility.GROUP))); + .lightLevel(s -> s.getValue(DashPanelBlock.POWERED) ? 0 : 1).emissiveRendering((s, l, p) -> !s.getValue(DashPanelBlock.POWERED)).noCollission()), b -> new DashPanelItem(b, new Item.Properties()), Automobility.GROUP); public static final Eventual GRASS_OFF_ROAD = register("grass_off_road", () -> new OffRoadBlock(BlockBehaviour.Properties.copy(Blocks.GRASS_BLOCK).noCollission(), AUtils.colorFromInt(0x406918)), Automobility.GROUP); public static final Eventual DIRT_OFF_ROAD = register("dirt_off_road", () -> new OffRoadBlock(BlockBehaviour.Properties.copy(Blocks.DIRT).noCollission(), AUtils.colorFromInt(0x594227)), Automobility.GROUP); public static final Eventual SAND_OFF_ROAD = register("sand_off_road", () -> new OffRoadBlock(BlockBehaviour.Properties.copy(Blocks.SAND).noCollission(), AUtils.colorFromInt(0xC2B185)), Automobility.GROUP); public static final Eventual SNOW_OFF_ROAD = register("snow_off_road", () -> new OffRoadBlock(BlockBehaviour.Properties.copy(Blocks.SNOW).noCollission(), AUtils.colorFromInt(0xD0E7ED)), Automobility.GROUP); - public static final Eventual LAUNCH_GEL = register("launch_gel", () -> new LaunchGelBlock(BlockBehaviour.Properties.of(Material.CLAY).strength(0.1f).sound(SoundType.HONEY_BLOCK).noCollission()), Automobility.GROUP); + public static final Eventual LAUNCH_GEL = register("launch_gel", () -> new LaunchGelBlock(BlockBehaviour.Properties.copy(Blocks.CLAY).strength(0.1f).sound(SoundType.HONEY_BLOCK).noCollission()), Automobility.GROUP); public static final Eventual ALLOW = register("allow", () -> new Block(BlockBehaviour.Properties.copy(Blocks.BARRIER).sound(SoundType.METAL)), b -> new TooltipBlockItem(b, Component.translatable("tooltip.block.automobility.allow").withStyle(ChatFormatting.AQUA), new Item.Properties())); - public static final Eventual> AUTOMOBILE_ASSEMBLER_ENTITY = RegistryQueue.register(Registry.BLOCK_ENTITY_TYPE, + public static final Eventual> AUTOMOBILE_ASSEMBLER_ENTITY = RegistryQueue.register(BuiltInRegistries.BLOCK_ENTITY_TYPE, Automobility.rl("automobile_assembler"), () -> Platform.get().blockEntity(AutomobileAssemblerBlockEntity::new, AUTOMOBILE_ASSEMBLER.require())); public static void init() { } public static Eventual register(String name, Supplier block) { - return RegistryQueue.register(Registry.BLOCK, Automobility.rl(name), block); + return RegistryQueue.register(BuiltInRegistries.BLOCK, Automobility.rl(name), block); } - public static Eventual register(String name, Supplier block, CreativeModeTab group) { - return register(name, block, b -> new BlockItem(b, new Item.Properties().tab(group))); + public static Eventual register(String name, Supplier block, Automobility.ItemGroup group) { + return register(name, block, b -> new BlockItem(b, new Item.Properties()), group); } - public static Eventual register(String name, Supplier block, Function item) { + public static Eventual register(String name, Supplier block, Function item, Automobility.ItemGroup group) { var blockPromise = register(name, block); - RegistryQueue.register(Registry.ITEM, Automobility.rl(name), () -> item.apply(blockPromise.require())); + var itemPromise = RegistryQueue.register(BuiltInRegistries.ITEM, Automobility.rl(name), () -> item.apply(blockPromise.require())); + + if (group != null) { + Automobility.addToItemGroup(group, itemPromise); + } return blockPromise; } + + public static Eventual register(String name, Supplier block, Function item) { + return register(name, block, item, null); + } } diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/OffRoadBlock.java b/common/src/main/java/io/github/foundationgames/automobility/block/OffRoadBlock.java index 2e95ed0..e5c1bc9 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/block/OffRoadBlock.java +++ b/common/src/main/java/io/github/foundationgames/automobility/block/OffRoadBlock.java @@ -1,6 +1,5 @@ package io.github.foundationgames.automobility.block; -import com.mojang.math.Vector3f; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.item.context.BlockPlaceContext; @@ -15,6 +14,7 @@ import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; import org.jetbrains.annotations.Nullable; +import org.joml.Vector3f; public class OffRoadBlock extends Block { public static final VoxelShape ONE_LAYER_SHAPE = box(0, 0, 0, 16, 2, 16); @@ -26,7 +26,7 @@ public class OffRoadBlock extends Block { public final Vector3f color; public OffRoadBlock(Properties settings, Vector3f color) { - super(settings); + super(settings.pushReaction(PushReaction.DESTROY)); registerDefaultState(defaultBlockState().setValue(LAYERS, 1)); this.color = color; } @@ -54,11 +54,6 @@ public void neighborChanged(BlockState state, Level world, BlockPos pos, Block b } } - @Override - public PushReaction getPistonPushReaction(BlockState state) { - return PushReaction.DESTROY; - } - @Override public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { return world.getBlockState(pos.below()).isFaceSturdy(world, pos.below(), Direction.UP); diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/entity/AutomobileAssemblerBlockEntity.java b/common/src/main/java/io/github/foundationgames/automobility/block/entity/AutomobileAssemblerBlockEntity.java index bc77724..33a11be 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/block/entity/AutomobileAssemblerBlockEntity.java +++ b/common/src/main/java/io/github/foundationgames/automobility/block/entity/AutomobileAssemblerBlockEntity.java @@ -1,6 +1,5 @@ package io.github.foundationgames.automobility.block.entity; -import com.mojang.math.Vector3f; import io.github.foundationgames.automobility.automobile.AutomobileEngine; import io.github.foundationgames.automobility.automobile.AutomobileFrame; import io.github.foundationgames.automobility.automobile.AutomobileStats; @@ -38,6 +37,7 @@ import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.Nullable; +import org.joml.Vector3f; import java.util.ArrayList; import java.util.List; diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/entity/render/AutomobileAssemblerBlockEntityRenderer.java b/common/src/main/java/io/github/foundationgames/automobility/block/entity/render/AutomobileAssemblerBlockEntityRenderer.java index c7436b0..fae1f2f 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/block/entity/render/AutomobileAssemblerBlockEntityRenderer.java +++ b/common/src/main/java/io/github/foundationgames/automobility/block/entity/render/AutomobileAssemblerBlockEntityRenderer.java @@ -1,7 +1,7 @@ package io.github.foundationgames.automobility.block.entity.render; import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.math.Vector3f; +import com.mojang.math.Axis; import io.github.foundationgames.automobility.automobile.render.AutomobileRenderer; import io.github.foundationgames.automobility.block.entity.AutomobileAssemblerBlockEntity; import net.minecraft.client.gui.Font; @@ -26,14 +26,14 @@ public void render(AutomobileAssemblerBlockEntity entity, float tickDelta, PoseS matrices.pushPose(); matrices.translate(0.5, 0, 0.5); - matrices.mulPose(Vector3f.YP.rotationDegrees(-entity.getBlockState().getValue(BlockStateProperties.HORIZONTAL_FACING).toYRot())); + matrices.mulPose(Axis.YP.rotationDegrees(-entity.getBlockState().getValue(BlockStateProperties.HORIZONTAL_FACING).toYRot())); matrices.translate(0, 0.372, 0.501); matrices.scale(0.008f, -0.008f, -0.008f); for (var text : entity.label) { matrices.pushPose(); matrices.translate(-0.5 * textRenderer.width(text), 0, 0); - textRenderer.drawShadow(matrices, text, 0, 0, 0xFFFFFF); + textRenderer.drawInBatch(text, 0f, 0f, 0xFFFFFF, true, matrices.last().pose(), vertexConsumers, Font.DisplayMode.NORMAL, 0, 0xFFFFFFFF); matrices.popPose(); matrices.translate(0, 12, 0); } diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/model/SlopeBakedModel.java b/common/src/main/java/io/github/foundationgames/automobility/block/model/SlopeBakedModel.java index bc777bf..464ad6b 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/block/model/SlopeBakedModel.java +++ b/common/src/main/java/io/github/foundationgames/automobility/block/model/SlopeBakedModel.java @@ -1,6 +1,5 @@ package io.github.foundationgames.automobility.block.model; -import com.mojang.math.Vector3f; import io.github.foundationgames.automobility.platform.Platform; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.block.model.BakedQuad; @@ -15,6 +14,7 @@ import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.Nullable; +import org.joml.Vector3f; import java.util.Collections; import java.util.List; @@ -155,9 +155,9 @@ private void plate(float height, float rise, boolean left, boolean right, Textur var southNormal = new Vector3f(0, height, 1); southNormal.normalize(); - var topFaceOffset = topNormal.copy(); // Translate from the surface of the slope to the surface of the plate + var topFaceOffset = new Vector3f(topNormal); // Translate from the surface of the slope to the surface of the plate topFaceOffset.mul(0.0625f); - var onePxUp = southNormal.copy(); // Translate one pixel up the slope + var onePxUp = new Vector3f(southNormal); // Translate one pixel up the slope onePxUp.normalize(); onePxUp.mul(0.0625f); diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/model/SlopeUnbakedModel.java b/common/src/main/java/io/github/foundationgames/automobility/block/model/SlopeUnbakedModel.java index 2781bb1..82c2721 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/block/model/SlopeUnbakedModel.java +++ b/common/src/main/java/io/github/foundationgames/automobility/block/model/SlopeUnbakedModel.java @@ -1,14 +1,12 @@ package io.github.foundationgames.automobility.block.model; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; -import com.mojang.datafixers.util.Pair; import io.github.foundationgames.automobility.Automobility; import net.minecraft.client.renderer.texture.TextureAtlas; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.client.resources.model.Material; -import net.minecraft.client.resources.model.ModelBakery; +import net.minecraft.client.resources.model.ModelBaker; import net.minecraft.client.resources.model.ModelState; import net.minecraft.client.resources.model.UnbakedModel; import net.minecraft.resources.ResourceLocation; @@ -19,7 +17,6 @@ import java.util.Collection; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.function.Function; import java.util.function.Supplier; @@ -72,16 +69,17 @@ public Collection getDependencies() { } @Override - public Collection getMaterials(Function function, Set> set) { - var list = Lists.newArrayList(this.frameTex); - if (this.plateInnerTex != null) { - list.add(this.plateInnerTex); - } - if (this.plateOuterTex != null) { - list.add(this.plateOuterTex); - } - - return list; + public void resolveParents(Function function) { + // ??? + // var list = Lists.newArrayList(this.frameTex); + // if (this.plateInnerTex != null) { + // list.add(this.plateInnerTex); + // } + // if (this.plateOuterTex != null) { + // list.add(this.plateOuterTex); + // } + // + // return list; } // TODO: Something better than this that supports other mods and resource packs @@ -97,7 +95,7 @@ private static Map createFrameTexOverrides(Funct @Nullable @Override - public BakedModel bake(ModelBakery modelBakery, Function function, ModelState modelState, ResourceLocation resourceLocation) { + public BakedModel bake(ModelBaker modelBaker, Function function, ModelState modelState, ResourceLocation resourceLocation) { return SlopeBakedModel.impl.create(function.apply(frameTex), createFrameTexOverrides(function), plateInnerTex != null ? function.apply(plateInnerTex) : null, plateOuterTex != null ? function.apply(plateOuterTex) : null, modelState, type); diff --git a/common/src/main/java/io/github/foundationgames/automobility/entity/AutomobileDamageSource.java b/common/src/main/java/io/github/foundationgames/automobility/entity/AutomobileDamageSource.java index bf38b17..509fa2d 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/entity/AutomobileDamageSource.java +++ b/common/src/main/java/io/github/foundationgames/automobility/entity/AutomobileDamageSource.java @@ -1,9 +1,11 @@ package io.github.foundationgames.automobility.entity; +import net.minecraft.core.Holder; import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.damagesource.DamageType; public class AutomobileDamageSource extends DamageSource { protected AutomobileDamageSource(String name) { - super(name); + super(new Holder.Direct<>(new DamageType(name, 0.0F))); } } diff --git a/common/src/main/java/io/github/foundationgames/automobility/entity/AutomobileEntity.java b/common/src/main/java/io/github/foundationgames/automobility/entity/AutomobileEntity.java index 8443551..0c6e99f 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/entity/AutomobileEntity.java +++ b/common/src/main/java/io/github/foundationgames/automobility/entity/AutomobileEntity.java @@ -1,6 +1,5 @@ package io.github.foundationgames.automobility.entity; -import com.mojang.math.Vector3f; import io.github.foundationgames.automobility.Automobility; import io.github.foundationgames.automobility.automobile.AutomobileEngine; import io.github.foundationgames.automobility.automobile.AutomobileFrame; @@ -31,6 +30,7 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.ClientGamePacketListener; import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; @@ -63,6 +63,7 @@ import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.Shapes; import org.jetbrains.annotations.Nullable; +import org.joml.Vector3f; import java.util.ArrayDeque; import java.util.ArrayList; @@ -309,7 +310,7 @@ public AutomobileEntity(Level world) { @Override public void recreateFromPacket(ClientboundAddEntityPacket packet) { super.recreateFromPacket(packet); - if (level.isClientSide()) { + if (level().isClientSide()) { ClientPackets.requestSyncAutomobileComponentsPacket(this); } } @@ -414,7 +415,7 @@ public boolean burningOut() { } private void setDrifting(boolean drifting) { - if (this.level.isClientSide() && !this.drifting && drifting) { + if (this.level().isClientSide() && !this.drifting && drifting) { skidSound.accept(this); } @@ -422,7 +423,7 @@ private void setDrifting(boolean drifting) { } private void setBurningOut(boolean burningOut) { - if (this.level.isClientSide() && !this.drifting && !this.burningOut && burningOut) { + if (this.level().isClientSide() && !this.drifting && !this.burningOut && burningOut) { skidSound.accept(this); } @@ -445,7 +446,7 @@ public void setRearAttachment(RearAttachmentType r this.rearAttachment = rearAttachment.constructor().apply(rearAttachment, this); this.rearAttachment.setYaw(this.getYRot()); - if (!level.isClientSide() && !this.rearAttachment.isRideable() && this.getPassengers().size() > 1) { + if (!level().isClientSide() && !this.rearAttachment.isRideable() && this.getPassengers().size() > 1) { this.getPassengers().get(1).stopRiding(); } @@ -471,14 +472,14 @@ public void setComponents(AutomobileFrame frame, AutomobileWheel wheel, Automobi this.frame = frame; this.wheels = wheel; this.engine = engine; - this.maxUpStep = wheels.size(); + this.setMaxUpStep(wheels.size()); this.stats.from(frame, wheel, engine); this.displacement.applyWheelbase(frame.model().wheelBase()); - if (!level.isClientSide()) syncComponents(); + if (!level().isClientSide()) syncComponents(); } public void forNearbyPlayers(int radius, boolean ignoreDriver, Consumer action) { - for (Player p : level.players()) { + for (Player p : level().players()) { if (ignoreDriver && p == getFirstPassenger()) { continue; } @@ -518,7 +519,7 @@ public void tick() { if (lastWheelAngle != wheelAngle) markDirty(); lastWheelAngle = wheelAngle; - if (!this.wasEngineRunning && this.engineRunning() && this.level.isClientSide()) { + if (!this.wasEngineRunning && this.engineRunning() && this.level().isClientSide()) { engineSound.accept(this); } this.wasEngineRunning = this.engineRunning(); @@ -553,7 +554,7 @@ public void tick() { } postMovementTick(); - if (!level.isClientSide()) { + if (!level().isClientSide()) { var prevTailPos = this.prevTailPos != null ? this.prevTailPos : this.getTailPos(); var tailPos = this.getTailPos(); @@ -565,7 +566,7 @@ public void tick() { dirty = false; } if (this.hasSpaceForPassengers() && !decorative) { - var touchingEntities = this.level.getEntities(this, this.getBoundingBox().inflate(0.2, 0, 0.2), EntitySelector.pushableBy(this)); + var touchingEntities = this.level().getEntities(this, this.getBoundingBox().inflate(0.2, 0, 0.2), EntitySelector.pushableBy(this)); for (Entity entity : touchingEntities) { if (!entity.hasPassenger(this)) { if (!entity.isPassenger() && entity.getBbWidth() <= this.getBbWidth() && entity instanceof Mob && !(entity instanceof WaterAnimal)) { @@ -693,7 +694,7 @@ public void provideMobDriverInputs(Mob driver) { // both slow enough and is at an extreme enough offset angle to incrementally move in reverse float mul = 0.5f + (Mth.clamp(hSpeed, 0, 1) * 0.5f); if (pos.length() < 20 * mul && Math.abs(offset) > 180 - (170 * mul)) { - long time = level.getGameTime(); + long time = level().getGameTime(); // this is so that the automobile alternates between reverse and forward, // like a driver would do in order to angle their vehicle toward a target location reverse = (time % 80 <= 30); @@ -733,12 +734,12 @@ public void movementTick() { } // Get block below's friction - var blockBelow = new BlockPos(getX(), getY() - 0.05, getZ()); - this.grip = 1 - ((Mth.clamp((level.getBlockState(blockBelow).getBlock().getFriction() - 0.6f) / 0.4f, 0, 1) * (1 - stats.getGrip() * 0.8f))); + var blockBelow = new BlockPos((int) getX(), (int) (getY() - 0.05), (int) getZ()); + this.grip = 1 - ((Mth.clamp((level().getBlockState(blockBelow).getBlock().getFriction() - 0.6f) / 0.4f, 0, 1) * (1 - stats.getGrip() * 0.8f))); this.grip *= this.grip; // Bounce on gel - if (this.automobileOnGround && this.jumpCooldown <= 0 && level.getBlockState(this.blockPosition()).getBlock() instanceof LaunchGelBlock) { + if (this.automobileOnGround && this.jumpCooldown <= 0 && level().getBlockState(this.blockPosition()).getBlock() instanceof LaunchGelBlock) { this.setSpeed(Math.max(this.getHSpeed(), 0.1f), Math.max(this.getVSpeed(), 0.9f)); this.jumpCooldown = 5; this.automobileOnGround = false; @@ -794,8 +795,8 @@ public void movementTick() { // Allows for the sticky slope effect to continue for a tick after not being on a slope // This prevents the automobile from randomly jumping if it's moving down a slope quickly - var below = new BlockPos(Math.floor(getX()), Math.floor(getY() - 0.51), Math.floor(getZ())); - var state = level.getBlockState(below); + var below = new BlockPos((int) getX(), (int) (getY() - 0.51), (int) getZ()); + var state = level().getBlockState(below); if (state.is(Automobility.STICKY_SLOPES)) { slopeStickingTimer = 1; } else { @@ -803,8 +804,8 @@ public void movementTick() { } // Handle being in off-road - if (boostSpeed < 0.4f && level.getBlockState(blockPosition()).getBlock() instanceof OffRoadBlock offRoad) { - int layers = level.getBlockState(blockPosition()).getValue(OffRoadBlock.LAYERS); + if (boostSpeed < 0.4f && level().getBlockState(blockPosition()).getBlock() instanceof OffRoadBlock offRoad) { + int layers = level().getBlockState(blockPosition()).getValue(OffRoadBlock.LAYERS); float cap = stats.getComfortableSpeed() * (1 - ((float)layers / 3.5f)); engineSpeed = Math.min(cap, engineSpeed); this.debrisColor = offRoad.color; @@ -865,7 +866,7 @@ public void movementTick() { public void runOverEntities(Vec3 velocity) { var frontBox = getBoundingBox().move(velocity.scale(0.5)); var velAdd = velocity.add(0, 0.1, 0).scale(3); - for (var entity : level.getEntities(EntityTypeTest.forClass(Entity.class), frontBox, entity -> entity != this && entity != getFirstPassenger())) { + for (var entity : level().getEntities(EntityTypeTest.forClass(Entity.class), frontBox, entity -> entity != this && entity != getFirstPassenger())) { if (!entity.isInvulnerable()) { if (entity instanceof LivingEntity living && entity.getVehicle() != this) { living.hurt(AutomobilityEntities.AUTOMOBILE_DAMAGE_SOURCE, hSpeed * 10); @@ -892,7 +893,7 @@ public void postMovementTick() { double knockSpeed = ((-0.2 * hSpeed) - 0.5); addedVelocity = addedVelocity.add(Math.sin(angle) * knockSpeed, 0, Math.cos(angle) * knockSpeed); - level.playLocalSound(this.getX(), this.getY(), this.getZ(), AutomobilitySounds.COLLISION.require(), SoundSource.AMBIENT, 0.76f, 0.65f + (0.06f * (this.level.random.nextFloat() - 0.5f)), true); + level().playLocalSound(this.getX(), this.getY(), this.getZ(), AutomobilitySounds.COLLISION.require(), SoundSource.AMBIENT, 0.76f, 0.65f + (0.06f * (this.level().random.nextFloat() - 0.5f)), true); } double yDisp = position().subtract(this.lastPosForDisplacement).y(); @@ -960,7 +961,7 @@ public void postMovementTick() { float yawInc = angularSpeed;// + (drifting ? (((this.steering + (driftDir)) * driftDir * 2.5f + 1.5f) * driftDir) * (((1 - stats.getGrip()) + 2) / 2.5f) : this.steering * ((4f * Math.min(hSpeed, 1)) + (hSpeed > 0 ? 2 : -3.5f))) * ((stats.getHandling() + 1) / 2); float prevYaw = getYRot(); this.setYRot(getYRot() + yawInc); - if (level.isClientSide) { + if (level().isClientSide) { var passenger = getFirstPassenger(); if (passenger instanceof Player player) { if (inLockedViewMode()) { @@ -979,7 +980,7 @@ public void postMovementTick() { } } } - if (level.isClientSide()) { + if (level().isClientSide()) { this.yRotO = prevYaw; } } @@ -987,7 +988,7 @@ public void postMovementTick() { @Override public void move(MoverType movementType, Vec3 movement) { - if (!this.level.isClientSide() && movementType == MoverType.PLAYER) { + if (!this.level().isClientSide() && movementType == MoverType.PLAYER) { AUtils.IGNORE_ENTITY_GROUND_CHECK_STEPPING = true; } super.move(movementType, movement); @@ -999,22 +1000,22 @@ public boolean causeFallDamage(float fallDistance, float damageMultiplier, Damag } public void accumulateCollisionAreas(Collection areas) { - this.level.getEntitiesOfClass(Entity.class, this.getBoundingBox().inflate(3, 3, 3), e -> e != this && e.getVehicle() != this) + this.level().getEntitiesOfClass(Entity.class, this.getBoundingBox().inflate(3, 3, 3), e -> e != this && e.getVehicle() != this) .forEach(e -> areas.add(CollisionArea.entity(e))); } public void displacementTick(boolean tick) { - if (this.level.isClientSide()) { + if (this.level().isClientSide()) { this.displacement.preTick(); if (tick) { this.displacement.otherColliders.clear(); this.accumulateCollisionAreas(this.displacement.otherColliders); - this.displacement.tick(this.level, this, this.position(), this.getYRot(), this.maxUpStep); + this.displacement.tick(this.level(), this, this.position(), this.getYRot(), this.maxUpStep()); } - if (level.getBlockState(this.blockPosition()).getBlock() instanceof AutomobileAssemblerBlock) { + if (level().getBlockState(this.blockPosition()).getBlock() instanceof AutomobileAssemblerBlock) { this.displacement.lastVertical = this.displacement.verticalTarget = (-this.wheels.model().radius() / 16); } } @@ -1034,23 +1035,23 @@ public void collisionStateTick() { var wid = (b.getXsize() + b.getZsize()) * 0.5f; var floorBox = new AABB(b.minX + (wid * 0.94), b.minY - 0.05, b.minZ + (wid * 0.94), b.maxX - (wid * 0.94), b.minY, b.maxZ - (wid * 0.94)); var wallBox = b.deflate(0.05).move(this.lastVelocity.normalize().scale(0.12)); - var start = new BlockPos(b.minX - 0.1, b.minY - 0.2, b.minZ - 0.1); - var end = new BlockPos(b.maxX + 0.1, b.maxY + 0.2 + this.maxUpStep, b.maxZ + 0.1); + var start = new BlockPos((int) (b.minX - 0.1), (int) (b.minY - 0.2), (int) (b.minZ - 0.1)); + var end = new BlockPos((int) (b.maxX + 0.1), (int) (b.maxY + 0.2 + this.maxUpStep()), (int) (b.maxZ + 0.1)); var groundCuboid = Shapes.create(groundBox); var floorCuboid = Shapes.create(floorBox); var wallCuboid = Shapes.create(wallBox); - var stepWallCuboid = wallCuboid.move(0, this.maxUpStep - 0.05, 0); + var stepWallCuboid = wallCuboid.move(0, this.maxUpStep() - 0.05, 0); boolean wallHit = false; boolean stepWallHit = false; var shapeCtx = CollisionContext.of(this); - if (this.level.hasChunksAt(start, end)) { + if (this.level().hasChunksAt(start, end)) { var pos = new BlockPos.MutableBlockPos(); for(int x = start.getX(); x <= end.getX(); ++x) { for(int y = start.getY(); y <= end.getY(); ++y) { for(int z = start.getZ(); z <= end.getZ(); ++z) { pos.set(x, y, z); - var state = this.level.getBlockState(pos); - var blockShape = state.getCollisionShape(this.level, pos, shapeCtx).move(pos.getX(), pos.getY(), pos.getZ()); + var state = this.level().getBlockState(pos); + var blockShape = state.getCollisionShape(this.level(), pos, shapeCtx).move(pos.getX(), pos.getY(), pos.getZ()); this.automobileOnGround |= Shapes.joinIsNotEmpty(blockShape, groundCuboid, BooleanOp.AND); this.isFloorDirectlyBelow |= Shapes.joinIsNotEmpty(blockShape, floorCuboid, BooleanOp.AND); wallHit |= Shapes.joinIsNotEmpty(blockShape, wallCuboid, BooleanOp.AND); @@ -1145,7 +1146,7 @@ private void driftingTick() { // Reduce speed when a drift starts, based on how long the last drift was for // This allows you to do a series of short drifts without tanking all your speed, while still reducing your speed when you begin the drift(s) engineSpeed -= 0.028 * engineSpeed; - } else if (steering == 0 && !this.getLevel().isClientSide() && this.getRearAttachment() instanceof DeployableRearAttachment att) { + } else if (steering == 0 && !this.level().isClientSide() && this.getRearAttachment() instanceof DeployableRearAttachment att) { att.deploy(); } } @@ -1203,7 +1204,7 @@ public void createDriftParticles() { .xRot((float) Math.toRadians(this.displacement.currAngularX)) .zRot((float) Math.toRadians(this.displacement.currAngularZ)) .yRot((float) Math.toRadians(-this.getYRot())).scale(0.0625).add(0, 0.4, 0); - level.addParticle(AutomobilityParticles.DRIFT_SMOKE.require(), origin.x + pos.x, origin.y + pos.y, origin.z + pos.z, 0, 0, 0); + level().addParticle(AutomobilityParticles.DRIFT_SMOKE.require(), origin.x + pos.x, origin.y + pos.y, origin.z + pos.z, 0, 0, 0); } } } @@ -1224,8 +1225,14 @@ public float getRearAttachmentYaw(float tickDelta) { @Nullable @Override - public Entity getControllingPassenger() { - return getFirstPassenger(); + public LivingEntity getControllingPassenger() { + final var firstPassenger = getFirstPassenger(); + + if (firstPassenger instanceof LivingEntity living) { + return living; + } else { + return null; + } } @Override @@ -1251,23 +1258,23 @@ public float getStandStillTime() { } public void playHitSound(Vec3 pos) { - level.gameEvent(this, GameEvent.ENTITY_DAMAGE, pos); - level.playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.COPPER_BREAK, SoundSource.AMBIENT, 1, 0.9f + (this.level.random.nextFloat() * 0.2f)); + level().gameEvent(this, GameEvent.ENTITY_DAMAGE, pos); + level().playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.COPPER_BREAK, SoundSource.AMBIENT, 1, 0.9f + (this.level().random.nextFloat() * 0.2f)); } private void dropParts(Vec3 pos) { - level.addFreshEntity(new ItemEntity(level, pos.x, pos.y, pos.z, AutomobilityItems.AUTOMOBILE_FRAME.require().createStack(this.getFrame()))); - level.addFreshEntity(new ItemEntity(level, pos.x, pos.y, pos.z, AutomobilityItems.AUTOMOBILE_ENGINE.require().createStack(this.getEngine()))); + level().addFreshEntity(new ItemEntity(level(), pos.x, pos.y, pos.z, AutomobilityItems.AUTOMOBILE_FRAME.require().createStack(this.getFrame()))); + level().addFreshEntity(new ItemEntity(level(), pos.x, pos.y, pos.z, AutomobilityItems.AUTOMOBILE_ENGINE.require().createStack(this.getEngine()))); var wheelStack = AutomobilityItems.AUTOMOBILE_WHEEL.require().createStack(this.getWheels()); wheelStack.setCount(this.getFrame().model().wheelBase().wheelCount); - level.addFreshEntity(new ItemEntity(level, pos.x, pos.y, pos.z, wheelStack)); + level().addFreshEntity(new ItemEntity(level(), pos.x, pos.y, pos.z, wheelStack)); } public void destroyRearAttachment(boolean drop) { if (drop) { var dropPos = this.rearAttachment.pos(); - level.addFreshEntity(new ItemEntity(level, dropPos.x, dropPos.y, dropPos.z, + level().addFreshEntity(new ItemEntity(level(), dropPos.x, dropPos.y, dropPos.z, AutomobilityItems.REAR_ATTACHMENT.require().createStack(this.getRearAttachmentType()))); } this.setRearAttachment(RearAttachmentType.EMPTY); @@ -1276,7 +1283,7 @@ public void destroyRearAttachment(boolean drop) { public void destroyFrontAttachment(boolean drop) { if (drop) { var dropPos = this.frontAttachment.pos(); - level.addFreshEntity(new ItemEntity(level, dropPos.x, dropPos.y, dropPos.z, + level().addFreshEntity(new ItemEntity(level(), dropPos.x, dropPos.y, dropPos.z, AutomobilityItems.FRONT_ATTACHMENT.require().createStack(this.getFrontAttachmentType()))); } this.setFrontAttachment(FrontAttachmentType.EMPTY); @@ -1299,7 +1306,7 @@ public void destroyAutomobile(boolean drop, RemovalReason reason) { public InteractionResult interact(Player player, InteractionHand hand) { if (player.isShiftKeyDown()) { if (this.hasInventory()) { - if (!level.isClientSide()) { + if (!level().isClientSide()) { openInventory(player); return InteractionResult.PASS; } else { @@ -1317,17 +1324,17 @@ public InteractionResult interact(Player player, InteractionHand hand) { this.destroyFrontAttachment(!player.isCreative()); this.playHitSound(this.getHeadPos()); - return InteractionResult.sidedSuccess(level.isClientSide); + return InteractionResult.sidedSuccess(level().isClientSide); } else if (!this.rearAttachment.type.isEmpty()) { this.destroyRearAttachment(!player.isCreative()); this.playHitSound(this.rearAttachment.pos()); - return InteractionResult.sidedSuccess(level.isClientSide); + return InteractionResult.sidedSuccess(level().isClientSide); } else { this.destroyAutomobile(!player.isCreative(), RemovalReason.KILLED); this.playHitSound(this.position()); - return InteractionResult.sidedSuccess(level.isClientSide); + return InteractionResult.sidedSuccess(level().isClientSide); } } @@ -1338,17 +1345,17 @@ public InteractionResult interact(Player player, InteractionHand hand) { if (!this.hasSpaceForPassengers()) { if (!(this.getFirstPassenger() instanceof Player)) { - if (!level.isClientSide()) { + if (!level().isClientSide()) { this.getFirstPassenger().stopRiding(); } - return InteractionResult.sidedSuccess(level.isClientSide); + return InteractionResult.sidedSuccess(level().isClientSide); } return InteractionResult.PASS; } - if (!level.isClientSide()) { + if (!level().isClientSide()) { player.startRiding(this); } - return InteractionResult.sidedSuccess(level.isClientSide()); + return InteractionResult.sidedSuccess(level().isClientSide()); } return InteractionResult.PASS; @@ -1360,14 +1367,14 @@ public double getPassengersRidingOffset() { } @Override - public void positionRider(Entity passenger) { + public void positionRider(Entity passenger, Entity.MoveFunction moveFunc) { if (passenger == this.getFirstPassenger()) { var pos = this.position().add(0, this.displacement.verticalTarget + passenger.getMyRidingOffset(), 0) .add(new Vec3(0, this.getPassengersRidingOffset(), 0) .xRot((float) Math.toRadians(-this.displacement.currAngularX)) .zRot((float) Math.toRadians(-this.displacement.currAngularZ))); - passenger.setPos(pos.x, pos.y, pos.z); + moveFunc.accept(passenger, pos.x, pos.y, pos.z); } else if (this.hasPassenger(passenger)) { var pos = this.position().add( new Vec3(0, this.displacement.verticalTarget, this.getFrame().model().rearAttachmentPos() * 0.0625) @@ -1376,7 +1383,7 @@ public void positionRider(Entity passenger) { .xRot((float) Math.toRadians(-this.displacement.currAngularX)) .zRot((float) Math.toRadians(-this.displacement.currAngularZ))); - passenger.setPos(pos.x, pos.y, pos.z); + moveFunc.accept(passenger, pos.x, pos.y, pos.z); } } @@ -1420,7 +1427,7 @@ public void onSyncedDataUpdated(EntityDataAccessor data) { } @Override - public Packet getAddEntityPacket() { + public Packet getAddEntityPacket() { return new ClientboundAddEntityPacket(this); } @@ -1450,7 +1457,7 @@ public float getTrackedFrontAttachmentAnimation() { public void bounce() { suspensionBounceTimer = 3; - level.playLocalSound(this.getX(), this.getY(), this.getZ(), AutomobilitySounds.LANDING.require(), SoundSource.AMBIENT, 1, 1.5f + (0.15f * (this.level.random.nextFloat() - 0.5f)), true); + level().playLocalSound(this.getX(), this.getY(), this.getZ(), AutomobilitySounds.LANDING.require(), SoundSource.AMBIENT, 1, 1.5f + (0.15f * (this.level().random.nextFloat() - 0.5f)), true); } public static final class Displacement { diff --git a/common/src/main/java/io/github/foundationgames/automobility/entity/AutomobilityEntities.java b/common/src/main/java/io/github/foundationgames/automobility/entity/AutomobilityEntities.java index db4eb41..ca05dfe 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/entity/AutomobilityEntities.java +++ b/common/src/main/java/io/github/foundationgames/automobility/entity/AutomobilityEntities.java @@ -4,7 +4,8 @@ import io.github.foundationgames.automobility.platform.Platform; import io.github.foundationgames.automobility.util.Eventual; import io.github.foundationgames.automobility.util.RegistryQueue; -import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; import net.minecraft.tags.TagKey; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.EntityDimensions; @@ -12,12 +13,12 @@ import net.minecraft.world.entity.MobCategory; public enum AutomobilityEntities {; - public static final Eventual> AUTOMOBILE = RegistryQueue.register(Registry.ENTITY_TYPE, + public static final Eventual> AUTOMOBILE = RegistryQueue.register(BuiltInRegistries.ENTITY_TYPE, Automobility.rl("automobile"), () -> Platform.get().entityType(MobCategory.MISC, AutomobileEntity::new, new EntityDimensions(1f, 0.66f, true), 3, 10) ); - public static final TagKey> DASH_PANEL_BOOSTABLES = TagKey.create(Registry.ENTITY_TYPE_REGISTRY, Automobility.rl("dash_panel_boostables")); + public static final TagKey> DASH_PANEL_BOOSTABLES = TagKey.create(Registries.ENTITY_TYPE, Automobility.rl("dash_panel_boostables")); public static final DamageSource AUTOMOBILE_DAMAGE_SOURCE = new AutomobileDamageSource("automobile"); diff --git a/common/src/main/java/io/github/foundationgames/automobility/entity/render/AutomobileEntityRenderer.java b/common/src/main/java/io/github/foundationgames/automobility/entity/render/AutomobileEntityRenderer.java index 0abb6a7..801c776 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/entity/render/AutomobileEntityRenderer.java +++ b/common/src/main/java/io/github/foundationgames/automobility/entity/render/AutomobileEntityRenderer.java @@ -1,9 +1,9 @@ package io.github.foundationgames.automobility.entity.render; import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.math.Quaternion; import io.github.foundationgames.automobility.automobile.render.AutomobileRenderer; import io.github.foundationgames.automobility.entity.AutomobileEntity; +import org.joml.Quaternionf; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.entity.EntityRenderer; import net.minecraft.client.renderer.entity.EntityRendererProvider; @@ -28,7 +28,7 @@ public void render(AutomobileEntity entity, float yaw, float tickDelta, PoseStac float offsetY = entity.getDisplacement().getVertical(tickDelta); pose.translate(0, offsetY, 0); - pose.mulPose(Quaternion.fromXYZ((float) Math.toRadians(angX), 0, (float) Math.toRadians(angZ))); + pose.mulPose(new Quaternionf().rotationXYZ((float) Math.toRadians(angX), 0, (float) Math.toRadians(angZ))); AutomobileRenderer.render(pose, buffers, light, OverlayTexture.NO_OVERLAY, tickDelta, entity); pose.popPose(); diff --git a/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileComponentItem.java b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileComponentItem.java index 2eb2ca9..af798e5 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileComponentItem.java +++ b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileComponentItem.java @@ -15,7 +15,7 @@ import java.util.List; -public class AutomobileComponentItem> extends Item { +public class AutomobileComponentItem> extends Item implements DynamicCreativeItem { protected final String nbtKey; protected final String translationKey; protected final SimpleMapContentRegistry registry; @@ -60,12 +60,10 @@ public void appendHoverText(ItemStack stack, @Nullable Level world, List stacks) { - if (this.allowedIn(group)) { - this.registry.forEach(component -> { - if (addToCreative(component)) stacks.add(this.createStack(component)); - }); - } + public void fillItemCategory(List stacks) { + this.registry.forEach(component -> { + if (addToCreative(component)) stacks.add(this.createStack(component)); + }); } public boolean isVisible(T component) { diff --git a/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileItem.java b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileItem.java index 6e755cf..2941ed0 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileItem.java +++ b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileItem.java @@ -7,10 +7,8 @@ import io.github.foundationgames.automobility.entity.AutomobilityEntities; import net.minecraft.ChatFormatting; import net.minecraft.client.gui.screens.Screen; -import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.world.InteractionResult; -import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; @@ -22,7 +20,7 @@ import java.util.Arrays; import java.util.List; -public class AutomobileItem extends Item { +public class AutomobileItem extends Item implements DynamicCreativeItem { public static final List PREFABS = new ArrayList<>(); private static final AutomobileData data = new AutomobileData(); private static final AutomobileStats stats = new AutomobileStats(); @@ -78,11 +76,9 @@ public static void addPrefabs(AutomobilePrefab ... prefabs) { } @Override - public void fillItemCategory(CreativeModeTab group, NonNullList stacks) { - if (allowedIn(group) || group == CreativeModeTab.TAB_TRANSPORTATION) { - for (var prefab : PREFABS) { - stacks.add(prefab.toStack()); - } + public void fillItemCategory(List stacks) { + for (var prefab : PREFABS) { + stacks.add(prefab.toStack()); } } } diff --git a/common/src/main/java/io/github/foundationgames/automobility/item/AutomobilityItems.java b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobilityItems.java index f45545f..f0abb8a 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/item/AutomobilityItems.java +++ b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobilityItems.java @@ -8,20 +8,21 @@ import io.github.foundationgames.automobility.util.Eventual; import io.github.foundationgames.automobility.util.RegistryQueue; import net.minecraft.ChatFormatting; -import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.chat.Component; +import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.Item; import java.util.function.Supplier; public enum AutomobilityItems {; - public static final Eventual CROWBAR = register("crowbar", () -> new TooltipItem(Component.translatable("tooltip.item.automobility.crowbar").withStyle(ChatFormatting.BLUE), new Item.Properties().stacksTo(1).tab(Automobility.GROUP))); - public static final Eventual AUTOMOBILE = register("automobile", () -> new AutomobileItem(new Item.Properties().stacksTo(1).tab(Automobility.PREFABS))); - public static final Eventual AUTOMOBILE_FRAME = register("automobile_frame", () -> new AutomobileFrameItem(new Item.Properties().stacksTo(16).tab(Automobility.GROUP))); - public static final Eventual AUTOMOBILE_WHEEL = register("automobile_wheel", () -> new AutomobileWheelItem(new Item.Properties().tab(Automobility.GROUP))); - public static final Eventual AUTOMOBILE_ENGINE = register("automobile_engine", () -> new AutomobileEngineItem(new Item.Properties().stacksTo(16).tab(Automobility.GROUP))); - public static final Eventual FRONT_ATTACHMENT = register("front_attachment", () -> new FrontAttachmentItem(new Item.Properties().stacksTo(1).tab(Automobility.GROUP))); - public static final Eventual REAR_ATTACHMENT = register("rear_attachment", () -> new RearAttachmentItem(new Item.Properties().stacksTo(1).tab(Automobility.GROUP))); + public static final Eventual CROWBAR = register("crowbar", () -> new TooltipItem(Component.translatable("tooltip.item.automobility.crowbar").withStyle(ChatFormatting.BLUE), new Item.Properties().stacksTo(1)), Automobility.GROUP); + public static final Eventual AUTOMOBILE = register("automobile", () -> new AutomobileItem(new Item.Properties().stacksTo(1)), Automobility.PREFABS); + public static final Eventual AUTOMOBILE_FRAME = register("automobile_frame", () -> new AutomobileFrameItem(new Item.Properties().stacksTo(16)), Automobility.GROUP); + public static final Eventual AUTOMOBILE_WHEEL = register("automobile_wheel", () -> new AutomobileWheelItem(new Item.Properties()), Automobility.GROUP); + public static final Eventual AUTOMOBILE_ENGINE = register("automobile_engine", () -> new AutomobileEngineItem(new Item.Properties().stacksTo(16)), Automobility.GROUP); + public static final Eventual FRONT_ATTACHMENT = register("front_attachment", () -> new FrontAttachmentItem(new Item.Properties().stacksTo(1)), Automobility.GROUP); + public static final Eventual REAR_ATTACHMENT = register("rear_attachment", () -> new RearAttachmentItem(new Item.Properties().stacksTo(1)), Automobility.GROUP); public static void init() { AutomobileItem.addPrefabs( @@ -60,7 +61,9 @@ public static void init() { ); } - public static Eventual register(String name, Supplier item) { - return RegistryQueue.register(Registry.ITEM, Automobility.rl(name), item); + public static Eventual register(String name, Supplier item, Automobility.ItemGroup group) { + var itemPromise = RegistryQueue.register(BuiltInRegistries.ITEM, Automobility.rl(name), item); + Automobility.addToItemGroup(group, itemPromise); + return itemPromise; } } diff --git a/common/src/main/java/io/github/foundationgames/automobility/item/DynamicCreativeItem.java b/common/src/main/java/io/github/foundationgames/automobility/item/DynamicCreativeItem.java new file mode 100644 index 0000000..c0db631 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/item/DynamicCreativeItem.java @@ -0,0 +1,9 @@ +package io.github.foundationgames.automobility.item; + +import net.minecraft.world.item.ItemStack; + +import java.util.List; + +public interface DynamicCreativeItem { + void fillItemCategory(List stacks); +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/item/FrontAttachmentItem.java b/common/src/main/java/io/github/foundationgames/automobility/item/FrontAttachmentItem.java index 3a4682a..f8097ad 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/item/FrontAttachmentItem.java +++ b/common/src/main/java/io/github/foundationgames/automobility/item/FrontAttachmentItem.java @@ -15,7 +15,7 @@ public FrontAttachmentItem(Properties settings) { @Override public InteractionResult interactAutomobile(ItemStack stack, Player player, InteractionHand hand, AutomobileEntity automobile) { if (automobile.getFrontAttachment().type.isEmpty()) { - if (player.level.isClientSide()) { + if (player.level().isClientSide()) { return InteractionResult.SUCCESS; } @@ -28,4 +28,4 @@ public InteractionResult interactAutomobile(ItemStack stack, Player player, Inte return InteractionResult.PASS; } -} \ No newline at end of file +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/item/RearAttachmentItem.java b/common/src/main/java/io/github/foundationgames/automobility/item/RearAttachmentItem.java index 6a44cfd..99e23f4 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/item/RearAttachmentItem.java +++ b/common/src/main/java/io/github/foundationgames/automobility/item/RearAttachmentItem.java @@ -15,7 +15,7 @@ public RearAttachmentItem(Properties settings) { @Override public InteractionResult interactAutomobile(ItemStack stack, Player player, InteractionHand hand, AutomobileEntity automobile) { if (automobile.getRearAttachment().type.isEmpty()) { - if (player.level.isClientSide()) { + if (player.level().isClientSide()) { return InteractionResult.SUCCESS; } diff --git a/common/src/main/java/io/github/foundationgames/automobility/item/SlopeBlockItem.java b/common/src/main/java/io/github/foundationgames/automobility/item/SlopeBlockItem.java index 2c1aafe..a935d3e 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/item/SlopeBlockItem.java +++ b/common/src/main/java/io/github/foundationgames/automobility/item/SlopeBlockItem.java @@ -20,7 +20,7 @@ public SlopeBlockItem(Block block, Properties settings) { @Override public BlockPlaceContext updatePlacementContext(BlockPlaceContext context) { var hitPos = context.getClickLocation(); - var pos = new BlockPos(Math.floor(hitPos.x), Math.floor(hitPos.y), Math.floor(hitPos.z)); + var pos = new BlockPos((int) hitPos.x, (int) hitPos.y, (int) hitPos.z); var world = context.getLevel(); if (world.getBlockState(pos).getBlock() instanceof SlopeBlock) { var facing = world.getBlockState(pos).getValue(BlockStateProperties.HORIZONTAL_FACING); diff --git a/common/src/main/java/io/github/foundationgames/automobility/item/SteepSlopeBlockItem.java b/common/src/main/java/io/github/foundationgames/automobility/item/SteepSlopeBlockItem.java index e6083b6..437db88 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/item/SteepSlopeBlockItem.java +++ b/common/src/main/java/io/github/foundationgames/automobility/item/SteepSlopeBlockItem.java @@ -19,7 +19,7 @@ public SteepSlopeBlockItem(Block block, Properties settings) { @Override public BlockPlaceContext updatePlacementContext(BlockPlaceContext context) { var hitPos = context.getClickLocation(); - var pos = new BlockPos(Math.floor(hitPos.x), Math.floor(hitPos.y), Math.floor(hitPos.z)); + var pos = new BlockPos((int) hitPos.x, (int) hitPos.y, (int) hitPos.z); var world = context.getLevel(); if (world.getBlockState(pos).getBlock() instanceof SteepSlopeBlock) { var facing = world.getBlockState(pos).getValue(BlockStateProperties.HORIZONTAL_FACING); diff --git a/common/src/main/java/io/github/foundationgames/automobility/particle/AutomobilityParticles.java b/common/src/main/java/io/github/foundationgames/automobility/particle/AutomobilityParticles.java index 007e0eb..8f3ae2a 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/particle/AutomobilityParticles.java +++ b/common/src/main/java/io/github/foundationgames/automobility/particle/AutomobilityParticles.java @@ -4,11 +4,11 @@ import io.github.foundationgames.automobility.platform.Platform; import io.github.foundationgames.automobility.util.Eventual; import io.github.foundationgames.automobility.util.RegistryQueue; -import net.minecraft.core.Registry; import net.minecraft.core.particles.SimpleParticleType; +import net.minecraft.core.registries.BuiltInRegistries; public class AutomobilityParticles { - public static final Eventual DRIFT_SMOKE = RegistryQueue.register(Registry.PARTICLE_TYPE, Automobility.rl("drift_smoke"), () -> Platform.get().simpleParticleType(true)); + public static final Eventual DRIFT_SMOKE = RegistryQueue.register(BuiltInRegistries.PARTICLE_TYPE, Automobility.rl("drift_smoke"), () -> Platform.get().simpleParticleType(true)); public static void init() { } diff --git a/common/src/main/java/io/github/foundationgames/automobility/platform/Platform.java b/common/src/main/java/io/github/foundationgames/automobility/platform/Platform.java index fbdad88..344d8c5 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/platform/Platform.java +++ b/common/src/main/java/io/github/foundationgames/automobility/platform/Platform.java @@ -10,7 +10,6 @@ import net.minecraft.client.gui.screens.inventory.MenuAccess; import net.minecraft.client.model.geom.ModelLayerLocation; import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.block.model.ItemTransforms; import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; import net.minecraft.client.renderer.entity.EntityRenderer; @@ -31,6 +30,7 @@ import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; @@ -39,6 +39,7 @@ import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.Nullable; +import java.util.List; import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.Function; @@ -57,9 +58,9 @@ static Platform get() { return GlobalPlatformInstance.INSTANCE; } - CreativeModeTab creativeTab(ResourceLocation rl, Supplier icon); + CreativeModeTab creativeTab(ResourceLocation rl, Supplier icon, CreativeModeTab.DisplayItemsGenerator displayItemsGenerator); - void builtinItemRenderer(Item item, HexCons renderer); + void builtinItemRenderer(Item item, HexCons renderer); MenuType menuType(BiFunction factory); diff --git a/common/src/main/java/io/github/foundationgames/automobility/recipe/AutoMechanicTableRecipe.java b/common/src/main/java/io/github/foundationgames/automobility/recipe/AutoMechanicTableRecipe.java index 292c200..2676ca5 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/recipe/AutoMechanicTableRecipe.java +++ b/common/src/main/java/io/github/foundationgames/automobility/recipe/AutoMechanicTableRecipe.java @@ -1,6 +1,8 @@ package io.github.foundationgames.automobility.recipe; import io.github.foundationgames.automobility.Automobility; + +import net.minecraft.core.RegistryAccess; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.Container; import net.minecraft.world.SimpleContainer; @@ -48,6 +50,10 @@ public boolean matches(SimpleContainer inv, Level lvl) { } @Override + public ItemStack assemble(SimpleContainer inv, RegistryAccess var2) { + return assemble(inv); + } + public ItemStack assemble(SimpleContainer inv) { for (var ing : this.ingredients) { for (int i = 0; i < inv.getContainerSize(); i++) { @@ -68,6 +74,10 @@ public boolean canCraftInDimensions(int width, int height) { } @Override + public ItemStack getResultItem(RegistryAccess var1) { + return getResultItem(); + } + public ItemStack getResultItem() { return this.result; } diff --git a/common/src/main/java/io/github/foundationgames/automobility/recipe/AutoMechanicTableRecipeSerializer.java b/common/src/main/java/io/github/foundationgames/automobility/recipe/AutoMechanicTableRecipeSerializer.java index b1ebcc7..09b3b1f 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/recipe/AutoMechanicTableRecipeSerializer.java +++ b/common/src/main/java/io/github/foundationgames/automobility/recipe/AutoMechanicTableRecipeSerializer.java @@ -3,7 +3,7 @@ import com.google.gson.JsonObject; import com.google.gson.JsonSyntaxException; import io.github.foundationgames.automobility.item.AutomobileComponentItem; -import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; @@ -18,7 +18,7 @@ public class AutoMechanicTableRecipeSerializer implements RecipeSerializer new ItemStack(i, count)).orElse(ItemStack.EMPTY); + var stack = BuiltInRegistries.ITEM.getOptional(id).map(i -> new ItemStack(i, count)).orElse(ItemStack.EMPTY); if (obj.has("component") && stack.getItem() instanceof AutomobileComponentItem item) { var component = ResourceLocation.tryParse(obj.get("component").getAsString()); diff --git a/common/src/main/java/io/github/foundationgames/automobility/screen/AutoMechanicTableScreen.java b/common/src/main/java/io/github/foundationgames/automobility/screen/AutoMechanicTableScreen.java index a8cf305..d779a75 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/screen/AutoMechanicTableScreen.java +++ b/common/src/main/java/io/github/foundationgames/automobility/screen/AutoMechanicTableScreen.java @@ -1,12 +1,10 @@ package io.github.foundationgames.automobility.screen; import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.PoseStack; import io.github.foundationgames.automobility.Automobility; import io.github.foundationgames.automobility.recipe.AutoMechanicTableRecipe; -import net.minecraft.client.gui.GuiComponent; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; -import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.resources.language.I18n; import net.minecraft.client.resources.sounds.SimpleSoundInstance; import net.minecraft.network.chat.Component; @@ -107,36 +105,34 @@ protected void containerTick() { } @Override - public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { - super.render(matrices, mouseX, mouseY, delta); - this.renderTooltip(matrices, mouseX, mouseY); + public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { + super.render(graphics, mouseX, mouseY, delta); + this.renderTooltip(graphics, mouseX, mouseY); } private void preDraw() { - RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderColor(1, 1, 1, 1); - RenderSystem.setShaderTexture(0, TEXTURE); } @Override - protected void renderBg(PoseStack matrices, float delta, int mouseX, int mouseY) { - this.renderBackground(matrices); + protected void renderBg(GuiGraphics graphics, float delta, int mouseX, int mouseY) { + this.renderBackground(graphics); this.preDraw(); - this.blit(matrices, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight); - this.drawCategoryBar(matrices, mouseX, mouseY); - this.drawRecipes(matrices, mouseX, mouseY); + graphics.blit(TEXTURE, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight); + this.drawCategoryBar(graphics, mouseX, mouseY); + this.drawRecipes(graphics, mouseX, mouseY); - this.drawMissingIngredients(matrices); + this.drawMissingIngredients(graphics); } @Override - protected void renderLabels(PoseStack matrices, int mouseX, int mouseY) { - super.renderLabels(matrices, mouseX, mouseY); + protected void renderLabels(GuiGraphics graphics, int mouseX, int mouseY) { + super.renderLabels(graphics, mouseX, mouseY); int hoveredRecipe = this.getHoveredRecipe(mouseX, mouseY); if (hoveredRecipe >= 0) { - this.renderTooltip(matrices, this.menu.recipes.get(hoveredRecipe).getResultItem(), mouseX - this.leftPos, mouseY - this.topPos); + graphics.renderTooltip(font, this.menu.recipes.get(hoveredRecipe).getResultItem(), mouseX - this.leftPos, mouseY - this.topPos); } } @@ -203,18 +199,18 @@ public boolean mouseScrolled(double mouseX, double mouseY, double amount) { return false; } - protected final void drawMissingIngredient(PoseStack matrices, Ingredient ing, int x, int y) { - GuiComponent.fill(matrices, x, y, x + 16, y + 16, 0x45FF0000); + protected final void drawMissingIngredient(GuiGraphics graphics, Ingredient ing, int x, int y) { + graphics.fill(x, y, x + 16, y + 16, 0x45FF0000); var stacks = ing.getItems(); - this.itemRenderer.renderAndDecorateFakeItem(stacks[Mth.floor((float)this.time / 30) % stacks.length], x, y); + graphics.renderFakeItem(stacks[Mth.floor((float)this.time / 30) % stacks.length], x, y); RenderSystem.depthFunc(516); - GuiComponent.fill(matrices, x, y, x + 16, y + 16, 0x30FFFFFF); + graphics.fill(x, y, x + 16, y + 16, 0x30FFFFFF); RenderSystem.depthFunc(515); } - protected void drawMissingIngredients(PoseStack matrices) { + protected void drawMissingIngredients(GuiGraphics graphics) { var inputInv = this.menu.inputInv; var missingIngs = new ArrayDeque<>(this.menu.missingIngredients); @@ -223,7 +219,7 @@ protected void drawMissingIngredients(PoseStack matrices) { int y = this.topPos + 88; if (inputInv.getItem(i).isEmpty()) { - this.drawMissingIngredient(matrices, missingIngs.removeFirst(), x, y); + this.drawMissingIngredient(graphics, missingIngs.removeFirst(), x, y); } } } @@ -277,21 +273,21 @@ protected int getHoveredRecipe(int mouseX, int mouseY) { return -2; } - protected void drawCategoryBar(PoseStack matrices, int mouseX, int mouseY) { + protected void drawCategoryBar(GuiGraphics graphics, int mouseX, int mouseY) { int hoveredCatButton = this.getHoveredCategoryButton(mouseX, mouseY); this.preDraw(); - this.blit(matrices, this.categoryButtonsX, this.categoryButtonsY, + graphics.blit(TEXTURE, this.categoryButtonsX, this.categoryButtonsY, 176, 17 + (hoveredCatButton < 0 ? CATEGORY_BUTTON_HEIGHT : 0), CATEGORY_BUTTON_WIDTH, CATEGORY_BUTTON_HEIGHT); - this.blit(matrices, this.categoryButtonsX + (CATEGORY_BUTTON_AREA_WIDTH - CATEGORY_BUTTON_WIDTH), this.categoryButtonsY, + graphics.blit(TEXTURE, this.categoryButtonsX + (CATEGORY_BUTTON_AREA_WIDTH - CATEGORY_BUTTON_WIDTH), this.categoryButtonsY, 188, 17 + (hoveredCatButton > 0 ? CATEGORY_BUTTON_HEIGHT : 0), CATEGORY_BUTTON_WIDTH, CATEGORY_BUTTON_HEIGHT); if (this.categoryTitle != null) { - GuiComponent.drawCenteredString(matrices, this.font, this.categoryTitle, this.leftPos + 120, this.topPos + 8, 0xFFFFFF); + graphics.drawCenteredString(this.font, this.categoryTitle, this.leftPos + 120, this.topPos + 8, 0xFFFFFF); } } - protected void drawRecipes(PoseStack matrices, int mouseX, int mouseY) { + protected void drawRecipes(GuiGraphics graphics, int mouseX, int mouseY) { if (this.orderedCategories.size() > 0) { var recipes = this.recipes.get(this.orderedCategories.get(this.currentCategory)); @@ -313,7 +309,7 @@ protected void drawRecipes(PoseStack matrices, int mouseX, int mouseY) { state = RecipeButtonState.HOVERED; } - this.drawRecipeEntry(entry, matrices, x, y, state); + this.drawRecipeEntry(entry, graphics, x, y, state); } else { break; } @@ -330,15 +326,15 @@ protected void drawRecipes(PoseStack matrices, int mouseX, int mouseY) { scrollBarY += (int)((SCROLL_BAR_AREA_HEIGHT - SCROLL_BAR_HEIGHT) * ((float)this.recipeScroll / maxScroll)); } - this.blit(matrices, scrollBarX, scrollBarY, 227, 0, SCROLL_BAR_WIDTH, SCROLL_BAR_HEIGHT); + graphics.blit(TEXTURE, scrollBarX, scrollBarY, 227, 0, SCROLL_BAR_WIDTH, SCROLL_BAR_HEIGHT); } - protected void drawRecipeEntry(RecipeEntry entry, PoseStack matrices, int x, int y, RecipeButtonState state) { + protected void drawRecipeEntry(RecipeEntry entry, GuiGraphics graphics, int x, int y, RecipeButtonState state) { this.preDraw(); - this.blit(matrices, x, y, 176 + (state.ordinal() * RECIPE_BUTTON_SIZE), 0, RECIPE_BUTTON_SIZE, RECIPE_BUTTON_SIZE); + graphics.blit(TEXTURE, x, y, 176 + (state.ordinal() * RECIPE_BUTTON_SIZE), 0, RECIPE_BUTTON_SIZE, RECIPE_BUTTON_SIZE); var stack = entry.recipe.getResultItem(); - this.itemRenderer.renderAndDecorateFakeItem(stack, x, y); + graphics.renderFakeItem(stack, x, y); } public static record RecipeEntry(int id, AutoMechanicTableRecipe recipe) {} diff --git a/common/src/main/java/io/github/foundationgames/automobility/screen/AutoMechanicTableScreenHandler.java b/common/src/main/java/io/github/foundationgames/automobility/screen/AutoMechanicTableScreenHandler.java index 3d3d2aa..85d3d96 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/screen/AutoMechanicTableScreenHandler.java +++ b/common/src/main/java/io/github/foundationgames/automobility/screen/AutoMechanicTableScreenHandler.java @@ -39,7 +39,7 @@ public AutoMechanicTableScreenHandler(int syncId, Inventory playerInv) { public AutoMechanicTableScreenHandler(int syncId, Inventory playerInv, ContainerLevelAccess ctx) { super(Automobility.AUTO_MECHANIC_SCREEN.require("Auto mechanic screen not registered!"), syncId); - this.world = playerInv.player.getLevel(); + this.world = playerInv.player.level(); this.context = ctx; this.inputInv = new SimpleContainer(9) { @Override public void setChanged() { AutoMechanicTableScreenHandler.this.onInputUpdated(); } @@ -144,7 +144,7 @@ public ItemStack quickMoveStack(Player player, int fromSlotId) { // Items transferred out of output slot if (fromSlotId == this.outputSlot.index) { - fromItem.onCraftedBy(fromStack, player.level, player); + fromItem.onCraftedBy(fromStack, player.level(), player); if (!this.moveItemStackTo(fromStack, this.playerInvSlot, this.playerInvSlot + 36, true)) { return ItemStack.EMPTY; } @@ -209,7 +209,7 @@ public void onTake(Player player, ItemStack stack) { AutoMechanicTableScreenHandler.this.getSelectedRecipe() .ifPresent(recipe -> { recipe.assemble(AutoMechanicTableScreenHandler.this.inputInv); - stack.getItem().onCraftedBy(stack, player.getLevel(), player); + stack.getItem().onCraftedBy(stack, player.level(), player); AutoMechanicTableScreenHandler.this.updateRecipeState(); }); } diff --git a/common/src/main/java/io/github/foundationgames/automobility/screen/AutomobileContainerLevelAccess.java b/common/src/main/java/io/github/foundationgames/automobility/screen/AutomobileContainerLevelAccess.java index 319173d..7bb1691 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/screen/AutomobileContainerLevelAccess.java +++ b/common/src/main/java/io/github/foundationgames/automobility/screen/AutomobileContainerLevelAccess.java @@ -16,7 +16,7 @@ public class AutomobileContainerLevelAccess implements ContainerLevelAccess { private final AutomobileEntity automobile; public AutomobileContainerLevelAccess(AutomobileEntity automobile) { - this.world = automobile.getLevel(); + this.world = automobile.level(); this.automobile = automobile; } diff --git a/common/src/main/java/io/github/foundationgames/automobility/screen/AutomobileHud.java b/common/src/main/java/io/github/foundationgames/automobility/screen/AutomobileHud.java index 7ee95d2..deaab09 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/screen/AutomobileHud.java +++ b/common/src/main/java/io/github/foundationgames/automobility/screen/AutomobileHud.java @@ -8,7 +8,7 @@ import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.Options; -import net.minecraft.client.gui.GuiComponent; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Player; @@ -24,8 +24,8 @@ public enum AutomobileHud {; new ControlHint("drift", options -> options.keyJump) ); - public static void render(PoseStack pose, Player player, AutomobileEntity auto, float tickDelta) { - renderSpeedometer(pose, auto); + public static void render(GuiGraphics graphics, Player player, AutomobileEntity auto, float tickDelta) { + renderSpeedometer(graphics, auto); if (!Platform.get().inControllerMode()) { float alpha = Math.max(0, (auto.getStandStillTime() * 2) - 1); @@ -34,22 +34,22 @@ public static void render(PoseStack pose, Player player, AutomobileEntity auto, // reason, and small enough numbers (which would result in 0 alpha as an int, but non zero as a float) would // result in a brief tick of 100% alpha, messing up the smoothness of the fade in animation if ((int)(alpha * 0xFF) > 0) { - renderControlHints(pose, alpha); + renderControlHints(graphics, alpha); } } } - private static void renderSpeedometer(PoseStack pose, AutomobileEntity auto) { + private static void renderSpeedometer(GuiGraphics graphics, AutomobileEntity auto) { float speed = (float) auto.getEffectiveSpeed() * 20; int color = 0xFFFFFF; if (auto.getBoostTimer() > 0) color = 0xFF6F00; if (auto.getTurboCharge() > AutomobileEntity.SMALL_TURBO_TIME) color = 0xFFEA4A; if (auto.getTurboCharge() > AutomobileEntity.MEDIUM_TURBO_TIME) color = 0x7DE9FF; if (auto.getTurboCharge() > AutomobileEntity.LARGE_TURBO_TIME) color = 0x906EFF; - GuiComponent.drawString(pose, Minecraft.getInstance().font, Component.literal(AUtils.DEC_TWO_PLACES.format(speed) +" m/s"), 20, 20, color); + graphics.drawString(Minecraft.getInstance().font, Component.literal(AUtils.DEC_TWO_PLACES.format(speed) +" m/s"), 20, 20, color); } - private static void renderControlHints(PoseStack pose, float alpha) { + private static void renderControlHints(GuiGraphics graphics, float alpha) { int x = 20; int y = 50; var options = Minecraft.getInstance().options; @@ -59,11 +59,11 @@ private static void renderControlHints(PoseStack pose, float alpha) { var keyTxt = control.getKeybindText(options); int keyTxtWid = font.width(keyTxt); - GuiComponent.fill(pose, x, y, x + keyTxtWid + 6, y + 14, ((int)(alpha * 0xAB) << 24)); + graphics.fill(x, y, x + keyTxtWid + 6, y + 14, ((int)(alpha * 0xAB) << 24)); int textColor = 0x00FFFFFF | ((int)(alpha * 0xFF) << 24); - GuiComponent.drawString(pose, font, keyTxt, x + 3, y + 3, textColor); - GuiComponent.drawString(pose, font, control.getText(), x + keyTxtWid + 9, y + 3, textColor); + graphics.drawString(font, keyTxt, x + 3, y + 3, textColor); + graphics.drawString(font, control.getText(), x + keyTxtWid + 9, y + 3, textColor); y += 17; } diff --git a/common/src/main/java/io/github/foundationgames/automobility/screen/SingleSlotScreen.java b/common/src/main/java/io/github/foundationgames/automobility/screen/SingleSlotScreen.java index 15b4e24..f1c7a3d 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/screen/SingleSlotScreen.java +++ b/common/src/main/java/io/github/foundationgames/automobility/screen/SingleSlotScreen.java @@ -3,6 +3,8 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import io.github.foundationgames.automobility.Automobility; + +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.gui.screens.inventory.MenuAccess; import net.minecraft.client.renderer.GameRenderer; @@ -22,18 +24,16 @@ public SingleSlotScreen(SingleSlotScreenHandler handler, Inventory inventory, Co } @Override - public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { - super.render(matrices, mouseX, mouseY, delta); - this.renderTooltip(matrices, mouseX, mouseY); + public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { + super.render(graphics, mouseX, mouseY, delta); + this.renderTooltip(graphics, mouseX, mouseY); } @Override - protected void renderBg(PoseStack matrices, float delta, int mouseX, int mouseY) { - this.renderBackground(matrices); + protected void renderBg(GuiGraphics graphics, float delta, int mouseX, int mouseY) { + this.renderBackground(graphics); - RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderColor(1, 1, 1, 1); - RenderSystem.setShaderTexture(0, TEXTURE); - this.blit(matrices, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight); + graphics.blit(TEXTURE, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight); } } diff --git a/common/src/main/java/io/github/foundationgames/automobility/sound/AutomobilitySounds.java b/common/src/main/java/io/github/foundationgames/automobility/sound/AutomobilitySounds.java index f3169c3..f15bafc 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/sound/AutomobilitySounds.java +++ b/common/src/main/java/io/github/foundationgames/automobility/sound/AutomobilitySounds.java @@ -4,6 +4,7 @@ import io.github.foundationgames.automobility.util.Eventual; import io.github.foundationgames.automobility.util.RegistryQueue; import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.sounds.SoundEvent; public class AutomobilitySounds { @@ -20,7 +21,7 @@ public class AutomobilitySounds { private static Eventual register(String path) { var id = Automobility.rl(path); - return RegistryQueue.register(Registry.SOUND_EVENT, id, () -> new SoundEvent(id)); + return RegistryQueue.register(BuiltInRegistries.SOUND_EVENT, id, () -> SoundEvent.createVariableRangeEvent(id)); } public static void init() { diff --git a/common/src/main/java/io/github/foundationgames/automobility/util/AUtils.java b/common/src/main/java/io/github/foundationgames/automobility/util/AUtils.java index 46eb7de..eb655fa 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/util/AUtils.java +++ b/common/src/main/java/io/github/foundationgames/automobility/util/AUtils.java @@ -2,13 +2,14 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; -import com.mojang.math.Vector3f; import io.github.foundationgames.automobility.Automobility; import io.github.foundationgames.automobility.automobile.AutomobileEngine; import io.github.foundationgames.automobility.automobile.AutomobileFrame; import io.github.foundationgames.automobility.automobile.AutomobilePrefab; import io.github.foundationgames.automobility.automobile.AutomobileWheel; import io.github.foundationgames.automobility.item.AutomobilityItems; +import org.joml.Vector3f; + import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.Direction; @@ -166,7 +167,7 @@ public static Vector3f colorFromInt(int color) { } public static boolean canMerge(ItemStack a, ItemStack b) { - return (a.sameItemStackIgnoreDurability(b)) && (a.getCount() + b.getCount() <= a.getMaxStackSize()); + return ItemStack.isSameItem(a, b) && (a.getCount() + b.getCount() <= a.getMaxStackSize()); } /** diff --git a/common/src/main/java/io/github/foundationgames/automobility/util/network/ClientPackets.java b/common/src/main/java/io/github/foundationgames/automobility/util/network/ClientPackets.java index cdcf0bc..e7a33d2 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/util/network/ClientPackets.java +++ b/common/src/main/java/io/github/foundationgames/automobility/util/network/ClientPackets.java @@ -37,7 +37,7 @@ public static void initClient() { FriendlyByteBuf dup = new FriendlyByteBuf(buf.copy()); int entityId = dup.readInt(); client.execute(() -> { - if (client.player.level.getEntity(entityId) instanceof AutomobileEntity automobile) { + if (client.player.level().getEntity(entityId) instanceof AutomobileEntity automobile) { automobile.readSyncToClientData(dup); } }); @@ -48,7 +48,7 @@ public static void initClient() { var wheel = AutomobileWheel.REGISTRY.getOrDefault(ResourceLocation.tryParse(buf.readUtf())); var engine = AutomobileEngine.REGISTRY.getOrDefault(ResourceLocation.tryParse(buf.readUtf())); client.execute(() -> { - if (client.player.level.getEntity(entityId) instanceof AutomobileEntity automobile) { + if (client.player.level().getEntity(entityId) instanceof AutomobileEntity automobile) { automobile.setComponents(frame, wheel, engine); } }); @@ -58,7 +58,7 @@ public static void initClient() { var rearAtt = RearAttachmentType.REGISTRY.getOrDefault(ResourceLocation.tryParse(buf.readUtf())); var frontAtt = FrontAttachmentType.REGISTRY.getOrDefault(ResourceLocation.tryParse(buf.readUtf())); client.execute(() -> { - if (client.player.level.getEntity(entityId) instanceof AutomobileEntity automobile) { + if (client.player.level().getEntity(entityId) instanceof AutomobileEntity automobile) { automobile.setRearAttachment(rearAtt); automobile.setFrontAttachment(frontAtt); } @@ -68,7 +68,7 @@ public static void initClient() { int entityId = buf.readInt(); var banner = buf.readNbt(); client.execute(() -> { - if (client.player.level.getEntity(entityId) instanceof AutomobileEntity automobile && + if (client.player.level().getEntity(entityId) instanceof AutomobileEntity automobile && automobile.getRearAttachment() instanceof BannerPostRearAttachment bannerPost) { bannerPost.setFromNbt(banner); } @@ -78,7 +78,7 @@ public static void initClient() { int entityId = buf.readInt(); boolean extended = buf.readBoolean(); client.execute(() -> { - if (client.player.level.getEntity(entityId) instanceof AutomobileEntity automobile && + if (client.player.level().getEntity(entityId) instanceof AutomobileEntity automobile && automobile.getRearAttachment() instanceof ExtendableRearAttachment att) { att.setExtended(extended); } diff --git a/common/src/main/java/io/github/foundationgames/automobility/util/network/CommonPackets.java b/common/src/main/java/io/github/foundationgames/automobility/util/network/CommonPackets.java index 5d0c556..d3cb617 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/util/network/CommonPackets.java +++ b/common/src/main/java/io/github/foundationgames/automobility/util/network/CommonPackets.java @@ -64,7 +64,7 @@ public static void init() { boolean space = buf.readBoolean(); int entityId = buf.readInt(); server.execute(() -> { - if (player.level.getEntity(entityId) instanceof AutomobileEntity automobile) { + if (player.level().getEntity(entityId) instanceof AutomobileEntity automobile) { automobile.setInputs(fwd, back, left, right, space); automobile.markDirty(); } @@ -73,7 +73,7 @@ public static void init() { Platform.get().serverReceivePacket(Automobility.rl("request_sync_automobile_components"), (server, player, buf) -> { int entityId = buf.readInt(); server.execute(() -> { - if (player.level.getEntity(entityId) instanceof AutomobileEntity automobile) { + if (player.level().getEntity(entityId) instanceof AutomobileEntity automobile) { sendSyncAutomobileComponentsPacket(automobile, player); sendSyncAutomobileAttachmentsPacket(automobile, player); diff --git a/fabric/build.gradle b/fabric/build.gradle index 133a5e0..8f3b0c5 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -6,11 +6,12 @@ plugins { version = "${project.mod_version}+${project.minecraft_version}-fabric" as Object repositories { + mavenLocal() maven { url = 'https://maven.gegy.dev/' } maven { url = 'https://maven.terraformersmc.com/' } maven { url = 'https://aperlambda.github.io/maven' } // maven { url = 'https://hephaestus.dev/release' } - maven { url = 'https://storage.googleapis.com/devan-maven/' } + maven { url = 'https://ueaj.dev/maven' } maven { url = 'https://api.modrinth.com/maven' } } @@ -24,7 +25,7 @@ dependencies { // Controller Support modImplementation "dev.lambdaurora:spruceui:${project.spruceui_version}" - modImplementation "maven.modrinth:midnightlib:${project.midnightlib_version}" + modImplementation "maven.modrinth:midnightlib:${project.midnightlib_version}-fabric" modImplementation "maven.modrinth:midnightcontrols:${project.midnightcontrols_version}" api('org.aperlambda:lambdajcommon:1.8.1') { exclude group: 'com.google.code.gson' @@ -40,8 +41,8 @@ dependencies { include "net.devtech:arrp:${project.arrp_version}" // Json entity models - modImplementation "maven.modrinth:jsonem:${project.jsonem_version}" - include "maven.modrinth:jsonem:${project.jsonem_version}" + modImplementation "io.github.foundationgames:jsonem:${project.jsonem_version}" + include "io.github.foundationgames:jsonem:${project.jsonem_version}" implementation project(':common') } diff --git a/fabric/src/main/java/io/github/foundationgames/automobility/fabric/AutomobilityFabric.java b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/AutomobilityFabric.java index 1d815e3..72901bc 100644 --- a/fabric/src/main/java/io/github/foundationgames/automobility/fabric/AutomobilityFabric.java +++ b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/AutomobilityFabric.java @@ -3,9 +3,11 @@ import io.github.foundationgames.automobility.Automobility; import io.github.foundationgames.automobility.fabric.block.AutomobilityFabricBlocks; import io.github.foundationgames.automobility.fabric.resource.AutomobilityData; +import io.github.foundationgames.automobility.platform.Platform; import io.github.foundationgames.automobility.util.RegistryQueue; import net.fabricmc.api.ModInitializer; import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; public class AutomobilityFabric implements ModInitializer { @Override @@ -13,15 +15,16 @@ public void onInitialize() { FabricPlatform.init(); Automobility.init(); - register(Registry.BLOCK); - register(Registry.BLOCK_ENTITY_TYPE); - register(Registry.ITEM); - register(Registry.ENTITY_TYPE); - register(Registry.PARTICLE_TYPE); - register(Registry.SOUND_EVENT); - register(Registry.MENU); - register(Registry.RECIPE_TYPE); - register(Registry.RECIPE_SERIALIZER); + register(BuiltInRegistries.BLOCK); + register(BuiltInRegistries.BLOCK_ENTITY_TYPE); + register(BuiltInRegistries.ITEM); + register(BuiltInRegistries.ENTITY_TYPE); + register(BuiltInRegistries.PARTICLE_TYPE); + register(BuiltInRegistries.SOUND_EVENT); + register(BuiltInRegistries.MENU); + register(BuiltInRegistries.RECIPE_TYPE); + register(BuiltInRegistries.RECIPE_SERIALIZER); + register(BuiltInRegistries.CREATIVE_MODE_TAB); AutomobilityData.setup(); AutomobilityFabricBlocks.init(); diff --git a/fabric/src/main/java/io/github/foundationgames/automobility/fabric/FabricPlatform.java b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/FabricPlatform.java index 7b0a88b..474b411 100644 --- a/fabric/src/main/java/io/github/foundationgames/automobility/fabric/FabricPlatform.java +++ b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/FabricPlatform.java @@ -7,7 +7,6 @@ import io.github.foundationgames.automobility.util.TriCons; import io.github.foundationgames.automobility.util.TriFunc; import io.github.foundationgames.jsonem.JsonEM; -import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.client.rendering.v1.BlockEntityRendererRegistry; import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry; @@ -17,6 +16,7 @@ import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder; import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder; import net.fabricmc.fabric.api.particle.v1.FabricParticleTypes; +import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup; import net.minecraft.client.Minecraft; import net.minecraft.client.color.block.BlockColor; import net.minecraft.client.gui.screens.MenuScreens; @@ -24,7 +24,6 @@ import net.minecraft.client.gui.screens.inventory.MenuAccess; import net.minecraft.client.model.geom.ModelLayerLocation; import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.block.model.ItemTransforms; import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; import net.minecraft.client.renderer.entity.EntityRenderer; @@ -41,10 +40,12 @@ import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.MobCategory; import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.flag.FeatureFlags; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; @@ -66,18 +67,22 @@ public static void init() { } @Override - public CreativeModeTab creativeTab(ResourceLocation rl, Supplier icon) { - return FabricItemGroupBuilder.build(rl, icon); + public CreativeModeTab creativeTab(ResourceLocation rl, Supplier icon, CreativeModeTab.DisplayItemsGenerator displayItemsGenerator) { + return FabricItemGroup.builder() + .icon(icon) + .title(Component.translatable("itemGroup." + rl.getNamespace() + "." + rl.getPath())) + .displayItems(displayItemsGenerator) + .build(); } @Override - public void builtinItemRenderer(Item item, HexCons renderer) { + public void builtinItemRenderer(Item item, HexCons renderer) { BuiltinItemRendererRegistry.INSTANCE.register(item, renderer::accept); } @Override public MenuType menuType(BiFunction factory) { - return new MenuType<>(factory::apply); + return new MenuType<>(factory::apply, FeatureFlags.DEFAULT_FLAGS); } @Override diff --git a/fabric/src/main/java/io/github/foundationgames/automobility/fabric/block/AutomobilityFabricBlocks.java b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/block/AutomobilityFabricBlocks.java index 891737d..9a6015c 100644 --- a/fabric/src/main/java/io/github/foundationgames/automobility/fabric/block/AutomobilityFabricBlocks.java +++ b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/block/AutomobilityFabricBlocks.java @@ -10,6 +10,7 @@ import net.fabricmc.fabric.api.event.registry.RegistryEntryAddedCallback; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.BlockItem; import net.minecraft.world.level.block.Block; @@ -28,11 +29,11 @@ public static void init() { } public static Block register(String name, Block block) { - return Registry.register(Registry.BLOCK, Automobility.rl(name), block); + return Registry.register(BuiltInRegistries.BLOCK, Automobility.rl(name), block); } public static Block register(String name, Block block, Function item) { - Registry.register(Registry.ITEM, Automobility.rl(name), item.apply(block)); + Registry.register(BuiltInRegistries.ITEM, Automobility.rl(name), item.apply(block)); return register(name, block); } @@ -46,9 +47,9 @@ private static void makeStairsSticky(Block candidate, ResourceLocation id) { public static void registerSlopes(String namespace) { AutomobilityData.NON_STEEP_SLOPE_TAG_CANDIDATES.add(Automobility.rl("sloped_dash_panel")); AutomobilityData.STEEP_SLOPE_TAG_CANDIDATES.add(Automobility.rl("steep_sloped_dash_panel")); - for (var base : Registry.BLOCK) { + for (var base : BuiltInRegistries.BLOCK) { if (base.getClass().equals(Block.class)) { - var id = Registry.BLOCK.getKey(base); + var id = BuiltInRegistries.BLOCK.getKey(base); if (id.getNamespace().equals(namespace)) { var path = id.getPath()+"_slope"; var steepPath = "steep_"+path; @@ -62,10 +63,10 @@ public static void registerSlopes(String namespace) { } } - makeStairsSticky(base, Registry.BLOCK.getKey(base)); + makeStairsSticky(base, BuiltInRegistries.BLOCK.getKey(base)); } - RegistryEntryAddedCallback.event(Registry.BLOCK).register((raw, id, block) -> { + RegistryEntryAddedCallback.event(BuiltInRegistries.BLOCK).register((raw, id, block) -> { makeStairsSticky(block, id); }); } diff --git a/fabric/src/main/java/io/github/foundationgames/automobility/fabric/block/render/FabricGeometryBuilder.java b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/block/render/FabricGeometryBuilder.java index 0ebf492..0c7c772 100644 --- a/fabric/src/main/java/io/github/foundationgames/automobility/fabric/block/render/FabricGeometryBuilder.java +++ b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/block/render/FabricGeometryBuilder.java @@ -1,13 +1,13 @@ package io.github.foundationgames.automobility.fabric.block.render; -import com.mojang.math.Matrix4f; -import com.mojang.math.Vector3f; -import com.mojang.math.Vector4f; import io.github.foundationgames.automobility.block.model.GeometryBuilder; import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.core.Direction; import org.jetbrains.annotations.Nullable; +import org.joml.Matrix4f; +import org.joml.Vector3f; +import org.joml.Vector4f; public class FabricGeometryBuilder implements GeometryBuilder { private final QuadEmitter quads; @@ -29,8 +29,8 @@ public GeometryBuilder vertex(float x, float y, float z, @Nullable Direction fac public GeometryBuilder vertex(float x, float y, float z, @Nullable Direction face, float nx, float ny, float nz, TextureAtlasSprite sprite, float u, float v, int color) { var pos = new Vector4f(x - 0.5f, y, z - 0.5f, 1); var tNormal = new Vector4f(nx, ny, nz, 1); - pos.transform(this.transform); - tNormal.transform(this.transform); // This is under the assumption that transform will always be a rotation + pos.mul(this.transform); + tNormal.mul(this.transform); // This is under the assumption that transform will always be a rotation var normal = new Vector3f(tNormal.x(), tNormal.y(), tNormal.z()); normal.normalize(); diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 440a2e6..bf017f4 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -29,7 +29,7 @@ "depends": { "fabricloader": ">=0.11.3", "fabric": "*", - "minecraft": "1.19.x", + "minecraft": "1.20.x", "java": ">=17" }, "suggests": { diff --git a/forge/src/main/java/io/github/foundationgames/automobility/forge/AutomobilityClientForge.java b/forge/src/main/java/io/github/foundationgames/automobility/forge/AutomobilityClientForge.java index 13e417b..13ebfe9 100644 --- a/forge/src/main/java/io/github/foundationgames/automobility/forge/AutomobilityClientForge.java +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/AutomobilityClientForge.java @@ -33,7 +33,7 @@ public static void initClient(FMLClientSetupEvent setup) { MinecraftForge.EVENT_BUS.addListener(evt -> { var player = Minecraft.getInstance().player; if (player.getVehicle() instanceof AutomobileEntity auto) { - AutomobileHud.render(evt.getPoseStack(), player, auto, evt.getPartialTick()); + AutomobileHud.render(evt.getGuiGraphics(), player, auto, evt.getPartialTick()); } }); @@ -43,7 +43,7 @@ public static void initClient(FMLClientSetupEvent setup) { @SubscribeEvent public static void registerParticleProviders(RegisterParticleProvidersEvent evt) { - evt.register(AutomobilityParticles.DRIFT_SMOKE.require(), DriftSmokeParticle.Factory::new); + evt.registerSpriteSet(AutomobilityParticles.DRIFT_SMOKE.require(), DriftSmokeParticle.Factory::new); } @SubscribeEvent diff --git a/forge/src/main/java/io/github/foundationgames/automobility/forge/AutomobilityForge.java b/forge/src/main/java/io/github/foundationgames/automobility/forge/AutomobilityForge.java index 784b8c5..7d94a95 100644 --- a/forge/src/main/java/io/github/foundationgames/automobility/forge/AutomobilityForge.java +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/AutomobilityForge.java @@ -5,6 +5,8 @@ import io.github.foundationgames.automobility.util.InitlessConstants; import io.github.foundationgames.automobility.util.RegistryQueue; import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; + import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.registries.RegisterEvent; @@ -22,15 +24,16 @@ public AutomobilityForge() { @SubscribeEvent @SuppressWarnings("deprecation") public static void registerAll(RegisterEvent evt) { - register(Registry.BLOCK, evt); - register(Registry.BLOCK_ENTITY_TYPE, evt); - register(Registry.ITEM, evt); - register(Registry.ENTITY_TYPE, evt); - register(Registry.PARTICLE_TYPE, evt); - register(Registry.SOUND_EVENT, evt); - register(Registry.MENU, evt); - register(Registry.RECIPE_TYPE, evt); - register(Registry.RECIPE_SERIALIZER, evt); + register(BuiltInRegistries.BLOCK, evt); + register(BuiltInRegistries.BLOCK_ENTITY_TYPE, evt); + register(BuiltInRegistries.ITEM, evt); + register(BuiltInRegistries.ENTITY_TYPE, evt); + register(BuiltInRegistries.PARTICLE_TYPE, evt); + register(BuiltInRegistries.SOUND_EVENT, evt); + register(BuiltInRegistries.MENU, evt); + register(BuiltInRegistries.RECIPE_TYPE, evt); + register(BuiltInRegistries.RECIPE_SERIALIZER, evt); + register(BuiltInRegistries.CREATIVE_MODE_TAB, evt); } public static void register(Registry registry, RegisterEvent evt) { diff --git a/forge/src/main/java/io/github/foundationgames/automobility/forge/ForgePlatform.java b/forge/src/main/java/io/github/foundationgames/automobility/forge/ForgePlatform.java index f2a0161..d474da5 100644 --- a/forge/src/main/java/io/github/foundationgames/automobility/forge/ForgePlatform.java +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/ForgePlatform.java @@ -16,7 +16,6 @@ import net.minecraft.client.gui.screens.inventory.MenuAccess; import net.minecraft.client.model.geom.ModelLayerLocation; import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.block.model.ItemTransforms; import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; import net.minecraft.client.renderer.blockentity.BlockEntityRenderers; @@ -35,10 +34,12 @@ import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.MobCategory; import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.flag.FeatureFlags; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; @@ -61,23 +62,22 @@ public static void init() { } @Override - public CreativeModeTab creativeTab(ResourceLocation rl, Supplier icon) { - return new CreativeModeTab(rl.getNamespace()+"."+rl.getPath()) { - @Override - public ItemStack makeIcon() { - return icon.get(); - } - }; + public CreativeModeTab creativeTab(ResourceLocation rl, Supplier icon, CreativeModeTab.DisplayItemsGenerator displayItemsGenerator) { + return CreativeModeTab.builder() + .icon(icon) + .title(Component.translatable("itemGroup." + rl.getNamespace() + "." + rl.getPath())) + .displayItems(displayItemsGenerator) + .build(); } @Override - public void builtinItemRenderer(Item item, HexCons renderer) { + public void builtinItemRenderer(Item item, HexCons renderer) { BEWLRs.add(item, renderer); } @Override public MenuType menuType(BiFunction factory) { - return new MenuType<>(factory::apply); + return new MenuType<>(factory::apply, FeatureFlags.DEFAULT_FLAGS); } @Override diff --git a/forge/src/main/java/io/github/foundationgames/automobility/forge/block/render/ForgeGeometryBuilder.java b/forge/src/main/java/io/github/foundationgames/automobility/forge/block/render/ForgeGeometryBuilder.java index d013e5b..f6c5fde 100644 --- a/forge/src/main/java/io/github/foundationgames/automobility/forge/block/render/ForgeGeometryBuilder.java +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/block/render/ForgeGeometryBuilder.java @@ -1,8 +1,5 @@ package io.github.foundationgames.automobility.forge.block.render; -import com.mojang.math.Matrix4f; -import com.mojang.math.Vector3f; -import com.mojang.math.Vector4f; import io.github.foundationgames.automobility.block.model.GeometryBuilder; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.texture.TextureAtlasSprite; @@ -10,6 +7,9 @@ import net.minecraftforge.client.model.pipeline.QuadBakingVertexConsumer; import net.minecraftforge.common.ForgeConfig; import org.jetbrains.annotations.Nullable; +import org.joml.Matrix4f; +import org.joml.Vector3f; +import org.joml.Vector4f; import java.util.List; @@ -43,8 +43,8 @@ public GeometryBuilder vertex(float x, float y, float z, @Nullable Direction fac var pos = new Vector4f(x - 0.5f, y, z - 0.5f, 1); var tNormal = new Vector4f(nx, ny, nz, 1); - pos.transform(this.transform); - tNormal.transform(this.transform); // This is under the assumption that transform will always be a rotation + pos.mul(this.transform); + tNormal.mul(this.transform); // This is under the assumption that transform will always be a rotation var normal = new Vector3f(tNormal.x(), tNormal.y(), tNormal.z()); normal.normalize(); diff --git a/forge/src/main/java/io/github/foundationgames/automobility/forge/client/BEWLRs.java b/forge/src/main/java/io/github/foundationgames/automobility/forge/client/BEWLRs.java index ccafde0..81bbb27 100644 --- a/forge/src/main/java/io/github/foundationgames/automobility/forge/client/BEWLRs.java +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/client/BEWLRs.java @@ -5,22 +5,23 @@ import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.block.model.ItemTransforms; import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.ItemStack; import java.util.HashMap; import java.util.Map; public class BEWLRs { - private static final Map> BEWLRS = new HashMap<>(); + private static final Map> BEWLRS = new HashMap<>(); - public static void add(Item item, HexCons renderer) { + public static void add(Item item, HexCons renderer) { BEWLRS.put(item, renderer); } /** * @return {@code true} to cancel the rest of the BEWLR item rendering */ - public static boolean tryRender(ItemStack stack, ItemTransforms.TransformType transform, PoseStack pose, MultiBufferSource buffers, int light, int overlay) { + public static boolean tryRender(ItemStack stack, ItemDisplayContext transform, PoseStack pose, MultiBufferSource buffers, int light, int overlay) { var item = stack.getItem(); if (BEWLRS.containsKey(item)) { BEWLRS.get(item).accept(stack, transform, pose, buffers, light, overlay); diff --git a/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/BlockEntityWithoutLevelRendererMixin.java b/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/BlockEntityWithoutLevelRendererMixin.java index 1a9578f..a0802c4 100644 --- a/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/BlockEntityWithoutLevelRendererMixin.java +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/BlockEntityWithoutLevelRendererMixin.java @@ -5,6 +5,7 @@ import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.block.model.ItemTransforms; +import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.ItemStack; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -14,7 +15,7 @@ @Mixin(BlockEntityWithoutLevelRenderer.class) public class BlockEntityWithoutLevelRendererMixin { @Inject(method = "renderByItem", at = @At("HEAD"), cancellable = true) - private void automobility$renderBEWLRS(ItemStack stack, ItemTransforms.TransformType transform, PoseStack pose, MultiBufferSource buffers, int light, int overlay, CallbackInfo ci) { + private void automobility$renderBEWLRS(ItemStack stack, ItemDisplayContext transform, PoseStack pose, MultiBufferSource buffers, int light, int overlay, CallbackInfo ci) { if (BEWLRs.tryRender(stack, transform, pose, buffers, light, overlay)) { ci.cancel(); } diff --git a/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/jsonem/CubeDefinitionAccess.java b/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/jsonem/CubeDefinitionAccess.java index 243e041..0c990c2 100644 --- a/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/jsonem/CubeDefinitionAccess.java +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/jsonem/CubeDefinitionAccess.java @@ -1,10 +1,14 @@ package io.github.foundationgames.automobility.forge.mixin.jsonem; -import com.mojang.math.Vector3f; +import java.util.Set; + import net.minecraft.client.model.geom.builders.CubeDefinition; import net.minecraft.client.model.geom.builders.CubeDeformation; import net.minecraft.client.model.geom.builders.UVPair; +import net.minecraft.core.Direction; + import org.jetbrains.annotations.Nullable; +import org.joml.Vector3f; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.gen.Invoker; @@ -33,7 +37,7 @@ public interface CubeDefinitionAccess { UVPair automobility$uvScale(); @Invoker("") - static CubeDefinition automobility$create(@Nullable String name, float textureX, float textureY, float offsetX, float offsetY, float offsetZ, float sizeX, float sizeY, float sizeZ, CubeDeformation extra, boolean mirror, float textureScaleX, float textureScaleY) { + static CubeDefinition automobility$create(@Nullable String name, float textureX, float textureY, float offsetX, float offsetY, float offsetZ, float sizeX, float sizeY, float sizeZ, CubeDeformation extra, boolean mirror, float textureScaleX, float textureScaleY, Set p_273201_) { throw new AssertionError(); } } diff --git a/forge/src/main/java/io/github/foundationgames/automobility/forge/vendored/jsonem/serialization/JsonEMCodecs.java b/forge/src/main/java/io/github/foundationgames/automobility/forge/vendored/jsonem/serialization/JsonEMCodecs.java index f05de0c..79c7eeb 100644 --- a/forge/src/main/java/io/github/foundationgames/automobility/forge/vendored/jsonem/serialization/JsonEMCodecs.java +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/vendored/jsonem/serialization/JsonEMCodecs.java @@ -1,7 +1,6 @@ package io.github.foundationgames.automobility.forge.vendored.jsonem.serialization; import com.google.common.collect.ImmutableList; -import com.mojang.math.Vector3f; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import io.github.foundationgames.automobility.forge.mixin.jsonem.CubeDefinitionAccess; @@ -10,6 +9,9 @@ import io.github.foundationgames.automobility.forge.mixin.jsonem.MaterialDefinitionAccess; import io.github.foundationgames.automobility.forge.mixin.jsonem.PartDefinitionAccess; import io.github.foundationgames.automobility.forge.vendored.jsonem.util.UVPairComparable; +import org.joml.Vector2f; +import org.joml.Vector3f; + import net.minecraft.Util; import net.minecraft.client.model.geom.PartPose; import net.minecraft.client.model.geom.builders.CubeDefinition; @@ -19,11 +21,21 @@ import net.minecraft.client.model.geom.builders.MeshDefinition; import net.minecraft.client.model.geom.builders.PartDefinition; import net.minecraft.client.model.geom.builders.UVPair; +import net.minecraft.core.Direction; +import java.util.EnumSet; import java.util.HashMap; import java.util.Optional; +import java.util.Set; public class JsonEMCodecs { + private static final Set ALL_DIRECTIONS = EnumSet.allOf(Direction.class); + + public static final Codec VECTOR3F = Codec.FLOAT.listOf().comapFlatMap((vec) -> + Util.fixedSize(vec, 3).map(coords -> new Vector3f(coords.get(0), coords.get(1), coords.get(2))), + (vec) -> ImmutableList.of(vec.x, vec.y, vec.z) + ); + public static final Codec MATERIAL_DEFINITION = RecordCodecBuilder.create((instance) -> instance.group( Codec.INT.fieldOf("width").forGetter(obj -> ((MaterialDefinitionAccess) obj).automobility$width()), @@ -33,12 +45,12 @@ public class JsonEMCodecs { public static final Codec PART_POSE = RecordCodecBuilder.create((instance) -> instance.group( - Vector3f.CODEC.optionalFieldOf("origin", Vector3f.ZERO).forGetter(obj -> new Vector3f(obj.x, obj.y, obj.z)), - Vector3f.CODEC.optionalFieldOf("rotation", Vector3f.ZERO).forGetter(obj -> new Vector3f(obj.xRot, obj.yRot, obj.zRot)) + VECTOR3F.optionalFieldOf("origin", new Vector3f()).forGetter(obj -> new Vector3f(obj.x, obj.y, obj.z)), + VECTOR3F.optionalFieldOf("rotation", new Vector3f()).forGetter(obj -> new Vector3f(obj.xRot, obj.yRot, obj.zRot)) ).apply(instance, (origin, rot) -> PartPose.offsetAndRotation(origin.x(), origin.y(), origin.z(), rot.x(), rot.y(), rot.z())) ); - public static final Codec CUBE_DEFORMATION = Vector3f.CODEC.xmap( + public static final Codec CUBE_DEFORMATION = VECTOR3F.xmap( vec -> new CubeDeformation(vec.x(), vec.y(), vec.z()), dil -> new Vector3f( ((CubeDeformationAccess) dil).automobility$radiusX(), @@ -52,7 +64,7 @@ public class JsonEMCodecs { ); private static CubeDefinition createCuboidData(Optional name, Vector3f offset, Vector3f dimensions, CubeDeformation dilation, boolean mirror, UVPair uv, UVPair uvSize) { - return CubeDefinitionAccess.automobility$create(name.orElse(null), uv.u(), uv.v(), offset.x(), offset.y(), offset.z(), dimensions.x(), dimensions.y(), dimensions.z(), dilation, mirror, uvSize.u(), uvSize.v()); + return CubeDefinitionAccess.automobility$create(name.orElse(null), uv.u(), uv.v(), offset.x(), offset.y(), offset.z(), dimensions.x(), dimensions.y(), dimensions.z(), dilation, mirror, uvSize.u(), uvSize.v(), ALL_DIRECTIONS); } private static final UVPair DEFAULT_UV_SCALE = new UVPairComparable(1.0f, 1.0f); @@ -60,8 +72,8 @@ private static CubeDefinition createCuboidData(Optional name, Vector3f o public static final Codec CUBE_DEFINITION = RecordCodecBuilder.create((instance) -> instance.group( Codec.STRING.optionalFieldOf("name").forGetter(obj -> Optional.ofNullable(((CubeDefinitionAccess)(Object)obj).automobility$name())), - Vector3f.CODEC.fieldOf("offset").forGetter(obj -> ((CubeDefinitionAccess)(Object)obj).automobility$offset()), - Vector3f.CODEC.fieldOf("dimensions").forGetter(obj -> ((CubeDefinitionAccess)(Object)obj).automobility$dimensions()), + VECTOR3F.fieldOf("offset").forGetter(obj -> ((CubeDefinitionAccess)(Object)obj).automobility$offset()), + VECTOR3F.fieldOf("dimensions").forGetter(obj -> ((CubeDefinitionAccess)(Object)obj).automobility$dimensions()), CUBE_DEFORMATION.optionalFieldOf("dilation", CubeDeformation.NONE).forGetter(obj -> ((CubeDefinitionAccess)(Object)obj).automobility$dilation()), Codec.BOOL.optionalFieldOf("mirror", false).forGetter(obj -> ((CubeDefinitionAccess)(Object)obj).automobility$mirror()), UV_PAIR.fieldOf("uv").forGetter(obj -> ((CubeDefinitionAccess)(Object)obj).automobility$uv()), diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index d8cf8bd..6eb125a 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -22,6 +22,6 @@ side="BOTH" [[dependencies.automobility]] modId="minecraft" mandatory=true -versionRange="[1.19.2,1.20)" +versionRange="[1.20,1.21)" ordering="NONE" side="BOTH" diff --git a/gradle.properties b/gradle.properties index 453b51a..43f74e8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,18 +1,18 @@ org.gradle.jvmargs=-Xmx1G -minecraft_version=1.19.2 -yarn_mappings=1.19.2+build.4 -fabric_version=0.14.9 -forge_version=43.1.30 +minecraft_version=1.20.1 +yarn_mappings=1.20.1+build.1 +fabric_version=0.14.21 +forge_version=47.0.19 # Fabric Dependencies -fabric_api_version=0.60.0+1.19.2 -midnightcontrols_version=1.5.0+1.19 -midnightlib_version=0.5.2 -spruceui_version=4.0.0+1.19 +fabric_api_version=0.84.0+1.20.1 +midnightcontrols_version=1.8.2+1.20 +midnightlib_version=1.4.1 +spruceui_version=5.0.0+1.20 myron_version=1.6.5+22w14a -arrp_version=0.6.2 -jsonem_version=0.1.2+1.19 +arrp_version=0.6.7 +jsonem_version=0.1.3+1.20.1 mod_version = 0.4.1 maven_group = io.github.foundationgames