diff --git a/.gitignore b/.gitignore index 09cd281..965ea51 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,15 @@ # gradle .gradle/ +common/.gradle/ +fabric/.gradle/ +forge/.gradle/ + build/ +common/build/ +fabric/build/ +forge/build/ + out/ classes/ @@ -28,6 +36,7 @@ bin/ *.DS_Store -# fabric - run/ +common/run/ +fabric/run/ +forge/run/ diff --git a/README.md b/README.md index 122a0e8..10f0878 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,21 @@ ![Automobility](./md/banner.png) ### A Minecraft mod adding customizable vehicles. +**Automobility is currently in BETA!**
+The mod isn't feature-complete, and any feature requests would be greatly appreciated. Discuss features on the mod's GitHub Discussions page, or in the [Discord](https://discord.gg/7Aw3y4RtY9). -## Available for Fabric/Quilt +## Available for Fabric/Quilt and Forge - Requires **[Fabric API](https://modrinth.com/mod/fabric-api)** (Fabric) or **[QSL](https://modrinth.com/mod/qsl)** (Quilt) +- No additional mods required for Forge -**Support for Forge or old versions is NOT PLANNED.** +**Currently maintained for version 1.19.2, older versions are retired.** ## Getting Started -- **Recipes:** Crafting recipes can be viewed using [**EMI**](https://www.curseforge.com/minecraft/mc-mods/emi). +- **Recipes:** Crafting recipes can be viewed using [**EMI**](https://www.curseforge.com/minecraft/mc-mods/emi) (Fabric/Quilt) or [**JEI**](https://www.curseforge.com/minecraft/mc-mods/jei) (Forge). - **Automobile Parts:** Craft an Auto Mechanic Table. Use the GUI to craft the frame, engine, and wheels for your automobile. You can optionally craft an attachment. -- **Building your Automobile:** Craft an Automobile Assembler, as well as a Crowbar. Place parts on the assembler until the vehicle is complete. Use a crowbar to destroy the vehicle. After building, add your attachments. +- **Building your Automobile:** Craft an Automobile Assembler, as well as a Crowbar. Place parts on the assembler until the vehicle is complete. Use a crowbar to destroy the vehicle. +- **Enhancing your Automobile:** Use your Auto Mechanic Table to craft attachments, which can be placed on your Automobile to add exciting functionality or utility. +- **Building:** You can use Slopes, Dash Panels, Off-Road tiles and more to build roads, racetracks, or obstacle courses. ![Automobile Construction](./md/construction.png) ![Automobile Types](./md/parking.png) @@ -19,13 +24,13 @@ - W - Accelerate - S - Brake/Reverse/Burnout - A/D - Steer left/right -- Space - Drift +- Space - Drift/Deploy -**Controller Support:** when using [MidnightControls](https://www.curseforge.com/minecraft/mc-mods/midnightcontrols), you will be able to control automobiles with the following default controls: +**Controller Support (*Fabric and Quilt Exclusive*):** when using [MidnightControls](https://www.curseforge.com/minecraft/mc-mods/midnightcontrols), you will be able to control automobiles with the following default controls: - A - Accelerate - B - Brake/Reverse - LStick - Steer left/right -- RTrigger - Drift +- RTrigger - Drift/Deploy ![Driving](./md/driving.png) diff --git a/build.gradle b/build.gradle index 5e1b84b..ab1c348 100644 --- a/build.gradle +++ b/build.gradle @@ -1,110 +1,30 @@ -plugins { - id 'fabric-loom' version '0.11-SNAPSHOT' - id 'maven-publish' -} - -sourceCompatibility = JavaVersion.VERSION_17 -targetCompatibility = JavaVersion.VERSION_17 - -archivesBaseName = project.archives_base_name -version = project.mod_version -group = project.maven_group - -repositories { - 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://api.modrinth.com/maven" } - - maven { url = "https://jitpack.io" } -} - -dependencies { - // To change the versions see the gradle.properties file - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" +subprojects { + apply plugin: 'java' - // Fabric API. This is technically optional, but you probably want it anyway. - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 - // Controller Support - modImplementation "dev.lambdaurora:spruceui:${project.spruceui_version}" - modImplementation "maven.modrinth:midnightlib:${project.midnightlib_version}" - modImplementation "maven.modrinth:midnightcontrols:${project.midnightcontrols_version}" - api('org.aperlambda:lambdajcommon:1.8.1') { - exclude group: 'com.google.code.gson' - exclude group: 'com.google.guava' - } - - // OBJ loader TODO: Update - // modImplementation "dev.monarkhes:myron:${project.myron_version}" - // include "dev.monarkhes:myron:${project.myron_version}" - - // Json't - modImplementation "net.devtech:arrp:${project.arrp_version}" - include "net.devtech:arrp:${project.arrp_version}" - - // Json entity models - modImplementation "maven.modrinth:jsonem:${project.jsonem_version}" - include "maven.modrinth:jsonem:${project.jsonem_version}" - - // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. - // You may need to force-disable transitiveness on them. -} + archivesBaseName = project.archives_base_name + group = project.maven_group -processResources { - inputs.property "version", project.version + java.toolchain.languageVersion = JavaLanguageVersion.of(17) + java.withSourcesJar() + java.withJavadocJar() - filesMatching("fabric.mod.json") { - expand "version": project.version + jar { + from("LICENSE") { + rename { "${it}_${project.archivesBaseName}"} + } } -} - -tasks.withType(JavaCompile).configureEach { - // ensure that the encoding is set to UTF-8, no matter what the system default is - // this fixes some edge cases with special characters not displaying correctly - // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html - // If Javadoc is generated, this must be specified in that task too. - it.options.encoding = "UTF-8" - - it.options.release = 17 -} - -java { - // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task - // if it is present. - // If you remove this line, sources will not be generated. - withSourcesJar() -} -jar { - from("LICENSE") { - rename { "${it}_${project.archivesBaseName}"} - } -} + repositories { + mavenCentral() -// configure the maven publication -publishing { - publications { - mavenJava(MavenPublication) { - // add all the jars that should be included when publishing to maven - artifact(remapJar) { - builtBy remapJar - } - artifact(sourcesJar) { - builtBy remapSourcesJar - } - } + maven { url = 'https://repo.spongepowered.org/repository/maven-public/' } } - // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. - repositories { - // Add repositories to publish to here. - // Notice: This block does NOT have the same function as the block in the top level. - // The repositories here will be used for publishing your artifact, not for - // retrieving dependencies. + tasks.withType(JavaCompile).configureEach { + it.options.encoding = "UTF-8" + it.options.release = 17 } } diff --git a/common/build.gradle b/common/build.gradle new file mode 100644 index 0000000..de2c8d0 --- /dev/null +++ b/common/build.gradle @@ -0,0 +1,46 @@ +plugins { + id 'java' + id 'org.spongepowered.gradle.vanilla' version '0.2.1-SNAPSHOT' + id 'maven-publish' +} + +version = "${project.mod_version}+${project.minecraft_version}-common" as Object + +minecraft { + version(project.minecraft_version) + runs { + client('(Common) Client') { + workingDirectory(this.file("run")) + } + server('(Common) Server') { + workingDirectory(this.file("run")) + } + } +} + +dependencies { + compileOnly group:'org.spongepowered', name:'mixin', version:'0.8.5' + implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.1' +} + +processResources { + def properties = project.properties.clone() + + filesMatching('pack.mcmeta') { + expand properties as Map + } +} + +publishing { + publications { + mavenJava(MavenPublication) { + from components.java + groupId project.group + artifactId project.archivesBaseName + version project.version + } + } + + repositories { + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/Automobility.java b/common/src/main/java/io/github/foundationgames/automobility/Automobility.java new file mode 100644 index 0000000..484b926 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/Automobility.java @@ -0,0 +1,60 @@ +package io.github.foundationgames.automobility; + +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.particle.AutomobilityParticles; +import io.github.foundationgames.automobility.platform.Platform; +import io.github.foundationgames.automobility.recipe.AutoMechanicTableRecipe; +import io.github.foundationgames.automobility.recipe.AutoMechanicTableRecipeSerializer; +import io.github.foundationgames.automobility.screen.AutoMechanicTableScreenHandler; +import io.github.foundationgames.automobility.screen.SingleSlotScreenHandler; +import io.github.foundationgames.automobility.sound.AutomobilitySounds; +import io.github.foundationgames.automobility.util.AUtils; +import io.github.foundationgames.automobility.util.Eventual; +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.resources.ResourceLocation; +import net.minecraft.tags.TagKey; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.level.block.Block; + +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 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 Eventual> AUTO_MECHANIC_SCREEN = + RegistryQueue.register(Registry.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)); + + public static void init() { + AutomobilitySounds.init(); + AutomobilityBlocks.init(); + AutomobilityItems.init(); + AutomobilityEntities.init(); + AutomobilityParticles.init(); + initOther(); + + CommonPackets.init(); + } + + public static void initOther() { + RegistryQueue.register(Registry.RECIPE_TYPE, AutoMechanicTableRecipe.ID, () -> AutoMechanicTableRecipe.TYPE); + RegistryQueue.register(Registry.RECIPE_SERIALIZER, AutoMechanicTableRecipe.ID, () -> AutoMechanicTableRecipeSerializer.INSTANCE); + } + + public static ResourceLocation rl(String path) { + return new ResourceLocation(MOD_ID, path); + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/AutomobilityClient.java b/common/src/main/java/io/github/foundationgames/automobility/AutomobilityClient.java new file mode 100644 index 0000000..88b8c65 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/AutomobilityClient.java @@ -0,0 +1,190 @@ +package io.github.foundationgames.automobility; + +import io.github.foundationgames.automobility.automobile.AutomobileComponent; +import io.github.foundationgames.automobility.automobile.AutomobileData; +import io.github.foundationgames.automobility.automobile.render.AutomobileModels; +import io.github.foundationgames.automobility.automobile.render.AutomobileRenderer; +import io.github.foundationgames.automobility.automobile.render.ExhaustFumesModel; +import io.github.foundationgames.automobility.automobile.render.SkidEffectModel; +import io.github.foundationgames.automobility.automobile.render.attachment.front.HarvesterFrontAttachmentModel; +import io.github.foundationgames.automobility.automobile.render.attachment.front.MobControllerFrontAttachmentModel; +import io.github.foundationgames.automobility.automobile.render.attachment.rear.BannerPostRearAttachmentModel; +import io.github.foundationgames.automobility.automobile.render.attachment.rear.BlockRearAttachmentModel; +import io.github.foundationgames.automobility.automobile.render.attachment.rear.ChestRearAttachmentModel; +import io.github.foundationgames.automobility.automobile.render.attachment.rear.GrindstoneRearAttachmentModel; +import io.github.foundationgames.automobility.automobile.render.attachment.rear.PassengerSeatRearAttachmentModel; +import io.github.foundationgames.automobility.automobile.render.attachment.rear.PlowRearAttachmentModel; +import io.github.foundationgames.automobility.automobile.render.attachment.rear.StonecutterRearAttachmentModel; +import io.github.foundationgames.automobility.automobile.render.engine.CopperEngineModel; +import io.github.foundationgames.automobility.automobile.render.engine.CreativeEngineModel; +import io.github.foundationgames.automobility.automobile.render.engine.DiamondEngineModel; +import io.github.foundationgames.automobility.automobile.render.engine.GoldEngineModel; +import io.github.foundationgames.automobility.automobile.render.engine.IronEngineModel; +import io.github.foundationgames.automobility.automobile.render.engine.StoneEngineModel; +import io.github.foundationgames.automobility.automobile.render.frame.CARRFrameModel; +import io.github.foundationgames.automobility.automobile.render.frame.MotorcarFrameModel; +import io.github.foundationgames.automobility.automobile.render.frame.PineappleFrameModel; +import io.github.foundationgames.automobility.automobile.render.frame.RickshawFrameModel; +import io.github.foundationgames.automobility.automobile.render.frame.ShoppingCartFrameModel; +import io.github.foundationgames.automobility.automobile.render.frame.StandardFrameModel; +import io.github.foundationgames.automobility.automobile.render.frame.TractorFrameModel; +import io.github.foundationgames.automobility.automobile.render.item.ItemRenderableAutomobile; +import io.github.foundationgames.automobility.automobile.render.wheel.CarriageWheelModel; +import io.github.foundationgames.automobility.automobile.render.wheel.OffRoadWheelModel; +import io.github.foundationgames.automobility.automobile.render.wheel.StandardWheelModel; +import io.github.foundationgames.automobility.automobile.render.wheel.SteelWheelModel; +import io.github.foundationgames.automobility.automobile.render.wheel.TractorWheelModel; +import io.github.foundationgames.automobility.block.AutomobilityBlocks; +import io.github.foundationgames.automobility.block.entity.render.AutomobileAssemblerBlockEntityRenderer; +import io.github.foundationgames.automobility.entity.AutomobileEntity; +import io.github.foundationgames.automobility.entity.AutomobilityEntities; +import io.github.foundationgames.automobility.entity.render.AutomobileEntityRenderer; +import io.github.foundationgames.automobility.item.AutomobileComponentItem; +import io.github.foundationgames.automobility.item.AutomobilityItems; +import io.github.foundationgames.automobility.platform.Platform; +import io.github.foundationgames.automobility.screen.AutoMechanicTableScreen; +import io.github.foundationgames.automobility.screen.SingleSlotScreen; +import io.github.foundationgames.automobility.sound.AutomobileSoundInstance; +import io.github.foundationgames.automobility.util.FloatFunc; +import io.github.foundationgames.automobility.util.network.ClientPackets; +import net.minecraft.client.Minecraft; +import net.minecraft.client.color.block.BlockColor; +import net.minecraft.client.color.item.ItemColor; +import net.minecraft.client.model.Model; +import net.minecraft.client.renderer.BiomeColors; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.GrassColor; + +import java.util.function.Function; + +public class AutomobilityClient { + public static final BlockColor GRASS_COLOR = (state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getAverageGrassColor(world, pos) : GrassColor.get(0.5D, 1.0D); + public static final ItemColor GRASS_ITEM_COLOR = (stack, tintIndex) -> GrassColor.get(0.5D, 1.0D); + + public static void init() { + AutomobileModels.init(); + + initBlocks(); + initItems(); + initEntities(); + ClientPackets.initClient(); + + Platform.get().registerMenuScreen(Automobility.AUTO_MECHANIC_SCREEN.require(), AutoMechanicTableScreen::new); + Platform.get().registerMenuScreen(Automobility.SINGLE_SLOT_SCREEN.require(), SingleSlotScreen::new); + } + + public static void initBlocks() { + Platform.get().blockEntityRenderer(AutomobilityBlocks.AUTOMOBILE_ASSEMBLER_ENTITY.require(), AutomobileAssemblerBlockEntityRenderer::new); + } + + public static void initItems() { + var automobileReader = new AutomobileData(); + var itemAutomobile = new ItemRenderableAutomobile(automobileReader); + + Platform.get().builtinItemRenderer(AutomobilityItems.AUTOMOBILE.require(), (stack, type, pose, buffers, light, overlay) -> { + automobileReader.read(stack.getOrCreateTagElement("Automobile")); + float wheelDist = automobileReader.getFrame().model().lengthPx() / 16; + float scale = 1; + scale /= wheelDist * 0.77f; + pose.scale(scale, scale, scale); + AutomobileRenderer.render(pose, buffers, light, overlay, Minecraft.getInstance().getFrameTime(), itemAutomobile); + }); + componentItemRenderer(AutomobilityItems.AUTOMOBILE_FRAME.require(), + t -> AutomobileModels.getModel(t.model().modelId()), + t -> t.model().texture(), t -> 1 / ((t.model().lengthPx() / 16) * 0.77f) + ); + componentItemRenderer(AutomobilityItems.AUTOMOBILE_WHEEL.require(), + t -> AutomobileModels.getModel(t.model().modelId()), + t -> t.model().texture(), t -> 6 / t.model().radius() + ); + componentItemRenderer(AutomobilityItems.AUTOMOBILE_ENGINE.require(), + t -> AutomobileModels.getModel(t.model().modelId()), + t -> t.model().texture(), t -> 1 + ); + componentItemRenderer(AutomobilityItems.REAR_ATTACHMENT.require(), + t -> AutomobileModels.getModel(t.model().modelId()), + t -> t.model().texture(), t -> 1 + ); + componentItemRenderer(AutomobilityItems.FRONT_ATTACHMENT.require(), + t -> AutomobileModels.getModel(t.model().modelId()), + t -> t.model().texture(), t -> t.model().scale() + ); + } + + public static > void componentItemRenderer(AutomobileComponentItem item, Function modelProvider, Function textureProvider, FloatFunc scaleProvider) { + Platform.get().builtinItemRenderer(item, (stack, mode, matrices, vertexConsumers, light, overlay) -> { + var component = item.getComponent(stack); + if (item.isVisible(component)) { + var model = modelProvider.apply(component); + float scale = scaleProvider.apply(component); + matrices.translate(0.5, 0, 0.5); + matrices.scale(scale, -scale, -scale); + model.renderToBuffer(matrices, vertexConsumers.getBuffer(model.renderType(textureProvider.apply(component))), light, overlay, 1, 1, 1, 1); + } + }); + } + + public static void initEntities() { + var libs = Platform.get(); + + libs.entityRenderer(AutomobilityEntities.AUTOMOBILE.require(), AutomobileEntityRenderer::new); + + libs.modelLayer(StandardFrameModel.MODEL_LAYER); + libs.modelLayer(TractorFrameModel.MODEL_LAYER); + libs.modelLayer(MotorcarFrameModel.MODEL_LAYER); + libs.modelLayer(ShoppingCartFrameModel.MODEL_LAYER); + libs.modelLayer(CARRFrameModel.MODEL_LAYER); + libs.modelLayer(PineappleFrameModel.MODEL_LAYER); + libs.modelLayer(RickshawFrameModel.MODEL_LAYER); + + libs.modelLayer(StandardWheelModel.MODEL_LAYER); + libs.modelLayer(OffRoadWheelModel.MODEL_LAYER); + libs.modelLayer(TractorWheelModel.MODEL_LAYER); + libs.modelLayer(CarriageWheelModel.MODEL_LAYER); + libs.modelLayer(SteelWheelModel.MODEL_LAYER); + + libs.modelLayer(StoneEngineModel.MODEL_LAYER); + libs.modelLayer(IronEngineModel.MODEL_LAYER); + libs.modelLayer(CopperEngineModel.MODEL_LAYER); + libs.modelLayer(GoldEngineModel.MODEL_LAYER); + libs.modelLayer(DiamondEngineModel.MODEL_LAYER); + libs.modelLayer(CreativeEngineModel.MODEL_LAYER); + + libs.modelLayer(PassengerSeatRearAttachmentModel.MODEL_LAYER); + libs.modelLayer(BlockRearAttachmentModel.MODEL_LAYER); + libs.modelLayer(GrindstoneRearAttachmentModel.MODEL_LAYER); + libs.modelLayer(StonecutterRearAttachmentModel.MODEL_LAYER); + libs.modelLayer(ChestRearAttachmentModel.MODEL_LAYER); + libs.modelLayer(BannerPostRearAttachmentModel.MODEL_LAYER); + libs.modelLayer(PlowRearAttachmentModel.MODEL_LAYER); + + libs.modelLayer(MobControllerFrontAttachmentModel.MODEL_LAYER); + libs.modelLayer(HarvesterFrontAttachmentModel.MODEL_LAYER); + + libs.modelLayer(SkidEffectModel.MODEL_LAYER); + libs.modelLayer(ExhaustFumesModel.MODEL_LAYER); + + AutomobileEntity.engineSound = auto -> { + if (auto.getEngine().isEmpty()) { + return; + } + + var client = Minecraft.getInstance(); + client.getSoundManager().play(new AutomobileSoundInstance.EngineSound(client, auto)); + }; + AutomobileEntity.skidSound = auto -> { + var client = Minecraft.getInstance(); + client.getSoundManager().play(new AutomobileSoundInstance.SkiddingSound(client, auto)); + }; + } + + public static double modifyBoostFov(Minecraft client, double old, float tickDelta) { + var player = client.player; + + if (player.getVehicle() instanceof AutomobileEntity auto) { + return old + ((Math.sqrt(auto.getBoostSpeed(tickDelta)) * 18) * client.options.fovEffectScale().get()); + } + + return old; + } +} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileComponent.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileComponent.java similarity index 100% rename from src/main/java/io/github/foundationgames/automobility/automobile/AutomobileComponent.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileComponent.java diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileData.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileData.java similarity index 57% rename from src/main/java/io/github/foundationgames/automobility/automobile/AutomobileData.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileData.java index be60472..0b70868 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileData.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileData.java @@ -1,7 +1,7 @@ package io.github.foundationgames.automobility.automobile; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.util.Identifier; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; public class AutomobileData { private AutomobileFrame frame; @@ -12,10 +12,10 @@ public class AutomobileData { public AutomobileData() { } - public void read(NbtCompound nbt) { - frame = AutomobileFrame.REGISTRY.getOrDefault(Identifier.tryParse(nbt.getString("frame"))); - wheel = AutomobileWheel.REGISTRY.getOrDefault(Identifier.tryParse(nbt.getString("wheels"))); - engine = AutomobileEngine.REGISTRY.getOrDefault(Identifier.tryParse(nbt.getString("engine"))); + public void read(CompoundTag nbt) { + frame = AutomobileFrame.REGISTRY.getOrDefault(ResourceLocation.tryParse(nbt.getString("frame"))); + wheel = AutomobileWheel.REGISTRY.getOrDefault(ResourceLocation.tryParse(nbt.getString("wheels"))); + engine = AutomobileEngine.REGISTRY.getOrDefault(ResourceLocation.tryParse(nbt.getString("engine"))); prefab = nbt.contains("isPrefab") && nbt.getBoolean("isPrefab"); } diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileEngine.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileEngine.java similarity index 57% rename from src/main/java/io/github/foundationgames/automobility/automobile/AutomobileEngine.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileEngine.java index 30f8c92..6d82614 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileEngine.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileEngine.java @@ -1,52 +1,47 @@ package io.github.foundationgames.automobility.automobile; import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.render.AutomobilityModels; import io.github.foundationgames.automobility.sound.AutomobilitySounds; import io.github.foundationgames.automobility.util.SimpleMapContentRegistry; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.model.Model; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.sound.SoundEvent; -import net.minecraft.sound.SoundEvents; -import net.minecraft.util.Identifier; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundEvents; import java.util.function.Consumer; -import java.util.function.Function; +import java.util.function.Supplier; public record AutomobileEngine( - Identifier id, + ResourceLocation id, float torque, float speed, - SoundEvent sound, + Supplier sound, EngineModel model ) implements AutomobileComponent { - public static final Identifier ID = Automobility.id("engine"); + public static final ResourceLocation ID = Automobility.rl("engine"); public static final SimpleMapContentRegistry REGISTRY = new SimpleMapContentRegistry<>(); public static final AutomobileEngine EMPTY = REGISTRY.register( - new AutomobileEngine(Automobility.id("empty"), 0.01f, 0.01f, - SoundEvents.ENTITY_MINECART_INSIDE, - new EngineModel(new Identifier("empty"), Automobility.id("empty")) + new AutomobileEngine(Automobility.rl("empty"), 0.01f, 0.01f, + () -> SoundEvents.MINECART_INSIDE, + new EngineModel(new ResourceLocation("empty"), Automobility.rl("empty")) ) ); public static final AutomobileEngine STONE = REGISTRY.register( - new AutomobileEngine(Automobility.id("stone"), 0.3f, 0.58f, - AutomobilitySounds.STONE_ENGINE, + new AutomobileEngine(Automobility.rl("stone"), 0.3f, 0.58f, + AutomobilitySounds.STONE_ENGINE::require, new EngineModel( - Automobility.id("textures/entity/automobile/engine/stone.png"), Automobility.id("engine_stone"), + Automobility.rl("textures/entity/automobile/engine/stone.png"), Automobility.rl("engine_stone"), new AutomobileEngine.ExhaustPos(0, 7f, -8.3f, 50, 0) ) ) ); public static final AutomobileEngine IRON = REGISTRY.register( - new AutomobileEngine(Automobility.id("iron"), 0.5f, 0.75f, - AutomobilitySounds.IRON_ENGINE, + new AutomobileEngine(Automobility.rl("iron"), 0.5f, 0.75f, + AutomobilitySounds.IRON_ENGINE::require, new EngineModel( - Automobility.id("textures/entity/automobile/engine/iron.png"), Automobility.id("engine_iron"), + Automobility.rl("textures/entity/automobile/engine/iron.png"), Automobility.rl("engine_iron"), new AutomobileEngine.ExhaustPos(-3.5f, 5.4f, -8, 26, 0), new AutomobileEngine.ExhaustPos(3.5f, 5.4f, -8, 26, 0) ) @@ -54,20 +49,20 @@ public record AutomobileEngine( ); public static final AutomobileEngine COPPER = REGISTRY.register( - new AutomobileEngine(Automobility.id("copper"), 0.375f, 0.68f, - AutomobilitySounds.COPPER_ENGINE, + new AutomobileEngine(Automobility.rl("copper"), 0.375f, 0.68f, + AutomobilitySounds.COPPER_ENGINE::require, new EngineModel( - Automobility.id("textures/entity/automobile/engine/copper.png"), Automobility.id("engine_copper"), + Automobility.rl("textures/entity/automobile/engine/copper.png"), Automobility.rl("engine_copper"), new AutomobileEngine.ExhaustPos(2, 1.625f, -8.95f, 26, 0) ) ) ); public static final AutomobileEngine GOLD = REGISTRY.register( - new AutomobileEngine(Automobility.id("gold"), 0.8f, 0.75f, - AutomobilitySounds.GOLD_ENGINE, + new AutomobileEngine(Automobility.rl("gold"), 0.8f, 0.75f, + AutomobilitySounds.GOLD_ENGINE::require, new EngineModel( - Automobility.id("textures/entity/automobile/engine/gold.png"), Automobility.id("engine_gold"), + Automobility.rl("textures/entity/automobile/engine/gold.png"), Automobility.rl("engine_gold"), new AutomobileEngine.ExhaustPos(4, 9.3f, -7.75f, 26, 0), new AutomobileEngine.ExhaustPos(-4, 9.3f, -7.75f, 26, 0) ) @@ -75,10 +70,10 @@ public record AutomobileEngine( ); public static final AutomobileEngine DIAMOND = REGISTRY.register( - new AutomobileEngine(Automobility.id("diamond"), 0.95f, 0.85f, - AutomobilitySounds.DIAMOND_ENGINE, + new AutomobileEngine(Automobility.rl("diamond"), 0.95f, 0.85f, + AutomobilitySounds.DIAMOND_ENGINE::require, new EngineModel( - Automobility.id("textures/entity/automobile/engine/diamond.png"), Automobility.id("engine_diamond"), + Automobility.rl("textures/entity/automobile/engine/diamond.png"), Automobility.rl("engine_diamond"), new AutomobileEngine.ExhaustPos(3, 3.8f, -7.6f, 40, 0), new AutomobileEngine.ExhaustPos(-3, 3.8f, -7.6f, 40, 0), new AutomobileEngine.ExhaustPos(4, 7.075f, -4.95f, 40, 0), @@ -88,10 +83,10 @@ public record AutomobileEngine( ); public static final AutomobileEngine CREATIVE = REGISTRY.register( - new AutomobileEngine(Automobility.id("creative"), 1f, 1f, - AutomobilitySounds.CREATIVE_ENGINE, + new AutomobileEngine(Automobility.rl("creative"), 1f, 1f, + AutomobilitySounds.CREATIVE_ENGINE::require, new EngineModel( - Automobility.id("textures/entity/automobile/engine/creative.png"), Automobility.id("engine_creative"), + Automobility.rl("textures/entity/automobile/engine/creative.png"), Automobility.rl("engine_creative"), new AutomobileEngine.ExhaustPos(0, 7, -7, 90, 0) ) ) @@ -106,7 +101,7 @@ public boolean isEmpty() { } @Override - public Identifier containerId() { + public ResourceLocation containerId() { return ID; } @@ -117,7 +112,7 @@ public void forEachStat(Consumer> action) { } @Override - public Identifier getId() { + public ResourceLocation getId() { return this.id; } @@ -126,15 +121,10 @@ public String getTranslationKey() { } public static record EngineModel( - Identifier texture, - Identifier modelId, + ResourceLocation texture, + ResourceLocation modelId, ExhaustPos ... exhausts - ) { - @Environment(EnvType.CLIENT) - public Function model() { - return AutomobilityModels.MODELS.get(modelId); - } - } + ) {} public static record ExhaustPos( float x, float y, float z, diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileFrame.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileFrame.java similarity index 80% rename from src/main/java/io/github/foundationgames/automobility/automobile/AutomobileFrame.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileFrame.java index 2dfaf8e..b9d60d6 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileFrame.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileFrame.java @@ -1,32 +1,26 @@ package io.github.foundationgames.automobility.automobile; import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.render.AutomobilityModels; import io.github.foundationgames.automobility.util.SimpleMapContentRegistry; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.model.Model; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.util.Identifier; +import net.minecraft.resources.ResourceLocation; import java.util.function.Consumer; -import java.util.function.Function; public record AutomobileFrame( - Identifier id, + ResourceLocation id, float weight, FrameModel model ) implements AutomobileComponent { - public static final Identifier ID = Automobility.id("frame"); + public static final ResourceLocation ID = Automobility.rl("frame"); public static final SimpleMapContentRegistry REGISTRY = new SimpleMapContentRegistry<>(); public static final AutomobileFrame EMPTY = REGISTRY.register( new AutomobileFrame( - Automobility.id("empty"), + Automobility.rl("empty"), 0.25f, new FrameModel( - new Identifier("empty"), - Automobility.id("empty"), + new ResourceLocation("empty"), + Automobility.rl("empty"), WheelBase.basic(16, 16), 16, 8, 8, 4, 8, 8 ) @@ -68,11 +62,11 @@ public record AutomobileFrame( public static final AutomobileFrame SHOPPING_CART = REGISTRY.register( new AutomobileFrame( - Automobility.id("shopping_cart"), + Automobility.rl("shopping_cart"), 0.25f, new FrameModel( - Automobility.id("textures/entity/automobile/frame/shopping_cart.png"), - Automobility.id("frame_shopping_cart"), + Automobility.rl("textures/entity/automobile/frame/shopping_cart.png"), + Automobility.rl("frame_shopping_cart"), WheelBase.basic(17, 12.05f), 25, 11, @@ -86,11 +80,11 @@ public record AutomobileFrame( public static final AutomobileFrame C_ARR = REGISTRY.register( new AutomobileFrame( - Automobility.id("c_arr"), + Automobility.rl("c_arr"), 0.85f, new FrameModel( - Automobility.id("textures/entity/automobile/frame/c_arr.png"), - Automobility.id("frame_c_arr"), + Automobility.rl("textures/entity/automobile/frame/c_arr.png"), + Automobility.rl("frame_c_arr"), WheelBase.basic(44.5f, 16), 44f, 6f, @@ -104,11 +98,11 @@ public record AutomobileFrame( public static final AutomobileFrame PINEAPPLE = REGISTRY.register( new AutomobileFrame( - Automobility.id("pineapple"), + Automobility.rl("pineapple"), 0.75f, new FrameModel( - Automobility.id("textures/entity/automobile/frame/pineapple.png"), - Automobility.id("frame_pineapple"), + Automobility.rl("textures/entity/automobile/frame/pineapple.png"), + Automobility.rl("frame_pineapple"), WheelBase.basic(10, 18), 20, 16, @@ -122,11 +116,11 @@ public record AutomobileFrame( public static final AutomobileFrame DABABY = REGISTRY.register( new AutomobileFrame( - Automobility.id("dababy"), + Automobility.rl("dababy"), 0.93f, new FrameModel( - Automobility.id("textures/entity/automobile/frame/c_arr.png"), - Automobility.id("frame_dababy"), + Automobility.rl("textures/entity/automobile/frame/c_arr.png"), + Automobility.rl("frame_dababy"), WheelBase.basic(40, 8), 40, 22, @@ -140,11 +134,11 @@ public record AutomobileFrame( private static AutomobileFrame standard(String color) { return new AutomobileFrame( - Automobility.id("standard_"+color), + Automobility.rl("standard_"+color), 0.6f, new FrameModel( - Automobility.id("textures/entity/automobile/frame/standard_"+color+".png"), - Automobility.id("frame_standard"), + Automobility.rl("textures/entity/automobile/frame/standard_"+color+".png"), + Automobility.rl("frame_standard"), WheelBase.basic(26, 10), 26, 5, @@ -158,11 +152,11 @@ private static AutomobileFrame standard(String color) { private static AutomobileFrame motorcar(String variant, float weight) { return new AutomobileFrame( - Automobility.id(variant+"_motorcar"), + Automobility.rl(variant+"_motorcar"), weight, new FrameModel( - Automobility.id("textures/entity/automobile/frame/"+variant+"_motorcar.png"), - Automobility.id("frame_motorcar"), + Automobility.rl("textures/entity/automobile/frame/"+variant+"_motorcar.png"), + Automobility.rl("frame_motorcar"), WheelBase.basic(32, 12), 28, 3, @@ -176,11 +170,11 @@ private static AutomobileFrame motorcar(String variant, float weight) { private static AutomobileFrame tractor(String color) { return new AutomobileFrame( - Automobility.id(color+"_tractor"), + Automobility.rl(color+"_tractor"), 0.9f, new FrameModel( - Automobility.id("textures/entity/automobile/frame/"+color+"_tractor.png"), - Automobility.id("frame_tractor"), + Automobility.rl("textures/entity/automobile/frame/"+color+"_tractor.png"), + Automobility.rl("frame_tractor"), new WheelBase( new WheelBase.WheelPos(-2, -7, 1.8f, 0, WheelBase.WheelEnd.BACK, WheelBase.WheelSide.LEFT), new WheelBase.WheelPos(-2, 7, 1.8f, 180, WheelBase.WheelEnd.BACK, WheelBase.WheelSide.RIGHT), @@ -199,11 +193,11 @@ private static AutomobileFrame tractor(String color) { private static AutomobileFrame rickshaw(String prefix, float weight) { return new AutomobileFrame( - Automobility.id(prefix+"_rickshaw"), + Automobility.rl(prefix+"_rickshaw"), weight, new FrameModel( - Automobility.id("textures/entity/automobile/frame/"+prefix+"_rickshaw.png"), - Automobility.id("frame_rickshaw"), + Automobility.rl("textures/entity/automobile/frame/"+prefix+"_rickshaw.png"), + Automobility.rl("frame_rickshaw"), new WheelBase( new WheelBase.WheelPos(-11, -7.5f, 1, 0, WheelBase.WheelEnd.BACK, WheelBase.WheelSide.LEFT), new WheelBase.WheelPos(-11, 7.5f, 1, 180, WheelBase.WheelEnd.BACK, WheelBase.WheelSide.RIGHT), @@ -228,7 +222,7 @@ public boolean isEmpty() { } @Override - public Identifier containerId() { + public ResourceLocation containerId() { return ID; } @@ -238,7 +232,7 @@ public void forEachStat(Consumer> action) { } @Override - public Identifier getId() { + public ResourceLocation getId() { return this.id; } @@ -247,8 +241,8 @@ public String getTranslationKey() { } public static record FrameModel( - Identifier texture, - Identifier modelId, + ResourceLocation texture, + ResourceLocation modelId, WheelBase wheelBase, float lengthPx, float seatHeight, @@ -256,10 +250,5 @@ public static record FrameModel( float enginePosUp, float rearAttachmentPos, float frontAttachmentPos - ) { - @Environment(EnvType.CLIENT) - public Function model() { - return AutomobilityModels.MODELS.get(modelId); - } - } + ) {} } diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/AutomobilePrefab.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobilePrefab.java similarity index 58% rename from src/main/java/io/github/foundationgames/automobility/automobile/AutomobilePrefab.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobilePrefab.java index 5e3d8ef..a3817f3 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/AutomobilePrefab.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobilePrefab.java @@ -1,18 +1,18 @@ package io.github.foundationgames.automobility.automobile; import io.github.foundationgames.automobility.item.AutomobilityItems; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Identifier; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; -public record AutomobilePrefab(Identifier id, AutomobileFrame frame, AutomobileWheel wheel, AutomobileEngine engine) { +public record AutomobilePrefab(ResourceLocation id, AutomobileFrame frame, AutomobileWheel wheel, AutomobileEngine engine) { public ItemStack toStack() { - var stack = new ItemStack(AutomobilityItems.AUTOMOBILE); - var automobile = stack.getOrCreateSubNbt("Automobile"); + var stack = new ItemStack(AutomobilityItems.AUTOMOBILE.require()); + var automobile = stack.getOrCreateTagElement("Automobile"); automobile.putString("frame", frame().getId().toString()); automobile.putString("wheels", wheel().getId().toString()); automobile.putString("engine", engine().getId().toString()); automobile.putBoolean("isPrefab", true); - var display = stack.getOrCreateSubNbt("display"); + var display = stack.getOrCreateTagElement("display"); display.putString("Name", String.format("{\"translate\":\"prefab.%s.%s\",\"italic\":\"false\"}", id().getNamespace(), id().getPath())); return stack; } diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileStats.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileStats.java similarity index 92% rename from src/main/java/io/github/foundationgames/automobility/automobile/AutomobileStats.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileStats.java index 9d46320..682741e 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileStats.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileStats.java @@ -1,12 +1,12 @@ package io.github.foundationgames.automobility.automobile; import io.github.foundationgames.automobility.Automobility; -import net.minecraft.util.Identifier; +import net.minecraft.resources.ResourceLocation; import java.util.function.Consumer; public class AutomobileStats implements StatContainer { - public static final Identifier ID = Automobility.id("automobile"); + public static final ResourceLocation ID = Automobility.rl("automobile"); public static final DisplayStat STAT_ACCELERATION = new DisplayStat<>("acceleration", AutomobileStats::getAcceleration); public static final DisplayStat STAT_COMFORTABLE_SPEED = new DisplayStat<>("comfortable_speed", stats -> stats.getComfortableSpeed() * 20); public static final DisplayStat STAT_HANDLING = new DisplayStat<>("handling", AutomobileStats::getHandling); @@ -44,7 +44,7 @@ public float getGrip() { } @Override - public Identifier containerId() { + public ResourceLocation containerId() { return ID; } diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileWheel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileWheel.java similarity index 53% rename from src/main/java/io/github/foundationgames/automobility/automobile/AutomobileWheel.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileWheel.java index 686ce3e..7ef1380 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileWheel.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileWheel.java @@ -1,45 +1,39 @@ package io.github.foundationgames.automobility.automobile; import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.render.AutomobilityModels; import io.github.foundationgames.automobility.util.SimpleMapContentRegistry; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.model.Model; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.util.Identifier; +import net.minecraft.resources.ResourceLocation; import java.util.function.Consumer; -import java.util.function.Function; public record AutomobileWheel( - Identifier id, + ResourceLocation id, float size, float grip, WheelModel model, Ability ... abilities ) implements AutomobileComponent { - public static final Identifier ID = Automobility.id("wheel"); + public static final ResourceLocation ID = Automobility.rl("wheel"); public static final SimpleMapContentRegistry REGISTRY = new SimpleMapContentRegistry<>(); public static final AutomobileWheel EMPTY = REGISTRY.register( - new AutomobileWheel(Automobility.id("empty"), 0.01f, 0.01f, new WheelModel(1, 1, new Identifier("empty"), Automobility.id("empty"))) + new AutomobileWheel(Automobility.rl("empty"), 0.01f, 0.01f, new WheelModel(1, 1, new ResourceLocation("empty"), Automobility.rl("empty"))) ); public static final AutomobileWheel STANDARD = REGISTRY.register( - new AutomobileWheel(Automobility.id("standard"), 0.6f, 0.5f, new WheelModel(3, 3, Automobility.id("textures/entity/automobile/wheel/standard.png"), Automobility.id("wheel_standard"))) + new AutomobileWheel(Automobility.rl("standard"), 0.6f, 0.5f, new WheelModel(3, 3, Automobility.rl("textures/entity/automobile/wheel/standard.png"), Automobility.rl("wheel_standard"))) ); public static final AutomobileWheel OFF_ROAD = REGISTRY.register( - new AutomobileWheel(Automobility.id("off_road"), 1.1f, 0.8f, new WheelModel(8.4f, 5, Automobility.id("textures/entity/automobile/wheel/off_road.png"), Automobility.id("wheel_off_road"))) + new AutomobileWheel(Automobility.rl("off_road"), 1.1f, 0.8f, new WheelModel(8.4f, 5, Automobility.rl("textures/entity/automobile/wheel/off_road.png"), Automobility.rl("wheel_off_road"))) ); public static final AutomobileWheel STEEL = REGISTRY.register( - new AutomobileWheel(Automobility.id("steel"), 0.69f, 0.4f, new WheelModel(3.625f, 3, Automobility.id("textures/entity/automobile/wheel/steel.png"), Automobility.id("wheel_steel"))) + new AutomobileWheel(Automobility.rl("steel"), 0.69f, 0.4f, new WheelModel(3.625f, 3, Automobility.rl("textures/entity/automobile/wheel/steel.png"), Automobility.rl("wheel_steel"))) ); public static final AutomobileWheel TRACTOR = REGISTRY.register( - new AutomobileWheel(Automobility.id("tractor"), 1.05f, 0.69f, new WheelModel(3.625f, 3, Automobility.id("textures/entity/automobile/wheel/tractor.png"), Automobility.id("wheel_tractor"))) + new AutomobileWheel(Automobility.rl("tractor"), 1.05f, 0.69f, new WheelModel(3.625f, 3, Automobility.rl("textures/entity/automobile/wheel/tractor.png"), Automobility.rl("wheel_tractor"))) ); public static final AutomobileWheel CARRIAGE = REGISTRY.register(carriage("carriage", 0.2f)); @@ -49,11 +43,11 @@ public record AutomobileWheel( public static final AutomobileWheel BEJEWELED = REGISTRY.register(carriage("bejeweled", 0.475f)); public static final AutomobileWheel CONVERTIBLE = REGISTRY.register( - new AutomobileWheel(Automobility.id("convertible"), 0.75f, 0.45f, new WheelModel(5.2f, 4.1f, Automobility.id("textures/entity/automobile/frame/c_arr.png"), Automobility.id("wheel_convertible"))) + new AutomobileWheel(Automobility.rl("convertible"), 0.75f, 0.45f, new WheelModel(5.2f, 4.1f, Automobility.rl("textures/entity/automobile/frame/c_arr.png"), Automobility.rl("wheel_convertible"))) ); private static AutomobileWheel carriage(String name, float grip) { - return new AutomobileWheel(Automobility.id(name), 1.05f, grip, new WheelModel(5, 2, Automobility.id("textures/entity/automobile/wheel/"+name+".png"), Automobility.id("wheel_carriage"))); + return new AutomobileWheel(Automobility.rl(name), 1.05f, grip, new WheelModel(5, 2, Automobility.rl("textures/entity/automobile/wheel/"+name+".png"), Automobility.rl("wheel_carriage"))); } public static final DisplayStat STAT_SIZE = new DisplayStat<>("size", AutomobileWheel::size); @@ -65,7 +59,7 @@ public boolean isEmpty() { } @Override - public Identifier containerId() { + public ResourceLocation containerId() { return ID; } @@ -76,7 +70,7 @@ public void forEachStat(Consumer> action) { } @Override - public Identifier getId() { + public ResourceLocation getId() { return this.id; } @@ -90,12 +84,7 @@ public enum Ability { public static record WheelModel( float radius, float width, - Identifier texture, - Identifier modelId - ) { - @Environment(EnvType.CLIENT) - public Function model() { - return AutomobilityModels.MODELS.get(modelId); - } - } + ResourceLocation texture, + ResourceLocation modelId + ) {} } diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/BasicWheelBase.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/BasicWheelBase.java similarity index 100% rename from src/main/java/io/github/foundationgames/automobility/automobile/BasicWheelBase.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/BasicWheelBase.java diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/DisplayStat.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/DisplayStat.java similarity index 54% rename from src/main/java/io/github/foundationgames/automobility/automobile/DisplayStat.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/DisplayStat.java index fc63e58..91c5a7e 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/DisplayStat.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/DisplayStat.java @@ -1,22 +1,22 @@ package io.github.foundationgames.automobility.automobile; import io.github.foundationgames.automobility.util.AUtils; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; import java.util.List; import java.util.function.ToDoubleFunction; public record DisplayStat>(String name, ToDoubleFunction statProvider) { - public static final Text STAT_SEPARATOR = Text.translatable("char.automobility.statSeparator"); + public static final Component STAT_SEPARATOR = Component.translatable("char.automobility.statSeparator"); - public void appendTooltip(List tooltip, C container) { + public void appendTooltip(List tooltip, C container) { var compKey = container.getContainerTextKey(); var statKey = "stat."+compKey+"."+this.name(); - tooltip.add(Text.translatable(statKey).formatted(Formatting.AQUA) + tooltip.add(Component.translatable(statKey).withStyle(ChatFormatting.AQUA) .append(STAT_SEPARATOR) - .append(Text.translatable(statKey+".readout", + .append(Component.translatable(statKey+".readout", AUtils.DEC_TWO_PLACES.format(this.statProvider().applyAsDouble(container)) - ).formatted(Formatting.GREEN))); + ).withStyle(ChatFormatting.GREEN))); } } diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/StatContainer.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/StatContainer.java similarity index 69% rename from src/main/java/io/github/foundationgames/automobility/automobile/StatContainer.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/StatContainer.java index b8e9d4d..f0de21e 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/StatContainer.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/StatContainer.java @@ -1,13 +1,13 @@ package io.github.foundationgames.automobility.automobile; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; import java.util.List; import java.util.function.Consumer; public interface StatContainer> { - Identifier containerId(); + ResourceLocation containerId(); default String getContainerTextKey() { var id = this.containerId(); @@ -16,7 +16,7 @@ default String getContainerTextKey() { void forEachStat(Consumer> action); - default void appendTexts(List texts, C container) { + default void appendTexts(List texts, C container) { this.forEachStat(stat -> stat.appendTooltip(texts, container)); } } diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/WheelBase.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/WheelBase.java similarity index 100% rename from src/main/java/io/github/foundationgames/automobility/automobile/WheelBase.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/WheelBase.java diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/BaseAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/BaseAttachment.java similarity index 67% rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/BaseAttachment.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/BaseAttachment.java index 7e89b8b..fe9c091 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/BaseAttachment.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/BaseAttachment.java @@ -3,11 +3,11 @@ import io.github.foundationgames.automobility.automobile.AutomobileComponent; import io.github.foundationgames.automobility.block.AutomobilityBlocks; import io.github.foundationgames.automobility.entity.AutomobileEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.util.math.Vec3d; -import net.minecraft.world.World; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.Vec3; public abstract class BaseAttachment> { public final T type; @@ -24,11 +24,11 @@ public final AutomobileEntity automobile() { return this.automobile; } - protected final World world() { - return this.automobile.world; + protected final Level world() { + return this.automobile.level; } - public abstract Vec3d pos(); + public abstract Vec3 pos(); public float animation() { return animation; @@ -50,28 +50,28 @@ public void tick() { public void onRemoved() { } - public abstract void writeNbt(NbtCompound nbt); + public abstract void writeNbt(CompoundTag nbt); - public abstract void readNbt(NbtCompound nbt); + public abstract void readNbt(CompoundTag nbt); - public void updatePacketRequested(ServerPlayerEntity player) { + public void updatePacketRequested(ServerPlayer player) { } protected boolean canModifyBlocks() { - if (this.automobile.getFirstPassenger() instanceof PlayerEntity player && player.canModifyBlocks()) { + if (this.automobile.getFirstPassenger() instanceof Player player && player.mayBuild()) { return true; } for (int i = 0; i < 4; i++) { - if (world().getBlockState(this.automobile.getBlockPos().down(i)).isOf(AutomobilityBlocks.ALLOW)) { + if (world().getBlockState(this.automobile.blockPosition().below(i)).is(AutomobilityBlocks.ALLOW.require())) { return true; } } return false; } - public final NbtCompound toNbt() { - var nbt = new NbtCompound(); + public final CompoundTag toNbt() { + var nbt = new CompoundTag(); nbt.putString("type", this.type.getId().toString()); this.writeNbt(nbt); return nbt; diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/FrontAttachmentType.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/FrontAttachmentType.java similarity index 61% rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/FrontAttachmentType.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/FrontAttachmentType.java index e236c4e..b4047ce 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/FrontAttachmentType.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/FrontAttachmentType.java @@ -9,41 +9,35 @@ import io.github.foundationgames.automobility.automobile.attachment.front.GrassCutterFrontAttachment; import io.github.foundationgames.automobility.automobile.attachment.front.MobControllerFrontAttachment; import io.github.foundationgames.automobility.entity.AutomobileEntity; -import io.github.foundationgames.automobility.render.AutomobilityModels; import io.github.foundationgames.automobility.util.SimpleMapContentRegistry; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.model.Model; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.util.Identifier; +import net.minecraft.resources.ResourceLocation; import java.util.function.BiFunction; import java.util.function.Consumer; -import java.util.function.Function; public record FrontAttachmentType( - Identifier id, BiFunction, AutomobileEntity, T> constructor, FrontAttachmentModel model + ResourceLocation id, BiFunction, AutomobileEntity, T> constructor, FrontAttachmentModel model ) implements AutomobileComponent> { - public static final Identifier ID = Automobility.id("front_attachment"); + public static final ResourceLocation ID = Automobility.rl("front_attachment"); public static final SimpleMapContentRegistry> REGISTRY = new SimpleMapContentRegistry<>(); public static final FrontAttachmentType EMPTY = register(new FrontAttachmentType<>( - Automobility.id("empty"), EmptyFrontAttachment::new, new FrontAttachmentModel(new Identifier("empty"), Automobility.id("empty"), 1) + Automobility.rl("empty"), EmptyFrontAttachment::new, new FrontAttachmentModel(new ResourceLocation("empty"), Automobility.rl("empty"), 1) )); public static final FrontAttachmentType MOB_CONTROLLER = register(new FrontAttachmentType<>( - Automobility.id("mob_controller"), MobControllerFrontAttachment::new, - new FrontAttachmentModel(Automobility.id("textures/entity/automobile/front_attachment/mob_controller.png"), Automobility.id("frontatt_mob_controller"), 1.7f) + Automobility.rl("mob_controller"), MobControllerFrontAttachment::new, + new FrontAttachmentModel(Automobility.rl("textures/entity/automobile/front_attachment/mob_controller.png"), Automobility.rl("frontatt_mob_controller"), 1.7f) )); public static final FrontAttachmentType CROP_HARVESTER = register(new FrontAttachmentType<>( - Automobility.id("crop_harvester"), CropHarvesterFrontAttachment::new, - new FrontAttachmentModel(Automobility.id("textures/entity/automobile/front_attachment/crop_harvester.png"), Automobility.id("frontatt_harvester"), 0.83f) + Automobility.rl("crop_harvester"), CropHarvesterFrontAttachment::new, + new FrontAttachmentModel(Automobility.rl("textures/entity/automobile/front_attachment/crop_harvester.png"), Automobility.rl("frontatt_harvester"), 0.83f) )); public static final FrontAttachmentType GRASS_CUTTER = register(new FrontAttachmentType<>( - Automobility.id("grass_cutter"), GrassCutterFrontAttachment::new, - new FrontAttachmentModel(Automobility.id("textures/entity/automobile/front_attachment/grass_cutter.png"), Automobility.id("frontatt_harvester"), 0.83f) + Automobility.rl("grass_cutter"), GrassCutterFrontAttachment::new, + new FrontAttachmentModel(Automobility.rl("textures/entity/automobile/front_attachment/grass_cutter.png"), Automobility.rl("frontatt_harvester"), 0.83f) )); @Override @@ -52,7 +46,7 @@ public boolean isEmpty() { } @Override - public Identifier containerId() { + public ResourceLocation containerId() { return ID; } @@ -61,7 +55,7 @@ public void forEachStat(Consumer>> action) { } @Override - public Identifier getId() { + public ResourceLocation getId() { return this.id(); } @@ -70,10 +64,5 @@ private static FrontAttachmentType register(Front return entry; } - public record FrontAttachmentModel(Identifier texture, Identifier modelId, float scale) { - @Environment(EnvType.CLIENT) - public Function model() { - return AutomobilityModels.MODELS.get(modelId); - } - } + public record FrontAttachmentModel(ResourceLocation texture, ResourceLocation modelId, float scale) {} } diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/RearAttachmentType.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/RearAttachmentType.java similarity index 68% rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/RearAttachmentType.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/RearAttachmentType.java index a9bf4fd..82fa32a 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/RearAttachmentType.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/RearAttachmentType.java @@ -6,45 +6,39 @@ import io.github.foundationgames.automobility.automobile.attachment.rear.BackhoeRearAttachment; import io.github.foundationgames.automobility.automobile.attachment.rear.BannerPostRearAttachment; import io.github.foundationgames.automobility.automobile.attachment.rear.BaseChestRearAttachment; +import io.github.foundationgames.automobility.automobile.attachment.rear.BlockRearAttachment; import io.github.foundationgames.automobility.automobile.attachment.rear.EmptyRearAttachment; import io.github.foundationgames.automobility.automobile.attachment.rear.PassengerSeatRearAttachment; import io.github.foundationgames.automobility.automobile.attachment.rear.PaverRearAttachment; import io.github.foundationgames.automobility.automobile.attachment.rear.RearAttachment; -import io.github.foundationgames.automobility.automobile.attachment.rear.BlockRearAttachment; import io.github.foundationgames.automobility.entity.AutomobileEntity; -import io.github.foundationgames.automobility.render.AutomobilityModels; import io.github.foundationgames.automobility.util.SimpleMapContentRegistry; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.model.Model; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.util.Identifier; +import net.minecraft.resources.ResourceLocation; import java.util.function.BiFunction; import java.util.function.Consumer; -import java.util.function.Function; public record RearAttachmentType( - Identifier id, BiFunction, AutomobileEntity, T> constructor, RearAttachmentModel model + ResourceLocation id, BiFunction, AutomobileEntity, T> constructor, RearAttachmentModel model ) implements AutomobileComponent> { - public static final Identifier ID = Automobility.id("rear_attachment"); + public static final ResourceLocation ID = Automobility.rl("rear_attachment"); public static final SimpleMapContentRegistry> REGISTRY = new SimpleMapContentRegistry<>(); public static final RearAttachmentType EMPTY = register(new RearAttachmentType<>( - Automobility.id("empty"), EmptyRearAttachment::new, new RearAttachmentModel(new Identifier("empty"), Automobility.id("empty"), 0) + Automobility.rl("empty"), EmptyRearAttachment::new, new RearAttachmentModel(new ResourceLocation("empty"), Automobility.rl("empty"), 0) )); public static final RearAttachmentType PASSENGER_SEAT = register(new RearAttachmentType<>( - Automobility.id("passenger_seat"), PassengerSeatRearAttachment::new, - new RearAttachmentModel(Automobility.id("textures/entity/automobile/rear_attachment/passenger_seat.png"), Automobility.id("rearatt_passenger_seat"), 11) + Automobility.rl("passenger_seat"), PassengerSeatRearAttachment::new, + new RearAttachmentModel(Automobility.rl("textures/entity/automobile/rear_attachment/passenger_seat.png"), Automobility.rl("rearatt_passenger_seat"), 11) )); public static final RearAttachmentType CRAFTING_TABLE = register(block("crafting_table", BlockRearAttachment::craftingTable)); public static final RearAttachmentType LOOM = register(block("loom", BlockRearAttachment::loom)); public static final RearAttachmentType CARTOGRAPHY_TABLE = register(block("cartography_table", BlockRearAttachment::cartographyTable)); public static final RearAttachmentType SMITHING_TABLE = register(block("smithing_table", BlockRearAttachment::smithingTable)); - public static final RearAttachmentType GRINDSTONE = register(block("grindstone", Automobility.id("rearatt_grindstone"), BlockRearAttachment::grindstone)); - public static final RearAttachmentType STONECUTTER = register(block("stonecutter", Automobility.id("rearatt_stonecutter"), BlockRearAttachment::stonecutter)); + public static final RearAttachmentType GRINDSTONE = register(block("grindstone", Automobility.rl("rearatt_grindstone"), BlockRearAttachment::grindstone)); + public static final RearAttachmentType STONECUTTER = register(block("stonecutter", Automobility.rl("rearatt_stonecutter"), BlockRearAttachment::stonecutter)); public static final RearAttachmentType AUTO_MECHANIC_TABLE = register(block("auto_mechanic_table", BlockRearAttachment::autoMechanicTable)); public static final RearAttachmentType CHEST = register(chest("chest", BaseChestRearAttachment::chest)); @@ -52,18 +46,18 @@ public record RearAttachmentType( public static final RearAttachmentType SADDLED_BARREL = register(block("saddled_barrel", BaseChestRearAttachment::saddledBarrel)); public static final RearAttachmentType BANNER_POST = register(new RearAttachmentType<>( - Automobility.id("banner_post"), BannerPostRearAttachment::new, - new RearAttachmentModel(Automobility.id("textures/entity/automobile/rear_attachment/banner_post.png"), Automobility.id("rearatt_banner_post"), 10) + Automobility.rl("banner_post"), BannerPostRearAttachment::new, + new RearAttachmentModel(Automobility.rl("textures/entity/automobile/rear_attachment/banner_post.png"), Automobility.rl("rearatt_banner_post"), 10) )); public static final RearAttachmentType BACKHOE = register(new RearAttachmentType<>( - Automobility.id("backhoe"), BackhoeRearAttachment::new, - new RearAttachmentModel(Automobility.id("textures/entity/automobile/rear_attachment/backhoe.png"), Automobility.id("rearatt_plow"), 11) + Automobility.rl("backhoe"), BackhoeRearAttachment::new, + new RearAttachmentModel(Automobility.rl("textures/entity/automobile/rear_attachment/backhoe.png"), Automobility.rl("rearatt_plow"), 11) )); public static final RearAttachmentType PAVER = register(new RearAttachmentType<>( - Automobility.id("paver"), PaverRearAttachment::new, - new RearAttachmentModel(Automobility.id("textures/entity/automobile/rear_attachment/paver.png"), Automobility.id("rearatt_plow"), 11) + Automobility.rl("paver"), PaverRearAttachment::new, + new RearAttachmentModel(Automobility.rl("textures/entity/automobile/rear_attachment/paver.png"), Automobility.rl("rearatt_plow"), 11) )); @Override @@ -72,7 +66,7 @@ public boolean isEmpty() { } @Override - public Identifier containerId() { + public ResourceLocation containerId() { return ID; } @@ -81,22 +75,22 @@ public void forEachStat(Consumer>> action) { } @Override - public Identifier getId() { + public ResourceLocation getId() { return this.id; } private static RearAttachmentType chest(String name, BiFunction, AutomobileEntity, BlockRearAttachment> constructor) { - return block(name, Automobility.id("rearatt_chest"), constructor); + return block(name, Automobility.rl("rearatt_chest"), constructor); } private static RearAttachmentType block(String name, BiFunction, AutomobileEntity, BlockRearAttachment> constructor) { - return block(name, Automobility.id("rearatt_block"), constructor); + return block(name, Automobility.rl("rearatt_block"), constructor); } - private static RearAttachmentType block(String name, Identifier model, BiFunction, AutomobileEntity, BlockRearAttachment> constructor) { + private static RearAttachmentType block(String name, ResourceLocation model, BiFunction, AutomobileEntity, BlockRearAttachment> constructor) { return new RearAttachmentType<>( - Automobility.id(name), constructor, - new RearAttachmentModel(Automobility.id("textures/entity/automobile/rear_attachment/"+name+".png"), model, 11) + Automobility.rl(name), constructor, + new RearAttachmentModel(Automobility.rl("textures/entity/automobile/rear_attachment/"+name+".png"), model, 11) ); } @@ -105,10 +99,5 @@ private static RearAttachmentType register(RearAtt return entry; } - public record RearAttachmentModel(Identifier texture, Identifier modelId, float pivotDistPx) { - @Environment(EnvType.CLIENT) - public Function model() { - return AutomobilityModels.MODELS.get(modelId); - } - } + public record RearAttachmentModel(ResourceLocation texture, ResourceLocation modelId, float pivotDistPx) {} } diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/BaseHarvesterFrontAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/BaseHarvesterFrontAttachment.java similarity index 67% rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/BaseHarvesterFrontAttachment.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/BaseHarvesterFrontAttachment.java index 0da92e2..fbb4843 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/BaseHarvesterFrontAttachment.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/BaseHarvesterFrontAttachment.java @@ -2,19 +2,19 @@ import io.github.foundationgames.automobility.automobile.attachment.FrontAttachmentType; import io.github.foundationgames.automobility.entity.AutomobileEntity; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.entity.Entity; -import net.minecraft.item.ItemStack; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3d; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.Vec3; import java.util.List; public abstract class BaseHarvesterFrontAttachment extends FrontAttachment { - private final BlockPos.Mutable blockIter = new BlockPos.Mutable(); - private Vec3d lastPos = null; + private final BlockPos.MutableBlockPos blockIter = new BlockPos.MutableBlockPos(); + private Vec3 lastPos = null; public BaseHarvesterFrontAttachment(FrontAttachmentType type, AutomobileEntity automobile) { super(type, automobile); @@ -25,14 +25,14 @@ public void tick() { super.tick(); var pos = this.pos(); - if (canModifyBlocks() && lastPos != null && lastPos.subtract(pos).length() > 0.03 && this.world() instanceof ServerWorld world) { + if (canModifyBlocks() && lastPos != null && lastPos.subtract(pos).length() > 0.03 && this.world() instanceof ServerLevel world) { this.harvest(pos, world); } this.lastPos = pos; } - public void harvest(Vec3d pos, ServerWorld world) { + public void harvest(Vec3 pos, ServerLevel world) { int minX = (int) Math.floor(pos.x - 0.5); int maxX = (int) Math.floor(pos.x + 0.5); int minZ = (int) Math.floor(pos.z - 0.5); @@ -40,7 +40,7 @@ public void harvest(Vec3d pos, ServerWorld world) { int y = (int) Math.floor(pos.y + 0.25); Entity entity = this.automobile; - if (this.automobile.hasPassengers()) { + if (this.automobile.isVehicle()) { entity = this.automobile.getFirstPassenger(); } @@ -49,8 +49,8 @@ public void harvest(Vec3d pos, ServerWorld world) { blockIter.set(x, y, z); var state = world.getBlockState(blockIter); if (canHarvest(state)) { - var stacks = Block.getDroppedStacks(state, world, blockIter, null, entity, ItemStack.EMPTY); - world.breakBlock(blockIter, false); + var stacks = Block.getDrops(state, world, blockIter, null, entity, ItemStack.EMPTY); + world.destroyBlock(blockIter, false); this.onBlockHarvested(state, blockIter, stacks); } } diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/CropHarvesterFrontAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/CropHarvesterFrontAttachment.java similarity index 70% rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/CropHarvesterFrontAttachment.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/CropHarvesterFrontAttachment.java index 070d3b3..831fbd1 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/CropHarvesterFrontAttachment.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/CropHarvesterFrontAttachment.java @@ -2,11 +2,11 @@ import io.github.foundationgames.automobility.automobile.attachment.FrontAttachmentType; import io.github.foundationgames.automobility.entity.AutomobileEntity; -import net.minecraft.block.BlockState; -import net.minecraft.block.CropBlock; -import net.minecraft.item.BlockItem; -import net.minecraft.item.ItemStack; -import net.minecraft.util.math.BlockPos; +import net.minecraft.core.BlockPos; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.CropBlock; +import net.minecraft.world.level.block.state.BlockState; import java.util.List; @@ -17,7 +17,7 @@ public CropHarvesterFrontAttachment(FrontAttachmentType type, AutomobileEntit @Override public boolean canHarvest(BlockState state) { - return state.getBlock() instanceof CropBlock crop && crop.isMature(state); + return state.getBlock() instanceof CropBlock crop && crop.isMaxAge(state); } @Override @@ -27,10 +27,10 @@ public void onBlockHarvested(BlockState state, BlockPos pos, List dro var world = world(); for (var drop : drops) { if (!replanted && drop.getItem() instanceof BlockItem item) { - var newState = item.getBlock().getDefaultState(); - if (newState.canPlaceAt(world, pos)) { - world.setBlockState(pos, newState); - drop.decrement(1); + var newState = item.getBlock().defaultBlockState(); + if (newState.canSurvive(world, pos)) { + world.setBlockAndUpdate(pos, newState); + drop.shrink(1); replanted = true; } } diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/EmptyFrontAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/EmptyFrontAttachment.java similarity index 100% rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/EmptyFrontAttachment.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/EmptyFrontAttachment.java diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/FrontAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/FrontAttachment.java similarity index 56% rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/FrontAttachment.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/FrontAttachment.java index 8befb3b..54a8255 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/FrontAttachment.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/FrontAttachment.java @@ -4,14 +4,14 @@ import io.github.foundationgames.automobility.automobile.attachment.FrontAttachmentType; import io.github.foundationgames.automobility.entity.AutomobileEntity; import io.github.foundationgames.automobility.util.AUtils; -import net.minecraft.entity.Entity; -import net.minecraft.entity.ItemEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.inventory.Inventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.util.Identifier; -import net.minecraft.util.math.Vec3d; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.Container; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.phys.Vec3; public abstract class FrontAttachment extends BaseAttachment> { public FrontAttachment(FrontAttachmentType type, AutomobileEntity automobile) { @@ -19,7 +19,7 @@ public FrontAttachment(FrontAttachmentType type, AutomobileEntity automobile) } @Override - public Vec3d pos() { + public Vec3 pos() { return this.automobile.getHeadPos(); } @@ -29,31 +29,31 @@ protected void updateTrackedAnimation(float animation) { } public boolean canDrive(Entity entity) { - return entity instanceof PlayerEntity; + return entity instanceof Player; } @Override - public void writeNbt(NbtCompound nbt) { + public void writeNbt(CompoundTag nbt) { } @Override - public void readNbt(NbtCompound nbt) { + public void readNbt(CompoundTag nbt) { } - public void dropOrTransfer(ItemStack stack, Vec3d dropPos) { + public void dropOrTransfer(ItemStack stack, Vec3 dropPos) { var rearAtt = this.automobile.getRearAttachment(); boolean drop = true; - if (rearAtt instanceof Inventory inv) { + if (rearAtt instanceof Container inv) { if (AUtils.transferInto(stack, inv)) { drop = false; } } if (drop) { - world().spawnEntity(new ItemEntity(world(), dropPos.x, dropPos.y, dropPos.z, stack)); + world().addFreshEntity(new ItemEntity(world(), dropPos.x, dropPos.y, dropPos.z, stack)); } } - public static FrontAttachmentType fromNbt(NbtCompound nbt) { - return FrontAttachmentType.REGISTRY.get(Identifier.tryParse(nbt.getString("type"))); + public static FrontAttachmentType fromNbt(CompoundTag nbt) { + return FrontAttachmentType.REGISTRY.get(ResourceLocation.tryParse(nbt.getString("type"))); } } diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/GrassCutterFrontAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/GrassCutterFrontAttachment.java similarity index 70% rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/GrassCutterFrontAttachment.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/GrassCutterFrontAttachment.java index fdda9f2..ef86bcc 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/GrassCutterFrontAttachment.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/GrassCutterFrontAttachment.java @@ -2,11 +2,11 @@ import io.github.foundationgames.automobility.automobile.attachment.FrontAttachmentType; import io.github.foundationgames.automobility.entity.AutomobileEntity; -import net.minecraft.block.BlockState; -import net.minecraft.block.CropBlock; -import net.minecraft.block.PlantBlock; -import net.minecraft.item.ItemStack; -import net.minecraft.util.math.BlockPos; +import net.minecraft.core.BlockPos; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.BushBlock; +import net.minecraft.world.level.block.CropBlock; +import net.minecraft.world.level.block.state.BlockState; import java.util.List; @@ -17,7 +17,7 @@ public GrassCutterFrontAttachment(FrontAttachmentType type, AutomobileEntity @Override public boolean canHarvest(BlockState state) { - return (state.getBlock() instanceof PlantBlock) && !(state.getBlock() instanceof CropBlock); + return (state.getBlock() instanceof BushBlock) && !(state.getBlock() instanceof CropBlock); } @Override diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/MobControllerFrontAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/MobControllerFrontAttachment.java similarity index 77% rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/MobControllerFrontAttachment.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/MobControllerFrontAttachment.java index 6e6828f..8364415 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/MobControllerFrontAttachment.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/MobControllerFrontAttachment.java @@ -2,8 +2,8 @@ import io.github.foundationgames.automobility.automobile.attachment.FrontAttachmentType; import io.github.foundationgames.automobility.entity.AutomobileEntity; -import net.minecraft.entity.Entity; -import net.minecraft.entity.mob.MobEntity; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.Mob; public class MobControllerFrontAttachment extends FrontAttachment { public MobControllerFrontAttachment(FrontAttachmentType type, AutomobileEntity automobile) { @@ -12,6 +12,6 @@ public MobControllerFrontAttachment(FrontAttachmentType type, AutomobileEntit @Override public boolean canDrive(Entity entity) { - return super.canDrive(entity) || (entity instanceof MobEntity); + return super.canDrive(entity) || (entity instanceof Mob); } } diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BackhoeRearAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BackhoeRearAttachment.java similarity index 68% rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BackhoeRearAttachment.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BackhoeRearAttachment.java index 8402226..837ac18 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BackhoeRearAttachment.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BackhoeRearAttachment.java @@ -2,13 +2,12 @@ import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType; import io.github.foundationgames.automobility.entity.AutomobileEntity; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.sound.SoundEvent; -import net.minecraft.sound.SoundEvents; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; +import net.minecraft.core.BlockPos; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; import java.util.List; @@ -21,7 +20,7 @@ public BackhoeRearAttachment(RearAttachmentType type, AutomobileEntity entity @Override public SoundEvent plowSound() { - return SoundEvents.ITEM_HOE_TILL; + return SoundEvents.HOE_TILL; } @Override @@ -31,10 +30,10 @@ public double searchHeight() { @Override public BlockState plowResult(BlockPos pos, BlockState state) { - if (!this.world().getBlockState(pos.up()).isAir()) { + if (!this.world().getBlockState(pos.above()).isAir()) { return state; } - return TILLABLE_BLOCKS.contains(state.getBlock()) ? Blocks.FARMLAND.getDefaultState() : state; + return TILLABLE_BLOCKS.contains(state.getBlock()) ? Blocks.FARMLAND.defaultBlockState() : state; } } diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BannerPostRearAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BannerPostRearAttachment.java similarity index 51% rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BannerPostRearAttachment.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BannerPostRearAttachment.java index b51dc85..26f3235 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BannerPostRearAttachment.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BannerPostRearAttachment.java @@ -4,40 +4,40 @@ import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType; import io.github.foundationgames.automobility.entity.AutomobileEntity; import io.github.foundationgames.automobility.screen.SingleSlotScreenHandler; -import io.github.foundationgames.automobility.util.network.PayloadPackets; -import net.minecraft.block.entity.BannerBlockEntity; -import net.minecraft.block.entity.BannerPattern; -import net.minecraft.inventory.Inventory; -import net.minecraft.inventory.SimpleInventory; -import net.minecraft.item.BannerItem; -import net.minecraft.item.BlockItem; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtList; -import net.minecraft.screen.NamedScreenHandlerFactory; -import net.minecraft.screen.ScreenHandlerContext; -import net.minecraft.screen.SimpleNamedScreenHandlerFactory; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.Text; -import net.minecraft.util.DyeColor; -import net.minecraft.util.ItemScatterer; -import net.minecraft.util.registry.RegistryEntry; +import io.github.foundationgames.automobility.util.network.CommonPackets; +import net.minecraft.core.Holder; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.Container; +import net.minecraft.world.Containers; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.SimpleContainer; +import net.minecraft.world.SimpleMenuProvider; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.item.BannerItem; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.DyeColor; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.entity.BannerBlockEntity; +import net.minecraft.world.level.block.entity.BannerPattern; import org.jetbrains.annotations.Nullable; import java.util.List; public class BannerPostRearAttachment extends RearAttachment { - private static final Text UI_TITLE = Text.translatable("container.automobility.banner_post"); + private static final Component UI_TITLE = Component.translatable("container.automobility.banner_post"); private @Nullable DyeColor baseColor = null; - private NbtList patternNbt = new NbtList(); - private List, DyeColor>> patterns; + private ListTag patternNbt = new ListTag(); + private List, DyeColor>> patterns; - public final Inventory inventory = new SimpleInventory(1) { + public final Container inventory = new SimpleContainer(1) { @Override - public void setStack(int slot, ItemStack stack) { - super.setStack(slot, stack); + public void setItem(int slot, ItemStack stack) { + super.setItem(slot, stack); BannerPostRearAttachment.this.setFromItem(stack); } @@ -48,25 +48,25 @@ public BannerPostRearAttachment(RearAttachmentType type, AutomobileEntity ent } public void sendPacket() { - var nbt = new NbtCompound(); + var nbt = new CompoundTag(); this.putToNbt(nbt); - if (!this.world().isClient()) { + if (!this.world().isClientSide()) { this.automobile().forNearbyPlayers(200, false, p -> - PayloadPackets.sendBannerPostAttachmentUpdatePacket(this.automobile(), nbt, p)); + CommonPackets.sendBannerPostAttachmentUpdatePacket(this.automobile(), nbt, p)); } } @Override - public void updatePacketRequested(ServerPlayerEntity player) { + public void updatePacketRequested(ServerPlayer player) { super.updatePacketRequested(player); - var nbt = new NbtCompound(); + var nbt = new CompoundTag(); this.putToNbt(nbt); - PayloadPackets.sendBannerPostAttachmentUpdatePacket(this.automobile(), nbt, player); + CommonPackets.sendBannerPostAttachmentUpdatePacket(this.automobile(), nbt, player); } - public void putToNbt(NbtCompound nbt) { + public void putToNbt(CompoundTag nbt) { if (this.baseColor != null) { nbt.putInt("Color", this.baseColor.getId()); } @@ -76,7 +76,7 @@ public void putToNbt(NbtCompound nbt) { } } - public void setFromNbt(NbtCompound nbt) { + public void setFromNbt(CompoundTag nbt) { if (nbt.contains("Color")) { this.baseColor = DyeColor.byId(nbt.getInt("Color")); } else { @@ -86,7 +86,7 @@ public void setFromNbt(NbtCompound nbt) { if (nbt.contains("Patterns", 9)) { this.patternNbt = nbt.getList("Patterns", 10); } else { - this.patternNbt = new NbtList(); + this.patternNbt = new ListTag(); } this.patterns = null; } @@ -99,15 +99,15 @@ public void setFromItem(ItemStack stack) { return; } - var nbt = BlockItem.getBlockEntityNbt(stack); + var nbt = BlockItem.getBlockEntityData(stack); if (nbt != null && nbt.contains("Patterns", 9)) { this.patternNbt = nbt.getList("Patterns", 10); } else { - this.patternNbt = new NbtList(); + this.patternNbt = new ListTag(); } this.patterns = null; - if (!this.world().isClient()) { + if (!this.world().isClientSide()) { this.sendPacket(); } } @@ -115,7 +115,7 @@ public void setFromItem(ItemStack stack) { public void erase() { this.baseColor = null; - if (!this.world().isClient()) { + if (!this.world().isClientSide()) { this.sendPacket(); } } @@ -124,9 +124,9 @@ public void erase() { return this.baseColor; } - public List, DyeColor>> getPatterns() { + public List, DyeColor>> getPatterns() { if (this.patterns == null) { - this.patterns = BannerBlockEntity.getPatternsFromNbt(this.baseColor, this.patternNbt); + this.patterns = BannerBlockEntity.createPatterns(this.baseColor, this.patternNbt); } return this.patterns; @@ -137,26 +137,26 @@ public void onRemoved() { super.onRemoved(); var pos = this.pos(); - ItemScatterer.spawn(this.world(), pos.x, pos.y, pos.z, this.inventory.getStack(0)); + Containers.dropItemStack(this.world(), pos.x, pos.y, pos.z, this.inventory.getItem(0)); } @Override - public void writeNbt(NbtCompound nbt) { + public void writeNbt(CompoundTag nbt) { super.writeNbt(nbt); this.putToNbt(nbt); - var item = new NbtCompound(); - this.inventory.getStack(0).writeNbt(item); + var item = new CompoundTag(); + this.inventory.getItem(0).save(item); nbt.put("Banner", item); } @Override - public void readNbt(NbtCompound nbt) { + public void readNbt(CompoundTag nbt) { super.readNbt(nbt); this.setFromNbt(nbt); - this.inventory.setStack(0, ItemStack.fromNbt(nbt.getCompound("Banner"))); + this.inventory.setItem(0, ItemStack.of(nbt.getCompound("Banner"))); } @Override @@ -165,8 +165,8 @@ public boolean hasMenu() { } @Override - public @Nullable NamedScreenHandlerFactory createMenu(ScreenHandlerContext ctx) { - return new SimpleNamedScreenHandlerFactory((syncId, playerInv, player) -> + public @Nullable MenuProvider createMenu(ContainerLevelAccess ctx) { + return new SimpleMenuProvider((syncId, playerInv, player) -> new SingleSlotScreenHandler(syncId, playerInv, this.inventory), UI_TITLE); } } diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BaseChestRearAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BaseChestRearAttachment.java new file mode 100644 index 0000000..77a0ecc --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BaseChestRearAttachment.java @@ -0,0 +1,126 @@ +package io.github.foundationgames.automobility.automobile.attachment.rear; + +import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType; +import io.github.foundationgames.automobility.entity.AutomobileEntity; +import io.github.foundationgames.automobility.util.duck.EnderChestContainerDuck; +import net.minecraft.core.BlockPos; +import net.minecraft.network.chat.Component; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.SimpleMenuProvider; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.ChestMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.entity.ChestLidController; +import net.minecraft.world.level.block.entity.ContainerOpenersCounter; +import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.Nullable; + +import java.util.function.BiFunction; + +public class BaseChestRearAttachment extends BlockRearAttachment { + public static final Component TITLE_CHEST = Component.translatable("container.chest"); + public static final Component TITLE_ENDER_CHEST = Component.translatable("container.enderchest"); + public static final Component TITLE_BARREL = Component.translatable("container.barrel"); + + private final ContainerOpenersCounter viewerManager; + public final ChestLidController lidAnimator; + + public BaseChestRearAttachment(RearAttachmentType type, AutomobileEntity entity, BlockState block, @Nullable BiFunction screenProvider) { + super(type, entity, block, screenProvider); + this.viewerManager = new ContainerOpenersCounter() { + protected void onOpen(Level world, BlockPos pos, BlockState state) { + sound(world, pos, BaseChestRearAttachment.this.getOpenSound()); + } + + protected void onClose(Level world, BlockPos pos, BlockState state) { + sound(world, pos, BaseChestRearAttachment.this.getCloseSound()); + } + + protected void openerCountChanged(Level world, BlockPos pos, BlockState state, int oldViewerCount, int newViewerCount) { + if (!world.isClientSide()) { + BaseChestRearAttachment.this.updateTrackedAnimation(newViewerCount); + } + } + + protected boolean isOwnContainer(Player player) { + if (!(player.containerMenu instanceof ChestMenu)) { + return false; + } else { + var inventory = ((ChestMenu)player.containerMenu).getContainer(); + return inventory == BaseChestRearAttachment.this; + } + } + }; + this.lidAnimator = new ChestLidController(); + } + + public void open(Player player) { + if (!player.isSpectator()) { + this.viewerManager.incrementOpeners(player, this.world(), this.automobile.blockPosition(), Blocks.AIR.defaultBlockState()); + } + } + + public void close(Player player) { + if (!player.isSpectator()) { + this.viewerManager.decrementOpeners(player, this.world(), this.automobile.blockPosition(), Blocks.AIR.defaultBlockState()); + } + } + + @Override + public void onTrackedAnimationUpdated(float animation) { + super.onTrackedAnimationUpdated(animation); + + this.lidAnimator.shouldBeOpen(animation > 0); + } + + @Override + public void tick() { + super.tick(); + + if (world().isClientSide()) { + this.lidAnimator.tickLid(); + } + } + + protected SoundEvent getOpenSound() { + return SoundEvents.ENDER_CHEST_OPEN; + } + + protected SoundEvent getCloseSound() { + return SoundEvents.ENDER_CHEST_CLOSE; + } + + private static void sound(Level world, BlockPos pos, SoundEvent soundEvent) { + world.playSound(null, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, soundEvent, SoundSource.BLOCKS, 0.5F, world.random.nextFloat() * 0.1F + 0.9F); + } + + public static BaseChestRearAttachment chest(RearAttachmentType type, AutomobileEntity entity) { + return new ChestRearAttachment(type, entity, + Blocks.ENDER_CHEST.defaultBlockState(), + (ctx, att) -> att instanceof ChestRearAttachment chest ? chest : null); + } + + public static BaseChestRearAttachment enderChest(RearAttachmentType type, AutomobileEntity entity) { + return new BaseChestRearAttachment(type, entity, + Blocks.ENDER_CHEST.defaultBlockState(), + (ctx, att) -> new SimpleMenuProvider((syncId, inventory, player) -> { + var enderChest = player.getEnderChestInventory(); + if (att instanceof BaseChestRearAttachment chest) { + EnderChestContainerDuck.of(enderChest).automobility$setActiveAttachment(chest); + } + return ChestMenu.threeRows(syncId, inventory, enderChest); + }, TITLE_ENDER_CHEST) + ); + } + + public static BaseChestRearAttachment saddledBarrel(RearAttachmentType type, AutomobileEntity entity) { + return new SaddledBarrelRearAttachment(type, entity, + Blocks.BARREL.defaultBlockState(), + (ctx, att) -> att instanceof SaddledBarrelRearAttachment barrel ? barrel : null); + } +} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BasePlowRearAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BasePlowRearAttachment.java similarity index 70% rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BasePlowRearAttachment.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BasePlowRearAttachment.java index 9d0165b..fce36bd 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BasePlowRearAttachment.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BasePlowRearAttachment.java @@ -2,18 +2,17 @@ import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType; import io.github.foundationgames.automobility.entity.AutomobileEntity; -import net.minecraft.block.BlockState; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.sound.SoundCategory; -import net.minecraft.sound.SoundEvent; -import net.minecraft.sound.SoundEvents; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3d; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.Vec3; public abstract class BasePlowRearAttachment extends ExtendableRearAttachment { - private final BlockPos.Mutable blockIter = new BlockPos.Mutable(); - private Vec3d lastPos = null; + private final BlockPos.MutableBlockPos blockIter = new BlockPos.MutableBlockPos(); + private Vec3 lastPos = null; public BasePlowRearAttachment(RearAttachmentType type, AutomobileEntity entity) { super(type, entity); @@ -23,16 +22,16 @@ public BasePlowRearAttachment(RearAttachmentType type, AutomobileEntity entit @Override public void tick() { super.tick(); - var pos = this.origin().add(this.yawVec().multiply(0.11 * this.type.model().pivotDistPx())); + var pos = this.origin().add(this.yawVec().scale(0.11 * this.type.model().pivotDistPx())); - if (this.extended() && canModifyBlocks() && lastPos != null && lastPos.subtract(pos).length() > 0.03 && this.world() instanceof ServerWorld world) { + if (this.extended() && canModifyBlocks() && lastPos != null && lastPos.subtract(pos).length() > 0.03 && this.world() instanceof ServerLevel world) { this.plow(pos, world); } this.lastPos = pos; } - public void plow(Vec3d pos, ServerWorld world) { + public void plow(Vec3 pos, ServerLevel world) { int minX = (int) Math.floor(pos.x - 0.5); int maxX = (int) Math.floor(pos.x + 0.5); int minZ = (int) Math.floor(pos.z - 0.5); @@ -47,22 +46,22 @@ public void plow(Vec3d pos, ServerWorld world) { var result = this.plowResult(blockIter, state); if (result != state) { - world.setBlockState(blockIter, result); + world.setBlockAndUpdate(blockIter, result); playSound = true; } } } if (playSound) { - world.playSound(null, pos.x, pos.y, pos.z, this.plowSound(), SoundCategory.BLOCKS, 0.8f, 1f); + world.playSound(null, pos.x, pos.y, pos.z, this.plowSound(), SoundSource.BLOCKS, 0.8f, 1f); } } @Override public void setExtended(boolean deployed) { - if (!world().isClient() && deployed != this.extended()) { + if (!world().isClientSide() && deployed != this.extended()) { var pos = this.pos(); - world().playSound(null, pos.x, pos.y, pos.z, SoundEvents.BLOCK_IRON_TRAPDOOR_CLOSE, SoundCategory.PLAYERS, 0.6f, 1.4f); + world().playSound(null, pos.x, pos.y, pos.z, SoundEvents.IRON_TRAPDOOR_CLOSE, SoundSource.PLAYERS, 0.6f, 1.4f); } super.setExtended(deployed); diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BlockRearAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BlockRearAttachment.java new file mode 100644 index 0000000..ba4b0da --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BlockRearAttachment.java @@ -0,0 +1,106 @@ +package io.github.foundationgames.automobility.automobile.attachment.rear; + +import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType; +import io.github.foundationgames.automobility.block.AutoMechanicTableBlock; +import io.github.foundationgames.automobility.block.AutomobilityBlocks; +import io.github.foundationgames.automobility.entity.AutomobileEntity; +import io.github.foundationgames.automobility.screen.AutoMechanicTableScreenHandler; +import net.minecraft.network.chat.Component; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.SimpleMenuProvider; +import net.minecraft.world.inventory.CartographyTableMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.CraftingMenu; +import net.minecraft.world.inventory.GrindstoneMenu; +import net.minecraft.world.inventory.LoomMenu; +import net.minecraft.world.inventory.SmithingMenu; +import net.minecraft.world.inventory.StonecutterMenu; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.Nullable; + +import java.util.function.BiFunction; + +public class BlockRearAttachment extends RearAttachment { + public static final Component TITLE_CRAFTING = Component.translatable("container.crafting"); + public static final Component TITLE_LOOM = Component.translatable("container.loom"); + public static final Component TITLE_CARTOGRAPHY = Component.translatable("container.cartography_table"); + public static final Component TITLE_SMITHING = Component.translatable("container.upgrade"); + public static final Component TITLE_GRINDSTONE = Component.translatable("container.grindstone_title"); + public static final Component TITLE_STONECUTTER = Component.translatable("container.stonecutter"); + + public final BlockState block; + private final @Nullable BiFunction screenProvider; + + public BlockRearAttachment(RearAttachmentType type, AutomobileEntity entity, BlockState block, @Nullable BiFunction screenProvider) { + super(type, entity); + this.block = block; + this.screenProvider = screenProvider; + } + + @Override + public boolean hasMenu() { + return this.screenProvider != null; + } + + @Override + public @Nullable MenuProvider createMenu(ContainerLevelAccess ctx) { + return this.screenProvider != null ? this.screenProvider.apply(ctx, this) : null; + } + + public static BlockRearAttachment craftingTable(RearAttachmentType type, AutomobileEntity entity) { + return new BlockRearAttachment(type, entity, + Blocks.CRAFTING_TABLE.defaultBlockState(), + (ctx, att) -> new SimpleMenuProvider((syncId, inventory, player) -> + new CraftingMenu(syncId, inventory, ctx), TITLE_CRAFTING) + ); + } + + public static BlockRearAttachment loom(RearAttachmentType type, AutomobileEntity entity) { + return new BlockRearAttachment(type, entity, + Blocks.LOOM.defaultBlockState(), + (ctx, att) -> new SimpleMenuProvider((syncId, inventory, player) -> + new LoomMenu(syncId, inventory, ctx), TITLE_LOOM) + ); + } + + public static BlockRearAttachment cartographyTable(RearAttachmentType type, AutomobileEntity entity) { + return new BlockRearAttachment(type, entity, + Blocks.CARTOGRAPHY_TABLE.defaultBlockState(), + (ctx, att) -> new SimpleMenuProvider((syncId, inventory, player) -> + new CartographyTableMenu(syncId, inventory, ctx), TITLE_CARTOGRAPHY) + ); + } + + public static BlockRearAttachment smithingTable(RearAttachmentType type, AutomobileEntity entity) { + return new BlockRearAttachment(type, entity, + Blocks.SMITHING_TABLE.defaultBlockState(), + (ctx, att) -> new SimpleMenuProvider((syncId, inventory, player) -> + new SmithingMenu(syncId, inventory, ctx), TITLE_SMITHING) + ); + } + + public static BlockRearAttachment grindstone(RearAttachmentType type, AutomobileEntity entity) { + return new BlockRearAttachment(type, entity, + Blocks.GRINDSTONE.defaultBlockState(), + (ctx, att) -> new SimpleMenuProvider((syncId, inventory, player) -> + new GrindstoneMenu(syncId, inventory, ctx), TITLE_GRINDSTONE) + ); + } + + public static BlockRearAttachment stonecutter(RearAttachmentType type, AutomobileEntity entity) { + return new BlockRearAttachment(type, entity, + Blocks.STONECUTTER.defaultBlockState(), + (ctx, att) -> new SimpleMenuProvider((syncId, inventory, player) -> + new StonecutterMenu(syncId, inventory, ctx), TITLE_STONECUTTER) + ); + } + + public static BlockRearAttachment autoMechanicTable(RearAttachmentType type, AutomobileEntity entity) { + return new BlockRearAttachment(type, entity, + AutomobilityBlocks.AUTO_MECHANIC_TABLE.require().defaultBlockState(), + (ctx, att) -> new SimpleMenuProvider((syncId, inventory, player) -> + new AutoMechanicTableScreenHandler(syncId, inventory, ctx), AutoMechanicTableBlock.UI_TITLE) + ); + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/ChestRearAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/ChestRearAttachment.java new file mode 100644 index 0000000..985a746 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/ChestRearAttachment.java @@ -0,0 +1,130 @@ +package io.github.foundationgames.automobility.automobile.attachment.rear; + +import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType; +import io.github.foundationgames.automobility.entity.AutomobileEntity; +import net.minecraft.core.NonNullList; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.Container; +import net.minecraft.world.ContainerHelper; +import net.minecraft.world.Containers; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ChestMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.Nullable; + +import java.util.function.BiFunction; + +public class ChestRearAttachment extends BaseChestRearAttachment implements Container, MenuProvider { + private NonNullList inventory; + + public ChestRearAttachment(RearAttachmentType type, AutomobileEntity entity, BlockState block, @Nullable BiFunction screenProvider) { + super(type, entity, block, screenProvider); + this.inventory = NonNullList.withSize(27, ItemStack.EMPTY); + } + + @Override + public void onRemoved() { + super.onRemoved(); + + var pos = this.pos(); + this.inventory.forEach(s -> Containers.dropItemStack(this.world(), pos.x, pos.y, pos.z, s)); + } + + @Override + public int getContainerSize() { + return this.inventory.size(); + } + + @Override + public boolean isEmpty() { + return this.inventory.stream().allMatch(ItemStack::isEmpty); + } + + @Override + public ItemStack getItem(int slot) { + return this.inventory.get(slot); + } + + @Override + public ItemStack removeItem(int slot, int amount) { + return ContainerHelper.removeItem(this.inventory, slot, amount); + } + + @Override + public ItemStack removeItemNoUpdate(int slot) { + return ContainerHelper.takeItem(this.inventory, slot); + } + + @Override + public void setItem(int slot, ItemStack stack) { + this.inventory.set(slot, stack); + } + + @Override + public void setChanged() { + this.automobile.markDirty(); + } + + @Override + public boolean stillValid(Player player) { + return true; + } + + @Override + public Component getDisplayName() { + return BaseChestRearAttachment.TITLE_CHEST; + } + + @Nullable + @Override + public AbstractContainerMenu createMenu(int syncId, Inventory inv, Player player) { + return ChestMenu.threeRows(syncId, inv, this); + } + + @Override + public void clearContent() { + this.inventory.clear(); + } + + @Override + public void startOpen(Player player) { + this.open(player); + } + + @Override + public void stopOpen(Player player) { + this.close(player); + } + + @Override + protected SoundEvent getOpenSound() { + return SoundEvents.CHEST_OPEN; + } + + @Override + protected SoundEvent getCloseSound() { + return SoundEvents.CHEST_CLOSE; + } + + @Override + public void writeNbt(CompoundTag nbt) { + super.writeNbt(nbt); + + nbt.put("Items", ContainerHelper.saveAllItems(new CompoundTag(), this.inventory)); + } + + @Override + public void readNbt(CompoundTag nbt) { + super.readNbt(nbt); + + ContainerHelper.loadAllItems(nbt.getCompound("Items"), this.inventory); + } +} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/DeployableRearAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/DeployableRearAttachment.java similarity index 100% rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/DeployableRearAttachment.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/DeployableRearAttachment.java diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/EmptyRearAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/EmptyRearAttachment.java similarity index 100% rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/EmptyRearAttachment.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/EmptyRearAttachment.java diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/ExtendableRearAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/ExtendableRearAttachment.java similarity index 73% rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/ExtendableRearAttachment.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/ExtendableRearAttachment.java index e7de335..88d0a57 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/ExtendableRearAttachment.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/ExtendableRearAttachment.java @@ -3,10 +3,10 @@ import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType; import io.github.foundationgames.automobility.entity.AutomobileEntity; import io.github.foundationgames.automobility.util.AUtils; -import io.github.foundationgames.automobility.util.network.PayloadPackets; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.util.math.MathHelper; +import io.github.foundationgames.automobility.util.network.CommonPackets; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.util.Mth; public abstract class ExtendableRearAttachment extends DeployableRearAttachment { protected boolean extended; @@ -19,11 +19,11 @@ protected ExtendableRearAttachment(RearAttachmentType type, AutomobileEntity } public float extendAnimation(float delta) { - return MathHelper.lerp(delta, lastExtendAnimation, extendAnimation) / 14; + return Mth.lerp(delta, lastExtendAnimation, extendAnimation) / 14; } public void setExtended(boolean extended) { - if (!this.world().isClient()) { + if (!this.world().isClientSide()) { this.updateTrackedAnimation(extended ? 1f : 0f); } @@ -38,28 +38,28 @@ public boolean extended() { public void tick() { super.tick(); - if (this.world().isClient()) { + if (this.world().isClientSide()) { this.lastExtendAnimation = this.extendAnimation; this.extendAnimation = AUtils.shift(this.extendAnimation, 1, this.extended() ? 0 : this.extendAnimTime()); } } @Override - public void updatePacketRequested(ServerPlayerEntity player) { + public void updatePacketRequested(ServerPlayer player) { super.updatePacketRequested(player); - PayloadPackets.sendExtendableAttachmentUpdatePacket(this.automobile(), this.extended(), player); + CommonPackets.sendExtendableAttachmentUpdatePacket(this.automobile(), this.extended(), player); } @Override - public void writeNbt(NbtCompound nbt) { + public void writeNbt(CompoundTag nbt) { super.writeNbt(nbt); nbt.putBoolean("extended", this.extended()); } @Override - public void readNbt(NbtCompound nbt) { + public void readNbt(CompoundTag nbt) { super.readNbt(nbt); this.setExtended(nbt.getBoolean("extended")); diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/PassengerSeatRearAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/PassengerSeatRearAttachment.java similarity index 100% rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/PassengerSeatRearAttachment.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/PassengerSeatRearAttachment.java diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/PaverRearAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/PaverRearAttachment.java similarity index 65% rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/PaverRearAttachment.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/PaverRearAttachment.java index 040d8ca..09fb589 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/PaverRearAttachment.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/PaverRearAttachment.java @@ -3,11 +3,10 @@ import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType; import io.github.foundationgames.automobility.entity.AutomobileEntity; import io.github.foundationgames.automobility.mixin.ShovelItemAccess; -import net.minecraft.block.BlockState; -import net.minecraft.sound.SoundEvent; -import net.minecraft.sound.SoundEvents; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; +import net.minecraft.core.BlockPos; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.level.block.state.BlockState; public class PaverRearAttachment extends BasePlowRearAttachment { public PaverRearAttachment(RearAttachmentType type, AutomobileEntity entity) { @@ -16,7 +15,7 @@ public PaverRearAttachment(RearAttachmentType type, AutomobileEntity entity) @Override public SoundEvent plowSound() { - return SoundEvents.ITEM_SHOVEL_FLATTEN; + return SoundEvents.SHOVEL_FLATTEN; } @Override @@ -26,10 +25,10 @@ public double searchHeight() { @Override public BlockState plowResult(BlockPos pos, BlockState state) { - if (!this.world().getBlockState(pos.up()).isAir()) { + if (!this.world().getBlockState(pos.above()).isAir()) { return state; } - return ShovelItemAccess.getPathStates().getOrDefault(state.getBlock(), state); + return ShovelItemAccess.getFlattenables().getOrDefault(state.getBlock(), state); } } \ No newline at end of file diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/RearAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/RearAttachment.java similarity index 62% rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/RearAttachment.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/RearAttachment.java index 0d7fb7a..d2a017c 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/RearAttachment.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/RearAttachment.java @@ -3,12 +3,12 @@ import io.github.foundationgames.automobility.automobile.attachment.BaseAttachment; import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType; import io.github.foundationgames.automobility.entity.AutomobileEntity; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.screen.NamedScreenHandlerFactory; -import net.minecraft.screen.ScreenHandlerContext; -import net.minecraft.util.Identifier; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.Vec3d; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.Nullable; public abstract class RearAttachment extends BaseAttachment> { @@ -22,20 +22,20 @@ protected RearAttachment(RearAttachmentType type, AutomobileEntity entity) { super(type, entity); } - public final Vec3d yawVec() { - return new Vec3d(0, 0, 1).rotateY((float) Math.toRadians(180 - this.yaw())); + public final Vec3 yawVec() { + return new Vec3(0, 0, 1).yRot((float) Math.toRadians(180 - this.yaw())); } - public final Vec3d scaledYawVec() { - return this.yawVec().multiply(this.type.model().pivotDistPx() * 0.0625); + public final Vec3 scaledYawVec() { + return this.yawVec().scale(this.type.model().pivotDistPx() * 0.0625); } - public final Vec3d origin() { + public final Vec3 origin() { return this.automobile.getTailPos(); } @Override - public final Vec3d pos() { + public final Vec3 pos() { return this.origin().add(this.scaledYawVec()); } @@ -44,13 +44,13 @@ public float yaw() { } public float yaw(float delta) { - return MathHelper.lerpAngleDegrees(delta, this.lastYaw, this.yaw()); + return Mth.rotLerp(delta, this.lastYaw, this.yaw()); } public void setYaw(float yaw) { - float diff = MathHelper.wrapDegrees(yaw - this.automobile.getYaw()); - if (diff < -90 && diff > -180) yaw = this.automobile.getYaw() - 90; - else if (diff > 90 && diff < 180) yaw = this.automobile.getYaw() + 90; + float diff = Mth.wrapDegrees(yaw - this.automobile.getYRot()); + if (diff < -90 && diff > -180) yaw = this.automobile.getYRot() - 90; + else if (diff > 90 && diff < 180) yaw = this.automobile.getYRot() + 90; this.yaw = yaw; } @@ -62,14 +62,14 @@ protected final void updateTrackedYaw(float yaw) { public void onTrackedYawUpdated(float yaw) { this.trackedYaw = yaw; - this.yawLerpProgress = this.automobile.getType().getTrackTickInterval() + 1; + this.yawLerpProgress = this.automobile.getType().updateInterval() + 1; } protected final void updateTrackedAnimation(float animation) { this.automobile.setTrackedRearAttachmentAnimation(animation); } - public final void pull(Vec3d movement) { + public final void pull(Vec3 movement) { var vec = this.scaledYawVec().add(movement); this.setYaw(180 - (float) Math.toDegrees(Math.atan2(vec.x, vec.z))); } @@ -81,11 +81,11 @@ public void tick() { } private void rotationTrackingTick() { - if (!world().isClient()) { + if (!world().isClientSide()) { this.yawLerpProgress = 0; updateTrackedYaw(yaw()); } else if (yawLerpProgress > 0) { - this.setYaw(this.yaw() + (MathHelper.wrapDegrees(this.trackedYaw - this.yaw()) / (float)this.yawLerpProgress)); + this.setYaw(this.yaw() + (Mth.wrapDegrees(this.trackedYaw - this.yaw()) / (float)this.yawLerpProgress)); this.yawLerpProgress--; } @@ -103,19 +103,19 @@ public boolean hasMenu() { return false; } - public @Nullable NamedScreenHandlerFactory createMenu(ScreenHandlerContext ctx) { + public @Nullable MenuProvider createMenu(ContainerLevelAccess ctx) { return null; } - public void writeNbt(NbtCompound nbt) { + public void writeNbt(CompoundTag nbt) { nbt.putFloat("yaw", this.yaw()); } - public void readNbt(NbtCompound nbt) { + public void readNbt(CompoundTag nbt) { this.setYaw(nbt.getFloat("yaw")); } - public static RearAttachmentType fromNbt(NbtCompound nbt) { - return RearAttachmentType.REGISTRY.get(Identifier.tryParse(nbt.getString("type"))); + public static RearAttachmentType fromNbt(CompoundTag nbt) { + return RearAttachmentType.REGISTRY.get(ResourceLocation.tryParse(nbt.getString("type"))); } } diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/SaddledBarrelRearAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/SaddledBarrelRearAttachment.java similarity index 66% rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/SaddledBarrelRearAttachment.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/SaddledBarrelRearAttachment.java index 22cdd46..5d3006c 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/SaddledBarrelRearAttachment.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/SaddledBarrelRearAttachment.java @@ -2,33 +2,33 @@ import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType; import io.github.foundationgames.automobility.entity.AutomobileEntity; -import net.minecraft.block.BlockState; -import net.minecraft.screen.NamedScreenHandlerFactory; -import net.minecraft.screen.ScreenHandlerContext; -import net.minecraft.sound.SoundEvent; -import net.minecraft.sound.SoundEvents; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.Nullable; import java.util.function.BiFunction; public class SaddledBarrelRearAttachment extends ChestRearAttachment { - public SaddledBarrelRearAttachment(RearAttachmentType type, AutomobileEntity entity, BlockState block, @Nullable BiFunction screenProvider) { + public SaddledBarrelRearAttachment(RearAttachmentType type, AutomobileEntity entity, BlockState block, @Nullable BiFunction screenProvider) { super(type, entity, block, screenProvider); } @Override protected SoundEvent getOpenSound() { - return SoundEvents.BLOCK_BARREL_OPEN; + return SoundEvents.BARREL_OPEN; } @Override protected SoundEvent getCloseSound() { - return SoundEvents.BLOCK_BARREL_CLOSE; + return SoundEvents.BARREL_CLOSE; } @Override - public Text getDisplayName() { + public Component getDisplayName() { return BaseChestRearAttachment.TITLE_BARREL; } diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/AutomobileModels.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/AutomobileModels.java new file mode 100644 index 0000000..bd0e1d6 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/AutomobileModels.java @@ -0,0 +1,118 @@ +package io.github.foundationgames.automobility.automobile.render; + +import io.github.foundationgames.automobility.Automobility; +import io.github.foundationgames.automobility.automobile.render.attachment.front.HarvesterFrontAttachmentModel; +import io.github.foundationgames.automobility.automobile.render.attachment.front.MobControllerFrontAttachmentModel; +import io.github.foundationgames.automobility.automobile.render.attachment.rear.BannerPostRearAttachmentModel; +import io.github.foundationgames.automobility.automobile.render.attachment.rear.BlockRearAttachmentModel; +import io.github.foundationgames.automobility.automobile.render.attachment.rear.ChestRearAttachmentModel; +import io.github.foundationgames.automobility.automobile.render.attachment.rear.GrindstoneRearAttachmentModel; +import io.github.foundationgames.automobility.automobile.render.attachment.rear.PassengerSeatRearAttachmentModel; +import io.github.foundationgames.automobility.automobile.render.attachment.rear.PlowRearAttachmentModel; +import io.github.foundationgames.automobility.automobile.render.attachment.rear.StonecutterRearAttachmentModel; +import io.github.foundationgames.automobility.automobile.render.engine.CopperEngineModel; +import io.github.foundationgames.automobility.automobile.render.engine.CreativeEngineModel; +import io.github.foundationgames.automobility.automobile.render.engine.DiamondEngineModel; +import io.github.foundationgames.automobility.automobile.render.engine.GoldEngineModel; +import io.github.foundationgames.automobility.automobile.render.engine.IronEngineModel; +import io.github.foundationgames.automobility.automobile.render.engine.StoneEngineModel; +import io.github.foundationgames.automobility.automobile.render.frame.CARRFrameModel; +import io.github.foundationgames.automobility.automobile.render.frame.DaBabyFrameModel; +import io.github.foundationgames.automobility.automobile.render.frame.MotorcarFrameModel; +import io.github.foundationgames.automobility.automobile.render.frame.PineappleFrameModel; +import io.github.foundationgames.automobility.automobile.render.frame.RickshawFrameModel; +import io.github.foundationgames.automobility.automobile.render.frame.ShoppingCartFrameModel; +import io.github.foundationgames.automobility.automobile.render.frame.StandardFrameModel; +import io.github.foundationgames.automobility.automobile.render.frame.TractorFrameModel; +import io.github.foundationgames.automobility.automobile.render.wheel.CarriageWheelModel; +import io.github.foundationgames.automobility.automobile.render.wheel.ConvertibleWheelModel; +import io.github.foundationgames.automobility.automobile.render.wheel.OffRoadWheelModel; +import io.github.foundationgames.automobility.automobile.render.wheel.StandardWheelModel; +import io.github.foundationgames.automobility.automobile.render.wheel.SteelWheelModel; +import io.github.foundationgames.automobility.automobile.render.wheel.TractorWheelModel; +import io.github.foundationgames.automobility.util.EntityRenderHelper; +import net.minecraft.client.model.Model; +import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.resources.ResourceLocation; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; + +public enum AutomobileModels {; + private static final ResourceLocation EMPTY = Automobility.rl("empty"); + + public static final ResourceLocation SKID_EFFECT = Automobility.rl("misc_skideffect"); + public static final ResourceLocation EXHAUST_FUMES = Automobility.rl("misc_exhaustfumes"); + + private static final Map> modelProviders = new HashMap<>(); + private static final Map models = new HashMap<>(); + + public static void register(ResourceLocation location, Function model) { + modelProviders.put(location, model); + } + + public static void init() { + EntityRenderHelper.registerContextListener(ctx -> { + models.clear(); + models.put(EMPTY, new EmptyModel()); + + for (var entry : modelProviders.entrySet()) { + models.put(entry.getKey(), entry.getValue().apply(ctx)); + } + }); + + register(Automobility.rl("frame_standard"), StandardFrameModel::new); + register(Automobility.rl("frame_tractor"), TractorFrameModel::new); + register(Automobility.rl("frame_shopping_cart"), ShoppingCartFrameModel::new); + register(Automobility.rl("frame_c_arr"), CARRFrameModel::new); + register(Automobility.rl("frame_pineapple"), PineappleFrameModel::new); + register(Automobility.rl("frame_motorcar"), MotorcarFrameModel::new); + register(Automobility.rl("frame_rickshaw"), RickshawFrameModel::new); + register(Automobility.rl("frame_dababy"), DaBabyFrameModel::new); + + register(Automobility.rl("wheel_standard"), StandardWheelModel::new); + register(Automobility.rl("wheel_off_road"), OffRoadWheelModel::new); + register(Automobility.rl("wheel_steel"), SteelWheelModel::new); + register(Automobility.rl("wheel_tractor"), TractorWheelModel::new); + register(Automobility.rl("wheel_carriage"), CarriageWheelModel::new); + register(Automobility.rl("wheel_convertible"), ConvertibleWheelModel::new); + + register(Automobility.rl("engine_stone"), StoneEngineModel::new); + register(Automobility.rl("engine_iron"), IronEngineModel::new); + register(Automobility.rl("engine_copper"), CopperEngineModel::new); + register(Automobility.rl("engine_gold"), GoldEngineModel::new); + register(Automobility.rl("engine_diamond"), DiamondEngineModel::new); + register(Automobility.rl("engine_creative"), CreativeEngineModel::new); + + register(Automobility.rl("rearatt_passenger_seat"), PassengerSeatRearAttachmentModel::new); + register(Automobility.rl("rearatt_block"), BlockRearAttachmentModel::new); + register(Automobility.rl("rearatt_grindstone"), GrindstoneRearAttachmentModel::new); + register(Automobility.rl("rearatt_stonecutter"), StonecutterRearAttachmentModel::new); + register(Automobility.rl("rearatt_chest"), ChestRearAttachmentModel::new); + register(Automobility.rl("rearatt_banner_post"), BannerPostRearAttachmentModel::new); + register(Automobility.rl("rearatt_plow"), PlowRearAttachmentModel::new); + + register(Automobility.rl("frontatt_mob_controller"), MobControllerFrontAttachmentModel::new); + register(Automobility.rl("frontatt_harvester"), HarvesterFrontAttachmentModel::new); + + register(SKID_EFFECT, SkidEffectModel::new); + register(EXHAUST_FUMES, ExhaustFumesModel::new); + } + + public static Model getModelOrNull(ResourceLocation location) { + return models.get(location); + } + + public static Model getModel(ResourceLocation location) { + var result = getModelOrNull(location); + if (result == null) { + return getEmpty(); + } + return result; + } + + public static Model getEmpty() { + return getModelOrNull(EMPTY); + } +} 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 new file mode 100644 index 0000000..7ac8b3a --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/AutomobileRenderer.java @@ -0,0 +1,208 @@ +package io.github.foundationgames.automobility.automobile.render; + +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import com.mojang.math.Vector3f; +import io.github.foundationgames.automobility.automobile.AutomobileEngine; +import io.github.foundationgames.automobility.automobile.WheelBase; +import io.github.foundationgames.automobility.automobile.render.attachment.front.FrontAttachmentRenderModel; +import io.github.foundationgames.automobility.automobile.render.attachment.rear.RearAttachmentRenderModel; +import io.github.foundationgames.automobility.automobile.render.wheel.WheelContextReceiver; +import io.github.foundationgames.automobility.entity.AutomobileEntity; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.resources.ResourceLocation; + +public enum AutomobileRenderer {; + public static void render( + PoseStack pose, MultiBufferSource buffers, int light, int overlay, + float tickDelta, RenderableAutomobile automobile + ) { + var frame = automobile.getFrame(); + var wheels = automobile.getWheels(); + var engine = automobile.getEngine(); + + var skidEffectModel = AutomobileModels.getModel(AutomobileModels.SKID_EFFECT); + var exhaustFumesModel = AutomobileModels.getModel(AutomobileModels.EXHAUST_FUMES); + + pose.pushPose(); + + pose.mulPose(Vector3f.ZP.rotationDegrees(180)); + pose.mulPose(Vector3f.YP.rotationDegrees(automobile.getAutomobileYaw(tickDelta) + 180)); + + float chassisRaise = wheels.model().radius() / 16; + float bounce = automobile.getSuspensionBounce(tickDelta) * 0.048f; + + var frameModel = AutomobileModels.getModel(automobile.getFrame().model().modelId()); + var wheelModel = AutomobileModels.getModel(automobile.getWheels().model().modelId()); + var engineModel = AutomobileModels.getModel(automobile.getEngine().model().modelId()); + var rearAttachmentModel = AutomobileModels.getModel(automobile.getRearAttachmentType().model().modelId()); + var frontAttachmentModel = AutomobileModels.getModel(automobile.getFrontAttachmentType().model().modelId()); + + pose.translate(0, -chassisRaise, 0); + + // Frame, engine, exhaust + pose.pushPose(); + + pose.translate(0, bounce + (automobile.engineRunning() ? (Math.cos((automobile.getTime() + tickDelta) * 2.7) / 156) : 0), 0); + var frameTexture = frame.model().texture(); + var engineTexture = engine.model().texture(); + if (!frame.isEmpty() && frameModel != null) { + frameModel.renderToBuffer(pose, buffers.getBuffer(frameModel.renderType(frameTexture)), light, overlay, 1, 1, 1, 1); + if (frameModel instanceof BaseModel base) { + base.doOtherLayerRender(pose, buffers, light, overlay); + } + } + + float eBack = frame.model().enginePosBack() / 16; + float eUp = frame.model().enginePosUp() / 16; + pose.translate(0, -eUp, eBack); + pose.mulPose(Vector3f.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) { + base.doOtherLayerRender(pose, buffers, light, overlay); + } + } + + VertexConsumer exhaustBuffer = null; + ResourceLocation[] exhaustTexes; + if (automobile.getBoostTimer() > 0) { + exhaustTexes = ExhaustFumesModel.FLAME_TEXTURES; + int index = (int)(automobile.getTime() % exhaustTexes.length); + exhaustBuffer = buffers.getBuffer(RenderType.eyes(exhaustTexes[index])); + } else if (automobile.engineRunning()) { + exhaustTexes = ExhaustFumesModel.SMOKE_TEXTURES; + int index = (int)Math.floor(((automobile.getTime() + tickDelta) / 1.5f) % exhaustTexes.length); + exhaustBuffer = buffers.getBuffer(RenderType.entityTranslucent(exhaustTexes[index])); + } + if (exhaustBuffer != null) { + for (AutomobileEngine.ExhaustPos exhaust : engine.model().exhausts()) { + 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())); + exhaustFumesModel.renderToBuffer(pose, exhaustBuffer, light, overlay, 1, 1, 1, 1); + + pose.popPose(); + } + } + pose.popPose(); + + // Rear Attachment + var rearAtt = automobile.getRearAttachmentType(); + 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.translate(0, 0, rearAtt.model().pivotDistPx() / 16); + if (rearAttachmentModel instanceof RearAttachmentRenderModel rm) { + rm.setRenderState(automobile.getRearAttachment(), (float) Math.toRadians(automobile.getWheelAngle(tickDelta)), tickDelta); + } + rearAttachmentModel.renderToBuffer(pose, buffers.getBuffer(rearAttachmentModel.renderType(rearAtt.model().texture())), light, overlay, 1, 1, 1, 1); + if (rearAttachmentModel instanceof BaseModel base) { + base.doOtherLayerRender(pose, buffers, light, overlay); + } + pose.popPose(); + } + + // Front Attachment + var frontAtt = automobile.getFrontAttachmentType(); + if (!frontAtt.isEmpty()) { + pose.pushPose(); + pose.translate(0, 0, frame.model().frontAttachmentPos() / -16); + + if (frontAttachmentModel instanceof FrontAttachmentRenderModel fm) { + fm.setRenderState(automobile.getFrontAttachment(), chassisRaise, tickDelta); + } + frontAttachmentModel.renderToBuffer(pose, buffers.getBuffer(frontAttachmentModel.renderType(frontAtt.model().texture())), light, overlay, 1, 1, 1, 1); + if (frontAttachmentModel instanceof BaseModel base) { + base.doOtherLayerRender(pose, buffers, light, overlay); + } + pose.popPose(); + } + + // WHEELS ---------------------------------------- + var wPoses = frame.model().wheelBase().wheels; + + if (!wheels.isEmpty()) { + var wheelBuffer = buffers.getBuffer(wheelModel.renderType(wheels.model().texture())); + float wheelAngle = automobile.getWheelAngle(tickDelta); + int wheelCount = automobile.getWheelCount(); + + for (var pos : wPoses) { + if (wheelCount <= 0) { + break; + } + + if (wheelModel instanceof WheelContextReceiver receiver) { + receiver.provideContext(pos); + } + float scale = pos.scale(); + float wheelRadius = wheels.model().radius() - (wheels.model().radius() * (scale - 1)); + pose.pushPose(); + + 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)); + pose.translate(0, -chassisRaise, 0); + pose.mulPose(Vector3f.XP.rotationDegrees(wheelAngle)); + pose.scale(scale, scale, scale); + + pose.mulPose(Vector3f.YP.rotationDegrees(180 + pos.yaw())); + + wheelModel.renderToBuffer(pose, wheelBuffer, light, overlay, 1, 1, 1, 1); + if (wheelModel instanceof BaseModel base) { + base.doOtherLayerRender(pose, buffers, light, overlay); + } + + pose.popPose(); + + wheelCount--; + } + } + + // Skid effects + if ((automobile.getTurboCharge() > AutomobileEntity.SMALL_TURBO_TIME || automobile.debris()) && automobile.automobileOnGround()) { + var skidTexes = SkidEffectModel.COOL_SPARK_TEXTURES; + boolean bright = true; + float r = 1; + float g = 1; + float b = 1; + if (automobile.getTurboCharge() > AutomobileEntity.LARGE_TURBO_TIME) { + skidTexes = SkidEffectModel.FLAME_TEXTURES; + } else if (automobile.getTurboCharge() > AutomobileEntity.MEDIUM_TURBO_TIME) { + skidTexes = SkidEffectModel.HOT_SPARK_TEXTURES; + } else if (automobile.debris()) { + skidTexes = SkidEffectModel.DEBRIS_TEXTURES; + var c = automobile.debrisColor(); + r = c.x() * 0.85f; + g = c.y() * 0.85f; + b = c.z() * 0.85f; + bright = false; + } + int index = (int)Math.floor(((automobile.getTime() + tickDelta) / 1.5f) % skidTexes.length); + var skidEffectBuffer = buffers.getBuffer(bright ? RenderType.eyes(skidTexes[index]) : RenderType.entitySmoothCutout(skidTexes[index])); + + for (var pos : wPoses) { + if (pos.end() == WheelBase.WheelEnd.BACK) { + float scale = pos.scale(); + float heightOffset = wheels.model().radius(); + float wheelRadius = wheels.model().radius() * scale; + float wheelWidth = (wheels.model().width() / 16) * scale; + float back = (wheelRadius > 2) ? (float) (Math.sqrt((wheelRadius * wheelRadius) - Math.pow(wheelRadius - 2, 2)) - 0.85) / 16 : 0.08f; + pose.pushPose(); + pose.translate((pos.right() / 16) + (wheelWidth * (pos.side() == WheelBase.WheelSide.RIGHT ? 1 : -1)), heightOffset / 16, (-pos.forward() / 16) + back); + pose.scale(pos.side() == WheelBase.WheelSide.LEFT ? -1 : 1, 1, -1); + skidEffectModel.renderToBuffer(pose, skidEffectBuffer, light, overlay, r, g, b, 0.6f); + pose.popPose(); + } + } + } + // ----------------------------------------------- + + pose.popPose(); + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/BaseModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/BaseModel.java new file mode 100644 index 0000000..450fcb8 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/BaseModel.java @@ -0,0 +1,47 @@ +package io.github.foundationgames.automobility.automobile.render; + +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.model.Model; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.resources.ResourceLocation; + +import java.util.function.Function; + +public class BaseModel extends Model { + protected final ModelPart root; + + public BaseModel(Function layerFactory, EntityRendererProvider.Context ctx, ModelLayerLocation layer) { + super(layerFactory); + this.root = ctx.bakeLayer(layer).getChild("main"); + } + + protected void prepare(PoseStack matrices) { + } + + @Override + public final void renderToBuffer(PoseStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) { + matrices.pushPose(); + this.prepare(matrices); + this.root.render(matrices, vertices, light, overlay, red, green, blue, alpha); + renderExtra(matrices, vertices, light, overlay, red, green, blue, alpha); + matrices.popPose(); + } + + public final void doOtherLayerRender(PoseStack matrices, MultiBufferSource consumers, int light, int overlay) { + matrices.pushPose(); + this.prepare(matrices); + this.renderOtherLayer(matrices, consumers, light, overlay); + matrices.popPose(); + } + + public void renderExtra(PoseStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) { + } + + public void renderOtherLayer(PoseStack matrices, MultiBufferSource consumers, int light, int overlay) { + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/EmptyModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/EmptyModel.java new file mode 100644 index 0000000..eba60af --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/EmptyModel.java @@ -0,0 +1,16 @@ +package io.github.foundationgames.automobility.automobile.render; + +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.model.Model; +import net.minecraft.client.renderer.RenderType; + +public class EmptyModel extends Model { + public EmptyModel() { + super(RenderType::entitySolid); + } + + @Override + public void renderToBuffer(PoseStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) { + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/ExhaustFumesModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/ExhaustFumesModel.java new file mode 100644 index 0000000..0df2b51 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/ExhaustFumesModel.java @@ -0,0 +1,28 @@ +package io.github.foundationgames.automobility.automobile.render; + +import io.github.foundationgames.automobility.Automobility; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.resources.ResourceLocation; + +public class ExhaustFumesModel extends BaseModel { + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile_exhaust_fumes"), "main"); + + public static final ResourceLocation[] SMOKE_TEXTURES = new ResourceLocation[] { + Automobility.rl("textures/entity/automobile/exhaust/exhaust_smoke_0.png"), + Automobility.rl("textures/entity/automobile/exhaust/exhaust_smoke_1.png"), + Automobility.rl("textures/entity/automobile/exhaust/exhaust_smoke_2.png"), + Automobility.rl("textures/entity/automobile/exhaust/exhaust_smoke_3.png") + }; + public static final ResourceLocation[] FLAME_TEXTURES = new ResourceLocation[] { + Automobility.rl("textures/entity/automobile/exhaust/exhaust_flames_0.png"), + Automobility.rl("textures/entity/automobile/exhaust/exhaust_flames_1.png"), + Automobility.rl("textures/entity/automobile/exhaust/exhaust_flames_2.png"), + Automobility.rl("textures/entity/automobile/exhaust/exhaust_flames_3.png") + }; + + public ExhaustFumesModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityCutout, ctx, MODEL_LAYER); + } +} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/RenderableAutomobile.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/RenderableAutomobile.java similarity index 79% rename from src/main/java/io/github/foundationgames/automobility/automobile/render/RenderableAutomobile.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/render/RenderableAutomobile.java index 90787f1..541f109 100644 --- a/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,5 +1,6 @@ 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; @@ -7,9 +8,6 @@ import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType; import io.github.foundationgames.automobility.automobile.attachment.front.FrontAttachment; import io.github.foundationgames.automobility.automobile.attachment.rear.RearAttachment; -import net.minecraft.client.model.Model; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.util.math.Vec3f; import org.jetbrains.annotations.Nullable; public interface RenderableAutomobile { @@ -37,16 +35,6 @@ default FrontAttachmentType getFrontAttachmentType() { return this.getFrontAttachment().type; } - Model getFrameModel(EntityRendererFactory.Context ctx); - - Model getWheelModel(EntityRendererFactory.Context ctx); - - Model getEngineModel(EntityRendererFactory.Context ctx); - - Model getRearAttachmentModel(EntityRendererFactory.Context ctx); - - Model getFrontAttachmentModel(EntityRendererFactory.Context ctx); - float getAutomobileYaw(float tickDelta); float getRearAttachmentYaw(float tickDelta); @@ -73,5 +61,5 @@ default int getWheelCount() { boolean debris(); - Vec3f debrisColor(); + Vector3f debrisColor(); } diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/SkidEffectModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/SkidEffectModel.java new file mode 100644 index 0000000..73a99b9 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/SkidEffectModel.java @@ -0,0 +1,36 @@ +package io.github.foundationgames.automobility.automobile.render; + +import io.github.foundationgames.automobility.Automobility; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.resources.ResourceLocation; + +public class SkidEffectModel extends BaseModel { + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile_skid_effect"), "main"); + + public static final ResourceLocation[] COOL_SPARK_TEXTURES = new ResourceLocation[] { + Automobility.rl("textures/entity/automobile/skid_effect/skid_cool_sparks_0.png"), + Automobility.rl("textures/entity/automobile/skid_effect/skid_cool_sparks_1.png"), + Automobility.rl("textures/entity/automobile/skid_effect/skid_cool_sparks_2.png") + }; + public static final ResourceLocation[] HOT_SPARK_TEXTURES = new ResourceLocation[] { + Automobility.rl("textures/entity/automobile/skid_effect/skid_hot_sparks_0.png"), + Automobility.rl("textures/entity/automobile/skid_effect/skid_hot_sparks_1.png"), + Automobility.rl("textures/entity/automobile/skid_effect/skid_hot_sparks_2.png") + }; + public static final ResourceLocation[] FLAME_TEXTURES = new ResourceLocation[] { + Automobility.rl("textures/entity/automobile/skid_effect/skid_flames_0.png"), + Automobility.rl("textures/entity/automobile/skid_effect/skid_flames_1.png"), + Automobility.rl("textures/entity/automobile/skid_effect/skid_flames_2.png") + }; + public static final ResourceLocation[] DEBRIS_TEXTURES = new ResourceLocation[] { + Automobility.rl("textures/entity/automobile/skid_effect/skid_debris_0.png"), + Automobility.rl("textures/entity/automobile/skid_effect/skid_debris_1.png"), + Automobility.rl("textures/entity/automobile/skid_effect/skid_debris_2.png") + }; + + public SkidEffectModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityCutout, ctx, MODEL_LAYER); + } +} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/FrontAttachmentRenderModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/FrontAttachmentRenderModel.java similarity index 59% rename from src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/FrontAttachmentRenderModel.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/FrontAttachmentRenderModel.java index 400eb7d..04b781f 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/FrontAttachmentRenderModel.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/FrontAttachmentRenderModel.java @@ -1,14 +1,14 @@ package io.github.foundationgames.automobility.automobile.render.attachment.front; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; import io.github.foundationgames.automobility.automobile.attachment.front.FrontAttachment; import io.github.foundationgames.automobility.automobile.render.BaseModel; -import net.minecraft.client.model.ModelPart; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.Identifier; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.Nullable; import java.util.NoSuchElementException; @@ -18,11 +18,11 @@ public class FrontAttachmentRenderModel extends BaseModel { protected final @Nullable ModelPart ground; private float groundHeight = 0; - public FrontAttachmentRenderModel(Function layerFactory, EntityRendererFactory.Context ctx, EntityModelLayer layer) { + public FrontAttachmentRenderModel(Function layerFactory, EntityRendererProvider.Context ctx, ModelLayerLocation layer) { super(layerFactory, ctx, layer); ModelPart ground; try { - ground = ctx.getPart(layer).getChild("ground"); + ground = ctx.bakeLayer(layer).getChild("ground"); } catch (NoSuchElementException ignored) { ground = null; } @@ -38,12 +38,12 @@ public void resetModel() { } @Override - public void renderExtra(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) { + public void renderExtra(PoseStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) { if (this.ground != null) { - matrices.push(); + matrices.pushPose(); matrices.translate(0, groundHeight, 0); this.ground.render(matrices, vertices, light, overlay, red, green, blue, alpha); - matrices.pop(); + matrices.popPose(); } } } diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/HarvesterFrontAttachmentModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/HarvesterFrontAttachmentModel.java similarity index 56% rename from src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/HarvesterFrontAttachmentModel.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/HarvesterFrontAttachmentModel.java index e8b5447..f09982a 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/HarvesterFrontAttachmentModel.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/HarvesterFrontAttachmentModel.java @@ -2,19 +2,19 @@ import io.github.foundationgames.automobility.Automobility; import io.github.foundationgames.automobility.automobile.attachment.front.FrontAttachment; -import net.minecraft.client.model.ModelPart; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; import org.jetbrains.annotations.Nullable; public class HarvesterFrontAttachmentModel extends FrontAttachmentRenderModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/front_attachment/harvester"), "main"); + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/front_attachment/harvester"), "main"); private final @Nullable ModelPart roller; - public HarvesterFrontAttachmentModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityCutout, ctx, MODEL_LAYER); + public HarvesterFrontAttachmentModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityCutout, ctx, MODEL_LAYER); if (this.ground != null) { this.roller = this.ground.getChild("roller"); @@ -29,9 +29,9 @@ public void setRenderState(@Nullable FrontAttachment attachment, float groundHei if (this.roller != null) { if (attachment != null) { - this.roller.setAngles((float) Math.toRadians(attachment.automobile().getWheelAngle(tickDelta)), 0, 0); + this.roller.setRotation((float) Math.toRadians(attachment.automobile().getWheelAngle(tickDelta)), 0, 0); } else { - this.roller.setAngles(0, 0, 0); + this.roller.setRotation(0, 0, 0); } } } diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/MobControllerFrontAttachmentModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/MobControllerFrontAttachmentModel.java new file mode 100644 index 0000000..2204a65 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/MobControllerFrontAttachmentModel.java @@ -0,0 +1,14 @@ +package io.github.foundationgames.automobility.automobile.render.attachment.front; + +import io.github.foundationgames.automobility.Automobility; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; + +public class MobControllerFrontAttachmentModel extends FrontAttachmentRenderModel { + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/front_attachment/mob_controller"), "main"); + + public MobControllerFrontAttachmentModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityCutout, ctx, MODEL_LAYER); + } +} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/BannerPostRearAttachmentModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/BannerPostRearAttachmentModel.java similarity index 58% rename from src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/BannerPostRearAttachmentModel.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/BannerPostRearAttachmentModel.java index 476cc9a..cbc5044 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/BannerPostRearAttachmentModel.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/BannerPostRearAttachmentModel.java @@ -1,27 +1,27 @@ package io.github.foundationgames.automobility.automobile.render.attachment.rear; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.datafixers.util.Pair; import io.github.foundationgames.automobility.Automobility; import io.github.foundationgames.automobility.automobile.attachment.rear.BannerPostRearAttachment; import io.github.foundationgames.automobility.automobile.attachment.rear.RearAttachment; -import net.minecraft.block.entity.BannerPattern; -import net.minecraft.client.model.ModelPart; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.render.block.entity.BannerBlockEntityRenderer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; -import net.minecraft.client.render.model.ModelLoader; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.DyeColor; -import net.minecraft.util.registry.RegistryEntry; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.blockentity.BannerRenderer; +import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.client.resources.model.ModelBakery; +import net.minecraft.core.Holder; +import net.minecraft.world.item.DyeColor; +import net.minecraft.world.level.block.entity.BannerPattern; import org.jetbrains.annotations.Nullable; import java.util.List; public class BannerPostRearAttachmentModel extends RearAttachmentRenderModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/rear_attachment/banner_post"), "main"); + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/rear_attachment/banner_post"), "main"); private final ModelPart fakePole; private final ModelPart pole; @@ -33,10 +33,10 @@ public class BannerPostRearAttachmentModel extends RearAttachmentRenderModel { private boolean renderPole; private boolean renderFlag; - private List, DyeColor>> patterns; + private List, DyeColor>> patterns; - public BannerPostRearAttachmentModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityCutoutNoCull, ctx, MODEL_LAYER); + public BannerPostRearAttachmentModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityCutoutNoCull, ctx, MODEL_LAYER); this.fakePole = this.root.getChild("fake_pole"); this.pole = this.root.getChild("pole"); @@ -55,16 +55,16 @@ public void setRenderState(@Nullable RearAttachment attachment, float wheelAngle super.setRenderState(attachment, wheelAngle, tickDelta); float push = attachment == null ? 0 : (float) Math.pow(Math.max(0, attachment.automobile().getHSpeed() * 0.368f), 2); - this.pole.pitch = -push; - this.bar.pitch = push; - this.flagPole.pitch = -push; - this.flagBar.pitch = push; + this.pole.xRot = -push; + this.bar.xRot = push; + this.flagPole.xRot = -push; + this.flagBar.xRot = push; if (attachment instanceof BannerPostRearAttachment bannerPost) { this.renderFlag = bannerPost.getBaseColor() != null; this.patterns = bannerPost.getPatterns(); - this.flag.setAngles(push, this.flag.yaw, 0.05f * (float)Math.sin((attachment.automobile().getTime() + tickDelta) / 20)); + this.flag.setRotation(push, this.flag.yRot, 0.05f * (float)Math.sin((attachment.automobile().getTime() + tickDelta) / 20)); } this.renderPole = attachment != null; @@ -72,17 +72,17 @@ public void setRenderState(@Nullable RearAttachment attachment, float wheelAngle } @Override - public void renderExtra(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) { + public void renderExtra(PoseStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) { if (this.renderPole) { this.pole.visible = true; - matrices.push(); + matrices.pushPose(); matrices.translate(0, -1f, 0); matrices.scale(0.666f, 0.666f, 0.666f); matrices.translate(0, 1f, 0); this.pole.render(matrices, vertices, light, overlay, red, green, blue, alpha); - matrices.pop(); + matrices.popPose(); this.pole.visible = false; this.renderPole = false; } @@ -90,17 +90,17 @@ public void renderExtra(MatrixStack matrices, VertexConsumer vertices, int light } @Override - public void renderOtherLayer(MatrixStack matrices, VertexConsumerProvider consumers, int light, int overlay) { + public void renderOtherLayer(PoseStack matrices, MultiBufferSource consumers, int light, int overlay) { if (this.renderFlag) { this.flagPole.visible = true; - matrices.push(); + matrices.pushPose(); matrices.translate(0, -1f, 0); matrices.scale(0.666f, 0.666f, 0.666f); matrices.translate(0, 1f, 0); - BannerBlockEntityRenderer.renderCanvas(matrices, consumers, light, overlay, this.flagPole, ModelLoader.BANNER_BASE, true, this.patterns, false); + BannerRenderer.renderPatterns(matrices, consumers, light, overlay, this.flagPole, ModelBakery.BANNER_BASE, true, this.patterns, false); - matrices.pop(); + matrices.popPose(); this.flagPole.visible = false; this.renderFlag = false; } diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/BlockRearAttachmentModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/BlockRearAttachmentModel.java new file mode 100644 index 0000000..597e329 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/BlockRearAttachmentModel.java @@ -0,0 +1,14 @@ +package io.github.foundationgames.automobility.automobile.render.attachment.rear; + +import io.github.foundationgames.automobility.Automobility; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; + +public class BlockRearAttachmentModel extends RearAttachmentRenderModel { + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/rear_attachment/block"), "main"); + + public BlockRearAttachmentModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityCutoutNoCull, ctx, MODEL_LAYER); + } +} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/ChestRearAttachmentModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/ChestRearAttachmentModel.java similarity index 58% rename from src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/ChestRearAttachmentModel.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/ChestRearAttachmentModel.java index b7f2dfc..5a3f7e5 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/ChestRearAttachmentModel.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/ChestRearAttachmentModel.java @@ -3,19 +3,19 @@ import io.github.foundationgames.automobility.Automobility; import io.github.foundationgames.automobility.automobile.attachment.rear.BaseChestRearAttachment; import io.github.foundationgames.automobility.automobile.attachment.rear.RearAttachment; -import net.minecraft.client.model.ModelPart; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; import org.jetbrains.annotations.Nullable; public class ChestRearAttachmentModel extends RearAttachmentRenderModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/rear_attachment/chest"), "main"); + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/rear_attachment/chest"), "main"); private final ModelPart lid; - public ChestRearAttachmentModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityCutoutNoCull, ctx, MODEL_LAYER); + public ChestRearAttachmentModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityCutoutNoCull, ctx, MODEL_LAYER); this.lid = this.root.getChild("lid"); } @@ -24,15 +24,15 @@ public void setRenderState(@Nullable RearAttachment attachment, float wheelAngle super.setRenderState(attachment, wheelAngle, tickDelta); if (attachment instanceof BaseChestRearAttachment chest) { - float angle = 1 - chest.lidAnimator.getProgress(tickDelta); + float angle = 1 - chest.lidAnimator.getOpenness(tickDelta); angle = 1 - (angle * angle * angle); - this.lid.setAngles((float) (angle * Math.PI * 0.5), 0, 0); + this.lid.setRotation((float) (angle * Math.PI * 0.5), 0, 0); } } @Override public void resetModel() { super.resetModel(); - this.lid.setAngles(0, 0, 0); + this.lid.setRotation(0, 0, 0); } } diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/GrindstoneRearAttachmentModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/GrindstoneRearAttachmentModel.java similarity index 54% rename from src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/GrindstoneRearAttachmentModel.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/GrindstoneRearAttachmentModel.java index 8a895f4..a3f5e19 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/GrindstoneRearAttachmentModel.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/GrindstoneRearAttachmentModel.java @@ -2,19 +2,19 @@ import io.github.foundationgames.automobility.Automobility; import io.github.foundationgames.automobility.automobile.attachment.rear.RearAttachment; -import net.minecraft.client.model.ModelPart; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; import org.jetbrains.annotations.Nullable; public class GrindstoneRearAttachmentModel extends RearAttachmentRenderModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/rear_attachment/grindstone"), "main"); + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/rear_attachment/grindstone"), "main"); private final ModelPart grindstone; - public GrindstoneRearAttachmentModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityCutoutNoCull, ctx, MODEL_LAYER); + public GrindstoneRearAttachmentModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityCutoutNoCull, ctx, MODEL_LAYER); this.grindstone = this.root.getChild("grindstone"); } @@ -23,7 +23,7 @@ public void setRenderState(@Nullable RearAttachment attachment, float wheelAngle super.setRenderState(attachment, wheelAngle, tickDelta); if (this.grindstone != null) { - this.grindstone.setAngles(wheelAngle * 0.25f, 0, 0); + this.grindstone.setRotation(wheelAngle * 0.25f, 0, 0); } } } diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/PassengerSeatRearAttachmentModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/PassengerSeatRearAttachmentModel.java new file mode 100644 index 0000000..a550155 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/PassengerSeatRearAttachmentModel.java @@ -0,0 +1,14 @@ +package io.github.foundationgames.automobility.automobile.render.attachment.rear; + +import io.github.foundationgames.automobility.Automobility; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; + +public class PassengerSeatRearAttachmentModel extends RearAttachmentRenderModel { + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/rear_attachment/passenger_seat"), "main"); + + public PassengerSeatRearAttachmentModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityCutoutNoCull, ctx, MODEL_LAYER); + } +} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/PlowRearAttachmentModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/PlowRearAttachmentModel.java similarity index 67% rename from src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/PlowRearAttachmentModel.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/PlowRearAttachmentModel.java index 41ab780..f3fe76e 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/PlowRearAttachmentModel.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/PlowRearAttachmentModel.java @@ -3,22 +3,22 @@ import io.github.foundationgames.automobility.Automobility; import io.github.foundationgames.automobility.automobile.attachment.rear.ExtendableRearAttachment; import io.github.foundationgames.automobility.automobile.attachment.rear.RearAttachment; -import net.minecraft.client.model.ModelPart; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; import org.jetbrains.annotations.Nullable; import java.util.NoSuchElementException; public class PlowRearAttachmentModel extends RearAttachmentRenderModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/rear_attachment/plow"), "main"); + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/rear_attachment/plow"), "main"); private final ModelPart assembly; private final ModelPart instrument; - public PlowRearAttachmentModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityCutoutNoCull, ctx, MODEL_LAYER); + public PlowRearAttachmentModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityCutoutNoCull, ctx, MODEL_LAYER); ModelPart assembly = null, instrument = null; try { @@ -36,8 +36,8 @@ public void setRenderState(@Nullable RearAttachment attachment, float wheelAngle if (this.assembly != null && this.instrument != null && attachment instanceof ExtendableRearAttachment att) { float anim = att.extendAnimation(tickDelta); - this.assembly.setAngles(6.5f * anim, 0, 0); - this.instrument.setAngles(-3 * anim, 0, 0); + this.assembly.setRotation(6.5f * anim, 0, 0); + this.instrument.setRotation(-3 * anim, 0, 0); } } } diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/RearAttachmentRenderModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/RearAttachmentRenderModel.java similarity index 66% rename from src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/RearAttachmentRenderModel.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/RearAttachmentRenderModel.java index d7f9864..3c57a6a 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/RearAttachmentRenderModel.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/RearAttachmentRenderModel.java @@ -2,11 +2,11 @@ import io.github.foundationgames.automobility.automobile.attachment.rear.RearAttachment; import io.github.foundationgames.automobility.automobile.render.BaseModel; -import net.minecraft.client.model.ModelPart; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; -import net.minecraft.util.Identifier; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.Nullable; import java.util.NoSuchElementException; @@ -15,7 +15,7 @@ public class RearAttachmentRenderModel extends BaseModel { private final @Nullable ModelPart wheels; - public RearAttachmentRenderModel(Function layerFactory, EntityRendererFactory.Context ctx, EntityModelLayer layer) { + public RearAttachmentRenderModel(Function layerFactory, EntityRendererProvider.Context ctx, ModelLayerLocation layer) { super(layerFactory, ctx, layer); ModelPart wheels; try { @@ -28,7 +28,7 @@ public RearAttachmentRenderModel(Function layerFactory, public void setRenderState(@Nullable RearAttachment attachment, float wheelAngle, float tickDelta) { if (this.wheels != null) { - this.wheels.setAngles(wheelAngle, 0, 0); + this.wheels.setRotation(wheelAngle, 0, 0); } } diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/StonecutterRearAttachmentModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/StonecutterRearAttachmentModel.java similarity index 54% rename from src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/StonecutterRearAttachmentModel.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/StonecutterRearAttachmentModel.java index d47c3b4..c582099 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/StonecutterRearAttachmentModel.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/StonecutterRearAttachmentModel.java @@ -2,19 +2,19 @@ import io.github.foundationgames.automobility.Automobility; import io.github.foundationgames.automobility.automobile.attachment.rear.RearAttachment; -import net.minecraft.client.model.ModelPart; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; import org.jetbrains.annotations.Nullable; public class StonecutterRearAttachmentModel extends RearAttachmentRenderModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/rear_attachment/stonecutter"), "main"); + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/rear_attachment/stonecutter"), "main"); private final ModelPart blade; - public StonecutterRearAttachmentModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityCutoutNoCull, ctx, MODEL_LAYER); + public StonecutterRearAttachmentModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityCutoutNoCull, ctx, MODEL_LAYER); this.blade = this.root.getChild("blade"); } @@ -23,7 +23,7 @@ public void setRenderState(@Nullable RearAttachment attachment, float wheelAngle super.setRenderState(attachment, wheelAngle, tickDelta); if (this.blade != null) { - this.blade.setAngles(wheelAngle * 0.45f, 0, 0); + this.blade.setRotation(wheelAngle * 0.45f, 0, 0); } } } 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 new file mode 100644 index 0000000..509f1da --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/CopperEngineModel.java @@ -0,0 +1,22 @@ +package io.github.foundationgames.automobility.automobile.render.engine; + +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.math.Vector3f; +import io.github.foundationgames.automobility.Automobility; +import io.github.foundationgames.automobility.automobile.render.BaseModel; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; + +public class CopperEngineModel extends BaseModel { + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/engine/copper"), "main"); + + public CopperEngineModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityCutout, ctx, MODEL_LAYER); + } + + @Override + protected void prepare(PoseStack matrices) { + matrices.mulPose(Vector3f.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 new file mode 100644 index 0000000..1b5fad0 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/CreativeEngineModel.java @@ -0,0 +1,22 @@ +package io.github.foundationgames.automobility.automobile.render.engine; + +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.math.Vector3f; +import io.github.foundationgames.automobility.Automobility; +import io.github.foundationgames.automobility.automobile.render.BaseModel; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; + +public class CreativeEngineModel extends BaseModel { + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/engine/creative"), "main"); + + public CreativeEngineModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityCutout, ctx, MODEL_LAYER); + } + + @Override + protected void prepare(PoseStack matrices) { + matrices.mulPose(Vector3f.YP.rotationDegrees(180)); + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/DiamondEngineModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/DiamondEngineModel.java new file mode 100644 index 0000000..3c00bde --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/DiamondEngineModel.java @@ -0,0 +1,15 @@ +package io.github.foundationgames.automobility.automobile.render.engine; + +import io.github.foundationgames.automobility.Automobility; +import io.github.foundationgames.automobility.automobile.render.BaseModel; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; + +public class DiamondEngineModel extends BaseModel { + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/engine/diamond"), "main"); + + public DiamondEngineModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityCutout, ctx, MODEL_LAYER); + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/GoldEngineModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/GoldEngineModel.java new file mode 100644 index 0000000..71301b1 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/GoldEngineModel.java @@ -0,0 +1,15 @@ +package io.github.foundationgames.automobility.automobile.render.engine; + +import io.github.foundationgames.automobility.Automobility; +import io.github.foundationgames.automobility.automobile.render.BaseModel; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; + +public class GoldEngineModel extends BaseModel { + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/engine/gold"), "main"); + + public GoldEngineModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityCutout, ctx, MODEL_LAYER); + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/IronEngineModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/IronEngineModel.java new file mode 100644 index 0000000..f024850 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/IronEngineModel.java @@ -0,0 +1,15 @@ +package io.github.foundationgames.automobility.automobile.render.engine; + +import io.github.foundationgames.automobility.Automobility; +import io.github.foundationgames.automobility.automobile.render.BaseModel; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; + +public class IronEngineModel extends BaseModel { + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/engine/iron"), "main"); + + public IronEngineModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityCutout, ctx, MODEL_LAYER); + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/StoneEngineModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/StoneEngineModel.java new file mode 100644 index 0000000..fb7206f --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/StoneEngineModel.java @@ -0,0 +1,15 @@ +package io.github.foundationgames.automobility.automobile.render.engine; + +import io.github.foundationgames.automobility.Automobility; +import io.github.foundationgames.automobility.automobile.render.BaseModel; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; + +public class StoneEngineModel extends BaseModel { + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/engine/stone"), "main"); + + public StoneEngineModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityCutout, ctx, MODEL_LAYER); + } +} 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 new file mode 100644 index 0000000..f7698b0 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/CARRFrameModel.java @@ -0,0 +1,22 @@ +package io.github.foundationgames.automobility.automobile.render.frame; + +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.math.Vector3f; +import io.github.foundationgames.automobility.Automobility; +import io.github.foundationgames.automobility.automobile.render.BaseModel; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; + +public class CARRFrameModel extends BaseModel { + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/frame/c_arr"), "main"); + + public CARRFrameModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityCutoutNoCull, ctx, MODEL_LAYER); + } + + @Override + protected void prepare(PoseStack matrices) { + matrices.mulPose(Vector3f.YP.rotationDegrees(-90)); + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/DaBabyFrameModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/DaBabyFrameModel.java new file mode 100644 index 0000000..6e78f3c --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/DaBabyFrameModel.java @@ -0,0 +1,29 @@ +package io.github.foundationgames.automobility.automobile.render.frame; + +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.model.Model; +import net.minecraft.client.renderer.Sheets; +import net.minecraft.client.renderer.entity.EntityRendererProvider; + +public class DaBabyFrameModel extends Model { + // Credit to https://github.com/Sk3leCreeper for model + // private final BakedModel model = Myron.getModel(Automobility.id("models/misc/automobile/frame/dababy")); + + public DaBabyFrameModel(EntityRendererProvider.Context ctx) { + super(id -> Sheets.solidBlockSheet()); + } + + @Override + public void renderToBuffer(PoseStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) { + /* + if (model == null) return; + matrices.push(); + matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(180)); + matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(90)); + matrices.translate(0.1, 0.04, 0); + AUtils.renderMyronObj(model, vertices, matrices, light, overlay); + matrices.pop(); + */ + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/MotorcarFrameModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/MotorcarFrameModel.java new file mode 100644 index 0000000..3d461f7 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/MotorcarFrameModel.java @@ -0,0 +1,15 @@ +package io.github.foundationgames.automobility.automobile.render.frame; + +import io.github.foundationgames.automobility.Automobility; +import io.github.foundationgames.automobility.automobile.render.BaseModel; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; + +public class MotorcarFrameModel extends BaseModel { + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/frame/motorcar"), "main"); + + public MotorcarFrameModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityTranslucentCull, ctx, MODEL_LAYER); + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/PineappleFrameModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/PineappleFrameModel.java new file mode 100644 index 0000000..bc36640 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/PineappleFrameModel.java @@ -0,0 +1,21 @@ +package io.github.foundationgames.automobility.automobile.render.frame; + +import com.mojang.blaze3d.vertex.PoseStack; +import io.github.foundationgames.automobility.Automobility; +import io.github.foundationgames.automobility.automobile.render.BaseModel; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; + +public class PineappleFrameModel extends BaseModel { + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/frame/pineapple"), "main"); + + public PineappleFrameModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityCutout, ctx, MODEL_LAYER); + } + + @Override + protected void prepare(PoseStack matrices) { + matrices.scale(2, 2, 2); + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/RickshawFrameModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/RickshawFrameModel.java new file mode 100644 index 0000000..8e0678f --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/RickshawFrameModel.java @@ -0,0 +1,15 @@ +package io.github.foundationgames.automobility.automobile.render.frame; + +import io.github.foundationgames.automobility.Automobility; +import io.github.foundationgames.automobility.automobile.render.BaseModel; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; + +public class RickshawFrameModel extends BaseModel { + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/frame/rickshaw"), "main"); + + public RickshawFrameModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityCutoutNoCull, ctx, MODEL_LAYER); + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/ShoppingCartFrameModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/ShoppingCartFrameModel.java new file mode 100644 index 0000000..06e5d33 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/ShoppingCartFrameModel.java @@ -0,0 +1,15 @@ +package io.github.foundationgames.automobility.automobile.render.frame; + +import io.github.foundationgames.automobility.Automobility; +import io.github.foundationgames.automobility.automobile.render.BaseModel; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; + +public class ShoppingCartFrameModel extends BaseModel { + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/frame/shopping_cart"), "main"); + + public ShoppingCartFrameModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityCutoutNoCull, ctx, MODEL_LAYER); + } +} 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 new file mode 100644 index 0000000..175aa10 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/StandardFrameModel.java @@ -0,0 +1,22 @@ +package io.github.foundationgames.automobility.automobile.render.frame; + +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.math.Vector3f; +import io.github.foundationgames.automobility.Automobility; +import io.github.foundationgames.automobility.automobile.render.BaseModel; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; + +public class StandardFrameModel extends BaseModel { + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/frame/standard"), "main"); + + public StandardFrameModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityCutout, ctx, MODEL_LAYER); + } + + @Override + protected void prepare(PoseStack matrices) { + matrices.mulPose(Vector3f.YP.rotationDegrees(-90)); + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/TractorFrameModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/TractorFrameModel.java new file mode 100644 index 0000000..365d638 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/TractorFrameModel.java @@ -0,0 +1,15 @@ +package io.github.foundationgames.automobility.automobile.render.frame; + +import io.github.foundationgames.automobility.Automobility; +import io.github.foundationgames.automobility.automobile.render.BaseModel; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; + +public class TractorFrameModel extends BaseModel { + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/frame/tractor"), "main"); + + public TractorFrameModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityCutout, ctx, MODEL_LAYER); + } +} 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 new file mode 100644 index 0000000..e8f0676 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/item/ItemRenderableAutomobile.java @@ -0,0 +1,104 @@ +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; +import io.github.foundationgames.automobility.automobile.AutomobileWheel; +import io.github.foundationgames.automobility.automobile.attachment.front.FrontAttachment; +import io.github.foundationgames.automobility.automobile.attachment.rear.RearAttachment; +import io.github.foundationgames.automobility.automobile.render.RenderableAutomobile; +import org.jetbrains.annotations.Nullable; + +public class ItemRenderableAutomobile implements RenderableAutomobile { + private final AutomobileData reader; + + public ItemRenderableAutomobile(AutomobileData reader) { + this.reader = reader; + } + + @Override + public AutomobileFrame getFrame() { + return reader.getFrame(); + } + + @Override + public AutomobileEngine getEngine() { + return reader.getEngine(); + } + + @Override + public AutomobileWheel getWheels() { + return reader.getWheel(); + } + + @Override + public @Nullable RearAttachment getRearAttachment() { + return null; + } + + @Override + public @Nullable FrontAttachment getFrontAttachment() { + return null; + } + + @Override + public float getAutomobileYaw(float tickDelta) { + return 0; + } + + @Override + public float getRearAttachmentYaw(float tickDelta) { + return 0; + } + + @Override + public float getWheelAngle(float tickDelta) { + return 0; + } + + @Override + public float getSteering(float tickDelta) { + return 0; + } + + @Override + public float getSuspensionBounce(float tickDelta) { + return 0; + } + + @Override + public boolean engineRunning() { + return false; + } + + @Override + public int getBoostTimer() { + return 0; + } + + @Override + public int getTurboCharge() { + return 0; + } + + @Override + public long getTime() { + return 0; + } + + @Override + public boolean automobileOnGround() { + return true; + } + + @Override + public boolean debris() { + return false; + } + + @Override + public Vector3f debrisColor() { + return new Vector3f(); + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/CarriageWheelModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/CarriageWheelModel.java new file mode 100644 index 0000000..2c6173f --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/CarriageWheelModel.java @@ -0,0 +1,15 @@ +package io.github.foundationgames.automobility.automobile.render.wheel; + +import io.github.foundationgames.automobility.Automobility; +import io.github.foundationgames.automobility.automobile.render.BaseModel; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; + +public class CarriageWheelModel extends BaseModel { + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/wheel/carriage"), "main"); + + public CarriageWheelModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityCutoutNoCull, ctx, MODEL_LAYER); + } +} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/ConvertibleWheelModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/ConvertibleWheelModel.java similarity index 50% rename from src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/ConvertibleWheelModel.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/ConvertibleWheelModel.java index 0153347..443b876 100644 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/ConvertibleWheelModel.java +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/ConvertibleWheelModel.java @@ -1,26 +1,21 @@ package io.github.foundationgames.automobility.automobile.render.wheel; -// import dev.monarkhes.myron.api.Myron; -import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.util.AUtils; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; import net.minecraft.client.model.Model; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.model.BakedModel; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.math.Vec3f; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; public class ConvertibleWheelModel extends Model { // Credit to https://github.com/Sk3leCreeper for model // private final BakedModel model = Myron.getModel(Automobility.id("models/misc/automobile/wheel/convertible")); - public ConvertibleWheelModel(EntityRendererFactory.Context ctx) { - super(id -> RenderLayer.getSolid()); + public ConvertibleWheelModel(EntityRendererProvider.Context ctx) { + super(id -> RenderType.solid()); } @Override - public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) { + public void renderToBuffer(PoseStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) { /* if (model == null) return; matrices.push(); 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 new file mode 100644 index 0000000..febc2cd --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/OffRoadWheelModel.java @@ -0,0 +1,22 @@ +package io.github.foundationgames.automobility.automobile.render.wheel; + +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.math.Vector3f; +import io.github.foundationgames.automobility.Automobility; +import io.github.foundationgames.automobility.automobile.render.BaseModel; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; + +public class OffRoadWheelModel extends BaseModel { + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/wheel/off_road"), "main"); + + public OffRoadWheelModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityCutout, ctx, MODEL_LAYER); + } + + @Override + protected void prepare(PoseStack matrices) { + matrices.mulPose(Vector3f.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 new file mode 100644 index 0000000..db9f875 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/StandardWheelModel.java @@ -0,0 +1,22 @@ +package io.github.foundationgames.automobility.automobile.render.wheel; + +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.math.Vector3f; +import io.github.foundationgames.automobility.Automobility; +import io.github.foundationgames.automobility.automobile.render.BaseModel; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; + +public class StandardWheelModel extends BaseModel { + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/wheel/standard"), "main"); + + public StandardWheelModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityCutout, ctx, MODEL_LAYER); + } + + @Override + protected void prepare(PoseStack matrices) { + matrices.mulPose(Vector3f.YP.rotationDegrees(-90)); + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/SteelWheelModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/SteelWheelModel.java new file mode 100644 index 0000000..3e4c06d --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/SteelWheelModel.java @@ -0,0 +1,15 @@ +package io.github.foundationgames.automobility.automobile.render.wheel; + +import io.github.foundationgames.automobility.Automobility; +import io.github.foundationgames.automobility.automobile.render.BaseModel; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; + +public class SteelWheelModel extends BaseModel { + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/wheel/steel"), "main"); + + public SteelWheelModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityCutout, ctx, MODEL_LAYER); + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/TractorWheelModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/TractorWheelModel.java new file mode 100644 index 0000000..3c6a878 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/TractorWheelModel.java @@ -0,0 +1,15 @@ +package io.github.foundationgames.automobility.automobile.render.wheel; + +import io.github.foundationgames.automobility.Automobility; +import io.github.foundationgames.automobility.automobile.render.BaseModel; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; + +public class TractorWheelModel extends BaseModel { + public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/wheel/tractor"), "main"); + + public TractorWheelModel(EntityRendererProvider.Context ctx) { + super(RenderType::entityCutout, ctx, MODEL_LAYER); + } +} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/WheelContextReceiver.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/WheelContextReceiver.java similarity index 100% rename from src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/WheelContextReceiver.java rename to common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/WheelContextReceiver.java diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/AutoMechanicTableBlock.java b/common/src/main/java/io/github/foundationgames/automobility/block/AutoMechanicTableBlock.java new file mode 100644 index 0000000..67b3699 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/block/AutoMechanicTableBlock.java @@ -0,0 +1,40 @@ +package io.github.foundationgames.automobility.block; + +import io.github.foundationgames.automobility.screen.AutoMechanicTableScreenHandler; +import net.minecraft.core.BlockPos; +import net.minecraft.network.chat.Component; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.SimpleMenuProvider; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.BlockHitResult; +import org.jetbrains.annotations.Nullable; + +public class AutoMechanicTableBlock extends Block { + public static final Component UI_TITLE = Component.translatable("container.automobility.auto_mechanic_table"); + + public AutoMechanicTableBlock(Properties settings) { + super(settings); + } + + @Override + public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { + if (world.isClientSide()) { + return InteractionResult.SUCCESS; + } else { + player.openMenu(state.getMenuProvider(world, pos)); + return InteractionResult.CONSUME; + } + } + + @Override + public @Nullable MenuProvider getMenuProvider(BlockState state, Level world, BlockPos pos) { + return new SimpleMenuProvider((syncId, playerInventory, player) -> + new AutoMechanicTableScreenHandler(syncId, playerInventory, ContainerLevelAccess.create(world, pos)), UI_TITLE); + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/AutomobileAssemblerBlock.java b/common/src/main/java/io/github/foundationgames/automobility/block/AutomobileAssemblerBlock.java new file mode 100644 index 0000000..6c3c2ca --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/block/AutomobileAssemblerBlock.java @@ -0,0 +1,112 @@ +package io.github.foundationgames.automobility.block; + +import io.github.foundationgames.automobility.block.entity.AutomobileAssemblerBlockEntity; +import net.minecraft.ChatFormatting; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.network.chat.Component; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.EntityBlock; +import net.minecraft.world.level.block.HorizontalDirectionalBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.Shapes; +import net.minecraft.world.phys.shapes.VoxelShape; +import org.jetbrains.annotations.Nullable; + +public class AutomobileAssemblerBlock extends HorizontalDirectionalBlock implements EntityBlock { + public static final Component USE_CROWBAR_DIALOG = Component.translatable("dialog.automobility.use_crowbar").withStyle(ChatFormatting.GOLD); + public static final Component INCOMPLETE_AUTOMOBILE_DIALOG = Component.translatable("dialog.automobility.incomplete_automobile").withStyle(ChatFormatting.RED); + + public static final BooleanProperty POWERED = BlockStateProperties.POWERED; + + private static final VoxelShape BASE = Shapes.or( + Block.box(0, 0, 0, 16, 4, 16), + Block.box(5, 4, 5, 11, 12, 11)); + + private static final VoxelShape NORTH_SOUTH = Shapes.or(BASE, + Block.box(0, 8, 6, 16, 12, 10)); + private static final VoxelShape EAST_WEST = Shapes.or(BASE, + Block.box(6, 8, 0, 10, 12, 16)); + + public AutomobileAssemblerBlock(Properties settings) { + super(settings); + this.registerDefaultState(this.defaultBlockState().setValue(FACING, Direction.NORTH).setValue(POWERED, false)); + } + + @Override + public void neighborChanged(BlockState state, Level world, BlockPos pos, Block block, BlockPos fromPos, boolean notify) { + super.neighborChanged(state, world, pos, block, fromPos, notify); + + boolean power = world.hasNeighborSignal(pos); + if (power != state.getValue(POWERED)) { + world.setBlockAndUpdate(pos, state.setValue(POWERED, power)); + } + } + + @Override + public void setPlacedBy(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack itemStack) { + if (!world.isClientSide() && placer instanceof Player player) { + player.displayClientMessage(USE_CROWBAR_DIALOG, true); + } + + super.setPlacedBy(world, pos, state, placer, itemStack); + } + + @Override + public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { + if (world.getBlockEntity(pos) instanceof AutomobileAssemblerBlockEntity assembler) { + return assembler.interact(player, hand); + } + + return super.use(state, world, pos, player, hand, hit); + } + + @Override + public void onRemove(BlockState state, Level world, BlockPos pos, BlockState newState, boolean moved) { + if (!newState.is(this) && world.getBlockEntity(pos) instanceof AutomobileAssemblerBlockEntity assembler) { + assembler.dropParts(); + } + + super.onRemove(state, world, pos, newState, moved); + } + + @Override + public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) { + return switch (state.getValue(FACING)) { + case EAST, WEST -> EAST_WEST; + default -> NORTH_SOUTH; + }; + } + + @Nullable + @Override + public BlockState getStateForPlacement(BlockPlaceContext ctx) { + return super.getStateForPlacement(ctx).setValue(FACING, ctx.getHorizontalDirection().getOpposite()); + } + + @Override + protected void createBlockStateDefinition(StateDefinition.Builder builder) { + super.createBlockStateDefinition(builder); + builder.add(FACING, POWERED); + } + + @Nullable + @Override + public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { + return new AutomobileAssemblerBlockEntity(pos, state); + } +} 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 new file mode 100644 index 0000000..274f5fe --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/block/AutomobilityBlocks.java @@ -0,0 +1,73 @@ +package io.github.foundationgames.automobility.block; + +import io.github.foundationgames.automobility.Automobility; +import io.github.foundationgames.automobility.block.entity.AutomobileAssemblerBlockEntity; +import io.github.foundationgames.automobility.item.DashPanelItem; +import io.github.foundationgames.automobility.item.SlopeBlockItem; +import io.github.foundationgames.automobility.item.SteepSlopeBlockItem; +import io.github.foundationgames.automobility.item.TooltipBlockItem; +import io.github.foundationgames.automobility.platform.Platform; +import io.github.foundationgames.automobility.util.AUtils; +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.network.chat.Component; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +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; + +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_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))); + + 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 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, + 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); + } + + 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, Function item) { + var blockPromise = register(name, block); + RegistryQueue.register(Registry.ITEM, Automobility.rl(name), () -> item.apply(blockPromise.require())); + + return blockPromise; + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/DashPanelBlock.java b/common/src/main/java/io/github/foundationgames/automobility/block/DashPanelBlock.java new file mode 100644 index 0000000..a3ea4ba --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/block/DashPanelBlock.java @@ -0,0 +1,121 @@ +package io.github.foundationgames.automobility.block; + +import io.github.foundationgames.automobility.entity.AutomobileEntity; +import io.github.foundationgames.automobility.entity.AutomobilityEntities; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.effect.MobEffects; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.HorizontalDirectionalBlock; +import net.minecraft.world.level.block.SimpleWaterloggedBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; +import org.jetbrains.annotations.Nullable; + +public class DashPanelBlock extends HorizontalDirectionalBlock implements SimpleWaterloggedBlock { + public static final BooleanProperty POWERED = BlockStateProperties.POWERED; + public static final BooleanProperty LEFT = BooleanProperty.create("left"); + public static final BooleanProperty RIGHT = BooleanProperty.create("right"); + public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; + + public static final VoxelShape SHAPE = box(0, 0, 0, 16, 1, 16); + + public DashPanelBlock(Properties settings) { + super(settings); + registerDefaultState(defaultBlockState().setValue(FACING, Direction.NORTH) + .setValue(LEFT, false).setValue(RIGHT, false) + .setValue(POWERED, false).setValue(WATERLOGGED, false)); + } + + @Override + protected void createBlockStateDefinition(StateDefinition.Builder builder) { + super.createBlockStateDefinition(builder); + builder.add(FACING, LEFT, RIGHT, POWERED, WATERLOGGED); + } + + @Override + public boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) { + return level.getBlockState(pos.below()).isFaceSturdy(level, pos.below(), Direction.UP); + } + + @Nullable + @Override + public BlockState getStateForPlacement(BlockPlaceContext ctx) { + return super.getStateForPlacement(ctx).setValue(FACING, ctx.getHorizontalDirection()).setValue(WATERLOGGED, ctx.getLevel().getBlockState(ctx.getClickedPos()).is(Blocks.WATER)); + } + + @Override + public BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { + var lState = world.getBlockState(pos.relative(state.getValue(FACING).getCounterClockWise(Direction.Axis.Y))); + var rState = world.getBlockState(pos.relative(state.getValue(FACING).getClockWise(Direction.Axis.Y))); + boolean left = lState.is(this) && (lState.getValue(POWERED) == state.getValue(POWERED)); + boolean right = rState.is(this) && (rState.getValue(POWERED) == state.getValue(POWERED)); + + return state.setValue(LEFT, left).setValue(RIGHT, right); + } + + @Override + public void neighborChanged(BlockState state, Level level, BlockPos pos, Block block, BlockPos fromPos, boolean notify) { + super.neighborChanged(state, level, pos, block, fromPos, notify); + + boolean levelPwr = level.hasNeighborSignal(pos); + boolean selfPwr = state.getValue(POWERED); + + if (levelPwr != selfPwr) { + level.setBlockAndUpdate(pos, state.setValue(POWERED, levelPwr)); + } + + if (!canSurvive(state, level, pos)) { + level.destroyBlock(pos, true); + } + } + + @Override + public FluidState getFluidState(BlockState state) { + return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); + } + + @Override + public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) { + super.entityInside(state, world, pos, entity); + onCollideWithDashPanel(state, entity); + } + + @Override + public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) { + return SHAPE; + } + + public static void onCollideWithDashPanel(@Nullable BlockState panelState, Entity entity) { + if (panelState != null && panelState.getValue(POWERED)) { + return; + } + + if (entity instanceof AutomobileEntity auto) { + auto.boost(0.45f, 50); + } else if (entity.getType().is(AutomobilityEntities.DASH_PANEL_BOOSTABLES)) { + if (entity instanceof LivingEntity living) { + living.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SPEED, 40, 6, true, false, false)); + } + double yaw = Math.toRadians(-entity.getYRot()); + var vel = new Vec3(Math.sin(yaw), 0, Math.cos(yaw)); + entity.push(vel.x, vel.y, vel.z); + } + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/LaunchGelBlock.java b/common/src/main/java/io/github/foundationgames/automobility/block/LaunchGelBlock.java new file mode 100644 index 0000000..eda77e7 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/block/LaunchGelBlock.java @@ -0,0 +1,53 @@ +package io.github.foundationgames.automobility.block; + +import io.github.foundationgames.automobility.entity.AutomobileEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; + +public class LaunchGelBlock extends Block { + public static final VoxelShape SHAPE = box(0, 0, 0, 16, 1, 16); + + public LaunchGelBlock(Properties settings) { + super(settings); + } + + public boolean canExistAt(LevelReader world, BlockPos pos) { + return world.getBlockState(pos.below()).isFaceSturdy(world, pos, Direction.UP); + } + + @Override + public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) { + super.entityInside(state, world, pos, entity); + + if (entity instanceof AutomobileEntity automobile && automobile.automobileOnGround()) { + automobile.boost(0.14f, 7); + } + } + + @Override + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { + return canExistAt(world, pos); + } + + @Override + public void neighborChanged(BlockState state, Level world, BlockPos pos, Block block, BlockPos fromPos, boolean notify) { + super.neighborChanged(state, world, pos, block, fromPos, notify); + + if (!canExistAt(world, pos)) { + world.destroyBlock(pos, true); + } + } + + @Override + public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) { + return SHAPE; + } +} 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 new file mode 100644 index 0000000..2e95ed0 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/block/OffRoadBlock.java @@ -0,0 +1,81 @@ +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; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.IntegerProperty; +import net.minecraft.world.level.material.PushReaction; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; +import org.jetbrains.annotations.Nullable; + +public class OffRoadBlock extends Block { + public static final VoxelShape ONE_LAYER_SHAPE = box(0, 0, 0, 16, 2, 16); + public static final VoxelShape TWO_LAYER_SHAPE = box(0, 0, 0, 16, 4, 16); + public static final VoxelShape THREE_LAYER_SHAPE = box(0, 0, 0, 16, 6, 16); + + public static final IntegerProperty LAYERS = IntegerProperty.create("layers", 1, 3); + + public final Vector3f color; + + public OffRoadBlock(Properties settings, Vector3f color) { + super(settings); + registerDefaultState(defaultBlockState().setValue(LAYERS, 1)); + this.color = color; + } + + @Nullable + @Override + public BlockState getStateForPlacement(BlockPlaceContext ctx) { + var state = ctx.getLevel().getBlockState(ctx.getClickedPos()); + if (state.is(this) && state.getValue(LAYERS) < 3) { + return state.setValue(LAYERS, state.getValue(LAYERS) + 1); + } + return super.getStateForPlacement(ctx); + } + + @Override + public boolean canBeReplaced(BlockState state, BlockPlaceContext context) { + return state.getValue(LAYERS) < 3 && context.getItemInHand().is(this.asItem()); + } + + @Override + public void neighborChanged(BlockState state, Level world, BlockPos pos, Block block, BlockPos fromPos, boolean notify) { + super.neighborChanged(state, world, pos, block, fromPos, notify); + if (!canSurvive(state, world, pos)) { + world.destroyBlock(pos, true); + } + } + + @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); + } + + @Override + public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) { + return switch (state.getValue(LAYERS)) { + case 2 -> TWO_LAYER_SHAPE; + case 3 -> THREE_LAYER_SHAPE; + default -> ONE_LAYER_SHAPE; + }; + } + + @Override + protected void createBlockStateDefinition(StateDefinition.Builder builder) { + super.createBlockStateDefinition(builder); + builder.add(LAYERS); + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/SlopeBlock.java b/common/src/main/java/io/github/foundationgames/automobility/block/SlopeBlock.java new file mode 100644 index 0000000..934b2de --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/block/SlopeBlock.java @@ -0,0 +1,203 @@ +package io.github.foundationgames.automobility.block; + +import io.github.foundationgames.automobility.item.SlopePlacementContext; +import io.github.foundationgames.automobility.util.AUtils; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.HorizontalDirectionalBlock; +import net.minecraft.world.level.block.SimpleWaterloggedBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.block.state.properties.EnumProperty; +import net.minecraft.world.level.block.state.properties.Half; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.Shapes; +import net.minecraft.world.phys.shapes.VoxelShape; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; + +public class SlopeBlock extends HorizontalDirectionalBlock implements SimpleWaterloggedBlock { + public static final VoxelShape NORTH_BOTTOM_SHAPE; + public static final VoxelShape SOUTH_BOTTOM_SHAPE; + public static final VoxelShape EAST_BOTTOM_SHAPE; + public static final VoxelShape WEST_BOTTOM_SHAPE; + public static final VoxelShape NORTH_TOP_SHAPE; + public static final VoxelShape SOUTH_TOP_SHAPE; + public static final VoxelShape EAST_TOP_SHAPE; + public static final VoxelShape WEST_TOP_SHAPE; + + public static final VoxelShape OLD_NORTH_BOTTOM_SHAPE; + public static final VoxelShape OLD_SOUTH_BOTTOM_SHAPE; + public static final VoxelShape OLD_EAST_BOTTOM_SHAPE; + public static final VoxelShape OLD_WEST_BOTTOM_SHAPE; + public static final VoxelShape OLD_NORTH_TOP_SHAPE; + public static final VoxelShape OLD_SOUTH_TOP_SHAPE; + public static final VoxelShape OLD_EAST_TOP_SHAPE; + public static final VoxelShape OLD_WEST_TOP_SHAPE; + + public static final EnumProperty HALF = BlockStateProperties.HALF; + public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; + + protected final boolean old; + + public SlopeBlock(Properties settings, boolean old) { + super(settings); + this.old = old; + registerDefaultState(defaultBlockState().setValue(FACING, Direction.NORTH).setValue(HALF, Half.BOTTOM).setValue(WATERLOGGED, false)); + } + + @Nullable + @Override + public BlockState getStateForPlacement(BlockPlaceContext ctx) { + return ctx instanceof SlopePlacementContext slopeCtx ? + super.getStateForPlacement(ctx) + .setValue(FACING, slopeCtx.getSlopeFacing()) + .setValue(WATERLOGGED, ctx.getLevel().getBlockState(ctx.getClickedPos()).is(Blocks.WATER)) + .setValue(HALF, slopeCtx.getSlopeHalf()) + : + super.getStateForPlacement(ctx) + .setValue(FACING, ctx.getHorizontalDirection().getOpposite()) + .setValue(WATERLOGGED, ctx.getLevel().getBlockState(ctx.getClickedPos()).is(Blocks.WATER)) + .setValue(HALF, ctx.getClickLocation().y - ctx.getClickedPos().getY() > 0.5 ? Half.TOP : Half.BOTTOM); + } + + @Override + protected void createBlockStateDefinition(StateDefinition.Builder builder) { + super.createBlockStateDefinition(builder); + builder.add(FACING, HALF, WATERLOGGED); + } + + @Override + public FluidState getFluidState(BlockState state) { + return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); + } + + @Override + public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) { + if (old) { + return switch (state.getValue(HALF)) { + case BOTTOM -> switch (state.getValue(FACING)) { + case NORTH -> OLD_NORTH_BOTTOM_SHAPE; + case SOUTH -> OLD_SOUTH_BOTTOM_SHAPE; + case WEST -> OLD_WEST_BOTTOM_SHAPE; + case EAST -> OLD_EAST_BOTTOM_SHAPE; + default -> Shapes.empty(); + }; + case TOP -> switch (state.getValue(FACING)) { + case NORTH -> OLD_NORTH_TOP_SHAPE; + case SOUTH -> OLD_SOUTH_TOP_SHAPE; + case WEST -> OLD_WEST_TOP_SHAPE; + case EAST -> OLD_EAST_TOP_SHAPE; + default -> Shapes.empty(); + }; + default -> Shapes.empty(); + }; + } else { + return switch (state.getValue(HALF)) { + case BOTTOM -> switch (state.getValue(FACING)) { + case NORTH -> NORTH_BOTTOM_SHAPE; + case SOUTH -> SOUTH_BOTTOM_SHAPE; + case WEST -> WEST_BOTTOM_SHAPE; + case EAST -> EAST_BOTTOM_SHAPE; + default -> Shapes.empty(); + }; + case TOP -> switch (state.getValue(FACING)) { + case NORTH -> NORTH_TOP_SHAPE; + case SOUTH -> SOUTH_TOP_SHAPE; + case WEST -> WEST_TOP_SHAPE; + case EAST -> EAST_TOP_SHAPE; + default -> Shapes.empty(); + }; + default -> Shapes.empty(); + }; + } + } + + public static VoxelShape slopeStep(Direction dir, double height) { + return switch (dir) { + case NORTH -> Block.box(0, 0, 0, 16, height, 0.5); + case SOUTH -> Block.box(0, 0, 15.5, 16, height, 16); + case EAST -> Block.box(15.5, 0, 0, 16, height, 16); + case WEST -> Block.box(0, 0, 0, 0.5, height, 16); + default -> Shapes.empty(); + }; + } + + static { + var shapes = new ArrayList(); + for (var dir : AUtils.HORIZONTAL_DIRS) { + for (int i = 0; i < 2; i++) { + double ox = switch (dir) { + case WEST -> 0.5; + case EAST -> -0.5; + default -> 0; + }; + double oz = switch (dir) { + case NORTH -> 0.5; + case SOUTH -> -0.5; + default -> 0; + }; + var finalShape = Shapes.empty(); + for (int j = 0; j < 32; j++) { + finalShape = Shapes.or(finalShape, slopeStep(dir, (i * 8) + (j * 0.25)).move((ox * j) / 16, 0, (oz * j) / 16)); + } + shapes.add(finalShape); + } + } + NORTH_BOTTOM_SHAPE = shapes.get(0); + NORTH_TOP_SHAPE = shapes.get(1); + SOUTH_BOTTOM_SHAPE = shapes.get(2); + SOUTH_TOP_SHAPE = shapes.get(3); + EAST_BOTTOM_SHAPE = shapes.get(4); + EAST_TOP_SHAPE = shapes.get(5); + WEST_BOTTOM_SHAPE = shapes.get(6); + WEST_TOP_SHAPE = shapes.get(7); + + // OLD SLOPE SHAPES + shapes.clear(); + for (var dir : AUtils.HORIZONTAL_DIRS) { + for (int i = 0; i < 2; i++) { + double ox = switch (dir) { + case WEST -> 0.5; + case EAST -> -0.5; + default -> 0; + }; + double oz = switch (dir) { + case NORTH -> 0.5; + case SOUTH -> -0.5; + default -> 0; + }; + var shape = switch (dir) { + case NORTH -> Block.box(0, -1.5, 0, 16, 0.5, 0.5); + case SOUTH -> Block.box(0, -1.5, 15.5, 16, 0.5, 16); + case EAST -> Block.box(15.5, -1.5, 0, 16, 0.5, 16); + case WEST -> Block.box(0, -1.5, 0, 0.5, 0.5, 16); + default -> Shapes.empty(); + }; + shape = shape.move(0, i * 0.5, 0); + var finalShape = shape; + for (int j = 1; j < 32; j++) { + finalShape = Shapes.or(finalShape, shape.move((ox * j) / 16, (0.25 * j) / 16, (oz * j) / 16)); + } + shapes.add(finalShape); + } + } + OLD_NORTH_BOTTOM_SHAPE = shapes.get(0); + OLD_NORTH_TOP_SHAPE = shapes.get(1); + OLD_SOUTH_BOTTOM_SHAPE = shapes.get(2); + OLD_SOUTH_TOP_SHAPE = shapes.get(3); + OLD_EAST_BOTTOM_SHAPE = shapes.get(4); + OLD_EAST_TOP_SHAPE = shapes.get(5); + OLD_WEST_BOTTOM_SHAPE = shapes.get(6); + OLD_WEST_TOP_SHAPE = shapes.get(7); + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/SlopeWithDashPanelBlock.java b/common/src/main/java/io/github/foundationgames/automobility/block/SlopeWithDashPanelBlock.java new file mode 100644 index 0000000..e84f8aa --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/block/SlopeWithDashPanelBlock.java @@ -0,0 +1,47 @@ +package io.github.foundationgames.automobility.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; + +public class SlopeWithDashPanelBlock extends SlopeBlock { + public SlopeWithDashPanelBlock(Properties settings) { + super(settings, false); + + registerDefaultState(defaultBlockState().setValue(DashPanelBlock.POWERED, false)); + } + + @Override + protected void createBlockStateDefinition(StateDefinition.Builder builder) { + super.createBlockStateDefinition(builder); + builder.add(DashPanelBlock.POWERED); + } + + @Override + public void neighborChanged(BlockState state, Level level, BlockPos pos, Block block, BlockPos fromPos, boolean notify) { + super.neighborChanged(state, level, pos, block, fromPos, notify); + + boolean levelPwr = level.hasNeighborSignal(pos); + boolean selfPwr = state.getValue(DashPanelBlock.POWERED); + + if (levelPwr != selfPwr) { + level.setBlockAndUpdate(pos, state.setValue(DashPanelBlock.POWERED, levelPwr)); + } + } + + @Override + public ItemStack getCloneItemStack(BlockGetter level, BlockPos pos, BlockState state) { + return new ItemStack(AutomobilityBlocks.DASH_PANEL.require()); + } + + @Override + public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) { + super.entityInside(state, world, pos, entity); + DashPanelBlock.onCollideWithDashPanel(state, entity); + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/SteepSlopeBlock.java b/common/src/main/java/io/github/foundationgames/automobility/block/SteepSlopeBlock.java new file mode 100644 index 0000000..791e791 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/block/SteepSlopeBlock.java @@ -0,0 +1,147 @@ +package io.github.foundationgames.automobility.block; + +import io.github.foundationgames.automobility.item.SlopePlacementContext; +import io.github.foundationgames.automobility.util.AUtils; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.HorizontalDirectionalBlock; +import net.minecraft.world.level.block.SimpleWaterloggedBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.Shapes; +import net.minecraft.world.phys.shapes.VoxelShape; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; + +public class SteepSlopeBlock extends HorizontalDirectionalBlock implements SimpleWaterloggedBlock { + public static final VoxelShape NORTH_SHAPE; + public static final VoxelShape SOUTH_SHAPE; + public static final VoxelShape EAST_SHAPE; + public static final VoxelShape WEST_SHAPE; + + public static final VoxelShape OLD_NORTH_SHAPE; + public static final VoxelShape OLD_SOUTH_SHAPE; + public static final VoxelShape OLD_EAST_SHAPE; + public static final VoxelShape OLD_WEST_SHAPE; + + public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; + + protected final boolean old; + + public SteepSlopeBlock(Properties settings, boolean old) { + super(settings.noOcclusion()); + this.old = old; + registerDefaultState(defaultBlockState().setValue(FACING, Direction.NORTH).setValue(WATERLOGGED, false)); + } + + @Nullable + @Override + public BlockState getStateForPlacement(BlockPlaceContext ctx) { + return ctx instanceof SlopePlacementContext slopeCtx ? + super.getStateForPlacement(ctx) + .setValue(FACING, slopeCtx.getSlopeFacing()) + .setValue(WATERLOGGED, ctx.getLevel().getBlockState(ctx.getClickedPos()).is(Blocks.WATER)) + : + super.getStateForPlacement(ctx) + .setValue(FACING, ctx.getHorizontalDirection().getOpposite()) + .setValue(WATERLOGGED, ctx.getLevel().getBlockState(ctx.getClickedPos()).is(Blocks.WATER)); + } + + @Override + protected void createBlockStateDefinition(StateDefinition.Builder builder) { + super.createBlockStateDefinition(builder); + builder.add(FACING, WATERLOGGED); + } + + @Override + public FluidState getFluidState(BlockState state) { + return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); + } + + @Override + public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) { + if (old) { + return switch (state.getValue(FACING)) { + case NORTH -> OLD_NORTH_SHAPE; + case SOUTH -> OLD_SOUTH_SHAPE; + case WEST -> OLD_WEST_SHAPE; + case EAST -> OLD_EAST_SHAPE; + default -> Shapes.empty(); + }; + } else { + return switch (state.getValue(FACING)) { + case NORTH -> NORTH_SHAPE; + case SOUTH -> SOUTH_SHAPE; + case WEST -> WEST_SHAPE; + case EAST -> EAST_SHAPE; + default -> Shapes.empty(); + }; + } + } + + static { + var shapes = new ArrayList(); + for (var dir : AUtils.HORIZONTAL_DIRS) { + double ox = switch (dir) { + case WEST -> 0.5; + case EAST -> -0.5; + default -> 0; + }; + double oz = switch (dir) { + case NORTH -> 0.5; + case SOUTH -> -0.5; + default -> 0; + }; + var finalShape = Shapes.empty(); + for (int j = 1; j < 32; j++) { + finalShape = Shapes.or(finalShape, SlopeBlock.slopeStep(dir, (j * 0.5)).move((ox * j) / 16, 0, (oz * j) / 16)); + } + shapes.add(finalShape); + } + NORTH_SHAPE = shapes.get(0); + SOUTH_SHAPE = shapes.get(1); + EAST_SHAPE = shapes.get(2); + WEST_SHAPE = shapes.get(3); + + // OLD SLOPE SHAPES + shapes.clear(); + for (var dir : AUtils.HORIZONTAL_DIRS) { + double ox = switch (dir) { + case WEST -> 0.5; + case EAST -> -0.5; + default -> 0; + }; + double oz = switch (dir) { + case NORTH -> 0.5; + case SOUTH -> -0.5; + default -> 0; + }; + var shape = switch (dir) { + case NORTH -> Block.box(0, -1.5, 0, 16, 0.5, 0.5); + case SOUTH -> Block.box(0, -1.5, 15.5, 16, 0.5, 16); + case EAST -> Block.box(15.5, -1.5, 0, 16, 0.5, 16); + case WEST -> Block.box(0, -1.5, 0, 0.5, 0.5, 16); + default -> Shapes.empty(); + }; + var finalShape = shape; + for (int i = 1; i < 32; i++) { + finalShape = Shapes.or(finalShape, shape.move((ox * i) / 16, (0.5 * i) / 16, (oz * i) / 16)); + } + shapes.add(finalShape); + } + OLD_NORTH_SHAPE = shapes.get(0); + OLD_SOUTH_SHAPE = shapes.get(1); + OLD_EAST_SHAPE = shapes.get(2); + OLD_WEST_SHAPE = shapes.get(3); + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/SteepSlopeWithDashPanelBlock.java b/common/src/main/java/io/github/foundationgames/automobility/block/SteepSlopeWithDashPanelBlock.java new file mode 100644 index 0000000..b3baf76 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/block/SteepSlopeWithDashPanelBlock.java @@ -0,0 +1,47 @@ +package io.github.foundationgames.automobility.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; + +public class SteepSlopeWithDashPanelBlock extends SteepSlopeBlock { + public SteepSlopeWithDashPanelBlock(Properties settings) { + super(settings, false); + + registerDefaultState(defaultBlockState().setValue(DashPanelBlock.POWERED, false)); + } + + @Override + protected void createBlockStateDefinition(StateDefinition.Builder builder) { + super.createBlockStateDefinition(builder); + builder.add(DashPanelBlock.POWERED); + } + + @Override + public void neighborChanged(BlockState state, Level level, BlockPos pos, Block block, BlockPos fromPos, boolean notify) { + super.neighborChanged(state, level, pos, block, fromPos, notify); + + boolean levelPwr = level.hasNeighborSignal(pos); + boolean selfPwr = state.getValue(DashPanelBlock.POWERED); + + if (levelPwr != selfPwr) { + level.setBlockAndUpdate(pos, state.setValue(DashPanelBlock.POWERED, levelPwr)); + } + } + + @Override + public ItemStack getCloneItemStack(BlockGetter level, BlockPos pos, BlockState state) { + return new ItemStack(AutomobilityBlocks.DASH_PANEL.require()); + } + + @Override + public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) { + super.entityInside(state, world, pos, entity); + DashPanelBlock.onCollideWithDashPanel(state, entity); + } +} 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 new file mode 100644 index 0000000..bc77724 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/block/entity/AutomobileAssemblerBlockEntity.java @@ -0,0 +1,345 @@ +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; +import io.github.foundationgames.automobility.automobile.AutomobileWheel; +import io.github.foundationgames.automobility.automobile.attachment.front.FrontAttachment; +import io.github.foundationgames.automobility.automobile.attachment.rear.RearAttachment; +import io.github.foundationgames.automobility.automobile.render.RenderableAutomobile; +import io.github.foundationgames.automobility.block.AutomobileAssemblerBlock; +import io.github.foundationgames.automobility.block.AutomobilityBlocks; +import io.github.foundationgames.automobility.entity.AutomobileEntity; +import io.github.foundationgames.automobility.item.AutomobileEngineItem; +import io.github.foundationgames.automobility.item.AutomobileFrameItem; +import io.github.foundationgames.automobility.item.AutomobileWheelItem; +import io.github.foundationgames.automobility.item.AutomobilityItems; +import net.minecraft.core.BlockPos; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.ClientGamePacketListener; +import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; +import net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.gameevent.GameEvent; +import net.minecraft.world.phys.Vec3; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; + +public class AutomobileAssemblerBlockEntity extends BlockEntity implements RenderableAutomobile { + protected AutomobileFrame frame = AutomobileFrame.EMPTY; + protected AutomobileEngine engine = AutomobileEngine.EMPTY; + protected AutomobileWheel wheel = AutomobileWheel.EMPTY; + protected int wheelCount = 0; + + public final List label = new ArrayList<>(); + protected final AutomobileStats stats = new AutomobileStats(); + + public AutomobileAssemblerBlockEntity(BlockPos pos, BlockState state) { + super(AutomobilityBlocks.AUTOMOBILE_ASSEMBLER_ENTITY.require(), pos, state); + } + + @Override + public AutomobileFrame getFrame() { + return frame; + } + + @Override + public AutomobileWheel getWheels() { + return wheel; + } + + @Override + public AutomobileEngine getEngine() { + return engine; + } + + @Override + public @Nullable RearAttachment getRearAttachment() { + return null; + } + + @Override + public @Nullable FrontAttachment getFrontAttachment() { + return null; + } + + private void partChanged() { + this.sync(); + this.setChanged(); + this.level.gameEvent(GameEvent.BLOCK_CHANGE, this.getBlockPos(), new GameEvent.Context(null, this.getBlockState())); + } + + protected InteractionResult handleItemInteract(Player player, ItemStack stack) { + // Returns success on the server since the client is never 100% confident that the action was valid + // Subsequent handling is performed with the action result + + if (stack.is(AutomobilityItems.CROWBAR.require())) { + if (!level.isClientSide()) { + this.dropParts(); + this.partChanged(); + return InteractionResult.SUCCESS; + } + return InteractionResult.PASS; + } + if (this.frame.isEmpty() && stack.getItem() instanceof AutomobileFrameItem frameItem) { + if (!level.isClientSide()) { + this.frame = frameItem.getComponent(stack); + if (!player.isCreative()) { + stack.shrink(1); + } + this.partChanged(); + return InteractionResult.SUCCESS; + } + return InteractionResult.PASS; + } + if (!this.frame.isEmpty()) { + if (this.engine.isEmpty() && stack.getItem() instanceof AutomobileEngineItem engineItem) { + if (!level.isClientSide()) { + this.engine = engineItem.getComponent(stack); + if (!player.isCreative()) { + stack.shrink(1); + } + this.partChanged(); + return InteractionResult.SUCCESS; + } + return InteractionResult.PASS; + } + if (stack.getItem() instanceof AutomobileWheelItem wheelItem) { + if (!level.isClientSide()) { + var wheelType = wheelItem.getComponent(stack); + if (this.wheel.isEmpty()) { + this.wheel = wheelType; + this.wheelCount = 0; // Fix wheel count if ever invalid + } + if (this.wheel == wheelType && this.wheelCount < this.frame.model().wheelBase().wheelCount) { + this.wheelCount++; + if (!player.isCreative()) { + stack.shrink(1); + } + this.partChanged(); + return InteractionResult.SUCCESS; + } + } else { + return InteractionResult.PASS; + } + } + } + if (!this.level.isClientSide() && stack.is(AutomobilityItems.FRONT_ATTACHMENT.require()) || stack.is(AutomobilityItems.REAR_ATTACHMENT.require())) { + player.displayClientMessage(AutomobileAssemblerBlock.INCOMPLETE_AUTOMOBILE_DIALOG, true); + } + + return InteractionResult.FAIL; + } + + public InteractionResult interact(Player player, InteractionHand hand) { + var stack = player.getItemInHand(hand); + var result = this.handleItemInteract(player, stack); + + if (!this.level.isClientSide() && result == InteractionResult.SUCCESS) { + if (!isComplete()) { + level.playSound(null, this.worldPosition, SoundEvents.COPPER_PLACE, SoundSource.BLOCKS, 0.7f, 0.6f + (this.level.random.nextFloat() * 0.15f)); + } + + tryConstructAutomobile(); + return InteractionResult.SUCCESS; + } + return result; + } + + protected Vec3 centerPos() { + return new Vec3(this.worldPosition.getX() + 0.5, this.worldPosition.getY() + 0.75, this.worldPosition.getZ() + 0.5); + } + + public boolean isComplete() { + return !this.frame.isEmpty() && + !this.engine.isEmpty() && + ((!this.wheel.isEmpty()) && (this.wheelCount >= this.frame.model().wheelBase().wheelCount)); + } + + public void tryConstructAutomobile() { + if (this.isComplete()) { + var pos = this.centerPos(); + var auto = new AutomobileEntity(this.level); + auto.moveTo(pos.x, pos.y, pos.z, this.getAutomobileYaw(0), 0); + auto.setComponents(this.frame, this.wheel, this.engine); + level.addFreshEntity(auto); + + level.players().forEach(p -> { + if (p instanceof ServerPlayer player && p.blockPosition().distSqr(this.worldPosition) < 80000) { + player.connection.send(new ClientboundLevelParticlesPacket(ParticleTypes.EXPLOSION, false, pos.x, pos.y + 0.47, pos.z, 0, 0, 0, 0, 1)); + } + }); + level.playSound(null, this.worldPosition, SoundEvents.ANVIL_PLACE, SoundSource.BLOCKS, 0.23f, 0.5f); + + this.clear(); + } + } + + public void dropParts() { + var pos = this.centerPos(); + + this.level.addFreshEntity(new ItemEntity(level, pos.x, pos.y, pos.z, AutomobilityItems.AUTOMOBILE_FRAME.require().createStack(this.getFrame()))); + this.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.wheelCount); + this.level.addFreshEntity(new ItemEntity(level, pos.x, pos.y, pos.z, wheelStack)); + + this.clear(); + } + + public void clear() { + this.frame = AutomobileFrame.EMPTY; + this.wheel = AutomobileWheel.EMPTY; + this.engine = AutomobileEngine.EMPTY; + this.wheelCount = 0; + } + + private boolean hasAllParts() { + return !this.frame.isEmpty() && !this.wheel.isEmpty() && !this.engine.isEmpty(); + } + + private void onComponentsUpdated() { + if (level == null || level.isClientSide()) { + this.label.clear(); + if (this.hasAllParts()) { + this.stats.from(this.frame, this.wheel, this.engine); + this.stats.appendTexts(this.label, this.stats); + } + } + } + + private void sync() { + if (this.level instanceof ServerLevel sWorld) { + sWorld.getChunkSource().blockChanged(this.worldPosition); + } + } + + @Override + public void load(CompoundTag nbt) { + super.load(nbt); + + this.frame = AutomobileFrame.REGISTRY.getOrDefault(ResourceLocation.tryParse(nbt.getString("frame"))); + this.engine = AutomobileEngine.REGISTRY.getOrDefault(ResourceLocation.tryParse(nbt.getString("engine"))); + + var wheelNbt = nbt.getCompound("wheels"); + this.wheel = AutomobileWheel.REGISTRY.getOrDefault(ResourceLocation.tryParse(wheelNbt.getString("type"))); + this.wheelCount = wheelNbt.getInt("count"); + + onComponentsUpdated(); + } + + @Override + protected void saveAdditional(CompoundTag nbt) { + super.saveAdditional(nbt); + + nbt.putString("frame", this.frame.getId().toString()); + nbt.putString("engine", this.engine.getId().toString()); + + var wheelNbt = new CompoundTag(); + wheelNbt.putString("type", this.wheel.getId().toString()); + wheelNbt.putInt("count", this.wheelCount); + nbt.put("wheels", wheelNbt); + } + + @Nullable + @Override + public Packet getUpdatePacket() { + return ClientboundBlockEntityDataPacket.create(this); + } + + @Override + public CompoundTag getUpdateTag() { + var nbt = new CompoundTag(); + this.saveAdditional(nbt); + return nbt; + } + + protected boolean powered() { + var state = this.level.getBlockState(this.worldPosition); + return state.hasProperty(AutomobileAssemblerBlock.POWERED) && state.getValue(AutomobileAssemblerBlock.POWERED); + } + + @Override + public float getAutomobileYaw(float tickDelta) { + var state = this.level.getBlockState(this.worldPosition); + return state.hasProperty(AutomobileAssemblerBlock.FACING) ? (state.getValue(AutomobileAssemblerBlock.FACING).toYRot() - 90) : 0; + } + + @Override + public int getWheelCount() { + return this.wheelCount; + } + + @Override + public float getRearAttachmentYaw(float tickDelta) { + return 0; + } + + @Override + public float getWheelAngle(float tickDelta) { + return this.powered() ? (this.getTime() + tickDelta) * 36 : 0; + } + + @Override + public float getSteering(float tickDelta) { + return 0; + } + + @Override + public float getSuspensionBounce(float tickDelta) { + return 0; + } + + @Override + public boolean engineRunning() { + return this.powered(); + } + + @Override + public int getBoostTimer() { + return this.powered() ? 1 : 0; + } + + @Override + public int getTurboCharge() { + return 0; + } + + @Override + public long getTime() { + return this.level.getGameTime(); + } + + @Override + public boolean automobileOnGround() { + return false; + } + + @Override + public boolean debris() { + return false; + } + + @Override + public Vector3f debrisColor() { + return null; + } +} 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 new file mode 100644 index 0000000..c7436b0 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/block/entity/render/AutomobileAssemblerBlockEntityRenderer.java @@ -0,0 +1,43 @@ +package io.github.foundationgames.automobility.block.entity.render; + +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.math.Vector3f; +import io.github.foundationgames.automobility.automobile.render.AutomobileRenderer; +import io.github.foundationgames.automobility.block.entity.AutomobileAssemblerBlockEntity; +import net.minecraft.client.gui.Font; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; +import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; + +public class AutomobileAssemblerBlockEntityRenderer implements BlockEntityRenderer { + private final Font textRenderer; + + public AutomobileAssemblerBlockEntityRenderer(BlockEntityRendererProvider.Context blockEntityCtx) { + this.textRenderer = blockEntityCtx.getFont(); + } + + @Override + public void render(AutomobileAssemblerBlockEntity entity, float tickDelta, PoseStack matrices, MultiBufferSource vertexConsumers, int light, int overlay) { + matrices.pushPose(); + matrices.translate(0.5, 0.75 - (entity.getWheels().model().radius() / 16), 0.5); + AutomobileRenderer.render(matrices, vertexConsumers, light, overlay, tickDelta, entity); + matrices.popPose(); + + matrices.pushPose(); + matrices.translate(0.5, 0, 0.5); + matrices.mulPose(Vector3f.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); + matrices.popPose(); + matrices.translate(0, 12, 0); + } + + matrices.popPose(); + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/model/GeometryBuilder.java b/common/src/main/java/io/github/foundationgames/automobility/block/model/GeometryBuilder.java new file mode 100644 index 0000000..9e91f99 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/block/model/GeometryBuilder.java @@ -0,0 +1,13 @@ +package io.github.foundationgames.automobility.block.model; + +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.core.Direction; +import org.jetbrains.annotations.Nullable; + +public interface GeometryBuilder { + GeometryBuilder vertex(float x, float y, float z, @Nullable Direction face, float nx, float ny, float nz, + TextureAtlasSprite sprite, float u, float v); + + 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); +} 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 new file mode 100644 index 0000000..bc777bf --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/block/model/SlopeBakedModel.java @@ -0,0 +1,247 @@ +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; +import net.minecraft.client.renderer.block.model.ItemOverrides; +import net.minecraft.client.renderer.block.model.ItemTransforms; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.client.resources.model.ModelState; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.util.RandomSource; +import net.minecraft.world.level.BlockAndTintGetter; +import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.Nullable; + +import java.util.Collections; +import java.util.List; +import java.util.Map; + +public class SlopeBakedModel implements BakedModel { + public static Factory impl = SlopeBakedModel::new; + + private final Map frameTexOverrides; + + protected final @Nullable TextureAtlasSprite plateInner; + protected final @Nullable TextureAtlasSprite plateOuter; + protected final ModelState settings; + protected final SlopeUnbakedModel.Type type; + private final TextureAtlasSprite frame; + + public SlopeBakedModel(TextureAtlasSprite frame, Map frameTexOverrides, @Nullable TextureAtlasSprite plateInner, + @Nullable TextureAtlasSprite plateOuter, ModelState settings, SlopeUnbakedModel.Type type) { + this.frame = frame; + this.frameTexOverrides = frameTexOverrides; + this.plateInner = plateInner; + this.plateOuter = plateOuter; + this.settings = settings; + this.type = type; + } + + public TextureAtlasSprite getFrameSprite(@Nullable BlockAndTintGetter level, @Nullable BlockPos pos) { + if (level != null && pos != null) { + var blockBelow = level.getBlockState(pos.below()); + + if (frameTexOverrides.containsKey(blockBelow)) { + return frameTexOverrides.get(blockBelow); + } + if (!blockBelow.isAir() && blockBelow.isCollisionShapeFullBlock(level, pos)) { + return Minecraft.getInstance().getBlockRenderer().getBlockModel(blockBelow).getParticleIcon(); + } + } + + return this.frame; + } + + public int getFrameColor(@Nullable BlockAndTintGetter level, @Nullable BlockPos pos) { + if (level != null && pos != null) { + var blockBelow = level.getBlockState(pos.below()); + var belowColor = Platform.get().blockColor(blockBelow); + + if (belowColor != null) { + return belowColor.getColor(blockBelow, level, pos.below(), 0) | 0xFF000000; + } + } + + return 0xFFFFFFFF; + } + + public void buildSlopeGeometry(TextureAtlasSprite sprite, GeometryBuilder geo, int frameColor, boolean borderedLeft, boolean borderedRight) { + boolean steep = type == SlopeUnbakedModel.Type.STEEP; + float height = steep ? 1 : 0.5f; + float rise = steep ? 0 : (type == SlopeUnbakedModel.Type.TOP ? 0.5f : 0); + boolean top = true; + + if (this.plateOuter != null && this.plateInner != null) { + top = false; + this.plate(height, rise, !borderedLeft, !borderedRight, this.plateInner, this.plateOuter, geo); + } + + rightTriPrism(height, rise, frameColor, top, sprite, geo); + + float invRH = 1 - (rise + height); + geo + // South face + .vertex(0, rise + height, 1, Direction.SOUTH, 0, 0, 1, sprite, 0, invRH, frameColor) + .vertex(0, 0, 1, Direction.SOUTH, 0, 0, 1, sprite, 0, 1, frameColor) + .vertex(1, 0, 1, Direction.SOUTH, 0, 0, 1, sprite, 1, 1, frameColor) + .vertex(1, rise + height, 1, Direction.SOUTH, 0, 0, 1, sprite, 1, invRH, frameColor) + + // Bottom face + .vertex(0, 0, 1, Direction.DOWN, 0, -1, 0, sprite, 0, 0, frameColor) + .vertex(0, 0, 0, Direction.DOWN, 0, -1, 0, sprite, 0, 1, frameColor) + .vertex(1, 0, 0, Direction.DOWN, 0, -1, 0, sprite, 1, 1, frameColor) + .vertex(1, 0, 1, Direction.DOWN, 0, -1, 0, sprite, 1, 0, frameColor); + + if (rise > 0) { + float invR = 1 - rise; + geo + // West face + .vertex(0, rise, 0, Direction.WEST, -1, 0, 0, sprite, 0, invR, frameColor) + .vertex(0, 0, 0, Direction.WEST, -1, 0, 0, sprite, 0, 1, frameColor) + .vertex(0, 0, 1, Direction.WEST, -1, 0, 0, sprite, 1, 1, frameColor) + .vertex(0, rise, 1, Direction.WEST, -1, 0, 0, sprite, 1, invR, frameColor) + + // East face + .vertex(1, rise, 1, Direction.EAST, 1, 0, 0, sprite, 1, invR, frameColor) + .vertex(1, 0, 1, Direction.EAST, 1, 0, 0, sprite, 1, 1, frameColor) + .vertex(1, 0, 0, Direction.EAST, 1, 0, 0, sprite, 0, 1, frameColor) + .vertex(1, rise, 0, Direction.EAST, 1, 0, 0, sprite, 0, invR, frameColor) + + // North face + .vertex(1, rise, 0, Direction.NORTH, 0, 0, 1, sprite, 1, invR, frameColor) + .vertex(1, 0, 0, Direction.NORTH, 0, 0, 1, sprite, 1, 1, frameColor) + .vertex(0, 0, 0, Direction.NORTH, 0, 0, 1, sprite, 0, 1, frameColor) + .vertex(0, rise, 0, Direction.NORTH, 0, 0, 1, sprite, 0, invR, frameColor); + } + } + + private void rightTriPrism(float height, float rise, int color, boolean top, TextureAtlasSprite sprite, GeometryBuilder geo) { + float invR = 1 - rise; + float invRH = 1 - (rise + height); + var topNormal = new Vector3f(0, 1, -height); // This actually makes sense math wise don't worry about it + topNormal.normalize(); + + geo + // West triangle + .vertex(0, rise + height, 1, Direction.WEST, -1, 0, 0, sprite, 1, invRH, color) + .vertex(0, rise, 0, Direction.WEST, -1, 0, 0, sprite, 0, invR, color) + .vertex(0, rise, 1, Direction.WEST, -1, 0, 0, sprite, 1, invR, color) + .vertex(0, rise + height, 1, Direction.WEST, -1, 0, 0, sprite, 1, invRH, color) + + // East triangle + .vertex(1, rise + height, 1, Direction.EAST, 1, 0, 0, sprite, 0, invRH, color) + .vertex(1, rise + height, 1, Direction.EAST, 1, 0, 0, sprite, 0, invRH, color) + .vertex(1, rise, 1, Direction.EAST, 1, 0, 0, sprite, 0, invR, color) + .vertex(1, rise, 0, Direction.EAST, 1, 0, 0, sprite, 1, invR, color); + + if (top) { + geo // Top face + .vertex(0, rise, 0, null, topNormal.x(), topNormal.y(), topNormal.z(), sprite, 1, 1, color) + .vertex(0, rise + height, 1, null, topNormal.x(), topNormal.y(), topNormal.z(), sprite, 1, 0, color) + .vertex(1, rise + height, 1, null, topNormal.x(), topNormal.y(), topNormal.z(), sprite, 0, 0, color) + .vertex(1, rise, 0, null, topNormal.x(), topNormal.y(), topNormal.z(), sprite, 0, 1, color); + } + } + + private void plate(float height, float rise, boolean left, boolean right, TextureAtlasSprite plateInner, TextureAtlasSprite plateOuter, GeometryBuilder geo) { + var topNormal = new Vector3f(0, 1, -height); + topNormal.normalize(); + var northNormal = new Vector3f(0, -height, 1); + northNormal.normalize(); + 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 + topFaceOffset.mul(0.0625f); + var onePxUp = southNormal.copy(); // Translate one pixel up the slope + onePxUp.normalize(); + onePxUp.mul(0.0625f); + + geo + // Top face inner + .vertex(right ? 0.9375f : 1, 0.001f + rise + topFaceOffset.y() + onePxUp.y(), topFaceOffset.z() + onePxUp.z(), null, topNormal.x(), topNormal.y(), topNormal.z(), plateInner, right ? 0.0625f : 0, 0.9375f) + .vertex(left ? 0.0625f : 0, 0.001f + rise + topFaceOffset.y() + onePxUp.y(), topFaceOffset.z() + onePxUp.z(), null, topNormal.x(), topNormal.y(), topNormal.z(), plateInner, left ? 0.9375f : 1, 0.9375f) + .vertex(left ? 0.0625f : 0, (0.001f + rise + height + topFaceOffset.y()) - onePxUp.y(), (1 + topFaceOffset.z()) - onePxUp.z(), null, topNormal.x(), topNormal.y(), topNormal.z(), plateInner, left ? 0.9375f : 1, 0.0625f) + .vertex(right ? 0.9375f : 1, (0.001f + rise + height + topFaceOffset.y()) - onePxUp.y(), (1 + topFaceOffset.z()) - onePxUp.z(), null, topNormal.x(), topNormal.y(), topNormal.z(), plateInner, right ? 0.0625f : 0, 0.0625f) + + // Top face outer + .vertex(1, rise + topFaceOffset.y(), topFaceOffset.z(), null, topNormal.x(), topNormal.y(), topNormal.z(), plateOuter, 0, 1) + .vertex(0, rise + topFaceOffset.y(), topFaceOffset.z(), null, topNormal.x(), topNormal.y(), topNormal.z(), plateOuter, 1, 1) + .vertex(0, rise + height + topFaceOffset.y(), 1 + topFaceOffset.z(), null, topNormal.x(), topNormal.y(), topNormal.z(), plateOuter, 1, 0) + .vertex(1, rise + height + topFaceOffset.y(), 1 + topFaceOffset.z(), null, topNormal.x(), topNormal.y(), topNormal.z(), plateOuter, 0, 0) + + // North face + .vertex(1, rise, 0, null, northNormal.x(), northNormal.y(), northNormal.z(), plateOuter, 0, 1) + .vertex(0, rise, 0, null, northNormal.x(), northNormal.y(), northNormal.z(), plateOuter, 1, 1) + .vertex(0, rise + topFaceOffset.y(), topFaceOffset.z(), null, northNormal.x(), northNormal.y(), northNormal.z(), plateOuter, 1, 0.9375f) + .vertex(1, rise + topFaceOffset.y(), topFaceOffset.z(), null, northNormal.x(), northNormal.y(), northNormal.z(), plateOuter, 0, 0.9375f) + + // South face + .vertex(1, rise + height + topFaceOffset.y(), 1 + topFaceOffset.z(), null, southNormal.x(), southNormal.y(), southNormal.z(), plateOuter, 0, 0) + .vertex(0, rise + height + topFaceOffset.y(), 1 + topFaceOffset.z(), null, southNormal.x(), southNormal.y(), southNormal.z(), plateOuter, 1, 0) + .vertex(0, rise + height, 1, null, southNormal.x(), southNormal.y(), southNormal.z(), plateOuter, 1, 0.0625f) + .vertex(1, rise + height, 1, null, southNormal.x(), southNormal.y(), southNormal.z(), plateOuter, 0, 0.0625f) + + // East face + .vertex(1, rise + height, 1, null, 1, 0, 0, plateOuter, 0, 0) + .vertex(1, rise, 0, null, 1, 0, 0, plateOuter, 0, 1) + .vertex(1, rise + topFaceOffset.y(), topFaceOffset.z(), null, 1, 0, 0, plateOuter, 0.0625f, 1) + .vertex(1, rise + height + topFaceOffset.y(), 1 + topFaceOffset.z(), null, 1, 0, 0, plateOuter, 0.0625f, 0) + + // West face + .vertex(0, rise + height + topFaceOffset.y(), 1 + topFaceOffset.z(), null, -1, 0, 0, plateOuter, 1, 0) + .vertex(0, rise + topFaceOffset.y(), topFaceOffset.z(), null, -1, 0, 0, plateOuter, 1, 1) + .vertex(0, rise, 0, null, -1, 0, 0, plateOuter, 0.9375f, 1) + .vertex(0, rise + height, 1, null, -1, 0, 0, plateOuter, 0.9375f, 0) + ; + } + + @Override + public List getQuads(@Nullable BlockState blockState, @Nullable Direction direction, RandomSource randomSource) { + return Collections.emptyList(); + } + + @Override + public boolean useAmbientOcclusion() { + return true; + } + + @Override + public boolean isGui3d() { + return true; + } + + @Override + public boolean usesBlockLight() { + return true; + } + + @Override + public boolean isCustomRenderer() { + return false; + } + + @Override + public TextureAtlasSprite getParticleIcon() { + return this.getFrameSprite(null, null); + } + + @Override + public ItemTransforms getTransforms() { + return ItemTransforms.NO_TRANSFORMS; + } + + @Override + public ItemOverrides getOverrides() { + return ItemOverrides.EMPTY; + } + + public interface Factory { + SlopeBakedModel create(TextureAtlasSprite frame, Map frameTexOverrides, @Nullable TextureAtlasSprite plateInner, + @Nullable TextureAtlasSprite plateOuter, ModelState settings, SlopeUnbakedModel.Type type); + } +} 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 new file mode 100644 index 0000000..2781bb1 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/block/model/SlopeUnbakedModel.java @@ -0,0 +1,113 @@ +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.ModelState; +import net.minecraft.client.resources.model.UnbakedModel; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.Nullable; + +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; + +public class SlopeUnbakedModel implements UnbakedModel { + public static final ResourceLocation MODEL_SLOPE_BOTTOM = Automobility.rl("block/slope_bottom"); + public static final ResourceLocation MODEL_SLOPE_TOP = Automobility.rl("block/slope_top"); + public static final ResourceLocation MODEL_STEEP_SLOPE = Automobility.rl("block/steep_slope"); + public static final ResourceLocation MODEL_SLOPE_BOTTOM_DASH_PANEL = Automobility.rl("block/slope_bottom_dash_panel"); + public static final ResourceLocation MODEL_SLOPE_TOP_DASH_PANEL = Automobility.rl("block/slope_top_dash_panel"); + public static final ResourceLocation MODEL_STEEP_SLOPE_DASH_PANEL = Automobility.rl("block/steep_slope_dash_panel"); + public static final ResourceLocation MODEL_SLOPE_BOTTOM_DASH_PANEL_OFF = Automobility.rl("block/slope_bottom_dash_panel_off"); + public static final ResourceLocation MODEL_SLOPE_TOP_DASH_PANEL_OFF = Automobility.rl("block/slope_top_dash_panel_off"); + public static final ResourceLocation MODEL_STEEP_SLOPE_DASH_PANEL_OFF = Automobility.rl("block/steep_slope_dash_panel_off"); + + public static final ResourceLocation TEX_FRAME = Automobility.rl("block/slope_frame"); + public static final ResourceLocation TEX_DASH_PANEL = Automobility.rl("block/dash_panel"); + public static final ResourceLocation TEX_DASH_PANEL_OFF = Automobility.rl("block/dash_panel_off"); + public static final ResourceLocation TEX_DASH_PANEL_FRAME = Automobility.rl("block/dash_panel_frame"); + + public static final Map> DEFAULT_MODELS = ImmutableMap.of( + MODEL_SLOPE_TOP, () -> new SlopeUnbakedModel(Type.TOP, TEX_FRAME, null, null), + MODEL_SLOPE_BOTTOM, () -> new SlopeUnbakedModel(Type.BOTTOM, TEX_FRAME, null, null), + MODEL_STEEP_SLOPE, () -> new SlopeUnbakedModel(Type.STEEP, TEX_FRAME, null, null), + MODEL_SLOPE_TOP_DASH_PANEL, () -> new SlopeUnbakedModel(Type.TOP, TEX_FRAME, TEX_DASH_PANEL, TEX_DASH_PANEL_FRAME), + MODEL_SLOPE_BOTTOM_DASH_PANEL, () -> new SlopeUnbakedModel(Type.BOTTOM, TEX_FRAME, TEX_DASH_PANEL, TEX_DASH_PANEL_FRAME), + MODEL_STEEP_SLOPE_DASH_PANEL, () -> new SlopeUnbakedModel(Type.STEEP, TEX_FRAME, TEX_DASH_PANEL, TEX_DASH_PANEL_FRAME), + MODEL_SLOPE_TOP_DASH_PANEL_OFF, () -> new SlopeUnbakedModel(Type.TOP, TEX_FRAME, TEX_DASH_PANEL_OFF, TEX_DASH_PANEL_FRAME), + MODEL_SLOPE_BOTTOM_DASH_PANEL_OFF, () -> new SlopeUnbakedModel(Type.BOTTOM, TEX_FRAME, TEX_DASH_PANEL_OFF, TEX_DASH_PANEL_FRAME), + MODEL_STEEP_SLOPE_DASH_PANEL_OFF, () -> new SlopeUnbakedModel(Type.STEEP, TEX_FRAME, TEX_DASH_PANEL_OFF, TEX_DASH_PANEL_FRAME) + ); + + private static final ResourceLocation PARENT = new ResourceLocation("block/block"); + + private final Type type; + private final Material frameTex; + private final @Nullable Material plateInnerTex; + private final @Nullable Material plateOuterTex; + + public SlopeUnbakedModel(Type type, ResourceLocation frameTex, @Nullable ResourceLocation plateInnerTex, + @Nullable ResourceLocation plateOuterTex) { + this.type = type; + this.frameTex = new Material(TextureAtlas.LOCATION_BLOCKS, frameTex); + this.plateInnerTex = plateInnerTex != null ? new Material(TextureAtlas.LOCATION_BLOCKS, plateInnerTex) : null; + this.plateOuterTex = plateOuterTex != null ? new Material(TextureAtlas.LOCATION_BLOCKS, plateOuterTex) : null; + } + + @Override + public Collection getDependencies() { + return List.of(PARENT); + } + + @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; + } + + // TODO: Something better than this that supports other mods and resource packs + private static Map createFrameTexOverrides(Function spriteGet) { + return ImmutableMap.of( + Blocks.GRASS_BLOCK.defaultBlockState(), vanillaSprite(spriteGet, "block/grass_block_top"), + Blocks.PODZOL.defaultBlockState(), vanillaSprite(spriteGet, "block/podzol_top"), + Blocks.MYCELIUM.defaultBlockState(), vanillaSprite(spriteGet, "block/mycelium_top"), + Blocks.CRIMSON_NYLIUM.defaultBlockState(), vanillaSprite(spriteGet, "block/crimson_nylium"), + Blocks.WARPED_NYLIUM.defaultBlockState(), vanillaSprite(spriteGet, "block/warped_nylium") + ); + } + + @Nullable + @Override + public BakedModel bake(ModelBakery modelBakery, 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); + } + + private static TextureAtlasSprite vanillaSprite(Function spriteGet, String name) { + return spriteGet.apply(new Material(TextureAtlas.LOCATION_BLOCKS, new ResourceLocation("minecraft", name))); + } + + public enum Type { + BOTTOM, TOP, STEEP + } +} diff --git a/src/main/java/io/github/foundationgames/automobility/entity/AutomobileDamageSource.java b/common/src/main/java/io/github/foundationgames/automobility/entity/AutomobileDamageSource.java similarity index 78% rename from src/main/java/io/github/foundationgames/automobility/entity/AutomobileDamageSource.java rename to common/src/main/java/io/github/foundationgames/automobility/entity/AutomobileDamageSource.java index 2ffde65..bf38b17 100644 --- a/src/main/java/io/github/foundationgames/automobility/entity/AutomobileDamageSource.java +++ b/common/src/main/java/io/github/foundationgames/automobility/entity/AutomobileDamageSource.java @@ -1,6 +1,6 @@ package io.github.foundationgames.automobility.entity; -import net.minecraft.entity.damage.DamageSource; +import net.minecraft.world.damagesource.DamageSource; public class AutomobileDamageSource extends DamageSource { protected AutomobileDamageSource(String name) { diff --git a/src/main/java/io/github/foundationgames/automobility/entity/AutomobileEntity.java b/common/src/main/java/io/github/foundationgames/automobility/entity/AutomobileEntity.java similarity index 65% rename from src/main/java/io/github/foundationgames/automobility/entity/AutomobileEntity.java rename to common/src/main/java/io/github/foundationgames/automobility/entity/AutomobileEntity.java index ec32f94..8443551 100644 --- a/src/main/java/io/github/foundationgames/automobility/entity/AutomobileEntity.java +++ b/common/src/main/java/io/github/foundationgames/automobility/entity/AutomobileEntity.java @@ -1,5 +1,6 @@ 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; @@ -12,61 +13,55 @@ import io.github.foundationgames.automobility.automobile.attachment.rear.DeployableRearAttachment; import io.github.foundationgames.automobility.automobile.attachment.rear.RearAttachment; import io.github.foundationgames.automobility.automobile.render.RenderableAutomobile; -import io.github.foundationgames.automobility.screen.AutomobileScreenHandlerContext; import io.github.foundationgames.automobility.block.AutomobileAssemblerBlock; import io.github.foundationgames.automobility.block.LaunchGelBlock; import io.github.foundationgames.automobility.block.OffRoadBlock; import io.github.foundationgames.automobility.item.AutomobileInteractable; import io.github.foundationgames.automobility.item.AutomobilityItems; import io.github.foundationgames.automobility.particle.AutomobilityParticles; -import io.github.foundationgames.automobility.sound.AutomobileSoundInstance; +import io.github.foundationgames.automobility.platform.Platform; +import io.github.foundationgames.automobility.screen.AutomobileContainerLevelAccess; import io.github.foundationgames.automobility.sound.AutomobilitySounds; import io.github.foundationgames.automobility.util.AUtils; import io.github.foundationgames.automobility.util.duck.CollisionArea; -import io.github.foundationgames.automobility.util.midnightcontrols.ControllerUtils; -import io.github.foundationgames.automobility.util.network.PayloadPackets; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.block.ShapeContext; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.model.Model; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.ItemEntity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.MovementType; -import net.minecraft.entity.damage.DamageSource; -import net.minecraft.entity.data.DataTracker; -import net.minecraft.entity.data.TrackedData; -import net.minecraft.entity.data.TrackedDataHandlerRegistry; -import net.minecraft.entity.mob.MobEntity; -import net.minecraft.entity.mob.WaterCreatureEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.vehicle.BoatEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.network.Packet; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket; -import net.minecraft.predicate.entity.EntityPredicates; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.sound.SoundCategory; -import net.minecraft.sound.SoundEvents; -import net.minecraft.util.ActionResult; -import net.minecraft.util.CuboidBlockIterator; -import net.minecraft.util.Hand; -import net.minecraft.util.Identifier; -import net.minecraft.util.TypeFilter; -import net.minecraft.util.function.BooleanBiFunction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Box; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.Vec3d; -import net.minecraft.util.math.Vec3f; -import net.minecraft.util.shape.VoxelShapes; -import net.minecraft.world.World; -import net.minecraft.world.event.GameEvent; +import io.github.foundationgames.automobility.util.network.ClientPackets; +import io.github.foundationgames.automobility.util.network.CommonPackets; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Cursor3D; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.util.Mth; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntitySelector; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.MoverType; +import net.minecraft.world.entity.animal.WaterAnimal; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.vehicle.Boat; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.entity.EntityTypeTest; +import net.minecraft.world.level.gameevent.GameEvent; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.phys.shapes.BooleanOp; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.Shapes; import org.jetbrains.annotations.Nullable; import java.util.ArrayDeque; @@ -79,9 +74,12 @@ import java.util.function.Consumer; public class AutomobileEntity extends Entity implements RenderableAutomobile, EntityWithInventory { - private static final TrackedData REAR_ATTACHMENT_YAW = DataTracker.registerData(AutomobileEntity.class, TrackedDataHandlerRegistry.FLOAT); - private static final TrackedData REAR_ATTACHMENT_ANIMATION = DataTracker.registerData(AutomobileEntity.class, TrackedDataHandlerRegistry.FLOAT); - private static final TrackedData FRONT_ATTACHMENT_ANIMATION = DataTracker.registerData(AutomobileEntity.class, TrackedDataHandlerRegistry.FLOAT); + public static Consumer engineSound = e -> {}; + public static Consumer skidSound = e -> {}; + + private static final EntityDataAccessor REAR_ATTACHMENT_YAW = SynchedEntityData.defineId(AutomobileEntity.class, EntityDataSerializers.FLOAT); + private static final EntityDataAccessor REAR_ATTACHMENT_ANIMATION = SynchedEntityData.defineId(AutomobileEntity.class, EntityDataSerializers.FLOAT); + private static final EntityDataAccessor FRONT_ATTACHMENT_ANIMATION = SynchedEntityData.defineId(AutomobileEntity.class, EntityDataSerializers.FLOAT); private AutomobileFrame frame = AutomobileFrame.REGISTRY.getOrDefault(null); private AutomobileWheel wheels = AutomobileWheel.REGISTRY.getOrDefault(null); @@ -91,17 +89,6 @@ public class AutomobileEntity extends Entity implements RenderableAutomobile, En private final AutomobileStats stats = new AutomobileStats(); - @Environment(EnvType.CLIENT) - private Model frameModel = null; - @Environment(EnvType.CLIENT) - private Model wheelModel = null; - @Environment(EnvType.CLIENT) - private Model engineModel = null; - @Environment(EnvType.CLIENT) - private @Nullable Model rearAttachmentModel = null; - @Environment(EnvType.CLIENT) - private @Nullable Model frontAttachmentModel = null; - public static final int SMALL_TURBO_TIME = 35; public static final int MEDIUM_TURBO_TIME = 70; public static final int LARGE_TURBO_TIME = 115; @@ -129,7 +116,7 @@ public class AutomobileEntity extends Entity implements RenderableAutomobile, En private float hSpeed = 0; private float vSpeed = 0; - private Vec3d addedVelocity = getVelocity(); + private Vec3 addedVelocity = getDeltaMovement(); private float steering = 0; private float lastSteering = steering; @@ -153,10 +140,10 @@ public class AutomobileEntity extends Entity implements RenderableAutomobile, En private boolean isFloorDirectlyBelow = true; private boolean touchingWall = false; - private Vec3d lastVelocity = Vec3d.ZERO; - private Vec3d lastPosForDisplacement = Vec3d.ZERO; + private Vec3 lastVelocity = Vec3.ZERO; + private Vec3 lastPosForDisplacement = Vec3.ZERO; - private Vec3d prevTailPos = null; + private Vec3 prevTailPos = null; private int slopeStickingTimer = 0; private float grip = 1; @@ -167,7 +154,7 @@ public class AutomobileEntity extends Entity implements RenderableAutomobile, En private final Deque prevYDisplacements = new ArrayDeque<>(); private boolean offRoad = false; - private Vec3f debrisColor = new Vec3f(); + private Vector3f debrisColor = new Vector3f(); private int fallTicks = 0; @@ -179,7 +166,7 @@ public class AutomobileEntity extends Entity implements RenderableAutomobile, En private float standStillTime = -1.3f; - public void writeSyncToClientData(PacketByteBuf buf) { + public void writeSyncToClientData(FriendlyByteBuf buf) { buf.writeInt(boostTimer); buf.writeFloat(steering); buf.writeFloat(wheelAngle); @@ -192,7 +179,7 @@ public void writeSyncToClientData(PacketByteBuf buf) { buf.writeBoolean(burningOut); } - public void readSyncToClientData(PacketByteBuf buf) { + public void readSyncToClientData(FriendlyByteBuf buf) { boostTimer = buf.readInt(); steering = buf.readFloat(); wheelAngle = buf.readFloat(); @@ -206,11 +193,11 @@ public void readSyncToClientData(PacketByteBuf buf) { } @Override - public void readCustomDataFromNbt(NbtCompound nbt) { + public void readAdditionalSaveData(CompoundTag nbt) { setComponents( - AutomobileFrame.REGISTRY.getOrDefault(Identifier.tryParse(nbt.getString("frame"))), - AutomobileWheel.REGISTRY.getOrDefault(Identifier.tryParse(nbt.getString("wheels"))), - AutomobileEngine.REGISTRY.getOrDefault(Identifier.tryParse(nbt.getString("engine"))) + AutomobileFrame.REGISTRY.getOrDefault(ResourceLocation.tryParse(nbt.getString("frame"))), + AutomobileWheel.REGISTRY.getOrDefault(ResourceLocation.tryParse(nbt.getString("wheels"))), + AutomobileEngine.REGISTRY.getOrDefault(ResourceLocation.tryParse(nbt.getString("engine"))) ); var rAtt = nbt.getCompound("rearAttachment"); @@ -246,12 +233,10 @@ public void readCustomDataFromNbt(NbtCompound nbt) { despawnTime = nbt.getInt("despawnTime"); despawnCountdown = nbt.getInt("despawnCountdown"); decorative = nbt.getBoolean("decorative"); - - updateModels = true; } @Override - public void writeCustomDataToNbt(NbtCompound nbt) { + public void addAdditionalSaveData(CompoundTag nbt) { nbt.putString("frame", frame.getId().toString()); nbt.putString("wheels", wheels.getId().toString()); nbt.putString("engine", engine.getId().toString()); @@ -310,25 +295,22 @@ public void readCompactedInputData(byte data) { accelerating = (1 & d) > 0; } - @Environment(EnvType.CLIENT) - public boolean updateModels = true; - - public AutomobileEntity(EntityType type, World world) { + public AutomobileEntity(EntityType type, Level world) { super(type, world); this.setRearAttachment(RearAttachmentType.REGISTRY.getOrDefault(null)); this.setFrontAttachment(FrontAttachmentType.REGISTRY.getOrDefault(null)); } - public AutomobileEntity(World world) { - this(AutomobilityEntities.AUTOMOBILE, world); + public AutomobileEntity(Level world) { + this(AutomobilityEntities.AUTOMOBILE.require(), world); } @Override - public void onSpawnPacket(EntitySpawnS2CPacket packet) { - super.onSpawnPacket(packet); - if (world.isClient()) { - PayloadPackets.requestSyncAutomobileComponentsPacket(this); + public void recreateFromPacket(ClientboundAddEntityPacket packet) { + super.recreateFromPacket(packet); + if (level.isClientSide()) { + ClientPackets.requestSyncAutomobileComponentsPacket(this); } } @@ -359,26 +341,26 @@ public AutomobileEngine getEngine() { @Override public float getSteering(float tickDelta) { - return MathHelper.lerp(tickDelta, lastSteering, steering); + return Mth.lerp(tickDelta, lastSteering, steering); } @Override public float getWheelAngle(float tickDelta) { - return MathHelper.lerp(tickDelta, lastWheelAngle, wheelAngle); + return Mth.lerp(tickDelta, lastWheelAngle, wheelAngle); } public float getBoostSpeed(float tickDelta) { - return MathHelper.lerp(tickDelta, lastBoostSpeed, boostSpeed); + return Mth.lerp(tickDelta, lastBoostSpeed, boostSpeed); } @Override public float getSuspensionBounce(float tickDelta) { - return MathHelper.lerp(tickDelta, lastSusBounceTimer, suspensionBounceTimer); + return Mth.lerp(tickDelta, lastSusBounceTimer, suspensionBounceTimer); } @Override public boolean engineRunning() { - return hasPassengers(); + return this.boostTimer > 0 || isVehicle(); } @Override @@ -405,7 +387,7 @@ public int getBoostTimer() { } public double getEffectiveSpeed() { - if (this.getPrimaryPassenger() instanceof PlayerEntity player && player.isMainPlayer()) { + if (this.getControllingPassenger() instanceof Player player && player.isLocalPlayer()) { return Math.max(this.addedVelocity.length(), Math.abs(this.hSpeed)); } @@ -423,7 +405,7 @@ public boolean debris() { } @Override - public Vec3f debrisColor() { + public Vector3f debrisColor() { return debrisColor; } @@ -432,16 +414,16 @@ public boolean burningOut() { } private void setDrifting(boolean drifting) { - if (this.world.isClient() && !this.drifting && drifting) { - playSkiddingSound(); + if (this.level.isClientSide() && !this.drifting && drifting) { + skidSound.accept(this); } this.drifting = drifting; } private void setBurningOut(boolean burningOut) { - if (this.world.isClient() && !this.drifting && !this.burningOut && burningOut) { - playSkiddingSound(); + if (this.level.isClientSide() && !this.drifting && !this.burningOut && burningOut) { + skidSound.accept(this); } this.burningOut = burningOut; @@ -461,13 +443,12 @@ public void setRearAttachment(RearAttachmentType r } this.rearAttachment = rearAttachment.constructor().apply(rearAttachment, this); - this.rearAttachment.setYaw(this.getYaw()); + this.rearAttachment.setYaw(this.getYRot()); - if (!world.isClient() && !this.rearAttachment.isRideable() && this.getPassengerList().size() > 1) { - this.getPassengerList().get(1).stopRiding(); + if (!level.isClientSide() && !this.rearAttachment.isRideable() && this.getPassengers().size() > 1) { + this.getPassengers().get(1).stopRiding(); } - this.updateModels = true; syncAttachments(); } } @@ -482,7 +463,6 @@ public void setFrontAttachment(FrontAttachmentType action) { - for (PlayerEntity p : world.getPlayers()) { + public void forNearbyPlayers(int radius, boolean ignoreDriver, Consumer action) { + for (Player p : level.players()) { if (ignoreDriver && p == getFirstPassenger()) { continue; } - if (p.getPos().distanceTo(getPos()) < radius && p instanceof ServerPlayerEntity player) { + if (p.position().distanceTo(position()) < radius && p instanceof ServerPlayer player) { action.accept(player); } } } - public Vec3d getTailPos() { - return this.getPos() - .add(new Vec3d(0, 0, this.getFrame().model().rearAttachmentPos() * 0.0625) - .rotateY((float) Math.toRadians(180 - this.getYaw())) + public Vec3 getTailPos() { + return this.position() + .add(new Vec3(0, 0, this.getFrame().model().rearAttachmentPos() * 0.0625) + .yRot((float) Math.toRadians(180 - this.getYRot())) ); } - public Vec3d getHeadPos() { - return this.getPos() - .add(new Vec3d(0, 0, this.getFrame().model().frontAttachmentPos() * 0.0625) - .rotateY((float) Math.toRadians(-this.getYaw())) + public Vec3 getHeadPos() { + return this.position() + .add(new Vec3(0, 0, this.getFrame().model().frontAttachmentPos() * 0.0625) + .yRot((float) Math.toRadians(-this.getYRot())) ); } public boolean hasSpaceForPassengers() { - return (this.rearAttachment.isRideable()) ? (this.getPassengerList().size() < 2) : (!this.hasPassengers()); + return (this.rearAttachment.isRideable()) ? (this.getPassengers().size() < 2) : (!this.isVehicle()); } public void setSpeed(float horizontal, float vertical) { @@ -532,35 +511,19 @@ public void setSpeed(float horizontal, float vertical) { this.vSpeed = vertical; } - @Environment(EnvType.CLIENT) - private void playEngineSound() { - if (this.getEngine().isEmpty()) { - return; - } - - var client = MinecraftClient.getInstance(); - client.getSoundManager().play(new AutomobileSoundInstance.EngineSound(client, this)); - } - - @Environment(EnvType.CLIENT) - private void playSkiddingSound() { - var client = MinecraftClient.getInstance(); - client.getSoundManager().play(new AutomobileSoundInstance.SkiddingSound(client, this)); - } - @Override public void tick() { - boolean first = this.firstUpdate; + boolean first = this.firstTick; if (lastWheelAngle != wheelAngle) markDirty(); lastWheelAngle = wheelAngle; - if (!this.wasEngineRunning && this.engineRunning() && this.world.isClient()) { - playEngineSound(); + if (!this.wasEngineRunning && this.engineRunning() && this.level.isClientSide()) { + engineSound.accept(this); } this.wasEngineRunning = this.engineRunning(); - if (!this.hasPassengers() || !this.getFrontAttachment().canDrive(this.getFirstPassenger())) { + if (!this.isVehicle() || !this.getFrontAttachment().canDrive(this.getFirstPassenger())) { accelerating = false; braking = false; steeringLeft = false; @@ -576,7 +539,7 @@ public void tick() { if (!this.rearAttachment.type.isEmpty()) this.rearAttachment.tick(); if (!this.frontAttachment.type.isEmpty()) this.frontAttachment.tick(); - var prevPos = this.getPos(); + var prevPos = this.position(); positionTrackingTick(); collisionStateTick(); @@ -585,12 +548,12 @@ public void tick() { burnoutTick(); movementTick(); - if (this.isLogicalSideForUpdatingMovement()) { - this.move(MovementType.SELF, this.getVelocity()); + if (this.isControlledByLocalInstance()) { + this.move(MoverType.SELF, this.getDeltaMovement()); } postMovementTick(); - if (!world.isClient()) { + if (!level.isClientSide()) { var prevTailPos = this.prevTailPos != null ? this.prevTailPos : this.getTailPos(); var tailPos = this.getTailPos(); @@ -602,17 +565,17 @@ public void tick() { dirty = false; } if (this.hasSpaceForPassengers() && !decorative) { - var touchingEntities = this.world.getOtherEntities(this, this.getBoundingBox().expand(0.2, 0, 0.2), EntityPredicates.canBePushedBy(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.hasVehicle() && entity.getWidth() <= this.getWidth() && entity instanceof MobEntity && !(entity instanceof WaterCreatureEntity)) { + if (!entity.isPassenger() && entity.getBbWidth() <= this.getBbWidth() && entity instanceof Mob && !(entity instanceof WaterAnimal)) { entity.startRiding(this); } } } } - if (this.hasPassengers()) { - if (this.getFrontAttachment().canDrive(this.getFirstPassenger()) && this.getFirstPassenger() instanceof MobEntity mob) { + if (this.isVehicle()) { + if (this.getFrontAttachment().canDrive(this.getFirstPassenger()) && this.getFirstPassenger() instanceof Mob mob) { provideMobDriverInputs(mob); } @@ -632,27 +595,27 @@ public void tick() { suspensionBounceTimer--; } - if (Math.abs(this.hSpeed) < 0.05 && !this.burningOut && this.getPrimaryPassenger() instanceof PlayerEntity) { + if (Math.abs(this.hSpeed) < 0.05 && !this.burningOut && this.getControllingPassenger() instanceof Player) { this.standStillTime = AUtils.shift(this.standStillTime, 0.05f, 1f); } else { this.standStillTime = AUtils.shift(this.standStillTime, 0.15f, -1.3f); } } - displacementTick(first || (this.getPos().subtract(prevPos).length() > 0 || this.getYaw() != this.prevYaw)); + displacementTick(first || (this.position().subtract(prevPos).length() > 0 || this.getYRot() != this.yRotO)); } public void positionTrackingTick() { - if (this.isLogicalSideForUpdatingMovement()) { + if (this.isControlledByLocalInstance()) { this.lerpTicks = 0; - updateTrackedPosition(getX(), getY(), getZ()); + syncPacketPositionCodec(getX(), getY(), getZ()); } else if (lerpTicks > 0) { - this.setPosition( + this.setPos( this.getX() + ((this.trackedX - this.getX()) / (double)this.lerpTicks), this.getY() + ((this.trackedY - this.getY()) / (double)this.lerpTicks), this.getZ() + ((this.trackedZ - this.getZ()) / (double)this.lerpTicks) ); - this.setYaw(this.getYaw() + (MathHelper.wrapDegrees(this.trackedYaw - this.getYaw()) / (float)this.lerpTicks)); + this.setYRot(this.getYRot() + (Mth.wrapDegrees(this.trackedYaw - this.getYRot()) / (float)this.lerpTicks)); this.lerpTicks--; } @@ -663,20 +626,20 @@ public void markDirty() { } private void syncData() { - forNearbyPlayers(200, true, player -> PayloadPackets.sendSyncAutomobileDataPacket(this, player)); + forNearbyPlayers(200, true, player -> CommonPackets.sendSyncAutomobileDataPacket(this, player)); } private void syncComponents() { - forNearbyPlayers(200, false, player -> PayloadPackets.sendSyncAutomobileComponentsPacket(this, player)); + forNearbyPlayers(200, false, player -> CommonPackets.sendSyncAutomobileComponentsPacket(this, player)); } private void syncAttachments() { - forNearbyPlayers(200, false, player -> PayloadPackets.sendSyncAutomobileAttachmentsPacket(this, player)); + forNearbyPlayers(200, false, player -> CommonPackets.sendSyncAutomobileAttachmentsPacket(this, player)); } public ItemStack asPrefabItem() { - var stack = new ItemStack(AutomobilityItems.AUTOMOBILE); - var automobile = stack.getOrCreateSubNbt("Automobile"); + var stack = new ItemStack(AutomobilityItems.AUTOMOBILE.require()); + var automobile = stack.getOrCreateTagElement("Automobile"); automobile.putString("frame", frame.getId().toString()); automobile.putString("wheels", wheels.getId().toString()); automobile.putString("engine", engine.getId().toString()); @@ -685,16 +648,16 @@ public ItemStack asPrefabItem() { @Nullable @Override - public ItemStack getPickBlockStack() { + public ItemStack getPickResult() { return asPrefabItem(); } // making mobs drive automobiles // technically the mobs don't drive, instead the automobile // self-drives to the mob's destination... - public void provideMobDriverInputs(MobEntity driver) { + public void provideMobDriverInputs(Mob driver) { // Don't move if the driver doesn't exist or can't drive - if (driver == null || driver.isDead() || driver.isRemoved()) { + if (driver == null || driver.isDeadOrDying() || driver.isRemoved()) { if (accelerating || steeringLeft || steeringRight) markDirty(); accelerating = false; steeringLeft = false; @@ -702,17 +665,17 @@ public void provideMobDriverInputs(MobEntity driver) { return; } - var path = driver.getNavigation().getCurrentPath(); + var path = driver.getNavigation().getPath(); // checks if there is a current, incomplete path that the entity has targeted - if (path != null && !path.isFinished() && path.getEnd() != null) { + if (path != null && !path.isDone() && path.getEndNode() != null) { // determines the relative position to drive to, based on the end of the path - var pos = path.getEnd().getPos().subtract(getPos()); + var pos = path.getEndNode().asVec3().subtract(position()); // determines the angle to that position - double target = MathHelper.wrapDegrees(Math.toDegrees(Math.atan2(pos.getX(), pos.getZ()))); + double target = Mth.wrapDegrees(Math.toDegrees(Math.atan2(pos.x(), pos.z()))); // determines another relative position, this time to the path's current node (in the case of the path directly to the end being obstructed) - var fnPos = path.getCurrentNode().getPos().subtract(getPos()); + var fnPos = path.getNextNode().asVec3().subtract(position()); // determines the angle to that current node's position - double fnTarget = MathHelper.wrapDegrees(Math.toDegrees(Math.atan2(fnPos.getX(), fnPos.getZ()))); + double fnTarget = Mth.wrapDegrees(Math.toDegrees(Math.atan2(fnPos.x(), fnPos.z()))); // if the difference in angle between the end position and the current node's position is too great, // the automobile will drive to that current node under the assumption that the path directly to the // end is obstructed @@ -721,16 +684,16 @@ public void provideMobDriverInputs(MobEntity driver) { target = fnTarget; } // fixes up the automobile's own yaw value - float yaw = MathHelper.wrapDegrees(-getYaw()); + float yaw = Mth.wrapDegrees(-getYRot()); // finds the difference between the target angle and the yaw - double offset = MathHelper.wrapDegrees(yaw - target); + double offset = Mth.wrapDegrees(yaw - target); // whether the automobile should go in reverse boolean reverse = false; // a value to determine the threshold used to determine whether the automobile is moving // both slow enough and is at an extreme enough offset angle to incrementally move in reverse - float mul = 0.5f + (MathHelper.clamp(hSpeed, 0, 1) * 0.5f); + float mul = 0.5f + (Mth.clamp(hSpeed, 0, 1) * 0.5f); if (pos.length() < 20 * mul && Math.abs(offset) > 180 - (170 * mul)) { - long time = world.getTime(); + 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); @@ -771,28 +734,28 @@ public void movementTick() { // Get block below's friction var blockBelow = new BlockPos(getX(), getY() - 0.05, getZ()); - this.grip = 1 - ((MathHelper.clamp((world.getBlockState(blockBelow).getBlock().getSlipperiness() - 0.6f) / 0.4f, 0, 1) * (1 - stats.getGrip() * 0.8f))); + 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 && world.getBlockState(this.getBlockPos()).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; } // Track the last position of the automobile - this.lastPosForDisplacement = getPos(); + this.lastPosForDisplacement = position(); // cumulative will be modified by the following code and then the automobile will be moved by it // Currently initialized with the value of addedVelocity (which is a general velocity vector applied to the automobile, i.e. for when it bumps into a wall and is pushed back) var cumulative = addedVelocity; // Reduce gravity underwater - cumulative = cumulative.add(0, (vSpeed * (isSubmergedInWater() ? 0.15f : 1)), 0); + cumulative = cumulative.add(0, (vSpeed * (isUnderWater() ? 0.15f : 1)), 0); // This is the general direction the automobile will move, which is slightly offset to the side when drifting - this.speedDirection = getYaw() - (drifting ? Math.min(turboCharge * 6, 43 + (-steering * 12)) * driftDir : -steering * 12); //MathHelper.lerp(grip, getYaw(), getYaw() - (drifting ? Math.min(turboCharge * 6, 43 + (-steering * 12)) * driftDir : -steering * 12)); + this.speedDirection = getYRot() - (drifting ? Math.min(turboCharge * 6, 43 + (-steering * 12)) * driftDir : -steering * 12); //MathHelper.lerp(grip, getYaw(), getYaw() - (drifting ? Math.min(turboCharge * 6, 43 + (-steering * 12)) * driftDir : -steering * 12)); // Handle acceleration if (accelerating) { @@ -832,16 +795,16 @@ 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 = world.getBlockState(below); - if (state.isIn(Automobility.STICKY_SLOPES)) { + var state = level.getBlockState(below); + if (state.is(Automobility.STICKY_SLOPES)) { slopeStickingTimer = 1; } else { slopeStickingTimer = Math.max(0, slopeStickingTimer--); } // Handle being in off-road - if (boostSpeed < 0.4f && world.getBlockState(getBlockPos()).getBlock() instanceof OffRoadBlock offRoad) { - int layers = world.getBlockState(getBlockPos()).get(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 +828,7 @@ public void movementTick() { float angle = (float) Math.toRadians(-speedDirection); if (this.burningOut()) { if (Math.abs(hSpeed) > 0.02) { - this.addedVelocity = new Vec3d(Math.sin(angle) * hSpeed, 0, Math.cos(angle) * hSpeed); + this.addedVelocity = new Vec3(Math.sin(angle) * hSpeed, 0, Math.cos(angle) * hSpeed); this.hSpeed = 0; cumulative = cumulative.add(addedVelocity); } @@ -874,9 +837,9 @@ public void movementTick() { cumulative = cumulative.add(Math.sin(angle) * hSpeed, 0, Math.cos(angle) * hSpeed); } - cumulative = cumulative.multiply(this.grip).add(this.lastVelocity.multiply(1 - this.grip)); + cumulative = cumulative.scale(this.grip).add(this.lastVelocity.scale(1 - this.grip)); if (cumulative.length() < 0.001) { - cumulative = Vec3d.ZERO; + cumulative = Vec3.ZERO; } // Turn the wheels @@ -885,11 +848,11 @@ public void movementTick() { wheelAngle += 300 * (hSpeed / wheelCircumference) + (hSpeed > 0 ? ((1 - grip) * 15) : 0); // made it a bit slower intentionally, also make it spin more when on slippery surface // Set the automobile's velocity - if (this.isLogicalSideForUpdatingMovement()) { - this.setVelocity(cumulative); + if (this.isControlledByLocalInstance()) { + this.setDeltaMovement(cumulative); } - this.scheduleVelocityUpdate(); - this.velocityDirty = true; + this.markHurt(); + this.hasImpulse = true; lastVelocity = cumulative; @@ -899,15 +862,15 @@ public void movementTick() { } } - public void runOverEntities(Vec3d velocity) { - var frontBox = getBoundingBox().offset(velocity.multiply(0.5)); - var velAdd = velocity.add(0, 0.1, 0).multiply(3); - for (var entity : world.getEntitiesByType(TypeFilter.instanceOf(Entity.class), frontBox, entity -> entity != this && entity != getFirstPassenger())) { + 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())) { if (!entity.isInvulnerable()) { if (entity instanceof LivingEntity living && entity.getVehicle() != this) { - living.damage(AutomobilityEntities.AUTOMOBILE_DAMAGE_SOURCE, hSpeed * 10); + living.hurt(AutomobilityEntities.AUTOMOBILE_DAMAGE_SOURCE, hSpeed * 10); - entity.addVelocity(velAdd.x, velAdd.y, velAdd.z); + entity.push(velAdd.x, velAdd.y, velAdd.z); } } } @@ -921,7 +884,7 @@ public void postMovementTick() { // Reduce the values of addedVelocity incrementally double addVelLen = addedVelocity.length(); - if (addVelLen > 0) addedVelocity = addedVelocity.multiply(Math.max(0, addVelLen - addedVelReduction) / addVelLen); + if (addVelLen > 0) addedVelocity = addedVelocity.scale(Math.max(0, addVelLen - addedVelReduction) / addVelLen); float angle = (float) Math.toRadians(-speedDirection); if (touchingWall && hSpeed > 0.1 && addedVelocity.length() <= 0) { @@ -929,10 +892,10 @@ public void postMovementTick() { double knockSpeed = ((-0.2 * hSpeed) - 0.5); addedVelocity = addedVelocity.add(Math.sin(angle) * knockSpeed, 0, Math.cos(angle) * knockSpeed); - world.playSound(this.getX(), this.getY(), this.getZ(), AutomobilitySounds.COLLISION, SoundCategory.AMBIENT, 0.76f, 0.65f + (0.06f * (this.world.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 = getPos().subtract(this.lastPosForDisplacement).getY(); + double yDisp = position().subtract(this.lastPosForDisplacement).y(); // Increment the falling timer if (!automobileOnGround && yDisp < 0) { @@ -947,7 +910,7 @@ public void postMovementTick() { highestPrevYDisp = Math.max(d, highestPrevYDisp); } if (wasOnGround && !automobileOnGround && !isFloorDirectlyBelow) { - vSpeed = (float)MathHelper.clamp(highestPrevYDisp, 0, hSpeed * 0.6f); + vSpeed = (float)Mth.clamp(highestPrevYDisp, 0, hSpeed * 0.6f); } // Handles gravity @@ -975,7 +938,7 @@ public void postMovementTick() { float acc = (1.7f / (1 + this.frame.weight())) + (4 * speed); float lim = 9 + (4 * speed); if (this.steering != 0) { - newAngularSpeed = MathHelper.clamp(newAngularSpeed + (acc * this.steering), -lim, lim); + newAngularSpeed = Mth.clamp(newAngularSpeed + (acc * this.steering), -lim, lim); } else { newAngularSpeed = AUtils.shift(newAngularSpeed, acc * 0.5f, 0); } @@ -995,63 +958,63 @@ public void postMovementTick() { // Turns the automobile based on steering/drifting if (hSpeed != 0 || this.burningOut()) { 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 = getYaw(); - this.setYaw(getYaw() + yawInc); - if (world.isClient) { + float prevYaw = getYRot(); + this.setYRot(getYRot() + yawInc); + if (level.isClientSide) { var passenger = getFirstPassenger(); - if (passenger instanceof PlayerEntity player) { + if (passenger instanceof Player player) { if (inLockedViewMode()) { - player.setYaw(MathHelper.wrapDegrees(getYaw() + lockedViewOffset)); - player.setBodyYaw(MathHelper.wrapDegrees(getYaw() + lockedViewOffset)); + player.setYRot(Mth.wrapDegrees(getYRot() + lockedViewOffset)); + player.setYBodyRot(Mth.wrapDegrees(getYRot() + lockedViewOffset)); } else { - player.setYaw(MathHelper.wrapDegrees(player.getYaw() + yawInc)); - player.setBodyYaw(MathHelper.wrapDegrees(player.getYaw() + yawInc)); + player.setYRot(Mth.wrapDegrees(player.getYRot() + yawInc)); + player.setYBodyRot(Mth.wrapDegrees(player.getYRot() + yawInc)); } } } else { - for (Entity e : getPassengerList()) { + for (Entity e : getPassengers()) { if (e == getFirstPassenger()) { - e.setYaw(MathHelper.wrapDegrees(e.getYaw() + yawInc)); - e.setBodyYaw(MathHelper.wrapDegrees(e.getYaw() + yawInc)); + e.setYRot(Mth.wrapDegrees(e.getYRot() + yawInc)); + e.setYBodyRot(Mth.wrapDegrees(e.getYRot() + yawInc)); } } } - if (world.isClient()) { - this.prevYaw = prevYaw; + if (level.isClientSide()) { + this.yRotO = prevYaw; } } } @Override - public void move(MovementType movementType, Vec3d movement) { - if (!this.world.isClient() && movementType == MovementType.PLAYER) { + public void move(MoverType movementType, Vec3 movement) { + if (!this.level.isClientSide() && movementType == MoverType.PLAYER) { AUtils.IGNORE_ENTITY_GROUND_CHECK_STEPPING = true; } super.move(movementType, movement); } @Override - public boolean handleFallDamage(float fallDistance, float damageMultiplier, DamageSource damageSource) { + public boolean causeFallDamage(float fallDistance, float damageMultiplier, DamageSource damageSource) { return false; // Riders shouldn't take fall damage } public void accumulateCollisionAreas(Collection areas) { - this.world.getEntitiesByClass(Entity.class, this.getBoundingBox().expand(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.world.isClient()) { + if (this.level.isClientSide()) { this.displacement.preTick(); if (tick) { this.displacement.otherColliders.clear(); this.accumulateCollisionAreas(this.displacement.otherColliders); - this.displacement.tick(this.world, this, this.getPos(), this.getYaw(), this.stepHeight); + this.displacement.tick(this.level, this, this.position(), this.getYRot(), this.maxUpStep); } - if (world.getBlockState(this.getBlockPos()).getBlock() instanceof AutomobileAssemblerBlock) { + if (level.getBlockState(this.blockPosition()).getBlock() instanceof AutomobileAssemblerBlock) { this.displacement.lastVertical = this.displacement.verticalTarget = (-this.wheels.model().radius() / 16); } } @@ -1067,31 +1030,31 @@ public void collisionStateTick() { isFloorDirectlyBelow = false; touchingWall = false; var b = getBoundingBox(); - var groundBox = new Box(b.minX, b.minY - 0.04, b.minZ, b.maxX, b.minY, b.maxZ); - var wid = (b.getXLength() + b.getZLength()) * 0.5f; - var floorBox = new Box(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.contract(0.05).offset(this.lastVelocity.normalize().multiply(0.12)); + var groundBox = new AABB(b.minX, b.minY - 0.04, b.minZ, b.maxX, b.minY, b.maxZ); + 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.stepHeight, b.maxZ + 0.1); - var groundCuboid = VoxelShapes.cuboid(groundBox); - var floorCuboid = VoxelShapes.cuboid(floorBox); - var wallCuboid = VoxelShapes.cuboid(wallBox); - var stepWallCuboid = wallCuboid.offset(0, this.stepHeight - 0.05, 0); + var end = new BlockPos(b.maxX + 0.1, b.maxY + 0.2 + this.maxUpStep, 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); boolean wallHit = false; boolean stepWallHit = false; - var shapeCtx = ShapeContext.of(this); - if (this.world.isRegionLoaded(start, end)) { - var pos = new BlockPos.Mutable(); + var shapeCtx = CollisionContext.of(this); + 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.world.getBlockState(pos); - var blockShape = state.getCollisionShape(this.world, pos, shapeCtx).offset(pos.getX(), pos.getY(), pos.getZ()); - this.automobileOnGround |= VoxelShapes.matchesAnywhere(blockShape, groundCuboid, BooleanBiFunction.AND); - this.isFloorDirectlyBelow |= VoxelShapes.matchesAnywhere(blockShape, floorCuboid, BooleanBiFunction.AND); - wallHit |= VoxelShapes.matchesAnywhere(blockShape, wallCuboid, BooleanBiFunction.AND); - stepWallHit |= VoxelShapes.matchesAnywhere(blockShape, stepWallCuboid, BooleanBiFunction.AND); + 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); + stepWallHit |= Shapes.joinIsNotEmpty(blockShape, stepWallCuboid, BooleanOp.AND); } } } @@ -1103,12 +1066,12 @@ public void collisionStateTick() { this.automobileOnGround |= otherColliders.stream().anyMatch(col -> col.boxIntersects(groundBox)); } - public void updateTrackedPositionAndAngles(double x, double y, double z, float yaw, float pitch, int interpolationSteps, boolean interpolate) { + public void lerpTo(double x, double y, double z, float yaw, float pitch, int interpolationSteps, boolean interpolate) { this.trackedX = x; this.trackedY = y; this.trackedZ = z; this.trackedYaw = yaw; - this.lerpTicks = this.getType().getTrackTickInterval() + 1; + this.lerpTicks = this.getType().updateInterval() + 1; } private float calculateAcceleration(float speed, AutomobileStats stats) { @@ -1116,7 +1079,6 @@ private float calculateAcceleration(float speed, AutomobileStats stats) { return (1 / ((300 * speed) + (18.5f - (stats.getAcceleration() * 5.3f)))) * (0.9f * ((stats.getAcceleration() + 1) / 2)); } - @Environment(EnvType.CLIENT) public void provideClientInput(boolean fwd, boolean back, boolean left, boolean right, boolean space) { // Receives inputs client-side and sends them to the server if (!( @@ -1127,7 +1089,7 @@ public void provideClientInput(boolean fwd, boolean back, boolean left, boolean space == holdingDrift )) { setInputs(fwd, back, left, right, space); - PayloadPackets.sendSyncAutomobileInputPacket(this, accelerating, braking, steeringLeft, steeringRight, holdingDrift); + ClientPackets.sendSyncAutomobileInputPacket(this, accelerating, braking, steeringLeft, steeringRight, holdingDrift); } } @@ -1144,7 +1106,7 @@ public void boost(float power, int time) { boostTimer = time; boostPower = power; } - if (this.isLogicalSideForUpdatingMovement()) { + if (this.isControlledByLocalInstance()) { this.engineSpeed = Math.max(this.engineSpeed, this.stats.getComfortableSpeed() * 0.5f); } } @@ -1183,7 +1145,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.getWorld().isClient() && this.getRearAttachment() instanceof DeployableRearAttachment att) { + } else if (steering == 0 && !this.getLevel().isClientSide() && this.getRearAttachment() instanceof DeployableRearAttachment att) { att.deploy(); } } @@ -1234,68 +1196,25 @@ private void burnoutTick() { } public void createDriftParticles() { - var origin = this.getPos().add(0, this.displacement.verticalTarget, 0); + var origin = this.position().add(0, this.displacement.verticalTarget, 0); for (var wheel : this.getFrame().model().wheelBase().wheels) { if (wheel.end() == WheelBase.WheelEnd.BACK) { - var pos = new Vec3d(wheel.right() + ((wheel.right() > 0 ? 1 : -1) * this.getWheels().model().width() * wheel.scale()), 0, wheel.forward()) - .rotateX((float) Math.toRadians(this.displacement.currAngularX)) - .rotateZ((float) Math.toRadians(this.displacement.currAngularZ)) - .rotateY((float) Math.toRadians(-this.getYaw())).multiply(0.0625).add(0, 0.4, 0); - world.addParticle(AutomobilityParticles.DRIFT_SMOKE, origin.x + pos.x, origin.y + pos.y, origin.z + pos.z, 0, 0, 0); + var pos = new Vec3(wheel.right() + ((wheel.right() > 0 ? 1 : -1) * this.getWheels().model().width() * wheel.scale()), 0, wheel.forward()) + .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); } } } private static boolean inLockedViewMode() { - return ControllerUtils.inControllerMode(); - } - - @Environment(EnvType.CLIENT) - private void updateModels(EntityRendererFactory.Context ctx) { - if (updateModels) { - this.frameModel = frame.model().model().apply(ctx); - this.wheelModel = wheels.model().model().apply(ctx); - this.engineModel = engine.model().model().apply(ctx); - this.rearAttachmentModel = this.rearAttachment.type.model().model().apply(ctx); - this.frontAttachmentModel = this.frontAttachment.type.model().model().apply(ctx); - - updateModels = false; - } - } - - @Environment(EnvType.CLIENT) - public Model getWheelModel(EntityRendererFactory.Context ctx) { - updateModels(ctx); - return wheelModel; - } - - @Environment(EnvType.CLIENT) - public Model getFrameModel(EntityRendererFactory.Context ctx) { - updateModels(ctx); - return frameModel; - } - - @Environment(EnvType.CLIENT) - public Model getEngineModel(EntityRendererFactory.Context ctx) { - updateModels(ctx); - return engineModel; - } - - @Override - public @Nullable Model getRearAttachmentModel(EntityRendererFactory.Context ctx) { - updateModels(ctx); - return rearAttachmentModel; - } - - @Override - public @Nullable Model getFrontAttachmentModel(EntityRendererFactory.Context ctx) { - updateModels(ctx); - return frontAttachmentModel; + return Platform.get().inControllerMode(); } @Override public float getAutomobileYaw(float tickDelta) { - return getYaw(tickDelta); + return getViewYRot(tickDelta); } @Override @@ -1305,7 +1224,7 @@ public float getRearAttachmentYaw(float tickDelta) { @Nullable @Override - public Entity getPrimaryPassenger() { + public Entity getControllingPassenger() { return getFirstPassenger(); } @@ -1320,10 +1239,10 @@ public boolean hasInventory() { } @Override - public void openInventory(PlayerEntity player) { - var factory = this.getRearAttachment().createMenu(new AutomobileScreenHandlerContext(this)); + public void openInventory(Player player) { + var factory = this.getRearAttachment().createMenu(new AutomobileContainerLevelAccess(this)); if (factory != null) { - player.openHandledScreen(factory); + player.openMenu(factory); } } @@ -1331,25 +1250,25 @@ public float getStandStillTime() { return this.standStillTime; } - public void playHitSound(Vec3d pos) { - world.emitGameEvent(this, GameEvent.ENTITY_DAMAGE, pos); - world.playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.BLOCK_COPPER_BREAK, SoundCategory.AMBIENT, 1, 0.9f + (this.world.random.nextFloat() * 0.2f)); + 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)); } - private void dropParts(Vec3d pos) { - world.spawnEntity(new ItemEntity(world, pos.x, pos.y, pos.z, AutomobilityItems.AUTOMOBILE_FRAME.createStack(this.getFrame()))); - world.spawnEntity(new ItemEntity(world, pos.x, pos.y, pos.z, AutomobilityItems.AUTOMOBILE_ENGINE.createStack(this.getEngine()))); + 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()))); - var wheelStack = AutomobilityItems.AUTOMOBILE_WHEEL.createStack(this.getWheels()); + var wheelStack = AutomobilityItems.AUTOMOBILE_WHEEL.require().createStack(this.getWheels()); wheelStack.setCount(this.getFrame().model().wheelBase().wheelCount); - world.spawnEntity(new ItemEntity(world, 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(); - world.spawnEntity(new ItemEntity(world, dropPos.x, dropPos.y, dropPos.z, - AutomobilityItems.REAR_ATTACHMENT.createStack(this.getRearAttachmentType()))); + level.addFreshEntity(new ItemEntity(level, dropPos.x, dropPos.y, dropPos.z, + AutomobilityItems.REAR_ATTACHMENT.require().createStack(this.getRearAttachmentType()))); } this.setRearAttachment(RearAttachmentType.EMPTY); } @@ -1357,8 +1276,8 @@ public void destroyRearAttachment(boolean drop) { public void destroyFrontAttachment(boolean drop) { if (drop) { var dropPos = this.frontAttachment.pos(); - world.spawnEntity(new ItemEntity(world, dropPos.x, dropPos.y, dropPos.z, - AutomobilityItems.FRONT_ATTACHMENT.createStack(this.getFrontAttachmentType()))); + level.addFreshEntity(new ItemEntity(level, dropPos.x, dropPos.y, dropPos.z, + AutomobilityItems.FRONT_ATTACHMENT.require().createStack(this.getFrontAttachmentType()))); } this.setFrontAttachment(FrontAttachmentType.EMPTY); } @@ -1371,44 +1290,44 @@ public void destroyAutomobile(boolean drop, RemovalReason reason) { this.destroyFrontAttachment(drop); } if (drop) { - this.dropParts(this.getPos().add(0, 0.3, 0)); + this.dropParts(this.position().add(0, 0.3, 0)); } this.remove(reason); } @Override - public ActionResult interact(PlayerEntity player, Hand hand) { - if (player.isSneaking()) { + public InteractionResult interact(Player player, InteractionHand hand) { + if (player.isShiftKeyDown()) { if (this.hasInventory()) { - if (!world.isClient()) { + if (!level.isClientSide()) { openInventory(player); - return ActionResult.PASS; + return InteractionResult.PASS; } else { - return ActionResult.SUCCESS; + return InteractionResult.SUCCESS; } } } - var stack = player.getStackInHand(hand); - if ((!this.decorative || player.isCreative()) && stack.isOf(AutomobilityItems.CROWBAR)) { + var stack = player.getItemInHand(hand); + if ((!this.decorative || player.isCreative()) && stack.is(AutomobilityItems.CROWBAR.require())) { double playerAngle = Math.toDegrees(Math.atan2(player.getZ() - this.getZ(), player.getX() - this.getX())); - double angleDiff = MathHelper.wrapDegrees(this.getYaw() - playerAngle); + double angleDiff = Mth.wrapDegrees(this.getYRot() - playerAngle); if (angleDiff < 0 && !this.frontAttachment.type.isEmpty()) { this.destroyFrontAttachment(!player.isCreative()); this.playHitSound(this.getHeadPos()); - return ActionResult.success(world.isClient); + return InteractionResult.sidedSuccess(level.isClientSide); } else if (!this.rearAttachment.type.isEmpty()) { this.destroyRearAttachment(!player.isCreative()); this.playHitSound(this.rearAttachment.pos()); - return ActionResult.success(world.isClient); + return InteractionResult.sidedSuccess(level.isClientSide); } else { this.destroyAutomobile(!player.isCreative(), RemovalReason.KILLED); - this.playHitSound(this.getPos()); + this.playHitSound(this.position()); - return ActionResult.success(world.isClient); + return InteractionResult.sidedSuccess(level.isClientSide); } } @@ -1418,61 +1337,61 @@ public ActionResult interact(PlayerEntity player, Hand hand) { } if (!this.hasSpaceForPassengers()) { - if (!(this.getFirstPassenger() instanceof PlayerEntity)) { - if (!world.isClient()) { + if (!(this.getFirstPassenger() instanceof Player)) { + if (!level.isClientSide()) { this.getFirstPassenger().stopRiding(); } - return ActionResult.success(world.isClient); + return InteractionResult.sidedSuccess(level.isClientSide); } - return ActionResult.PASS; + return InteractionResult.PASS; } - if (!world.isClient()) { + if (!level.isClientSide()) { player.startRiding(this); } - return ActionResult.success(world.isClient()); + return InteractionResult.sidedSuccess(level.isClientSide()); } - return ActionResult.PASS; + return InteractionResult.PASS; } @Override - public double getMountedHeightOffset() { + public double getPassengersRidingOffset() { return ((wheels.model().radius() + frame.model().seatHeight() - 4) / 16); } @Override - public void updatePassengerPosition(Entity passenger) { + public void positionRider(Entity passenger) { if (passenger == this.getFirstPassenger()) { - var pos = this.getPos().add(0, this.displacement.verticalTarget + passenger.getHeightOffset(), 0) - .add(new Vec3d(0, this.getMountedHeightOffset(), 0) - .rotateX((float) Math.toRadians(-this.displacement.currAngularX)) - .rotateZ((float) Math.toRadians(-this.displacement.currAngularZ))); + 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.setPosition(pos.x, pos.y, pos.z); + passenger.setPos(pos.x, pos.y, pos.z); } else if (this.hasPassenger(passenger)) { - var pos = this.getPos().add( - new Vec3d(0, this.displacement.verticalTarget, this.getFrame().model().rearAttachmentPos() * 0.0625) - .rotateY((float) Math.toRadians(180 - this.getYaw())).add(0, this.rearAttachment.getPassengerHeightOffset() + passenger.getHeightOffset() - 0.14, 0) + var pos = this.position().add( + new Vec3(0, this.displacement.verticalTarget, this.getFrame().model().rearAttachmentPos() * 0.0625) + .yRot((float) Math.toRadians(180 - this.getYRot())).add(0, this.rearAttachment.getPassengerHeightOffset() + passenger.getMyRidingOffset() - 0.14, 0) .add(this.rearAttachment.scaledYawVec()) - .rotateX((float) Math.toRadians(-this.displacement.currAngularX)) - .rotateZ((float) Math.toRadians(-this.displacement.currAngularZ))); + .xRot((float) Math.toRadians(-this.displacement.currAngularX)) + .zRot((float) Math.toRadians(-this.displacement.currAngularZ))); - passenger.setPosition(pos.x, pos.y, pos.z); + passenger.setPos(pos.x, pos.y, pos.z); } } @Override - public boolean collidesWith(Entity other) { - return BoatEntity.canCollide(this, other); + public boolean canCollideWith(Entity other) { + return Boat.canVehicleCollide(this, other); } @Override - public boolean isCollidable() { + public boolean canBeCollidedWith() { return true; } @Override - public boolean canHit() { + public boolean isPickable() { return !this.isRemoved(); } @@ -1482,14 +1401,14 @@ public boolean isPushable() { } @Override - protected void initDataTracker() { - this.dataTracker.startTracking(REAR_ATTACHMENT_YAW, 0f); - this.dataTracker.startTracking(REAR_ATTACHMENT_ANIMATION, 0f); + protected void defineSynchedData() { + this.entityData.define(REAR_ATTACHMENT_YAW, 0f); + this.entityData.define(REAR_ATTACHMENT_ANIMATION, 0f); } @Override - public void onTrackedDataSet(TrackedData data) { - super.onTrackedDataSet(data); + public void onSyncedDataUpdated(EntityDataAccessor data) { + super.onSyncedDataUpdated(data); if (REAR_ATTACHMENT_YAW.equals(data)) { this.rearAttachment.onTrackedYawUpdated(getTrackedRearAttachmentYaw()); @@ -1501,37 +1420,37 @@ public void onTrackedDataSet(TrackedData data) { } @Override - public Packet createSpawnPacket() { - return new EntitySpawnS2CPacket(this); + public Packet getAddEntityPacket() { + return new ClientboundAddEntityPacket(this); } public void setTrackedRearAttachmentYaw(float value) { - this.dataTracker.set(REAR_ATTACHMENT_YAW, value); + this.entityData.set(REAR_ATTACHMENT_YAW, value); } public float getTrackedRearAttachmentYaw() { - return this.dataTracker.get(REAR_ATTACHMENT_YAW); + return this.entityData.get(REAR_ATTACHMENT_YAW); } public void setTrackedRearAttachmentAnimation(float animation) { - this.dataTracker.set(REAR_ATTACHMENT_ANIMATION, animation); + this.entityData.set(REAR_ATTACHMENT_ANIMATION, animation); } public float getTrackedRearAttachmentAnimation() { - return this.dataTracker.get(REAR_ATTACHMENT_ANIMATION); + return this.entityData.get(REAR_ATTACHMENT_ANIMATION); } public void setTrackedFrontAttachmentAnimation(float animation) { - this.dataTracker.set(FRONT_ATTACHMENT_ANIMATION, animation); + this.entityData.set(FRONT_ATTACHMENT_ANIMATION, animation); } public float getTrackedFrontAttachmentAnimation() { - return this.dataTracker.get(FRONT_ATTACHMENT_ANIMATION); + return this.entityData.get(FRONT_ATTACHMENT_ANIMATION); } public void bounce() { suspensionBounceTimer = 3; - world.playSound(this.getX(), this.getY(), this.getZ(), AutomobilitySounds.LANDING, SoundCategory.AMBIENT, 1, 1.5f + (0.15f * (this.world.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 { @@ -1547,7 +1466,7 @@ public static final class Displacement { private float verticalTarget = 0; private float angularXTarget = 0; private float angularZTarget = 0; - private final List scanPoints = new ArrayList<>(); + private final List scanPoints = new ArrayList<>(); public final Set otherColliders = new HashSet<>(); public void preTick() { @@ -1559,17 +1478,17 @@ public void preTick() { this.currAngularZ = AUtils.shift(this.currAngularZ, 9, this.angularZTarget); } - public void tick(World world, AutomobileEntity entity, Vec3d centerPos, double yaw, double stepHeight) { + public void tick(Level world, AutomobileEntity entity, Vec3 centerPos, double yaw, double stepHeight) { yaw = 360 - yaw; - Vec3d lowestDisplacementPos = null; - Vec3d highestDisplacementPos = null; - var scannedPoints = new ArrayList(); + Vec3 lowestDisplacementPos = null; + Vec3 highestDisplacementPos = null; + var scannedPoints = new ArrayList(); var colliders = new HashSet(); boolean anyOnGround = false; boolean allOnGround = true; for (var scanPoint : scanPoints) { scanPoint = scanPoint - .rotateY((float) Math.toRadians(yaw)); + .yRot((float) Math.toRadians(yaw)); var pointPos = scanPoint.add(centerPos); colliders.clear(); colliders.addAll(this.otherColliders); @@ -1577,7 +1496,7 @@ public void tick(World world, AutomobileEntity entity, Vec3d centerPos, double y double scanDist = scanPoint.length(); int heightOffset = (int) Math.ceil(scanDist); - var iter = new CuboidBlockIterator( + var iter = new Cursor3D( (int) Math.min(Math.floor(centerPos.x), Math.floor(pointPos.x)), (int) Math.floor(centerPos.y) - heightOffset, (int) Math.min(Math.floor(centerPos.z), Math.floor(pointPos.z)), @@ -1586,21 +1505,21 @@ public void tick(World world, AutomobileEntity entity, Vec3d centerPos, double y (int) Math.max(Math.floor(centerPos.z), Math.floor(pointPos.z)) ); - var mpos = new BlockPos.Mutable(); - while (iter.step()) { - mpos.set(iter.getX(), iter.getY(), iter.getZ()); + var mpos = new BlockPos.MutableBlockPos(); + while (iter.advance()) { + mpos.set(iter.nextX(), iter.nextY(), iter.nextZ()); var shape = world.getBlockState(mpos).getCollisionShape(world, mpos); if (!shape.isEmpty()) { - if (shape == VoxelShapes.fullCube()) { + if (shape == Shapes.block()) { colliders.add(CollisionArea.box(mpos.getX(), mpos.getY() - (INV_SCAN_STEPS * 2), mpos.getZ(), mpos.getX() + 1, mpos.getY() + 1, mpos.getZ() + 1)); } else { - shape.offset(mpos.getX(), mpos.getY(), mpos.getZ()).forEachBox(((minX, minY, minZ, maxX, maxY, maxZ) -> + shape.move(mpos.getX(), mpos.getY(), mpos.getZ()).forAllBoxes(((minX, minY, minZ, maxX, maxY, maxZ) -> colliders.add(CollisionArea.box(minX, minY - (INV_SCAN_STEPS * 2), minZ, maxX, maxY, maxZ)))); } } } - var pointDir = new Vec3d(scanPoint.x, 0, scanPoint.z).normalize().multiply(INV_SCAN_STEPS); + var pointDir = new Vec3(scanPoint.x, 0, scanPoint.z).normalize().scale(INV_SCAN_STEPS); double pointY = centerPos.y; for (int i = 0; i < Math.ceil(scanDist * SCAN_STEPS_PER_BLOCK); i++) { @@ -1626,7 +1545,7 @@ public void tick(World world, AutomobileEntity entity, Vec3d centerPos, double y } } - pointPos = new Vec3d(pointPos.x, pointY, pointPos.z); + pointPos = new Vec3(pointPos.x, pointY, pointPos.z); if (lowestDisplacementPos == null || pointPos.y < lowestDisplacementPos.y) { lowestDisplacementPos = pointPos; @@ -1652,45 +1571,45 @@ public void tick(World world, AutomobileEntity entity, Vec3d centerPos, double y verticalTarget = 0; if (lowestDisplacementPos != null) { - var displacementCenterPos = new Vec3d(centerPos.x, (lowestDisplacementPos.y + highestDisplacementPos.y) * 0.5, centerPos.z); + var displacementCenterPos = new Vec3(centerPos.x, (lowestDisplacementPos.y + highestDisplacementPos.y) * 0.5, centerPos.z); - var combinedNormals = Vec3d.ZERO; + var combinedNormals = Vec3.ZERO; int normalCount = 0; - Vec3d positiveXOffset = null; - Vec3d negativeXOffset = null; - Vec3d positiveZOffset = null; - Vec3d negativeZOffset = null; + Vec3 positiveXOffset = null; + Vec3 negativeXOffset = null; + Vec3 positiveZOffset = null; + Vec3 negativeZOffset = null; for (var pointPos : scannedPoints) { var pointOffset = pointPos.subtract(displacementCenterPos); if (pointOffset.x > 0) { if (positiveXOffset != null) { - var normal = positiveXOffset.crossProduct(pointOffset).normalize(); - if (normal.y < 0) normal = normal.negate(); + var normal = positiveXOffset.cross(pointOffset).normalize(); + if (normal.y < 0) normal = normal.reverse(); combinedNormals = combinedNormals.add(normal); normalCount++; positiveXOffset = null; } else positiveXOffset = pointOffset; } else if (pointOffset.x < 0) { if (negativeXOffset != null) { - var normal = negativeXOffset.crossProduct(pointOffset).normalize(); - if (normal.y < 0) normal = normal.negate(); + var normal = negativeXOffset.cross(pointOffset).normalize(); + if (normal.y < 0) normal = normal.reverse(); combinedNormals = combinedNormals.add(normal); normalCount++; negativeXOffset = null; } else negativeXOffset = pointOffset; } else if (pointOffset.z > 0) { if (positiveZOffset != null) { - var normal = positiveZOffset.crossProduct(pointOffset).normalize(); - if (normal.y < 0) normal = normal.negate(); + var normal = positiveZOffset.cross(pointOffset).normalize(); + if (normal.y < 0) normal = normal.reverse(); combinedNormals = combinedNormals.add(normal); normalCount++; positiveZOffset = null; } else positiveZOffset = pointOffset; } else if (pointOffset.z < 0) { if (negativeZOffset != null) { - var normal = negativeZOffset.crossProduct(pointOffset).normalize(); - if (normal.y < 0) normal = normal.negate(); + var normal = negativeZOffset.cross(pointOffset).normalize(); + if (normal.y < 0) normal = normal.reverse(); combinedNormals = combinedNormals.add(normal); normalCount++; negativeZOffset = null; @@ -1698,10 +1617,10 @@ public void tick(World world, AutomobileEntity entity, Vec3d centerPos, double y } } - combinedNormals = normalCount > 0 ? combinedNormals.multiply(1f / normalCount) : new Vec3d(0, 1, 0); + combinedNormals = normalCount > 0 ? combinedNormals.scale(1f / normalCount) : new Vec3(0, 1, 0); - angularXTarget = MathHelper.wrapDegrees(90f - (float) Math.toDegrees(Math.atan2(combinedNormals.y, combinedNormals.z))); - angularZTarget = MathHelper.wrapDegrees(270f + (float) Math.toDegrees(Math.atan2(combinedNormals.y, combinedNormals.x))); + angularXTarget = Mth.wrapDegrees(90f - (float) Math.toDegrees(Math.atan2(combinedNormals.y, combinedNormals.z))); + angularZTarget = Mth.wrapDegrees(270f + (float) Math.toDegrees(Math.atan2(combinedNormals.y, combinedNormals.x))); verticalTarget = (float) displacementCenterPos.subtract(centerPos).y; } @@ -1710,20 +1629,20 @@ public void tick(World world, AutomobileEntity entity, Vec3d centerPos, double y public void applyWheelbase(WheelBase wheelBase) { this.scanPoints.clear(); for (WheelBase.WheelPos pos : wheelBase.wheels) { - this.scanPoints.add(new Vec3d(pos.right() / 16, 0, pos.forward() / 16)); + this.scanPoints.add(new Vec3(pos.right() / 16, 0, pos.forward() / 16)); } } public float getVertical(float tickDelta) { - return MathHelper.lerp(tickDelta, lastVertical, verticalTarget); + return Mth.lerp(tickDelta, lastVertical, verticalTarget); } public float getAngularX(float tickDelta) { - return MathHelper.lerpAngleDegrees(tickDelta, lastAngularX, currAngularX); + return Mth.rotLerp(tickDelta, lastAngularX, currAngularX); } public float getAngularZ(float tickDelta) { - return MathHelper.lerpAngleDegrees(tickDelta, lastAngularZ, currAngularZ); + return Mth.rotLerp(tickDelta, lastAngularZ, currAngularZ); } } } 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 new file mode 100644 index 0000000..db4eb41 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/entity/AutomobilityEntities.java @@ -0,0 +1,26 @@ +package io.github.foundationgames.automobility.entity; + +import io.github.foundationgames.automobility.Automobility; +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.tags.TagKey; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.EntityDimensions; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.MobCategory; + +public enum AutomobilityEntities {; + public static final Eventual> AUTOMOBILE = RegistryQueue.register(Registry.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 DamageSource AUTOMOBILE_DAMAGE_SOURCE = new AutomobileDamageSource("automobile"); + + public static void init() { + } +} diff --git a/src/main/java/io/github/foundationgames/automobility/entity/EntityWithInventory.java b/common/src/main/java/io/github/foundationgames/automobility/entity/EntityWithInventory.java similarity index 57% rename from src/main/java/io/github/foundationgames/automobility/entity/EntityWithInventory.java rename to common/src/main/java/io/github/foundationgames/automobility/entity/EntityWithInventory.java index 691dbd8..243ad7c 100644 --- a/src/main/java/io/github/foundationgames/automobility/entity/EntityWithInventory.java +++ b/common/src/main/java/io/github/foundationgames/automobility/entity/EntityWithInventory.java @@ -1,9 +1,9 @@ package io.github.foundationgames.automobility.entity; -import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.world.entity.player.Player; public interface EntityWithInventory { boolean hasInventory(); - void openInventory(PlayerEntity player); + void openInventory(Player player); } 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 new file mode 100644 index 0000000..0abb6a7 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/entity/render/AutomobileEntityRenderer.java @@ -0,0 +1,36 @@ +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 net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.entity.EntityRenderer; +import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.client.renderer.texture.OverlayTexture; +import net.minecraft.resources.ResourceLocation; + +public class AutomobileEntityRenderer extends EntityRenderer { + public AutomobileEntityRenderer(EntityRendererProvider.Context ctx) { + super(ctx); + } + + @Override + public ResourceLocation getTextureLocation(AutomobileEntity entity) { + return null; + } + + @Override + public void render(AutomobileEntity entity, float yaw, float tickDelta, PoseStack pose, MultiBufferSource buffers, int light) { + pose.pushPose(); + float angX = entity.getDisplacement().getAngularX(tickDelta); + float angZ = entity.getDisplacement().getAngularZ(tickDelta); + float offsetY = entity.getDisplacement().getVertical(tickDelta); + + pose.translate(0, offsetY, 0); + pose.mulPose(Quaternion.fromXYZ((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 new file mode 100644 index 0000000..2eb2ca9 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileComponentItem.java @@ -0,0 +1,78 @@ +package io.github.foundationgames.automobility.item; + +import io.github.foundationgames.automobility.automobile.AutomobileComponent; +import io.github.foundationgames.automobility.util.SimpleMapContentRegistry; +import net.minecraft.ChatFormatting; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.level.Level; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class AutomobileComponentItem> extends Item { + protected final String nbtKey; + protected final String translationKey; + protected final SimpleMapContentRegistry registry; + + public AutomobileComponentItem(Properties settings, String nbtKey, String translationKey, SimpleMapContentRegistry registry) { + super(settings); + this.nbtKey = nbtKey; + this.translationKey = translationKey; + this.registry = registry; + } + + public ItemStack createStack(T component) { + if (component.isEmpty()) { + return ItemStack.EMPTY; + } + + var stack = new ItemStack(this); + this.setComponent(stack, component.getId()); + return stack; + } + + public void setComponent(ItemStack stack, ResourceLocation component) { + stack.getOrCreateTag().putString(this.nbtKey, component.toString()); + } + + public T getComponent(ItemStack stack) { + if (stack.hasTag() && stack.getTag().contains(this.nbtKey)) { + return this.registry.getOrDefault(ResourceLocation.tryParse(stack.getTag().getString(this.nbtKey))); + } + return this.registry.getOrDefault(null); + } + + @Override + public void appendHoverText(ItemStack stack, @Nullable Level world, List tooltip, TooltipFlag context) { + super.appendHoverText(stack, world, tooltip, context); + var component = this.getComponent(stack); + var id = component.getId(); + var compKey = id.getNamespace()+"."+id.getPath(); + tooltip.add(Component.translatable(this.translationKey+"."+compKey).withStyle(ChatFormatting.BLUE)); + + component.appendTexts(tooltip, component); + } + + @Override + public void fillItemCategory(CreativeModeTab group, NonNullList stacks) { + if (this.allowedIn(group)) { + this.registry.forEach(component -> { + if (addToCreative(component)) stacks.add(this.createStack(component)); + }); + } + } + + public boolean isVisible(T component) { + return !component.isEmpty(); + } + + protected boolean addToCreative(T component) { + return !component.isEmpty(); + } +} diff --git a/src/main/java/io/github/foundationgames/automobility/item/AutomobileEngineItem.java b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileEngineItem.java similarity index 84% rename from src/main/java/io/github/foundationgames/automobility/item/AutomobileEngineItem.java rename to common/src/main/java/io/github/foundationgames/automobility/item/AutomobileEngineItem.java index d664541..8f508f0 100644 --- a/src/main/java/io/github/foundationgames/automobility/item/AutomobileEngineItem.java +++ b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileEngineItem.java @@ -3,7 +3,7 @@ import io.github.foundationgames.automobility.automobile.AutomobileEngine; public class AutomobileEngineItem extends AutomobileComponentItem { - public AutomobileEngineItem(Settings settings) { + public AutomobileEngineItem(Properties settings) { super(settings, "engine", "engine", AutomobileEngine.REGISTRY); } } diff --git a/src/main/java/io/github/foundationgames/automobility/item/AutomobileFrameItem.java b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileFrameItem.java similarity index 89% rename from src/main/java/io/github/foundationgames/automobility/item/AutomobileFrameItem.java rename to common/src/main/java/io/github/foundationgames/automobility/item/AutomobileFrameItem.java index b58ddd1..e834397 100644 --- a/src/main/java/io/github/foundationgames/automobility/item/AutomobileFrameItem.java +++ b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileFrameItem.java @@ -3,7 +3,7 @@ import io.github.foundationgames.automobility.automobile.AutomobileFrame; public class AutomobileFrameItem extends AutomobileComponentItem { - public AutomobileFrameItem(Settings settings) { + public AutomobileFrameItem(Properties settings) { super(settings, "frame", "frame", AutomobileFrame.REGISTRY); } diff --git a/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileInteractable.java b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileInteractable.java new file mode 100644 index 0000000..db85876 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileInteractable.java @@ -0,0 +1,11 @@ +package io.github.foundationgames.automobility.item; + +import io.github.foundationgames.automobility.entity.AutomobileEntity; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; + +public interface AutomobileInteractable { + InteractionResult interactAutomobile(ItemStack stack, Player player, InteractionHand hand, AutomobileEntity automobile); +} 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 new file mode 100644 index 0000000..6e755cf --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileItem.java @@ -0,0 +1,88 @@ +package io.github.foundationgames.automobility.item; + +import io.github.foundationgames.automobility.automobile.AutomobileData; +import io.github.foundationgames.automobility.automobile.AutomobilePrefab; +import io.github.foundationgames.automobility.automobile.AutomobileStats; +import io.github.foundationgames.automobility.entity.AutomobileEntity; +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; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.level.Level; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class AutomobileItem extends Item { + public static final List PREFABS = new ArrayList<>(); + private static final AutomobileData data = new AutomobileData(); + private static final AutomobileStats stats = new AutomobileStats(); + + public AutomobileItem(Properties settings) { + super(settings); + } + + @Override + public InteractionResult useOn(UseOnContext context) { + if (!context.getLevel().isClientSide()) { + var stack = context.getItemInHand(); + data.read(stack.getOrCreateTagElement("Automobile")); + var e = new AutomobileEntity(AutomobilityEntities.AUTOMOBILE.require(), context.getLevel()); + var pos = context.getClickLocation(); + e.moveTo(pos.x, pos.y, pos.z, context.getHorizontalDirection().toYRot(), 0); + e.setComponents(data.getFrame(), data.getWheel(), data.getEngine()); + context.getLevel().addFreshEntity(e); + stack.shrink(1); + return InteractionResult.PASS; + } + return InteractionResult.SUCCESS; + } + + @Override + public void appendHoverText(ItemStack stack, @Nullable Level world, List tooltip, TooltipFlag context) { + super.appendHoverText(stack, world, tooltip, context); + data.read(stack.getOrCreateTagElement("Automobile")); + if (Screen.hasShiftDown()) { + stats.from(data.getFrame(), data.getWheel(), data.getEngine()); + stats.appendTexts(tooltip, stats); + } else { + if (!data.isPrefab()) { + tooltip.add( + Component.translatable("tooltip.automobility.frameLabel").withStyle(ChatFormatting.BLUE) + .append(Component.translatable(data.getFrame().getTranslationKey()).withStyle(ChatFormatting.DARK_GREEN)) + ); + tooltip.add( + Component.translatable("tooltip.automobility.wheelLabel").withStyle(ChatFormatting.BLUE) + .append(Component.translatable(data.getWheel().getTranslationKey()).withStyle(ChatFormatting.DARK_GREEN)) + ); + tooltip.add( + Component.translatable("tooltip.automobility.engineLabel").withStyle(ChatFormatting.BLUE) + .append(Component.translatable(data.getEngine().getTranslationKey()).withStyle(ChatFormatting.DARK_GREEN)) + ); + } + tooltip.add(Component.translatable("tooltip.automobility.shiftForStats").withStyle(ChatFormatting.GOLD)); + } + } + + public static void addPrefabs(AutomobilePrefab ... prefabs) { + PREFABS.addAll(Arrays.asList(prefabs)); + } + + @Override + public void fillItemCategory(CreativeModeTab group, NonNullList stacks) { + if (allowedIn(group) || group == CreativeModeTab.TAB_TRANSPORTATION) { + for (var prefab : PREFABS) { + stacks.add(prefab.toStack()); + } + } + } +} diff --git a/src/main/java/io/github/foundationgames/automobility/item/AutomobileWheelItem.java b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileWheelItem.java similarity index 89% rename from src/main/java/io/github/foundationgames/automobility/item/AutomobileWheelItem.java rename to common/src/main/java/io/github/foundationgames/automobility/item/AutomobileWheelItem.java index b2c2983..8ae99bc 100644 --- a/src/main/java/io/github/foundationgames/automobility/item/AutomobileWheelItem.java +++ b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileWheelItem.java @@ -3,7 +3,7 @@ import io.github.foundationgames.automobility.automobile.AutomobileWheel; public class AutomobileWheelItem extends AutomobileComponentItem { - public AutomobileWheelItem(Settings settings) { + public AutomobileWheelItem(Properties settings) { super(settings, "wheel", "wheel", AutomobileWheel.REGISTRY); } 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 new file mode 100644 index 0000000..f45545f --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobilityItems.java @@ -0,0 +1,66 @@ +package io.github.foundationgames.automobility.item; + +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.util.Eventual; +import io.github.foundationgames.automobility.util.RegistryQueue; +import net.minecraft.ChatFormatting; +import net.minecraft.core.Registry; +import net.minecraft.network.chat.Component; +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 void init() { + AutomobileItem.addPrefabs( + new AutomobilePrefab(Automobility.rl("wooden_motorcar"), AutomobileFrame.WOODEN_MOTORCAR, AutomobileWheel.CARRIAGE, AutomobileEngine.STONE), + new AutomobilePrefab(Automobility.rl("copper_motorcar"), AutomobileFrame.COPPER_MOTORCAR, AutomobileWheel.PLATED, AutomobileEngine.COPPER), + new AutomobilePrefab(Automobility.rl("steel_motorcar"), AutomobileFrame.STEEL_MOTORCAR, AutomobileWheel.STREET, AutomobileEngine.IRON), + new AutomobilePrefab(Automobility.rl("golden_motorcar"), AutomobileFrame.GOLDEN_MOTORCAR, AutomobileWheel.GILDED, AutomobileEngine.GOLD), + new AutomobilePrefab(Automobility.rl("bejeweled_motorcar"), AutomobileFrame.BEJEWELED_MOTORCAR, AutomobileWheel.BEJEWELED, AutomobileEngine.DIAMOND), + new AutomobilePrefab(Automobility.rl("standard_white"), AutomobileFrame.STANDARD_WHITE, AutomobileWheel.STANDARD, AutomobileEngine.IRON), + new AutomobilePrefab(Automobility.rl("standard_orange"), AutomobileFrame.STANDARD_ORANGE, AutomobileWheel.STANDARD, AutomobileEngine.IRON), + new AutomobilePrefab(Automobility.rl("standard_magenta"), AutomobileFrame.STANDARD_MAGENTA, AutomobileWheel.STANDARD, AutomobileEngine.IRON), + new AutomobilePrefab(Automobility.rl("standard_light_blue"), AutomobileFrame.STANDARD_LIGHT_BLUE, AutomobileWheel.STANDARD, AutomobileEngine.IRON), + new AutomobilePrefab(Automobility.rl("standard_yellow"), AutomobileFrame.STANDARD_YELLOW, AutomobileWheel.STANDARD, AutomobileEngine.IRON), + new AutomobilePrefab(Automobility.rl("standard_lime"), AutomobileFrame.STANDARD_LIME, AutomobileWheel.STANDARD, AutomobileEngine.IRON), + new AutomobilePrefab(Automobility.rl("standard_pink"), AutomobileFrame.STANDARD_PINK, AutomobileWheel.STANDARD, AutomobileEngine.IRON), + new AutomobilePrefab(Automobility.rl("standard_gray"), AutomobileFrame.STANDARD_GRAY, AutomobileWheel.STANDARD, AutomobileEngine.IRON), + new AutomobilePrefab(Automobility.rl("standard_light_gray"), AutomobileFrame.STANDARD_LIGHT_GRAY, AutomobileWheel.STANDARD, AutomobileEngine.IRON), + new AutomobilePrefab(Automobility.rl("standard_cyan"), AutomobileFrame.STANDARD_CYAN, AutomobileWheel.STANDARD, AutomobileEngine.IRON), + new AutomobilePrefab(Automobility.rl("standard_purple"), AutomobileFrame.STANDARD_PURPLE, AutomobileWheel.STANDARD, AutomobileEngine.IRON), + new AutomobilePrefab(Automobility.rl("standard_blue"), AutomobileFrame.STANDARD_BLUE, AutomobileWheel.STANDARD, AutomobileEngine.IRON), + new AutomobilePrefab(Automobility.rl("standard_brown"), AutomobileFrame.STANDARD_BROWN, AutomobileWheel.STANDARD, AutomobileEngine.IRON), + new AutomobilePrefab(Automobility.rl("standard_green"), AutomobileFrame.STANDARD_GREEN, AutomobileWheel.STANDARD, AutomobileEngine.IRON), + new AutomobilePrefab(Automobility.rl("standard_red"), AutomobileFrame.STANDARD_RED, AutomobileWheel.STANDARD, AutomobileEngine.IRON), + new AutomobilePrefab(Automobility.rl("standard_black"), AutomobileFrame.STANDARD_BLACK, AutomobileWheel.STANDARD, AutomobileEngine.IRON), + new AutomobilePrefab(Automobility.rl("amethyst_rickshaw"), AutomobileFrame.AMETHYST_RICKSHAW, AutomobileWheel.BEJEWELED, AutomobileEngine.STONE), + new AutomobilePrefab(Automobility.rl("quartz_rickshaw"), AutomobileFrame.QUARTZ_RICKSHAW, AutomobileWheel.GILDED, AutomobileEngine.GOLD), + new AutomobilePrefab(Automobility.rl("prismarine_rickshaw"), AutomobileFrame.PRISMARINE_RICKSHAW, AutomobileWheel.PLATED, AutomobileEngine.COPPER), + new AutomobilePrefab(Automobility.rl("echo_rickshaw"), AutomobileFrame.ECHO_RICKSHAW, AutomobileWheel.STREET, AutomobileEngine.DIAMOND), + new AutomobilePrefab(Automobility.rl("red_tractor"), AutomobileFrame.RED_TRACTOR, AutomobileWheel.TRACTOR, AutomobileEngine.COPPER), + new AutomobilePrefab(Automobility.rl("yellow_tractor"), AutomobileFrame.YELLOW_TRACTOR, AutomobileWheel.TRACTOR, AutomobileEngine.COPPER), + new AutomobilePrefab(Automobility.rl("green_tractor"), AutomobileFrame.GREEN_TRACTOR, AutomobileWheel.TRACTOR, AutomobileEngine.COPPER), + new AutomobilePrefab(Automobility.rl("blue_tractor"), AutomobileFrame.BLUE_TRACTOR, AutomobileWheel.TRACTOR, AutomobileEngine.COPPER), + new AutomobilePrefab(Automobility.rl("shopping_cart"), AutomobileFrame.SHOPPING_CART, AutomobileWheel.STEEL, AutomobileEngine.STONE), + new AutomobilePrefab(Automobility.rl("c_arr"), AutomobileFrame.C_ARR, AutomobileWheel.OFF_ROAD, AutomobileEngine.DIAMOND), + new AutomobilePrefab(Automobility.rl("pineapple"), AutomobileFrame.PINEAPPLE, AutomobileWheel.TRACTOR, AutomobileEngine.GOLD) + ); + } + + public static Eventual register(String name, Supplier item) { + return RegistryQueue.register(Registry.ITEM, Automobility.rl(name), item); + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/item/DashPanelItem.java b/common/src/main/java/io/github/foundationgames/automobility/item/DashPanelItem.java new file mode 100644 index 0000000..13a83cd --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/item/DashPanelItem.java @@ -0,0 +1,64 @@ +package io.github.foundationgames.automobility.item; + +import io.github.foundationgames.automobility.block.AutomobilityBlocks; +import io.github.foundationgames.automobility.block.SlopeBlock; +import io.github.foundationgames.automobility.block.SteepSlopeBlock; +import net.minecraft.ChatFormatting; +import net.minecraft.core.BlockPos; +import net.minecraft.network.chat.Component; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import org.jetbrains.annotations.Nullable; + +public class DashPanelItem extends TooltipBlockItem { + private static final Component TOOLTIP = Component.translatable("tooltip.block.automobility.dash_panel") + .withStyle(ChatFormatting.BLUE); + + public DashPanelItem(Block block, Properties settings) { + super(block, TOOLTIP, settings); + } + + @Override + public InteractionResult useOn(UseOnContext ctx) { + var lvl = ctx.getLevel(); + var pos = ctx.getClickedPos(); + var state = lvl.getBlockState(pos); + + if (state.is(AutomobilityBlocks.SLOPE.require())) { + if (!lvl.isClientSide()) { + ctx.getLevel().setBlockAndUpdate(pos, AutomobilityBlocks.SLOPE_WITH_DASH_PANEL.require() + .withPropertiesOf(state)); + } + afterPlace(ctx.getItemInHand(), lvl, ctx.getPlayer(), pos); + + return InteractionResult.SUCCESS; + } + if (state.is(AutomobilityBlocks.STEEP_SLOPE.require())) { + if (!lvl.isClientSide()) { + ctx.getLevel().setBlockAndUpdate(pos, AutomobilityBlocks.STEEP_SLOPE_WITH_DASH_PANEL.require() + .withPropertiesOf(state)); + } + afterPlace(ctx.getItemInHand(), lvl, ctx.getPlayer(), pos); + + return InteractionResult.SUCCESS; + } + + return super.useOn(ctx); + } + + private void afterPlace(ItemStack stack, Level level, @Nullable Player player, BlockPos pos) { + if (!level.isClientSide()) { + level.playSound(null, pos, SoundEvents.METAL_PLACE, SoundSource.BLOCKS, 1, 1.25f); + + if (player == null || !player.isCreative()) { + stack.shrink(1); + } + } + } +} diff --git a/src/main/java/io/github/foundationgames/automobility/item/FrontAttachmentItem.java b/common/src/main/java/io/github/foundationgames/automobility/item/FrontAttachmentItem.java similarity index 57% rename from src/main/java/io/github/foundationgames/automobility/item/FrontAttachmentItem.java rename to common/src/main/java/io/github/foundationgames/automobility/item/FrontAttachmentItem.java index 37fc1e0..3a4682a 100644 --- a/src/main/java/io/github/foundationgames/automobility/item/FrontAttachmentItem.java +++ b/common/src/main/java/io/github/foundationgames/automobility/item/FrontAttachmentItem.java @@ -2,30 +2,30 @@ import io.github.foundationgames.automobility.automobile.attachment.FrontAttachmentType; import io.github.foundationgames.automobility.entity.AutomobileEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; public class FrontAttachmentItem extends AutomobileComponentItem> implements AutomobileInteractable { - public FrontAttachmentItem(Settings settings) { + public FrontAttachmentItem(Properties settings) { super(settings, "attachment", "attachment.front", FrontAttachmentType.REGISTRY); } @Override - public ActionResult interactAutomobile(ItemStack stack, PlayerEntity player, Hand hand, AutomobileEntity automobile) { + public InteractionResult interactAutomobile(ItemStack stack, Player player, InteractionHand hand, AutomobileEntity automobile) { if (automobile.getFrontAttachment().type.isEmpty()) { - if (player.world.isClient()) { - return ActionResult.SUCCESS; + if (player.level.isClientSide()) { + return InteractionResult.SUCCESS; } automobile.setFrontAttachment(getComponent(stack)); automobile.playHitSound(automobile.getHeadPos()); if (!player.isCreative()) { - stack.decrement(1); + stack.shrink(1); } } - return ActionResult.PASS; + return InteractionResult.PASS; } } \ No newline at end of file diff --git a/src/main/java/io/github/foundationgames/automobility/item/RearAttachmentItem.java b/common/src/main/java/io/github/foundationgames/automobility/item/RearAttachmentItem.java similarity index 57% rename from src/main/java/io/github/foundationgames/automobility/item/RearAttachmentItem.java rename to common/src/main/java/io/github/foundationgames/automobility/item/RearAttachmentItem.java index a11cdbc..6a44cfd 100644 --- a/src/main/java/io/github/foundationgames/automobility/item/RearAttachmentItem.java +++ b/common/src/main/java/io/github/foundationgames/automobility/item/RearAttachmentItem.java @@ -2,30 +2,30 @@ import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType; import io.github.foundationgames.automobility.entity.AutomobileEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; public class RearAttachmentItem extends AutomobileComponentItem> implements AutomobileInteractable { - public RearAttachmentItem(Settings settings) { + public RearAttachmentItem(Properties settings) { super(settings, "attachment", "attachment.rear", RearAttachmentType.REGISTRY); } @Override - public ActionResult interactAutomobile(ItemStack stack, PlayerEntity player, Hand hand, AutomobileEntity automobile) { + public InteractionResult interactAutomobile(ItemStack stack, Player player, InteractionHand hand, AutomobileEntity automobile) { if (automobile.getRearAttachment().type.isEmpty()) { - if (player.world.isClient()) { - return ActionResult.SUCCESS; + if (player.level.isClientSide()) { + return InteractionResult.SUCCESS; } automobile.setRearAttachment(getComponent(stack)); automobile.playHitSound(automobile.getTailPos()); if (!player.isCreative()) { - stack.decrement(1); + stack.shrink(1); } } - return ActionResult.PASS; + return InteractionResult.PASS; } } 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 new file mode 100644 index 0000000..2c1aafe --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/item/SlopeBlockItem.java @@ -0,0 +1,41 @@ +package io.github.foundationgames.automobility.item; + +import io.github.foundationgames.automobility.block.SlopeBlock; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.Half; +import org.jetbrains.annotations.Nullable; + +public class SlopeBlockItem extends BlockItem { + public SlopeBlockItem(Block block, Properties settings) { + super(block, settings); + } + + @Nullable + @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 world = context.getLevel(); + if (world.getBlockState(pos).getBlock() instanceof SlopeBlock) { + var facing = world.getBlockState(pos).getValue(BlockStateProperties.HORIZONTAL_FACING); + var half = world.getBlockState(pos).getValue(BlockStateProperties.HALF); + var playerFacing = context.getHorizontalDirection(); + var vOffset = playerFacing == facing && half == Half.BOTTOM ? Direction.DOWN : playerFacing == facing.getOpposite() && half == Half.TOP ? Direction.UP : null; + var place = pos.relative(playerFacing); + if (vOffset != null) place = place.relative(vOffset); + var pState = world.getBlockState(place); + var nHalf = half; + if (playerFacing == facing || playerFacing == facing.getOpposite()) nHalf = half == Half.TOP ? Half.BOTTOM : Half.TOP; + if (pState.isAir() || pState.is(Blocks.WATER)) { + return new SlopePlacementContext(BlockPlaceContext.at(context, place, Direction.UP), facing, nHalf); + } + } + return super.updatePlacementContext(context); + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/item/SlopePlacementContext.java b/common/src/main/java/io/github/foundationgames/automobility/item/SlopePlacementContext.java new file mode 100644 index 0000000..07380fd --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/item/SlopePlacementContext.java @@ -0,0 +1,29 @@ +package io.github.foundationgames.automobility.item; + +import net.minecraft.core.Direction; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.level.block.state.properties.Half; + +public class SlopePlacementContext extends BlockPlaceContext { + private final Direction slopeFacing; + private final Half slopeHalf; + + public SlopePlacementContext(UseOnContext context, Direction slopeFacing, Half slopeHalf) { + super(context); + this.slopeFacing = slopeFacing; + this.slopeHalf = slopeHalf; + } + + public SlopePlacementContext(UseOnContext context, Direction slopeFacing) { + this(context, slopeFacing, Half.BOTTOM); + } + + public Direction getSlopeFacing() { + return slopeFacing; + } + + public Half getSlopeHalf() { + return slopeHalf; + } +} 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 new file mode 100644 index 0000000..e6083b6 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/item/SteepSlopeBlockItem.java @@ -0,0 +1,37 @@ +package io.github.foundationgames.automobility.item; + +import io.github.foundationgames.automobility.block.SteepSlopeBlock; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import org.jetbrains.annotations.Nullable; + +public class SteepSlopeBlockItem extends BlockItem { + public SteepSlopeBlockItem(Block block, Properties settings) { + super(block, settings); + } + + @Nullable + @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 world = context.getLevel(); + if (world.getBlockState(pos).getBlock() instanceof SteepSlopeBlock) { + var facing = world.getBlockState(pos).getValue(BlockStateProperties.HORIZONTAL_FACING); + var playerFacing = context.getHorizontalDirection(); + var vOffset = playerFacing == facing ? Direction.DOWN : playerFacing == facing.getOpposite() ? Direction.UP : null; + var place = pos.relative(playerFacing); + if (vOffset != null) place = place.relative(vOffset); + var pState = world.getBlockState(place); + if (pState.isAir() || pState.is(Blocks.WATER)) { + return new SlopePlacementContext(BlockPlaceContext.at(context, place, Direction.UP), facing); + } + } + return super.updatePlacementContext(context); + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/item/TooltipBlockItem.java b/common/src/main/java/io/github/foundationgames/automobility/item/TooltipBlockItem.java new file mode 100644 index 0000000..2b0c180 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/item/TooltipBlockItem.java @@ -0,0 +1,26 @@ +package io.github.foundationgames.automobility.item; + +import net.minecraft.network.chat.Component; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class TooltipBlockItem extends BlockItem { + private final Component tooltip; + + public TooltipBlockItem(Block block, Component tooltip, Properties settings) { + super(block, settings); + this.tooltip = tooltip; + } + + @Override + public void appendHoverText(ItemStack stack, @Nullable Level world, List tooltip, TooltipFlag context) { + super.appendHoverText(stack, world, tooltip, context); + tooltip.add(this.tooltip); + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/item/TooltipItem.java b/common/src/main/java/io/github/foundationgames/automobility/item/TooltipItem.java new file mode 100644 index 0000000..7eba5a5 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/item/TooltipItem.java @@ -0,0 +1,25 @@ +package io.github.foundationgames.automobility.item; + +import net.minecraft.network.chat.Component; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.level.Level; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class TooltipItem extends Item { + private final Component tooltip; + + public TooltipItem(Component tooltip, Properties settings) { + super(settings); + this.tooltip = tooltip; + } + + @Override + public void appendHoverText(ItemStack stack, @Nullable Level world, List tooltip, TooltipFlag context) { + super.appendHoverText(stack, world, tooltip, context); + tooltip.add(this.tooltip); + } +} diff --git a/src/main/java/io/github/foundationgames/automobility/mixin/BoxMixin.java b/common/src/main/java/io/github/foundationgames/automobility/mixin/AABBMixin.java similarity index 64% rename from src/main/java/io/github/foundationgames/automobility/mixin/BoxMixin.java rename to common/src/main/java/io/github/foundationgames/automobility/mixin/AABBMixin.java index 01220cc..b703e75 100644 --- a/src/main/java/io/github/foundationgames/automobility/mixin/BoxMixin.java +++ b/common/src/main/java/io/github/foundationgames/automobility/mixin/AABBMixin.java @@ -1,26 +1,26 @@ package io.github.foundationgames.automobility.mixin; import io.github.foundationgames.automobility.util.duck.CollisionArea; -import net.minecraft.util.math.Box; +import net.minecraft.world.phys.AABB; import org.spongepowered.asm.mixin.Mixin; -@Mixin(Box.class) -public class BoxMixin implements CollisionArea { +@Mixin(AABB.class) +public class AABBMixin implements CollisionArea { @Override public boolean isPointInside(double x, double y, double z) { - var self = (Box)(Object)this; + var self = (AABB)(Object)this; return (x >= self.minX && x <= self.maxX) && (y >= self.minY && y <= self.maxY) && (z >= self.minZ && z <= self.maxZ); } @Override - public boolean boxIntersects(Box box) { - return ((Box)(Object)this).intersects(box); + public boolean boxIntersects(AABB box) { + return ((AABB)(Object)this).intersects(box); } @Override public double highestY(double x, double y, double z) { - return ((Box)(Object)this).maxY; + return ((AABB)(Object)this).maxY; } } diff --git a/common/src/main/java/io/github/foundationgames/automobility/mixin/AbstractContainerMenuMixin.java b/common/src/main/java/io/github/foundationgames/automobility/mixin/AbstractContainerMenuMixin.java new file mode 100644 index 0000000..3bc36a7 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/mixin/AbstractContainerMenuMixin.java @@ -0,0 +1,26 @@ +package io.github.foundationgames.automobility.mixin; + +import io.github.foundationgames.automobility.screen.AutomobileContainerLevelAccess; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.level.block.Block; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(AbstractContainerMenu.class) +public class AbstractContainerMenuMixin { + @Inject( + method = "stillValid(Lnet/minecraft/world/inventory/ContainerLevelAccess;Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/level/block/Block;)Z", + at = @At("HEAD"), cancellable = true) + private static void automobility$spoofAutomobileAttachmentScreens(ContainerLevelAccess context, Player player, Block block, CallbackInfoReturnable cir) { + if (context instanceof AutomobileContainerLevelAccess ctx) { + boolean isClose = ctx.evaluate((world, pos) -> (player.blockPosition().distSqr(pos) < 64), true); + if (isClose && ctx.getAttachmentBlockState().is(block)) { + cir.setReturnValue(true); + } + } + } +} diff --git a/src/main/java/io/github/foundationgames/automobility/mixin/EntityMixin.java b/common/src/main/java/io/github/foundationgames/automobility/mixin/EntityMixin.java similarity index 62% rename from src/main/java/io/github/foundationgames/automobility/mixin/EntityMixin.java rename to common/src/main/java/io/github/foundationgames/automobility/mixin/EntityMixin.java index 1f75acd..3f18862 100644 --- a/src/main/java/io/github/foundationgames/automobility/mixin/EntityMixin.java +++ b/common/src/main/java/io/github/foundationgames/automobility/mixin/EntityMixin.java @@ -1,8 +1,8 @@ package io.github.foundationgames.automobility.mixin; import io.github.foundationgames.automobility.util.AUtils; -import net.minecraft.entity.Entity; -import net.minecraft.util.math.Vec3d; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -15,16 +15,16 @@ public class EntityMixin { @Shadow protected boolean onGround; - @Inject(method = "adjustMovementForCollisions(Lnet/minecraft/util/math/Vec3d;)Lnet/minecraft/util/math/Vec3d;", at = @At("HEAD")) - private void automobility$spoofGroundStart(Vec3d movement, CallbackInfoReturnable cir) { + @Inject(method = "collide", at = @At("HEAD")) + private void automobility$spoofGroundStart(Vec3 movement, CallbackInfoReturnable cir) { if (AUtils.IGNORE_ENTITY_GROUND_CHECK_STEPPING) { this.automobility$cacheOnGround = this.onGround; this.onGround = true; } } - @Inject(method = "adjustMovementForCollisions(Lnet/minecraft/util/math/Vec3d;)Lnet/minecraft/util/math/Vec3d;", at = @At("TAIL")) - private void automobility$spoofGroundEnd(Vec3d movement, CallbackInfoReturnable cir) { + @Inject(method = "collide", at = @At("TAIL")) + private void automobility$spoofGroundEnd(Vec3 movement, CallbackInfoReturnable cir) { if (AUtils.IGNORE_ENTITY_GROUND_CHECK_STEPPING) { this.onGround = this.automobility$cacheOnGround; AUtils.IGNORE_ENTITY_GROUND_CHECK_STEPPING = false; diff --git a/src/main/java/io/github/foundationgames/automobility/mixin/EntityRenderersMixin.java b/common/src/main/java/io/github/foundationgames/automobility/mixin/EntityRenderersMixin.java similarity index 57% rename from src/main/java/io/github/foundationgames/automobility/mixin/EntityRenderersMixin.java rename to common/src/main/java/io/github/foundationgames/automobility/mixin/EntityRenderersMixin.java index ef51a2e..56a6709 100644 --- a/src/main/java/io/github/foundationgames/automobility/mixin/EntityRenderersMixin.java +++ b/common/src/main/java/io/github/foundationgames/automobility/mixin/EntityRenderersMixin.java @@ -1,10 +1,10 @@ package io.github.foundationgames.automobility.mixin; import io.github.foundationgames.automobility.util.EntityRenderHelper; -import net.minecraft.client.render.entity.EntityRenderer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.EntityRenderers; -import net.minecraft.entity.EntityType; +import net.minecraft.client.renderer.entity.EntityRenderer; +import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.client.renderer.entity.EntityRenderers; +import net.minecraft.world.entity.EntityType; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -14,8 +14,8 @@ @Mixin(EntityRenderers.class) public class EntityRenderersMixin { - @Inject(method = "reloadEntityRenderers", at = @At("HEAD")) - private static void automobility$reloadContextListeners(EntityRendererFactory.Context ctx, CallbackInfoReturnable, EntityRenderer>> cir) { + @Inject(method = "createEntityRenderers", at = @At("HEAD")) + private static void automobility$reloadContextListeners(EntityRendererProvider.Context ctx, CallbackInfoReturnable, EntityRenderer>> cir) { EntityRenderHelper.reload(ctx); } } diff --git a/common/src/main/java/io/github/foundationgames/automobility/mixin/ItemCombinerMenuMixin.java b/common/src/main/java/io/github/foundationgames/automobility/mixin/ItemCombinerMenuMixin.java new file mode 100644 index 0000000..e219718 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/mixin/ItemCombinerMenuMixin.java @@ -0,0 +1,32 @@ +package io.github.foundationgames.automobility.mixin; + +import io.github.foundationgames.automobility.screen.AutomobileContainerLevelAccess; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.ItemCombinerMenu; +import net.minecraft.world.level.block.state.BlockState; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(ItemCombinerMenu.class) +public abstract class ItemCombinerMenuMixin { + @Shadow @Final protected ContainerLevelAccess access; + + @Shadow protected abstract boolean isValidBlock(BlockState state); + + @Inject( + method = "stillValid", + at = @At("HEAD"), cancellable = true) + private void automobility$allowSmithingMenuAutomobileSpoof(Player player, CallbackInfoReturnable cir) { + if (this.access instanceof AutomobileContainerLevelAccess access) { + boolean isClose = access.evaluate((world, pos) -> (player.blockPosition().distSqr(pos) < 64), true); + if (isClose && this.isValidBlock(access.getAttachmentBlockState())) { + cir.setReturnValue(true); + } + } + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/mixin/LocalPlayerMixin.java b/common/src/main/java/io/github/foundationgames/automobility/mixin/LocalPlayerMixin.java new file mode 100644 index 0000000..1789ae2 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/mixin/LocalPlayerMixin.java @@ -0,0 +1,41 @@ +package io.github.foundationgames.automobility.mixin; + +import io.github.foundationgames.automobility.entity.AutomobileEntity; +import io.github.foundationgames.automobility.platform.Platform; +import net.minecraft.client.player.Input; +import net.minecraft.client.player.LocalPlayer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(LocalPlayer.class) +public class LocalPlayerMixin { + @Shadow + public Input input; + + @Inject(method = "rideTick", at = @At("TAIL")) + public void automobility$setAutomobileInputs(CallbackInfo ci) { + LocalPlayer self = (LocalPlayer)(Object)this; + if (self.getVehicle() instanceof AutomobileEntity vehicle) { + if (Platform.get().inControllerMode()) { + vehicle.provideClientInput( + Platform.get().controllerAccel(), + Platform.get().controllerBrake(), + input.left, + input.right, + Platform.get().controllerDrift() + ); + } else { + vehicle.provideClientInput( + input.up, + input.down, + input.left, + input.right, + input.jumping + ); + } + } + } +} diff --git a/src/main/java/io/github/foundationgames/automobility/mixin/ClientPlayerInteractionManagerMixin.java b/common/src/main/java/io/github/foundationgames/automobility/mixin/MultiPlayerGameModeMixin.java similarity index 54% rename from src/main/java/io/github/foundationgames/automobility/mixin/ClientPlayerInteractionManagerMixin.java rename to common/src/main/java/io/github/foundationgames/automobility/mixin/MultiPlayerGameModeMixin.java index 3818030..897c032 100644 --- a/src/main/java/io/github/foundationgames/automobility/mixin/ClientPlayerInteractionManagerMixin.java +++ b/common/src/main/java/io/github/foundationgames/automobility/mixin/MultiPlayerGameModeMixin.java @@ -1,8 +1,8 @@ package io.github.foundationgames.automobility.mixin; import io.github.foundationgames.automobility.entity.EntityWithInventory; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.ClientPlayerInteractionManager; +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.MultiPlayerGameMode; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -10,13 +10,13 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(ClientPlayerInteractionManager.class) -public class ClientPlayerInteractionManagerMixin { - @Shadow @Final private MinecraftClient client; +@Mixin(MultiPlayerGameMode.class) +public class MultiPlayerGameModeMixin { + @Shadow @Final private Minecraft minecraft; - @Inject(method = "hasRidingInventory", at = @At("HEAD"), cancellable = true) + @Inject(method = "isServerControlledInventory", at = @At("HEAD"), cancellable = true) private void automobility$allowCustomRidingInventories(CallbackInfoReturnable cir) { - if (this.client.player != null && this.client.player.getVehicle() instanceof EntityWithInventory invEntity && invEntity.hasInventory()) { + if (this.minecraft.player != null && this.minecraft.player.getVehicle() instanceof EntityWithInventory invEntity && invEntity.hasInventory()) { cir.setReturnValue(true); } } diff --git a/src/main/java/io/github/foundationgames/automobility/mixin/EnderChestInventoryMixin.java b/common/src/main/java/io/github/foundationgames/automobility/mixin/PlayerEnderChestContainerMixin.java similarity index 66% rename from src/main/java/io/github/foundationgames/automobility/mixin/EnderChestInventoryMixin.java rename to common/src/main/java/io/github/foundationgames/automobility/mixin/PlayerEnderChestContainerMixin.java index 3681a79..bae9631 100644 --- a/src/main/java/io/github/foundationgames/automobility/mixin/EnderChestInventoryMixin.java +++ b/common/src/main/java/io/github/foundationgames/automobility/mixin/PlayerEnderChestContainerMixin.java @@ -1,9 +1,9 @@ package io.github.foundationgames.automobility.mixin; import io.github.foundationgames.automobility.automobile.attachment.rear.BaseChestRearAttachment; -import io.github.foundationgames.automobility.util.duck.EnderChestInventoryDuck; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.inventory.EnderChestInventory; +import io.github.foundationgames.automobility.util.duck.EnderChestContainerDuck; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.PlayerEnderChestContainer; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -11,8 +11,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(EnderChestInventory.class) -public class EnderChestInventoryMixin implements EnderChestInventoryDuck { +@Mixin(PlayerEnderChestContainer.class) +public class PlayerEnderChestContainerMixin implements EnderChestContainerDuck { private @Nullable BaseChestRearAttachment automobility$activeAttachment = null; @Override @@ -20,22 +20,22 @@ public class EnderChestInventoryMixin implements EnderChestInventoryDuck { this.automobility$activeAttachment = attachment; } - @Inject(method = "canPlayerUse", at = @At("HEAD"), cancellable = true) - private void automobility$allowPlayerUseWithAttachment(PlayerEntity player, CallbackInfoReturnable cir) { + @Inject(method = "stillValid", at = @At("HEAD"), cancellable = true) + private void automobility$allowPlayerUseWithAttachment(Player player, CallbackInfoReturnable cir) { if (this.automobility$activeAttachment != null) { cir.setReturnValue(true); } } - @Inject(method = "onOpen", at = @At("TAIL")) - private void automobility$openActiveAttachment(PlayerEntity player, CallbackInfo ci) { + @Inject(method = "startOpen", at = @At("TAIL")) + private void automobility$openActiveAttachment(Player player, CallbackInfo ci) { if (this.automobility$activeAttachment != null) { this.automobility$activeAttachment.open(player); } } - @Inject(method = "onClose", at = @At("TAIL")) - private void automobility$closeActiveAttachment(PlayerEntity player, CallbackInfo ci) { + @Inject(method = "stopOpen", at = @At("TAIL")) + private void automobility$closeActiveAttachment(Player player, CallbackInfo ci) { if (this.automobility$activeAttachment != null) { this.automobility$activeAttachment.close(player); } diff --git a/common/src/main/java/io/github/foundationgames/automobility/mixin/ServerGamePacketListenerImplMixin.java b/common/src/main/java/io/github/foundationgames/automobility/mixin/ServerGamePacketListenerImplMixin.java new file mode 100644 index 0000000..04c3747 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/mixin/ServerGamePacketListenerImplMixin.java @@ -0,0 +1,27 @@ +package io.github.foundationgames.automobility.mixin; + +import io.github.foundationgames.automobility.entity.AutomobileEntity; +import net.minecraft.network.protocol.game.ServerboundPlayerCommandPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerGamePacketListenerImpl; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ServerGamePacketListenerImpl.class) +public class ServerGamePacketListenerImplMixin { + @Shadow public ServerPlayer player; + + @Inject(method = "handlePlayerCommand", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;resetLastActionTime()V", shift = At.Shift.AFTER), cancellable = true) + private void automobility$openAutomobileInventory(ServerboundPlayerCommandPacket packet, CallbackInfo ci) { + var vehicle = this.player.getVehicle(); + if (packet.getAction() == ServerboundPlayerCommandPacket.Action.OPEN_INVENTORY && vehicle instanceof AutomobileEntity automobile) { + if (automobile.hasInventory()) { + automobile.openInventory(this.player); + ci.cancel(); + } + } + } +} diff --git a/src/main/java/io/github/foundationgames/automobility/mixin/ShovelItemAccess.java b/common/src/main/java/io/github/foundationgames/automobility/mixin/ShovelItemAccess.java similarity index 54% rename from src/main/java/io/github/foundationgames/automobility/mixin/ShovelItemAccess.java rename to common/src/main/java/io/github/foundationgames/automobility/mixin/ShovelItemAccess.java index f77300d..240f75a 100644 --- a/src/main/java/io/github/foundationgames/automobility/mixin/ShovelItemAccess.java +++ b/common/src/main/java/io/github/foundationgames/automobility/mixin/ShovelItemAccess.java @@ -1,8 +1,8 @@ package io.github.foundationgames.automobility.mixin; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.item.ShovelItem; +import net.minecraft.world.item.ShovelItem; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; @@ -10,8 +10,8 @@ @Mixin(ShovelItem.class) public interface ShovelItemAccess { - @Accessor("PATH_STATES") - static Map getPathStates() { + @Accessor("FLATTENABLES") + static Map getFlattenables() { throw new AssertionError(); } } 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 new file mode 100644 index 0000000..007e0eb --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/particle/AutomobilityParticles.java @@ -0,0 +1,15 @@ +package io.github.foundationgames.automobility.particle; + +import io.github.foundationgames.automobility.Automobility; +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; + +public class AutomobilityParticles { + public static final Eventual DRIFT_SMOKE = RegistryQueue.register(Registry.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/particle/DriftSmokeParticle.java b/common/src/main/java/io/github/foundationgames/automobility/particle/DriftSmokeParticle.java new file mode 100644 index 0000000..ad274f2 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/particle/DriftSmokeParticle.java @@ -0,0 +1,47 @@ +package io.github.foundationgames.automobility.particle; + +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.particle.Particle; +import net.minecraft.client.particle.ParticleProvider; +import net.minecraft.client.particle.ParticleRenderType; +import net.minecraft.client.particle.SpriteSet; +import net.minecraft.client.particle.TextureSheetParticle; +import net.minecraft.core.particles.SimpleParticleType; + +public class DriftSmokeParticle extends TextureSheetParticle { + private static final float SCALE_FACTOR = 0.83f; + private static final int MAX_AGE = (int)(Math.log(0.1) / Math.log(SCALE_FACTOR)); + + protected DriftSmokeParticle(ClientLevel world, double x, double y, double z) { + super(world, x, y, z); + this.quadSize = 0.6f - (world.random.nextFloat() * 0.1f); + this.alpha = this.quadSize; + this.setLifetime(MAX_AGE); + } + + @Override + public void tick() { + this.scale(SCALE_FACTOR); + this.alpha = this.quadSize; + } + + @Override + public ParticleRenderType getRenderType() { + return ParticleRenderType.PARTICLE_SHEET_TRANSLUCENT; + } + + public static class Factory implements ParticleProvider { + private final SpriteSet sprites; + + public Factory(SpriteSet sprites) { + this.sprites = sprites; + } + + @Override + public Particle createParticle(SimpleParticleType type, ClientLevel world, double x, double y, double z, double vx, double vy, double vz) { + var particle = new DriftSmokeParticle(world, x, y, z); + particle.pickSprite(this.sprites); + return particle; + } + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/platform/GlobalPlatformInstance.java b/common/src/main/java/io/github/foundationgames/automobility/platform/GlobalPlatformInstance.java new file mode 100644 index 0000000..73bc055 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/platform/GlobalPlatformInstance.java @@ -0,0 +1,5 @@ +package io.github.foundationgames.automobility.platform; + +class GlobalPlatformInstance { + static Platform INSTANCE = null; +} 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 new file mode 100644 index 0000000..fbdad88 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/platform/Platform.java @@ -0,0 +1,97 @@ +package io.github.foundationgames.automobility.platform; + +import com.mojang.blaze3d.vertex.PoseStack; +import io.github.foundationgames.automobility.util.HexCons; +import io.github.foundationgames.automobility.util.TriCons; +import io.github.foundationgames.automobility.util.TriFunc; +import net.minecraft.client.Minecraft; +import net.minecraft.client.color.block.BlockColor; +import net.minecraft.client.gui.screens.Screen; +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; +import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.core.BlockPos; +import net.minecraft.core.particles.SimpleParticleType; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityDimensions; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.MobCategory; +import net.minecraft.world.entity.player.Inventory; +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.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.Nullable; + +import java.util.function.BiConsumer; +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.function.Supplier; + +public interface Platform { + static void init(Platform instance) { + GlobalPlatformInstance.INSTANCE = instance; + } + + static Platform get() { + if (GlobalPlatformInstance.INSTANCE == null) { + throw new RuntimeException("Automobility's load order was disrupted!"); + } + + return GlobalPlatformInstance.INSTANCE; + } + + CreativeModeTab creativeTab(ResourceLocation rl, Supplier icon); + + void builtinItemRenderer(Item item, HexCons renderer); + + MenuType menuType(BiFunction factory); + + > void registerMenuScreen(MenuType type, TriFunc factory); + + @Nullable BlockColor blockColor(BlockState state); + + BlockEntityType blockEntity(BiFunction factory, Block... blocks); + + void blockEntityRenderer(BlockEntityType type, Function> provider); + + void serverSendPacket(ServerPlayer player, ResourceLocation rl, FriendlyByteBuf buf); + + void clientSendPacket(ResourceLocation rl, FriendlyByteBuf buf); + + void serverReceivePacket(ResourceLocation rl, TriCons run); + + void clientReceivePacket(ResourceLocation rl, BiConsumer run); + + EntityType entityType(MobCategory category, BiFunction, Level, T> factory, EntityDimensions size, int updateRate, int updateRange); + + void entityRenderer(EntityType entity, Function> factory); + + void modelLayer(ModelLayerLocation layer); + + SimpleParticleType simpleParticleType(boolean z); + + boolean controllerAccel(); + + boolean controllerBrake(); + + boolean controllerDrift(); + + boolean inControllerMode(); +} diff --git a/src/main/java/io/github/foundationgames/automobility/recipe/AutoMechanicTableRecipe.java b/common/src/main/java/io/github/foundationgames/automobility/recipe/AutoMechanicTableRecipe.java similarity index 56% rename from src/main/java/io/github/foundationgames/automobility/recipe/AutoMechanicTableRecipe.java rename to common/src/main/java/io/github/foundationgames/automobility/recipe/AutoMechanicTableRecipe.java index b55586c..292c200 100644 --- a/src/main/java/io/github/foundationgames/automobility/recipe/AutoMechanicTableRecipe.java +++ b/common/src/main/java/io/github/foundationgames/automobility/recipe/AutoMechanicTableRecipe.java @@ -1,15 +1,15 @@ package io.github.foundationgames.automobility.recipe; import io.github.foundationgames.automobility.Automobility; -import net.minecraft.inventory.Inventory; -import net.minecraft.inventory.SimpleInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.recipe.Ingredient; -import net.minecraft.recipe.Recipe; -import net.minecraft.recipe.RecipeSerializer; -import net.minecraft.recipe.RecipeType; -import net.minecraft.util.Identifier; -import net.minecraft.world.World; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.Container; +import net.minecraft.world.SimpleContainer; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeSerializer; +import net.minecraft.world.item.crafting.RecipeType; +import net.minecraft.world.level.Level; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -17,17 +17,17 @@ import java.util.function.Consumer; import java.util.stream.Collectors; -public class AutoMechanicTableRecipe implements Recipe, Comparable { - public static final Identifier ID = Automobility.id("auto_mechanic_table"); +public class AutoMechanicTableRecipe implements Recipe, Comparable { + public static final ResourceLocation ID = Automobility.rl("auto_mechanic_table"); public static final RecipeType TYPE = new RecipeType<>() {}; - private final Identifier id; + private final ResourceLocation id; - protected final Identifier category; + protected final ResourceLocation category; protected final Set ingredients; protected final ItemStack result; protected final int sortNum; - public AutoMechanicTableRecipe(Identifier id, Identifier category, Set ingredients, ItemStack result, int sortNum) { + public AutoMechanicTableRecipe(ResourceLocation id, ResourceLocation category, Set ingredients, ItemStack result, int sortNum) { this.id = id; this.category = category; this.ingredients = ingredients; @@ -35,25 +35,25 @@ public AutoMechanicTableRecipe(Identifier id, Identifier category, Set result[0] = false); + this.forMissingIngredients(inv, ing -> result[0] = false); return result[0]; } @Override - public ItemStack craft(SimpleInventory inv) { + public ItemStack assemble(SimpleContainer inv) { for (var ing : this.ingredients) { - for (int i = 0; i < inv.size(); i++) { - var stack = inv.getStack(i); + for (int i = 0; i < inv.getContainerSize(); i++) { + var stack = inv.getItem(i); if (ing.test(stack)) { - stack.decrement(1); + stack.shrink(1); break; } } @@ -63,17 +63,17 @@ public ItemStack craft(SimpleInventory inv) { } @Override - public boolean fits(int width, int height) { + public boolean canCraftInDimensions(int width, int height) { return true; } @Override - public ItemStack getOutput() { + public ItemStack getResultItem() { return this.result; } @Override - public Identifier getId() { + public ResourceLocation getId() { return this.id; } @@ -87,10 +87,10 @@ public RecipeType getType() { return TYPE; } - public void forMissingIngredients(Inventory inv, Consumer action) { + public void forMissingIngredients(Container inv, Consumer action) { var invCopy = new ArrayList(); - for (int i = 0; i < inv.size(); i++) { - invCopy.add(inv.getStack(i)); + for (int i = 0; i < inv.getContainerSize(); i++) { + invCopy.add(inv.getItem(i)); } for (var ing : this.ingredients) { diff --git a/src/main/java/io/github/foundationgames/automobility/recipe/AutoMechanicTableRecipeSerializer.java b/common/src/main/java/io/github/foundationgames/automobility/recipe/AutoMechanicTableRecipeSerializer.java similarity index 62% rename from src/main/java/io/github/foundationgames/automobility/recipe/AutoMechanicTableRecipeSerializer.java rename to common/src/main/java/io/github/foundationgames/automobility/recipe/AutoMechanicTableRecipeSerializer.java index 8bbcbb8..b1ebcc7 100644 --- a/src/main/java/io/github/foundationgames/automobility/recipe/AutoMechanicTableRecipeSerializer.java +++ b/common/src/main/java/io/github/foundationgames/automobility/recipe/AutoMechanicTableRecipeSerializer.java @@ -3,26 +3,25 @@ import com.google.gson.JsonObject; import com.google.gson.JsonSyntaxException; import io.github.foundationgames.automobility.item.AutomobileComponentItem; -import net.minecraft.item.ItemStack; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.recipe.Ingredient; -import net.minecraft.recipe.RecipeSerializer; -import net.minecraft.util.Identifier; -import net.minecraft.util.registry.Registry; +import net.minecraft.core.Registry; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.item.crafting.RecipeSerializer; -import java.util.HashSet; import java.util.LinkedHashSet; public class AutoMechanicTableRecipeSerializer implements RecipeSerializer { public static final AutoMechanicTableRecipeSerializer INSTANCE = new AutoMechanicTableRecipeSerializer(); public static ItemStack autoComponentStackFromJson(JsonObject obj) throws JsonSyntaxException, IllegalStateException { - var id = Identifier.tryParse(obj.get("item").getAsString()); + var id = ResourceLocation.tryParse(obj.get("item").getAsString()); int count = obj.has("count") ? obj.get("count").getAsInt() : 1; - var stack = Registry.ITEM.getOrEmpty(id).map(i -> new ItemStack(i, count)).orElse(ItemStack.EMPTY); + var stack = Registry.ITEM.getOptional(id).map(i -> new ItemStack(i, count)).orElse(ItemStack.EMPTY); if (obj.has("component") && stack.getItem() instanceof AutomobileComponentItem item) { - var component = Identifier.tryParse(obj.get("component").getAsString()); + var component = ResourceLocation.tryParse(obj.get("component").getAsString()); if (component != null) { item.setComponent(stack, component); } @@ -32,9 +31,9 @@ public static ItemStack autoComponentStackFromJson(JsonObject obj) throws JsonSy } @Override - public AutoMechanicTableRecipe read(Identifier id, JsonObject json) { + public AutoMechanicTableRecipe fromJson(ResourceLocation id, JsonObject json) { try { - var category = Identifier.tryParse(json.get("category").getAsString()); + var category = ResourceLocation.tryParse(json.get("category").getAsString()); var ingredients = new LinkedHashSet(); for (var ele : json.get("ingredients").getAsJsonArray()) { ingredients.add(Ingredient.fromJson(ele)); @@ -52,27 +51,27 @@ public AutoMechanicTableRecipe read(Identifier id, JsonObject json) { } @Override - public AutoMechanicTableRecipe read(Identifier id, PacketByteBuf buf) { - var category = Identifier.tryParse(buf.readString()); + public AutoMechanicTableRecipe fromNetwork(ResourceLocation id, FriendlyByteBuf buf) { + var category = ResourceLocation.tryParse(buf.readUtf()); int size = buf.readByte(); var ingredients = new LinkedHashSet(); for (int i = 0; i < size; i++) { - ingredients.add(Ingredient.fromPacket(buf)); + ingredients.add(Ingredient.fromNetwork(buf)); } - var result = buf.readItemStack(); + var result = buf.readItem(); int sortNum = buf.readInt(); return new AutoMechanicTableRecipe(id, category, ingredients, result, sortNum); } @Override - public void write(PacketByteBuf buf, AutoMechanicTableRecipe recipe) { - buf.writeString(recipe.category.toString()); + public void toNetwork(FriendlyByteBuf buf, AutoMechanicTableRecipe recipe) { + buf.writeUtf(recipe.category.toString()); buf.writeByte(recipe.ingredients.size()); - recipe.ingredients.forEach(ing -> ing.write(buf)); - buf.writeItemStack(recipe.result); + recipe.ingredients.forEach(ing -> ing.toNetwork(buf)); + buf.writeItem(recipe.result); buf.writeInt(recipe.sortNum); } } diff --git a/src/main/java/io/github/foundationgames/automobility/screen/AutoMechanicTableScreen.java b/common/src/main/java/io/github/foundationgames/automobility/screen/AutoMechanicTableScreen.java similarity index 59% rename from src/main/java/io/github/foundationgames/automobility/screen/AutoMechanicTableScreen.java rename to common/src/main/java/io/github/foundationgames/automobility/screen/AutoMechanicTableScreen.java index 3bef36c..a8cf305 100644 --- a/src/main/java/io/github/foundationgames/automobility/screen/AutoMechanicTableScreen.java +++ b/common/src/main/java/io/github/foundationgames/automobility/screen/AutoMechanicTableScreen.java @@ -1,22 +1,21 @@ 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.DrawableHelper; -import net.minecraft.client.gui.screen.ingame.HandledScreen; -import net.minecraft.client.item.TooltipContext; -import net.minecraft.client.render.GameRenderer; -import net.minecraft.client.resource.language.I18n; -import net.minecraft.client.sound.PositionedSoundInstance; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.recipe.Ingredient; -import net.minecraft.sound.SoundEvents; -import net.minecraft.text.OrderedText; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; -import net.minecraft.util.math.MathHelper; +import net.minecraft.client.gui.GuiComponent; +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; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.util.FormattedCharSequence; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.item.crafting.Ingredient; import org.lwjgl.glfw.GLFW; import java.util.ArrayDeque; @@ -26,8 +25,8 @@ import java.util.List; import java.util.Map; -public class AutoMechanicTableScreen extends HandledScreen { - private static final Identifier TEXTURE = Automobility.id("textures/gui/container/auto_mechanic_table.png"); +public class AutoMechanicTableScreen extends AbstractContainerScreen { + private static final ResourceLocation TEXTURE = Automobility.rl("textures/gui/container/auto_mechanic_table.png"); private static final int RECIPE_BUTTON_SIZE = 17; private static final int RECIPE_PANEL_WIDTH = 85; @@ -51,17 +50,17 @@ public class AutoMechanicTableScreen extends HandledScreen orderedCategories = createDefaultCategories(); - private final Map> recipes = new HashMap<>(); + private final List orderedCategories = createDefaultCategories(); + private final Map> recipes = new HashMap<>(); - private OrderedText categoryTitle; + private FormattedCharSequence categoryTitle; - public AutoMechanicTableScreen(AutoMechanicTableScreenHandler handler, PlayerInventory inventory, Text title) { + public AutoMechanicTableScreen(AutoMechanicTableScreenHandler handler, Inventory inventory, Component title) { super(handler, inventory, title); - this.backgroundWidth = 176; - this.backgroundHeight = 209; + this.imageWidth = 176; + this.imageHeight = 209; - this.titleY = 8; + this.titleLabelY = 8; for (int id = 0; id < handler.recipes.size(); id++) { var recipe = handler.recipes.get(id); @@ -75,14 +74,14 @@ public AutoMechanicTableScreen(AutoMechanicTableScreenHandler handler, PlayerInv this.recipes.get(category).add(new RecipeEntry(id, recipe)); } - this.playerInventoryTitleY = this.y + 115; + this.inventoryLabelY = this.topPos + 115; } - private static List createDefaultCategories() { - var list = new ArrayList(); - list.add(Automobility.id("frames")); - list.add(Automobility.id("engines")); - list.add(Automobility.id("wheels")); + private static List createDefaultCategories() { + var list = new ArrayList(); + list.add(Automobility.rl("frames")); + list.add(Automobility.rl("engines")); + list.add(Automobility.rl("wheels")); return list; } @@ -91,26 +90,26 @@ private static List createDefaultCategories() { protected void init() { super.init(); - this.recipePanelX = this.x + 76; - this.recipePanelY = this.y + 21; + this.recipePanelX = this.leftPos + 76; + this.recipePanelY = this.topPos + 21; - this.categoryButtonsX = this.x + 75; - this.categoryButtonsY = this.y + 4; + this.categoryButtonsX = this.leftPos + 75; + this.categoryButtonsY = this.topPos + 4; this.categoryTitle = this.createCategoryTitle(this.orderedCategories.get(0)); } @Override - protected void handledScreenTick() { - super.handledScreenTick(); + protected void containerTick() { + super.containerTick(); this.time++; } @Override - public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { super.render(matrices, mouseX, mouseY, delta); - this.drawMouseoverTooltip(matrices, mouseX, mouseY); + this.renderTooltip(matrices, mouseX, mouseY); } private void preDraw() { @@ -120,11 +119,11 @@ private void preDraw() { } @Override - protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY) { + protected void renderBg(PoseStack matrices, float delta, int mouseX, int mouseY) { this.renderBackground(matrices); this.preDraw(); - this.drawTexture(matrices, this.x, this.y, 0, 0, this.backgroundWidth, this.backgroundHeight); + this.blit(matrices, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight); this.drawCategoryBar(matrices, mouseX, mouseY); this.drawRecipes(matrices, mouseX, mouseY); @@ -132,12 +131,12 @@ protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int } @Override - protected void drawForeground(MatrixStack matrices, int mouseX, int mouseY) { - super.drawForeground(matrices, mouseX, mouseY); + protected void renderLabels(PoseStack matrices, int mouseX, int mouseY) { + super.renderLabels(matrices, mouseX, mouseY); int hoveredRecipe = this.getHoveredRecipe(mouseX, mouseY); if (hoveredRecipe >= 0) { - this.renderTooltip(matrices, this.handler.recipes.get(hoveredRecipe).getOutput(), mouseX - this.x, mouseY - this.y); + this.renderTooltip(matrices, this.menu.recipes.get(hoveredRecipe).getResultItem(), mouseX - this.leftPos, mouseY - this.topPos); } } @@ -147,17 +146,17 @@ private void changeCategory(int by) { this.recipeScroll = 0; } - private OrderedText createCategoryTitle(Identifier category) { - var translated = I18n.translate("part_category."+category.getNamespace()+"."+category.getPath()); - if (this.textRenderer.getWidth(translated) > 64) { - return Text.literal(this.textRenderer.trimToWidth(translated, 57) + "...").asOrderedText(); + private FormattedCharSequence createCategoryTitle(ResourceLocation category) { + var translated = I18n.get("part_category."+category.getNamespace()+"."+category.getPath()); + if (this.font.width(translated) > 64) { + return Component.literal(this.font.plainSubstrByWidth(translated, 57) + "...").getVisualOrderText(); } - return Text.literal(this.textRenderer.trimToWidth(translated, 64)).asOrderedText(); + return Component.literal(this.font.plainSubstrByWidth(translated, 64)).getVisualOrderText(); } private void buttonClicked() { - if (this.client != null) { - this.client.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F)); + if (this.minecraft != null) { + this.minecraft.getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F)); } } @@ -184,19 +183,19 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { } private void selectRecipe(int id) { - this.handler.onButtonClick(this.client.player, id); - this.client.interactionManager.clickButton(this.handler.syncId, id); + this.menu.clickMenuButton(this.minecraft.player, id); + this.minecraft.gameMode.handleInventoryButtonClick(this.menu.containerId, id); } private int getMaxRecipeScroll() { - return Math.max(0, MathHelper.ceil((float)this.getRecipeList().size() / 5) - 3); + return Math.max(0, Mth.ceil((float)this.getRecipeList().size() / 5) - 3); } @Override public boolean mouseScrolled(double mouseX, double mouseY, double amount) { if (amount != 0 && this.getHoveredRecipe((int) mouseX, (int) mouseY) >= -1) { this.recipeScroll += amount > 0 ? -1 : 1; - this.recipeScroll = MathHelper.clamp(this.recipeScroll, 0, this.getMaxRecipeScroll()); + this.recipeScroll = Mth.clamp(this.recipeScroll, 0, this.getMaxRecipeScroll()); return true; } @@ -204,26 +203,26 @@ public boolean mouseScrolled(double mouseX, double mouseY, double amount) { return false; } - protected final void drawMissingIngredient(MatrixStack matrices, Ingredient ing, int x, int y) { - DrawableHelper.fill(matrices, x, y, x + 16, y + 16, 0x45FF0000); + protected final void drawMissingIngredient(PoseStack matrices, Ingredient ing, int x, int y) { + GuiComponent.fill(matrices, x, y, x + 16, y + 16, 0x45FF0000); - var stacks = ing.getMatchingStacks(); - this.itemRenderer.renderInGui(stacks[MathHelper.floor((float)this.time / 30) % stacks.length], x, y); + var stacks = ing.getItems(); + this.itemRenderer.renderAndDecorateFakeItem(stacks[Mth.floor((float)this.time / 30) % stacks.length], x, y); RenderSystem.depthFunc(516); - DrawableHelper.fill(matrices, x, y, x + 16, y + 16, 0x30FFFFFF); + GuiComponent.fill(matrices, x, y, x + 16, y + 16, 0x30FFFFFF); RenderSystem.depthFunc(515); } - protected void drawMissingIngredients(MatrixStack matrices) { - var inputInv = this.handler.inputInv; - var missingIngs = new ArrayDeque<>(this.handler.missingIngredients); + protected void drawMissingIngredients(PoseStack matrices) { + var inputInv = this.menu.inputInv; + var missingIngs = new ArrayDeque<>(this.menu.missingIngredients); - for (int i = 0; i < inputInv.size(); i++) if (missingIngs.size() > 0) { - int x = this.x + 8 + (i * 18); - int y = this.y + 88; + for (int i = 0; i < inputInv.getContainerSize(); i++) if (missingIngs.size() > 0) { + int x = this.leftPos + 8 + (i * 18); + int y = this.topPos + 88; - if (inputInv.getStack(i).isEmpty()) { + if (inputInv.getItem(i).isEmpty()) { this.drawMissingIngredient(matrices, missingIngs.removeFirst(), x, y); } } @@ -261,8 +260,8 @@ protected int getHoveredRecipe(int mouseX, int mouseY) { if (this.currentCategory < this.orderedCategories.size() && this.currentCategory >= 0 && (mouseX >= 0 && mouseX < RECIPE_PANEL_WIDTH) && (mouseY >= 0 && mouseY < RECIPE_PANEL_HEIGHT)) { - int row = MathHelper.floor((float)mouseY / RECIPE_BUTTON_SIZE); - int col = MathHelper.floor((float)mouseX / RECIPE_BUTTON_SIZE); + int row = Mth.floor((float)mouseY / RECIPE_BUTTON_SIZE); + int col = Mth.floor((float)mouseX / RECIPE_BUTTON_SIZE); if (row >= 0 && col >= 0) { int idx = (5 * (row + this.recipeScroll)) + col; @@ -278,21 +277,21 @@ protected int getHoveredRecipe(int mouseX, int mouseY) { return -2; } - protected void drawCategoryBar(MatrixStack matrices, int mouseX, int mouseY) { + protected void drawCategoryBar(PoseStack matrices, int mouseX, int mouseY) { int hoveredCatButton = this.getHoveredCategoryButton(mouseX, mouseY); this.preDraw(); - this.drawTexture(matrices, this.categoryButtonsX, this.categoryButtonsY, + this.blit(matrices, this.categoryButtonsX, this.categoryButtonsY, 176, 17 + (hoveredCatButton < 0 ? CATEGORY_BUTTON_HEIGHT : 0), CATEGORY_BUTTON_WIDTH, CATEGORY_BUTTON_HEIGHT); - this.drawTexture(matrices, this.categoryButtonsX + (CATEGORY_BUTTON_AREA_WIDTH - CATEGORY_BUTTON_WIDTH), this.categoryButtonsY, + this.blit(matrices, 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) { - DrawableHelper.drawCenteredTextWithShadow(matrices, this.textRenderer, this.categoryTitle, this.x + 120, this.y + 8, 0xFFFFFF); + GuiComponent.drawCenteredString(matrices, this.font, this.categoryTitle, this.leftPos + 120, this.topPos + 8, 0xFFFFFF); } } - protected void drawRecipes(MatrixStack matrices, int mouseX, int mouseY) { + protected void drawRecipes(PoseStack matrices, int mouseX, int mouseY) { if (this.orderedCategories.size() > 0) { var recipes = this.recipes.get(this.orderedCategories.get(this.currentCategory)); @@ -307,8 +306,8 @@ protected void drawRecipes(MatrixStack matrices, int mouseX, int mouseY) { var entry = recipes.get(idx); var state = RecipeButtonState.DEFAULT; - if (this.handler.getSelectedRecipe().isPresent() && - this.handler.getSelectedRecipeId() == entry.id()) { + if (this.menu.getSelectedRecipe().isPresent() && + this.menu.getSelectedRecipeId() == entry.id()) { state = RecipeButtonState.SELECTED; } else if (this.getHoveredRecipe(mouseX, mouseY) == entry.id()) { state = RecipeButtonState.HOVERED; @@ -325,21 +324,21 @@ protected void drawRecipes(MatrixStack matrices, int mouseX, int mouseY) { this.preDraw(); int maxScroll = this.getMaxRecipeScroll(); - int scrollBarX = this.x + 162; - int scrollBarY = this.y + 21; + int scrollBarX = this.leftPos + 162; + int scrollBarY = this.topPos + 21; if (maxScroll > 0) { scrollBarY += (int)((SCROLL_BAR_AREA_HEIGHT - SCROLL_BAR_HEIGHT) * ((float)this.recipeScroll / maxScroll)); } - this.drawTexture(matrices, scrollBarX, scrollBarY, 227, 0, SCROLL_BAR_WIDTH, SCROLL_BAR_HEIGHT); + this.blit(matrices, scrollBarX, scrollBarY, 227, 0, SCROLL_BAR_WIDTH, SCROLL_BAR_HEIGHT); } - protected void drawRecipeEntry(RecipeEntry entry, MatrixStack matrices, int x, int y, RecipeButtonState state) { + protected void drawRecipeEntry(RecipeEntry entry, PoseStack matrices, int x, int y, RecipeButtonState state) { this.preDraw(); - this.drawTexture(matrices, x, y, 176 + (state.ordinal() * RECIPE_BUTTON_SIZE), 0, RECIPE_BUTTON_SIZE, RECIPE_BUTTON_SIZE); + this.blit(matrices, x, y, 176 + (state.ordinal() * RECIPE_BUTTON_SIZE), 0, RECIPE_BUTTON_SIZE, RECIPE_BUTTON_SIZE); - var stack = entry.recipe.getOutput(); - this.itemRenderer.renderInGui(stack, x, y); + var stack = entry.recipe.getResultItem(); + this.itemRenderer.renderAndDecorateFakeItem(stack, x, y); } public static record RecipeEntry(int id, AutoMechanicTableRecipe recipe) {} diff --git a/src/main/java/io/github/foundationgames/automobility/screen/AutoMechanicTableScreenHandler.java b/common/src/main/java/io/github/foundationgames/automobility/screen/AutoMechanicTableScreenHandler.java similarity index 54% rename from src/main/java/io/github/foundationgames/automobility/screen/AutoMechanicTableScreenHandler.java rename to common/src/main/java/io/github/foundationgames/automobility/screen/AutoMechanicTableScreenHandler.java index 2068633..3d3d2aa 100644 --- a/src/main/java/io/github/foundationgames/automobility/screen/AutoMechanicTableScreenHandler.java +++ b/common/src/main/java/io/github/foundationgames/automobility/screen/AutoMechanicTableScreenHandler.java @@ -3,52 +3,52 @@ import io.github.foundationgames.automobility.Automobility; import io.github.foundationgames.automobility.block.AutomobilityBlocks; import io.github.foundationgames.automobility.recipe.AutoMechanicTableRecipe; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.Inventory; -import net.minecraft.inventory.SimpleInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.recipe.Ingredient; -import net.minecraft.screen.Property; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.screen.ScreenHandlerContext; -import net.minecraft.screen.slot.Slot; -import net.minecraft.world.World; +import net.minecraft.world.Container; +import net.minecraft.world.SimpleContainer; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.DataSlot; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.level.Level; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Optional; -public class AutoMechanicTableScreenHandler extends ScreenHandler { - private final World world; - private final ScreenHandlerContext context; - private final Property selectedRecipe = Property.create(); +public class AutoMechanicTableScreenHandler extends AbstractContainerMenu { + private final Level world; + private final ContainerLevelAccess context; + private final DataSlot selectedRecipe = DataSlot.standalone(); public List recipes; public final List missingIngredients = new ArrayList<>(); - public final SimpleInventory inputInv; + public final SimpleContainer inputInv; public final Slot outputSlot; private final int playerInvSlot; - public AutoMechanicTableScreenHandler(int syncId, PlayerInventory playerInv) { - this(syncId, playerInv, ScreenHandlerContext.EMPTY); + public AutoMechanicTableScreenHandler(int syncId, Inventory playerInv) { + this(syncId, playerInv, ContainerLevelAccess.NULL); } - public AutoMechanicTableScreenHandler(int syncId, PlayerInventory playerInv, ScreenHandlerContext ctx) { - super(Automobility.AUTO_MECHANIC_SCREEN, syncId); - this.world = playerInv.player.getWorld(); + 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.context = ctx; - this.inputInv = new SimpleInventory(9) { - @Override public void markDirty() { AutoMechanicTableScreenHandler.this.onInputUpdated(); } + this.inputInv = new SimpleContainer(9) { + @Override public void setChanged() { AutoMechanicTableScreenHandler.this.onInputUpdated(); } }; for(int s = 0; s < 9; s++) { this.addSlot(new InputSlot(this.inputInv, s, 8 + (s * 18), 88)); } - this.outputSlot = this.addSlot(new OutputSlot(new SimpleInventory(1), 0, 26, 38)); + this.outputSlot = this.addSlot(new OutputSlot(new SimpleContainer(1), 0, 26, 38)); this.playerInvSlot = this.slots.size(); int playerInvY = 127; @@ -61,11 +61,11 @@ public AutoMechanicTableScreenHandler(int syncId, PlayerInventory playerInv, Scr this.addSlot(new Slot(playerInv, s, 8 + (s * 18), playerInvY + 58)); } - this.recipes = new ArrayList<>(world.getRecipeManager().listAllOfType(AutoMechanicTableRecipe.TYPE)); + this.recipes = new ArrayList<>(world.getRecipeManager().getAllRecipesFor(AutoMechanicTableRecipe.TYPE)); Collections.sort(this.recipes); this.selectedRecipe.set(-1); - this.addProperty(this.selectedRecipe); + this.addDataSlot(this.selectedRecipe); } public Optional getSelectedRecipe() { @@ -88,21 +88,21 @@ private void updateRecipeState() { this.getSelectedRecipe().ifPresent(recipe -> { if (recipe.matches(this.inputInv, this.world)) { - this.outputSlot.setStack(recipe.getOutput().copy()); + this.outputSlot.set(recipe.getResultItem().copy()); } else { - this.outputSlot.setStack(ItemStack.EMPTY); + this.outputSlot.set(ItemStack.EMPTY); } }); } @Override - public boolean onButtonClick(PlayerEntity player, int id) { + public boolean clickMenuButton(Player player, int id) { if (id >= 0 && id < this.recipes.size()) { this.selectRecipe(id); return true; } - return super.onButtonClick(player, id); + return super.clickMenuButton(player, id); } private void onInputUpdated() { @@ -115,101 +115,101 @@ private void selectRecipe(int id) { } @Override - public void close(PlayerEntity player) { - super.close(player); + public void removed(Player player) { + super.removed(player); - this.outputSlot.setStack(ItemStack.EMPTY); - this.context.run((world, pos) -> this.dropInventory(player, this.inputInv)); + this.outputSlot.set(ItemStack.EMPTY); + this.context.execute((world, pos) -> this.clearContainer(player, this.inputInv)); } @Override - public boolean canUse(PlayerEntity player) { - return canUse(this.context, player, AutomobilityBlocks.AUTO_MECHANIC_TABLE); + public boolean stillValid(Player player) { + return stillValid(this.context, player, AutomobilityBlocks.AUTO_MECHANIC_TABLE.require()); } @Override - public boolean canInsertIntoSlot(ItemStack stack, Slot slot) { - return slot.inventory != this.outputSlot && super.canInsertIntoSlot(stack, slot); + public boolean canTakeItemForPickAll(ItemStack stack, Slot slot) { + return slot.container != this.outputSlot && super.canTakeItemForPickAll(stack, slot); } @Override - public ItemStack transferSlot(PlayerEntity player, int fromSlotId) { + public ItemStack quickMoveStack(Player player, int fromSlotId) { var newStack = ItemStack.EMPTY; var fromSlot = this.slots.get(fromSlotId); - if (fromSlot.hasStack()) { - var fromStack = fromSlot.getStack(); + if (fromSlot.hasItem()) { + var fromStack = fromSlot.getItem(); var fromItem = fromStack.getItem(); newStack = fromStack.copy(); // Items transferred out of output slot - if (fromSlotId == this.outputSlot.id) { - fromItem.onCraft(fromStack, player.world, player); - if (!this.insertItem(fromStack, this.playerInvSlot, this.playerInvSlot + 36, true)) { + if (fromSlotId == this.outputSlot.index) { + fromItem.onCraftedBy(fromStack, player.level, player); + if (!this.moveItemStackTo(fromStack, this.playerInvSlot, this.playerInvSlot + 36, true)) { return ItemStack.EMPTY; } - fromSlot.onQuickTransfer(fromStack, newStack); + fromSlot.onQuickCraft(fromStack, newStack); // Items transferred out of input row - } else if (this.slots.stream().anyMatch(s -> s.inventory == this.inputInv && s.id == fromSlotId)) { - if (!this.insertItem(fromStack, this.playerInvSlot, this.playerInvSlot + 36, false)) { + } else if (this.slots.stream().anyMatch(s -> s.container == this.inputInv && s.index == fromSlotId)) { + if (!this.moveItemStackTo(fromStack, this.playerInvSlot, this.playerInvSlot + 36, false)) { return ItemStack.EMPTY; } // Items being transferred into the input row, which match the missing ingredients } else if (this.missingIngredients.stream().anyMatch(ing -> ing.test(fromStack))) { - if (!this.insertItem(fromStack, 0, 8, false)) { + if (!this.moveItemStackTo(fromStack, 0, 8, false)) { return ItemStack.EMPTY; } // Items transferred from inventory to hotbar } else if (fromSlotId >= this.playerInvSlot && fromSlotId < this.playerInvSlot + 27) { - if (!this.insertItem(fromStack, this.playerInvSlot + 27, this.playerInvSlot + 36, false)) { + if (!this.moveItemStackTo(fromStack, this.playerInvSlot + 27, this.playerInvSlot + 36, false)) { return ItemStack.EMPTY; } // Items transferred from hotbar to inventory } else if (fromSlotId >= this.playerInvSlot + 27 && fromSlotId < this.playerInvSlot + 36 && - !this.insertItem(fromStack, this.playerInvSlot, this.playerInvSlot + 27, false)) { + !this.moveItemStackTo(fromStack, this.playerInvSlot, this.playerInvSlot + 27, false)) { return ItemStack.EMPTY; } if (fromStack.isEmpty()) { - fromSlot.setStack(ItemStack.EMPTY); + fromSlot.set(ItemStack.EMPTY); } - fromSlot.markDirty(); + fromSlot.setChanged(); if (fromStack.getCount() == newStack.getCount()) { return ItemStack.EMPTY; } - fromSlot.onTakeItem(player, fromStack); - this.sendContentUpdates(); + fromSlot.onTake(player, fromStack); + this.broadcastChanges(); } return newStack; } public static class InputSlot extends Slot { - public InputSlot(Inventory inventory, int index, int x, int y) { + public InputSlot(Container inventory, int index, int x, int y) { super(inventory, index, x, y); } } public class OutputSlot extends Slot { - public OutputSlot(Inventory inventory, int index, int x, int y) { + public OutputSlot(Container inventory, int index, int x, int y) { super(inventory, index, x, y); } @Override - public boolean canInsert(ItemStack stack) { + public boolean mayPlace(ItemStack stack) { return false; } @Override - public void onTakeItem(PlayerEntity player, ItemStack stack) { - super.onTakeItem(player, stack); + public void onTake(Player player, ItemStack stack) { + super.onTake(player, stack); AutoMechanicTableScreenHandler.this.getSelectedRecipe() .ifPresent(recipe -> { - recipe.craft(AutoMechanicTableScreenHandler.this.inputInv); - stack.getItem().onCraft(stack, player.getWorld(), player); + recipe.assemble(AutoMechanicTableScreenHandler.this.inputInv); + stack.getItem().onCraftedBy(stack, player.getLevel(), 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 new file mode 100644 index 0000000..319173d --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/screen/AutomobileContainerLevelAccess.java @@ -0,0 +1,31 @@ +package io.github.foundationgames.automobility.screen; + +import io.github.foundationgames.automobility.automobile.attachment.rear.BlockRearAttachment; +import io.github.foundationgames.automobility.entity.AutomobileEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; + +import java.util.Optional; +import java.util.function.BiFunction; + +public class AutomobileContainerLevelAccess implements ContainerLevelAccess { + private final Level world; + private final AutomobileEntity automobile; + + public AutomobileContainerLevelAccess(AutomobileEntity automobile) { + this.world = automobile.getLevel(); + this.automobile = automobile; + } + + @Override + public Optional evaluate(BiFunction getter) { + return Optional.of(getter.apply(world, automobile.blockPosition())); + } + + public BlockState getAttachmentBlockState() { + return automobile.getRearAttachment() instanceof BlockRearAttachment att ? att.block : Blocks.AIR.defaultBlockState(); + } +} 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 new file mode 100644 index 0000000..7ee95d2 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/screen/AutomobileHud.java @@ -0,0 +1,81 @@ +package io.github.foundationgames.automobility.screen; + +import com.google.common.collect.Lists; +import com.mojang.blaze3d.vertex.PoseStack; +import io.github.foundationgames.automobility.entity.AutomobileEntity; +import io.github.foundationgames.automobility.platform.Platform; +import io.github.foundationgames.automobility.util.AUtils; +import net.minecraft.client.KeyMapping; +import net.minecraft.client.Minecraft; +import net.minecraft.client.Options; +import net.minecraft.client.gui.GuiComponent; +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.player.Player; + +import java.util.List; +import java.util.function.Function; + +public enum AutomobileHud {; + public static final List CONTROL_HINTS = Lists.newArrayList( + new ControlHint("accelerate", options -> options.keyUp), + new ControlHint("brake", options -> options.keyDown), + new ControlHint("steer_left", options -> options.keyLeft), + new ControlHint("steer_right", options -> options.keyRight), + new ControlHint("drift", options -> options.keyJump) + ); + + public static void render(PoseStack pose, Player player, AutomobileEntity auto, float tickDelta) { + renderSpeedometer(pose, auto); + + if (!Platform.get().inControllerMode()) { + float alpha = Math.max(0, (auto.getStandStillTime() * 2) - 1); + + // Check on a 0-255 converted version of alpha, because 0 alpha will render things at 100% alpha for some + // 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); + } + } + } + + private static void renderSpeedometer(PoseStack pose, 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); + } + + private static void renderControlHints(PoseStack pose, float alpha) { + int x = 20; + int y = 50; + var options = Minecraft.getInstance().options; + var font = Minecraft.getInstance().font; + + for (var control : CONTROL_HINTS) { + var keyTxt = control.getKeybindText(options); + int keyTxtWid = font.width(keyTxt); + + GuiComponent.fill(pose, 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); + + y += 17; + } + } + + public record ControlHint(String name, Function keybind) { + public Component getText() { + return Component.translatable("automobile_control."+name); + } + + public Component getKeybindText(Options options) { + return keybind.apply(options).getTranslatedKeyMessage(); + } + } +} 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 new file mode 100644 index 0000000..15b4e24 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/screen/SingleSlotScreen.java @@ -0,0 +1,39 @@ +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 net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.client.gui.screens.inventory.MenuAccess; +import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Inventory; + +public class SingleSlotScreen extends AbstractContainerScreen implements MenuAccess { + private static final ResourceLocation TEXTURE = Automobility.rl("textures/gui/container/single_slot.png"); + + public SingleSlotScreen(SingleSlotScreenHandler handler, Inventory inventory, Component title) { + super(handler, inventory, title); + + this.imageHeight = 140; + this.inventoryLabelY = 47; + this.titleLabelX = 60; + } + + @Override + public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { + super.render(matrices, mouseX, mouseY, delta); + this.renderTooltip(matrices, mouseX, mouseY); + } + + @Override + protected void renderBg(PoseStack matrices, float delta, int mouseX, int mouseY) { + this.renderBackground(matrices); + + 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); + } +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/screen/SingleSlotScreenHandler.java b/common/src/main/java/io/github/foundationgames/automobility/screen/SingleSlotScreenHandler.java new file mode 100644 index 0000000..0af459f --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/screen/SingleSlotScreenHandler.java @@ -0,0 +1,70 @@ +package io.github.foundationgames.automobility.screen; + +import io.github.foundationgames.automobility.Automobility; +import net.minecraft.world.Container; +import net.minecraft.world.SimpleContainer; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; + +public class SingleSlotScreenHandler extends AbstractContainerMenu { + private final Container inventory; + + public SingleSlotScreenHandler(int syncId, Inventory playerInv) { + this(syncId, playerInv, new SimpleContainer(1)); + } + + public SingleSlotScreenHandler(int syncId, Inventory playerInv, Container inv) { + super(Automobility.SINGLE_SLOT_SCREEN.require("Single slot screen not registered!"), syncId); + + checkContainerSize(inv, 1); + this.inventory = inv; + inv.startOpen(playerInv.player); + + this.addSlot(new Slot(inventory, 0, 80, 23)); + + // Player inventory + int row; + int col; + for(row = 0; row < 3; ++row) { + for(col = 0; col < 9; ++col) { + this.addSlot(new Slot(playerInv, col + row * 9 + 9, 8 + col * 18, 58 + row * 18)); + } + } + for(row = 0; row < 9; ++row) { + this.addSlot(new Slot(playerInv, row, 8 + row * 18, 116)); + } + } + + @Override + public boolean stillValid(Player player) { + return true; + } + + public ItemStack quickMoveStack(Player player, int fromSlotId) { + var newStack = ItemStack.EMPTY; + var fromSlot = this.slots.get(fromSlotId); + + if (fromSlot.hasItem()) { + var fromStack = fromSlot.getItem(); + newStack = fromStack.copy(); + if (fromSlotId == 0) { + if (!this.moveItemStackTo(fromStack, 1, 37, true)) { + return ItemStack.EMPTY; + } + } else if (!this.moveItemStackTo(fromStack, 0, 1, false)) { + return ItemStack.EMPTY; + } + + if (fromStack.isEmpty()) { + fromSlot.set(ItemStack.EMPTY); + } else { + fromSlot.setChanged(); + } + } + + return newStack; + } +} diff --git a/src/main/java/io/github/foundationgames/automobility/sound/AutomobileSoundInstance.java b/common/src/main/java/io/github/foundationgames/automobility/sound/AutomobileSoundInstance.java similarity index 71% rename from src/main/java/io/github/foundationgames/automobility/sound/AutomobileSoundInstance.java rename to common/src/main/java/io/github/foundationgames/automobility/sound/AutomobileSoundInstance.java index ec1f46d..94f5471 100644 --- a/src/main/java/io/github/foundationgames/automobility/sound/AutomobileSoundInstance.java +++ b/common/src/main/java/io/github/foundationgames/automobility/sound/AutomobileSoundInstance.java @@ -1,13 +1,13 @@ package io.github.foundationgames.automobility.sound; import io.github.foundationgames.automobility.entity.AutomobileEntity; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.sound.MovingSoundInstance; -import net.minecraft.sound.SoundCategory; -import net.minecraft.sound.SoundEvent; +import net.minecraft.client.Minecraft; +import net.minecraft.client.resources.sounds.AbstractTickableSoundInstance; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundSource; -public abstract class AutomobileSoundInstance extends MovingSoundInstance { - private final MinecraftClient client; +public abstract class AutomobileSoundInstance extends AbstractTickableSoundInstance { + private final Minecraft client; private final AutomobileEntity automobile; private double lastDistance; @@ -15,12 +15,12 @@ public abstract class AutomobileSoundInstance extends MovingSoundInstance { private int fade = 0; private boolean die = false; - public AutomobileSoundInstance(SoundEvent sound, MinecraftClient client, AutomobileEntity automobile) { - super(sound, SoundCategory.AMBIENT, automobile.getEntityWorld().getRandom()); + public AutomobileSoundInstance(SoundEvent sound, Minecraft client, AutomobileEntity automobile) { + super(sound, SoundSource.AMBIENT, automobile.getCommandSenderWorld().getRandom()); this.client = client; this.automobile = automobile; - this.repeat = true; - this.repeatDelay = 0; + this.looping = true; + this.delay = 0; } protected abstract boolean canPlay(AutomobileEntity automobile); @@ -33,7 +33,7 @@ public AutomobileSoundInstance(SoundEvent sound, MinecraftClient client, Automob public void tick() { var player = this.client.player; if (automobile.isRemoved() || player == null) { - this.setDone(); + this.stop(); return; } else if (!this.canPlay(automobile)) { this.die = true; @@ -42,7 +42,7 @@ public void tick() { if (this.die) { if (this.fade > 0) this.fade--; else if (this.fade == 0) { - this.setDone(); + this.stop(); return; } } else if (this.fade < 3) { @@ -57,7 +57,7 @@ else if (this.fade == 0) { this.pitch = this.getPitch(this.automobile); if (player.getVehicle() != this.automobile) { - double distance = this.automobile.getPos().subtract(player.getPos()).length(); + double distance = this.automobile.position().subtract(player.position()).length(); this.pitch += (0.36 * Math.atan(lastDistance - distance)); this.lastDistance = distance; @@ -67,13 +67,13 @@ else if (this.fade == 0) { } public static class EngineSound extends AutomobileSoundInstance { - public EngineSound(MinecraftClient client, AutomobileEntity automobile) { - super(automobile.getEngine().sound(), client, automobile); + public EngineSound(Minecraft client, AutomobileEntity automobile) { + super(automobile.getEngine().sound().get(), client, automobile); } @Override protected boolean canPlay(AutomobileEntity automobile) { - return automobile.engineRunning() || automobile.getBoostTimer() > 0; + return automobile.engineRunning(); } @Override @@ -88,8 +88,8 @@ protected float getVolume(AutomobileEntity automobile) { } public static class SkiddingSound extends AutomobileSoundInstance { - public SkiddingSound(MinecraftClient client, AutomobileEntity automobile) { - super(AutomobilitySounds.SKID, client, automobile); + public SkiddingSound(Minecraft client, AutomobileEntity automobile) { + super(AutomobilitySounds.SKID.require(), client, automobile); } @Override 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 new file mode 100644 index 0000000..f3169c3 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/sound/AutomobilitySounds.java @@ -0,0 +1,28 @@ +package io.github.foundationgames.automobility.sound; + +import io.github.foundationgames.automobility.Automobility; +import io.github.foundationgames.automobility.util.Eventual; +import io.github.foundationgames.automobility.util.RegistryQueue; +import net.minecraft.core.Registry; +import net.minecraft.sounds.SoundEvent; + +public class AutomobilitySounds { + public static final Eventual COLLISION = register("entity.automobile.collision"); + public static final Eventual LANDING = register("entity.automobile.landing"); + public static final Eventual SKID = register("entity.automobile.skid"); + + public static final Eventual STONE_ENGINE = register("entity.automobile.stone_engine"); + public static final Eventual COPPER_ENGINE = register("entity.automobile.copper_engine"); + public static final Eventual IRON_ENGINE = register("entity.automobile.iron_engine"); + public static final Eventual GOLD_ENGINE = register("entity.automobile.gold_engine"); + public static final Eventual DIAMOND_ENGINE = register("entity.automobile.diamond_engine"); + public static final Eventual CREATIVE_ENGINE = register("entity.automobile.creative_engine"); + + private static Eventual register(String path) { + var id = Automobility.rl(path); + return RegistryQueue.register(Registry.SOUND_EVENT, id, () -> new SoundEvent(id)); + } + + public static void init() { + } +} diff --git a/src/main/java/io/github/foundationgames/automobility/util/AUtils.java b/common/src/main/java/io/github/foundationgames/automobility/util/AUtils.java similarity index 75% rename from src/main/java/io/github/foundationgames/automobility/util/AUtils.java rename to common/src/main/java/io/github/foundationgames/automobility/util/AUtils.java index 7b104dc..46eb7de 100644 --- a/src/main/java/io/github/foundationgames/automobility/util/AUtils.java +++ b/common/src/main/java/io/github/foundationgames/automobility/util/AUtils.java @@ -1,23 +1,22 @@ package io.github.foundationgames.automobility.util; +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.block.AutomobilityBlocks; import io.github.foundationgames.automobility.item.AutomobilityItems; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.render.model.BakedModel; -import net.minecraft.client.render.model.BakedQuad; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.inventory.Inventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.util.math.Direction; -import net.minecraft.util.math.Vec3d; -import net.minecraft.util.math.Vec3f; -import net.minecraft.util.math.random.Random; +import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.util.RandomSource; +import net.minecraft.world.Container; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.phys.Vec3; import java.text.DecimalFormat; @@ -42,7 +41,7 @@ public enum AUtils {; */ public static boolean IGNORE_ENTITY_GROUND_CHECK_STEPPING = false; - private static final Random RANDOM = Random.create(); + private static final RandomSource RANDOM = RandomSource.create(); /** * Shifts the number 'in' towards zero by the amount 'by' @@ -120,11 +119,11 @@ public static float furthestFromZero(float a, float b) { * @param vec The vector to be written * @return An NbtCompound containing the values of the passed vector */ - public static NbtCompound v3dToNbt(Vec3d vec) { - var r = new NbtCompound(); - r.putDouble("x", vec.getX()); - r.putDouble("y", vec.getY()); - r.putDouble("z", vec.getZ()); + public static CompoundTag v3dToNbt(Vec3 vec) { + var r = new CompoundTag(); + r.putDouble("x", vec.x()); + r.putDouble("y", vec.y()); + r.putDouble("z", vec.z()); return r; } @@ -133,8 +132,8 @@ public static NbtCompound v3dToNbt(Vec3d vec) { * @param nbt The NbtCompound to read from * @return A Vec3d containing the values in the passed NbtCompound */ - public static Vec3d v3dFromNbt(NbtCompound nbt) { - return new Vec3d(nbt.getDouble("x"), nbt.getDouble("y"), nbt.getDouble("z")); + public static Vec3 v3dFromNbt(CompoundTag nbt) { + return new Vec3(nbt.getDouble("x"), nbt.getDouble("y"), nbt.getDouble("z")); } /** @@ -145,11 +144,11 @@ public static Vec3d v3dFromNbt(NbtCompound nbt) { * @param light The lightmap coordinates to render with * @param overlay The overlay coordinates to render with */ - public static void renderMyronObj(BakedModel model, VertexConsumer vertices, MatrixStack matrices, int light, int overlay) { + public static void renderMyronObj(BakedModel model, VertexConsumer vertices, PoseStack matrices, int light, int overlay) { // For some reason with Iris, model.getQuads() throws a NPE try { for (BakedQuad quad : model.getQuads(null, null, RANDOM)) { - vertices.quad(matrices.peek(), quad, 1, 1, 1, light, overlay); + vertices.putBulkData(matrices.last(), quad, 1, 1, 1, light, overlay); } } catch (NullPointerException ignored) {} } @@ -159,15 +158,15 @@ public static void renderMyronObj(BakedModel model, VertexConsumer vertices, Mat * @param color An RGB color integer * @return A Vec3f containing the color integer's RGB, with x being r, y being g, and z being b. All values are from 0 to 1. */ - public static Vec3f colorFromInt(int color) { + public static Vector3f colorFromInt(int color) { int r = (color >> 16) & 0xFF; int g = (color >> 8) & 0xFF; int b = color & 0xFF; - return new Vec3f((float)r / 255, (float)g / 255, (float)b / 255); + return new Vector3f((float)r / 255, (float)g / 255, (float)b / 255); } public static boolean canMerge(ItemStack a, ItemStack b) { - return (a.isItemEqual(b)) && (a.getCount() + b.getCount() <= a.getMaxCount()); + return (a.sameItemStackIgnoreDurability(b)) && (a.getCount() + b.getCount() <= a.getMaxStackSize()); } /** @@ -177,18 +176,18 @@ public static boolean canMerge(ItemStack a, ItemStack b) { * @param inv The inventory to insert into * @return {@code true} if the entire stack was consumed, or {@code false} if some or all of the stack is remaining */ - public static boolean transferInto(ItemStack stack, Inventory inv) { - for (int slot = 0; slot < inv.size(); slot++) { - if (inv.isValid(slot, stack)) { - var slotStack = inv.getStack(slot); + public static boolean transferInto(ItemStack stack, Container inv) { + for (int slot = 0; slot < inv.getContainerSize(); slot++) { + if (inv.canPlaceItem(slot, stack)) { + var slotStack = inv.getItem(slot); if (slotStack.isEmpty()) { - inv.setStack(slot, stack); + inv.setItem(slot, stack); return true; } if (canMerge(slotStack, stack)) { - int amount = Math.min(stack.getCount(), stack.getMaxCount() - slotStack.getCount()); - stack.decrement(amount); - slotStack.increment(amount); + int amount = Math.min(stack.getCount(), stack.getMaxStackSize() - slotStack.getCount()); + stack.shrink(amount); + slotStack.grow(amount); return stack.isEmpty(); } } @@ -197,14 +196,10 @@ public static boolean transferInto(ItemStack stack, Inventory inv) { } public static ItemStack createGroupIcon() { - return new ItemStack(AutomobilityItems.CROWBAR); - } - - public static ItemStack createCourseElementsIcon() { - return new ItemStack(AutomobilityBlocks.SLOPED_DASH_PANEL); + return new ItemStack(AutomobilityItems.CROWBAR.require()); } public static ItemStack createPrefabsIcon() { - return new AutomobilePrefab(Automobility.id("standard_light_blue"), AutomobileFrame.STANDARD_LIGHT_BLUE, AutomobileWheel.STANDARD, AutomobileEngine.IRON).toStack(); + return new AutomobilePrefab(Automobility.rl("standard_light_blue"), AutomobileFrame.STANDARD_LIGHT_BLUE, AutomobileWheel.STANDARD, AutomobileEngine.IRON).toStack(); } } diff --git a/src/main/java/io/github/foundationgames/automobility/util/EntityRenderHelper.java b/common/src/main/java/io/github/foundationgames/automobility/util/EntityRenderHelper.java similarity index 56% rename from src/main/java/io/github/foundationgames/automobility/util/EntityRenderHelper.java rename to common/src/main/java/io/github/foundationgames/automobility/util/EntityRenderHelper.java index 0f12659..ab45c7d 100644 --- a/src/main/java/io/github/foundationgames/automobility/util/EntityRenderHelper.java +++ b/common/src/main/java/io/github/foundationgames/automobility/util/EntityRenderHelper.java @@ -1,19 +1,19 @@ package io.github.foundationgames.automobility.util; -import net.minecraft.client.render.entity.EntityRendererFactory; +import net.minecraft.client.renderer.entity.EntityRendererProvider; import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; public enum EntityRenderHelper {; - private static final List> LISTENERS = new ArrayList<>(); + private static final List> LISTENERS = new ArrayList<>(); - public static void registerContextListener(Consumer listener) { + public static void registerContextListener(Consumer listener) { LISTENERS.add(listener); } - public static void reload(EntityRendererFactory.Context ctx) { + public static void reload(EntityRendererProvider.Context ctx) { for (var l : LISTENERS) { l.accept(ctx); } diff --git a/common/src/main/java/io/github/foundationgames/automobility/util/Eventual.java b/common/src/main/java/io/github/foundationgames/automobility/util/Eventual.java new file mode 100644 index 0000000..47e01a5 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/util/Eventual.java @@ -0,0 +1,34 @@ +package io.github.foundationgames.automobility.util; + +import java.util.Optional; +import java.util.function.Supplier; + +public class Eventual { + private final Supplier provider; + private V value = null; + + public Eventual(Supplier provider) { + this.provider = provider; + } + + public Optional get() { + return Optional.ofNullable(value); + } + + public V require(String error) { + if (this.value == null) { + throw new RuntimeException(error); + } + + return this.value; + } + + public V require() { + return this.require("Not yet created!"); + } + + public V create() { + this.value = provider.get(); + return this.value; + } +} diff --git a/src/main/java/io/github/foundationgames/automobility/util/FloatFunc.java b/common/src/main/java/io/github/foundationgames/automobility/util/FloatFunc.java similarity index 100% rename from src/main/java/io/github/foundationgames/automobility/util/FloatFunc.java rename to common/src/main/java/io/github/foundationgames/automobility/util/FloatFunc.java diff --git a/common/src/main/java/io/github/foundationgames/automobility/util/HexCons.java b/common/src/main/java/io/github/foundationgames/automobility/util/HexCons.java new file mode 100644 index 0000000..9125176 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/util/HexCons.java @@ -0,0 +1,5 @@ +package io.github.foundationgames.automobility.util; + +public interface HexCons { + void accept(A a, B b, C c, D d, E e, F f); +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/util/InitlessConstants.java b/common/src/main/java/io/github/foundationgames/automobility/util/InitlessConstants.java new file mode 100644 index 0000000..a7e6228 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/util/InitlessConstants.java @@ -0,0 +1,5 @@ +package io.github.foundationgames.automobility.util; + +public enum InitlessConstants {; + public static final String AUTOMOBILITY = "automobility"; +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/util/RegistryQueue.java b/common/src/main/java/io/github/foundationgames/automobility/util/RegistryQueue.java new file mode 100644 index 0000000..0d9c116 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/util/RegistryQueue.java @@ -0,0 +1,27 @@ +package io.github.foundationgames.automobility.util; + +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Supplier; + +public class RegistryQueue extends ArrayList> { + private static final Map, RegistryQueue> QUEUES = new HashMap<>(); + + @SuppressWarnings("unchecked") + public static Eventual register(Registry registry, ResourceLocation rl, Supplier entry) { + var result = new Eventual<>(entry); + QUEUES.computeIfAbsent(registry, reg -> new RegistryQueue()).add((Entry) new Entry<>(result, rl)); + return result; + } + + @SuppressWarnings("unchecked") + public static RegistryQueue getQueue(Registry registry) { + return (RegistryQueue) QUEUES.get(registry); + } + + public record Entry (Eventual entry, ResourceLocation rl) {} +} diff --git a/src/main/java/io/github/foundationgames/automobility/util/SimpleMapContentRegistry.java b/common/src/main/java/io/github/foundationgames/automobility/util/SimpleMapContentRegistry.java similarity index 72% rename from src/main/java/io/github/foundationgames/automobility/util/SimpleMapContentRegistry.java rename to common/src/main/java/io/github/foundationgames/automobility/util/SimpleMapContentRegistry.java index d9274bd..fd068e7 100644 --- a/src/main/java/io/github/foundationgames/automobility/util/SimpleMapContentRegistry.java +++ b/common/src/main/java/io/github/foundationgames/automobility/util/SimpleMapContentRegistry.java @@ -1,7 +1,7 @@ package io.github.foundationgames.automobility.util; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; -import net.minecraft.util.Identifier; +import net.minecraft.resources.ResourceLocation; import java.util.ArrayList; import java.util.List; @@ -9,8 +9,8 @@ import java.util.function.Consumer; public class SimpleMapContentRegistry { - private final Map entries = new Object2ObjectOpenHashMap<>(); - private final List orderedKeys = new ArrayList<>(); + private final Map entries = new Object2ObjectOpenHashMap<>(); + private final List orderedKeys = new ArrayList<>(); public SimpleMapContentRegistry() { } @@ -21,11 +21,11 @@ public V register(V entry) { return entry; } - public V get(Identifier name) { + public V get(ResourceLocation name) { return entries.get(name); } - public V getOrDefault(Identifier name) { + public V getOrDefault(ResourceLocation name) { if (orderedKeys.size() <= 0) throw new IllegalStateException("Tried to get from empty registry!"); return entries.getOrDefault(name, entries.get(orderedKeys.get(0))); } @@ -35,6 +35,6 @@ public void forEach(Consumer action) { } public interface Identifiable { - Identifier getId(); + ResourceLocation getId(); } } diff --git a/common/src/main/java/io/github/foundationgames/automobility/util/TriCons.java b/common/src/main/java/io/github/foundationgames/automobility/util/TriCons.java new file mode 100644 index 0000000..b3ab892 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/util/TriCons.java @@ -0,0 +1,5 @@ +package io.github.foundationgames.automobility.util; + +public interface TriCons { + void accept(A a, B b, C c); +} diff --git a/common/src/main/java/io/github/foundationgames/automobility/util/TriFunc.java b/common/src/main/java/io/github/foundationgames/automobility/util/TriFunc.java new file mode 100644 index 0000000..1ee5298 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/util/TriFunc.java @@ -0,0 +1,5 @@ +package io.github.foundationgames.automobility.util; + +public interface TriFunc { + R apply(A a, B b, C c); +} diff --git a/src/main/java/io/github/foundationgames/automobility/util/duck/CollisionArea.java b/common/src/main/java/io/github/foundationgames/automobility/util/duck/CollisionArea.java similarity index 73% rename from src/main/java/io/github/foundationgames/automobility/util/duck/CollisionArea.java rename to common/src/main/java/io/github/foundationgames/automobility/util/duck/CollisionArea.java index e503f24..5f56701 100644 --- a/src/main/java/io/github/foundationgames/automobility/util/duck/CollisionArea.java +++ b/common/src/main/java/io/github/foundationgames/automobility/util/duck/CollisionArea.java @@ -1,17 +1,17 @@ package io.github.foundationgames.automobility.util.duck; -import net.minecraft.entity.Entity; -import net.minecraft.util.math.Box; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.phys.AABB; public interface CollisionArea { boolean isPointInside(double x, double y, double z); - boolean boxIntersects(Box box); + boolean boxIntersects(AABB box); double highestY(double x, double y, double z); static CollisionArea box(double ax, double ay, double az, double bx, double by, double bz) { - return (CollisionArea) new Box(ax, ay, az, bx, by, bz); + return (CollisionArea) new AABB(ax, ay, az, bx, by, bz); } static CollisionArea entity(Entity entity) { diff --git a/src/main/java/io/github/foundationgames/automobility/util/duck/EnderChestInventoryDuck.java b/common/src/main/java/io/github/foundationgames/automobility/util/duck/EnderChestContainerDuck.java similarity index 52% rename from src/main/java/io/github/foundationgames/automobility/util/duck/EnderChestInventoryDuck.java rename to common/src/main/java/io/github/foundationgames/automobility/util/duck/EnderChestContainerDuck.java index a366007..d63d636 100644 --- a/src/main/java/io/github/foundationgames/automobility/util/duck/EnderChestInventoryDuck.java +++ b/common/src/main/java/io/github/foundationgames/automobility/util/duck/EnderChestContainerDuck.java @@ -1,12 +1,12 @@ package io.github.foundationgames.automobility.util.duck; import io.github.foundationgames.automobility.automobile.attachment.rear.BaseChestRearAttachment; -import net.minecraft.inventory.EnderChestInventory; +import net.minecraft.world.inventory.PlayerEnderChestContainer; -public interface EnderChestInventoryDuck { +public interface EnderChestContainerDuck { void automobility$setActiveAttachment(BaseChestRearAttachment attachment); - static EnderChestInventoryDuck of(EnderChestInventory inv) { - return (EnderChestInventoryDuck) inv; + static EnderChestContainerDuck of(PlayerEnderChestContainer inv) { + return (EnderChestContainerDuck) inv; } } 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 new file mode 100644 index 0000000..cdcf0bc --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/util/network/ClientPackets.java @@ -0,0 +1,88 @@ +package io.github.foundationgames.automobility.util.network; + +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.AutomobileWheel; +import io.github.foundationgames.automobility.automobile.attachment.FrontAttachmentType; +import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType; +import io.github.foundationgames.automobility.automobile.attachment.rear.BannerPostRearAttachment; +import io.github.foundationgames.automobility.automobile.attachment.rear.ExtendableRearAttachment; +import io.github.foundationgames.automobility.entity.AutomobileEntity; +import io.github.foundationgames.automobility.platform.Platform; +import io.netty.buffer.Unpooled; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; + +public enum ClientPackets {; + public static void sendSyncAutomobileInputPacket(AutomobileEntity entity, boolean fwd, boolean back, boolean left, boolean right, boolean space) { + var buf = new FriendlyByteBuf(Unpooled.buffer()); + buf.writeBoolean(fwd); + buf.writeBoolean(back); + buf.writeBoolean(left); + buf.writeBoolean(right); + buf.writeBoolean(space); + buf.writeInt(entity.getId()); + Platform.get().clientSendPacket(Automobility.rl("sync_automobile_inputs"), buf); + } + + public static void requestSyncAutomobileComponentsPacket(AutomobileEntity entity) { + var buf = new FriendlyByteBuf(Unpooled.buffer()); + buf.writeInt(entity.getId()); + Platform.get().clientSendPacket(Automobility.rl("request_sync_automobile_components"), buf); + } + + public static void initClient() { + Platform.get().clientReceivePacket(Automobility.rl("sync_automobile_data"), (client, buf) -> { + FriendlyByteBuf dup = new FriendlyByteBuf(buf.copy()); + int entityId = dup.readInt(); + client.execute(() -> { + if (client.player.level.getEntity(entityId) instanceof AutomobileEntity automobile) { + automobile.readSyncToClientData(dup); + } + }); + }); + Platform.get().clientReceivePacket(Automobility.rl("sync_automobile_components"), (client, buf) -> { + int entityId = buf.readInt(); + var frame = AutomobileFrame.REGISTRY.getOrDefault(ResourceLocation.tryParse(buf.readUtf())); + 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) { + automobile.setComponents(frame, wheel, engine); + } + }); + }); + Platform.get().clientReceivePacket(Automobility.rl("sync_automobile_attachments"), (client, buf) -> { + int entityId = buf.readInt(); + 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) { + automobile.setRearAttachment(rearAtt); + automobile.setFrontAttachment(frontAtt); + } + }); + }); + Platform.get().clientReceivePacket(Automobility.rl("update_banner_post"), (client, buf) -> { + int entityId = buf.readInt(); + var banner = buf.readNbt(); + client.execute(() -> { + if (client.player.level.getEntity(entityId) instanceof AutomobileEntity automobile && + automobile.getRearAttachment() instanceof BannerPostRearAttachment bannerPost) { + bannerPost.setFromNbt(banner); + } + }); + }); + Platform.get().clientReceivePacket(Automobility.rl("update_extendable_attachment"), (client, buf) -> { + int entityId = buf.readInt(); + boolean extended = buf.readBoolean(); + client.execute(() -> { + 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 new file mode 100644 index 0000000..5d0c556 --- /dev/null +++ b/common/src/main/java/io/github/foundationgames/automobility/util/network/CommonPackets.java @@ -0,0 +1,89 @@ +package io.github.foundationgames.automobility.util.network; + +import io.github.foundationgames.automobility.Automobility; +import io.github.foundationgames.automobility.automobile.attachment.rear.BannerPostRearAttachment; +import io.github.foundationgames.automobility.automobile.attachment.rear.ExtendableRearAttachment; +import io.github.foundationgames.automobility.entity.AutomobileEntity; +import io.github.foundationgames.automobility.platform.Platform; +import io.netty.buffer.Unpooled; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.server.level.ServerPlayer; + +public enum CommonPackets {; + public static void sendSyncAutomobileDataPacket(AutomobileEntity entity, ServerPlayer player) { + var buf = new FriendlyByteBuf(Unpooled.buffer()); + buf.writeInt(entity.getId()); + entity.writeSyncToClientData(buf); + Platform.get().serverSendPacket(player, Automobility.rl("sync_automobile_data"), buf); + } + + public static void sendSyncAutomobileComponentsPacket(AutomobileEntity entity, ServerPlayer player) { + var buf = new FriendlyByteBuf(Unpooled.buffer()); + buf.writeInt(entity.getId()); + buf.writeUtf(entity.getFrame().id().toString()); + buf.writeUtf(entity.getWheels().id().toString()); + buf.writeUtf(entity.getEngine().id().toString()); + Platform.get().serverSendPacket(player, Automobility.rl("sync_automobile_components"), buf); + } + + public static void sendSyncAutomobileAttachmentsPacket(AutomobileEntity entity, ServerPlayer player) { + var buf = new FriendlyByteBuf(Unpooled.buffer()); + buf.writeInt(entity.getId()); + buf.writeUtf(entity.getRearAttachmentType().id().toString()); + buf.writeUtf(entity.getFrontAttachmentType().id().toString()); + Platform.get().serverSendPacket(player, Automobility.rl("sync_automobile_attachments"), buf); + } + + public static void sendBannerPostAttachmentUpdatePacket(AutomobileEntity entity, CompoundTag banner, ServerPlayer player) { + var buf = new FriendlyByteBuf(Unpooled.buffer()); + + if (entity.getRearAttachment() instanceof BannerPostRearAttachment) { + buf.writeInt(entity.getId()); + buf.writeNbt(banner); + Platform.get().serverSendPacket(player, Automobility.rl("update_banner_post"), buf); + } + } + + public static void sendExtendableAttachmentUpdatePacket(AutomobileEntity entity, boolean extended, ServerPlayer player) { + var buf = new FriendlyByteBuf(Unpooled.buffer()); + + if (entity.getRearAttachment() instanceof ExtendableRearAttachment) { + buf.writeInt(entity.getId()); + buf.writeBoolean(extended); + Platform.get().serverSendPacket(player, Automobility.rl("update_extendable_attachment"), buf); + } + } + + public static void init() { + Platform.get().serverReceivePacket(Automobility.rl("sync_automobile_inputs"), (server, player, buf) -> { + boolean fwd = buf.readBoolean(); + boolean back = buf.readBoolean(); + boolean left = buf.readBoolean(); + boolean right = buf.readBoolean(); + boolean space = buf.readBoolean(); + int entityId = buf.readInt(); + server.execute(() -> { + if (player.level.getEntity(entityId) instanceof AutomobileEntity automobile) { + automobile.setInputs(fwd, back, left, right, space); + automobile.markDirty(); + } + }); + }); + 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) { + sendSyncAutomobileComponentsPacket(automobile, player); + sendSyncAutomobileAttachmentsPacket(automobile, player); + + var fAtt = automobile.getFrontAttachment(); + if (fAtt != null) fAtt.updatePacketRequested(player); + + var rAtt = automobile.getRearAttachment(); + if (rAtt != null) rAtt.updatePacketRequested(player); + } + }); + }); + } +} diff --git a/src/main/resources/assets/automobility/blockstates/allow.json b/common/src/main/resources/assets/automobility/blockstates/allow.json similarity index 100% rename from src/main/resources/assets/automobility/blockstates/allow.json rename to common/src/main/resources/assets/automobility/blockstates/allow.json diff --git a/src/main/resources/assets/automobility/blockstates/auto_mechanic_table.json b/common/src/main/resources/assets/automobility/blockstates/auto_mechanic_table.json similarity index 100% rename from src/main/resources/assets/automobility/blockstates/auto_mechanic_table.json rename to common/src/main/resources/assets/automobility/blockstates/auto_mechanic_table.json diff --git a/src/main/resources/assets/automobility/blockstates/automobile_assembler.json b/common/src/main/resources/assets/automobility/blockstates/automobile_assembler.json similarity index 100% rename from src/main/resources/assets/automobility/blockstates/automobile_assembler.json rename to common/src/main/resources/assets/automobility/blockstates/automobile_assembler.json diff --git a/common/src/main/resources/assets/automobility/blockstates/dash_panel.json b/common/src/main/resources/assets/automobility/blockstates/dash_panel.json new file mode 100644 index 0000000..3314b26 --- /dev/null +++ b/common/src/main/resources/assets/automobility/blockstates/dash_panel.json @@ -0,0 +1,132 @@ +{ + "variants": { + "powered=false,left=true,right=false,facing=west": { + "model": "automobility:block/dash_panel_left", + "y": 270 + }, + "powered=false,left=true,right=true,facing=west": { + "model": "automobility:block/dash_panel_center", + "y": 270 + }, + "powered=false,left=false,right=false,facing=east": { + "model": "automobility:block/dash_panel_single", + "y": 450 + }, + "powered=false,left=false,right=true,facing=south": { + "model": "automobility:block/dash_panel_right", + "y": 180 + }, + "powered=false,left=true,right=true,facing=north": { + "model": "automobility:block/dash_panel_center", + "y": 360 + }, + "powered=false,left=false,right=false,facing=north": { + "model": "automobility:block/dash_panel_single", + "y": 360 + }, + "powered=false,left=false,right=true,facing=west": { + "model": "automobility:block/dash_panel_right", + "y": 270 + }, + "powered=false,left=false,right=false,facing=west": { + "model": "automobility:block/dash_panel_single", + "y": 270 + }, + "powered=false,left=false,right=true,facing=east": { + "model": "automobility:block/dash_panel_right", + "y": 450 + }, + "powered=false,left=true,right=false,facing=east": { + "model": "automobility:block/dash_panel_left", + "y": 450 + }, + "powered=false,left=true,right=false,facing=south": { + "model": "automobility:block/dash_panel_left", + "y": 180 + }, + "powered=false,left=false,right=false,facing=south": { + "model": "automobility:block/dash_panel_single", + "y": 180 + }, + "powered=false,left=true,right=true,facing=east": { + "model": "automobility:block/dash_panel_center", + "y": 450 + }, + "powered=false,left=false,right=true,facing=north": { + "model": "automobility:block/dash_panel_right", + "y": 360 + }, + "powered=false,left=true,right=false,facing=north": { + "model": "automobility:block/dash_panel_left", + "y": 360 + }, + "powered=false,left=true,right=true,facing=south": { + "model": "automobility:block/dash_panel_center", + "y": 180 + }, + "powered=true,left=true,right=false,facing=west": { + "model": "automobility:block/dash_panel_left_off", + "y": 270 + }, + "powered=true,left=true,right=true,facing=west": { + "model": "automobility:block/dash_panel_center_off", + "y": 270 + }, + "powered=true,left=false,right=false,facing=east": { + "model": "automobility:block/dash_panel_single_off", + "y": 450 + }, + "powered=true,left=false,right=true,facing=south": { + "model": "automobility:block/dash_panel_right_off", + "y": 180 + }, + "powered=true,left=true,right=true,facing=north": { + "model": "automobility:block/dash_panel_center_off", + "y": 360 + }, + "powered=true,left=false,right=false,facing=north": { + "model": "automobility:block/dash_panel_single_off", + "y": 360 + }, + "powered=true,left=false,right=true,facing=west": { + "model": "automobility:block/dash_panel_right_off", + "y": 270 + }, + "powered=true,left=false,right=false,facing=west": { + "model": "automobility:block/dash_panel_single_off", + "y": 270 + }, + "powered=true,left=false,right=true,facing=east": { + "model": "automobility:block/dash_panel_right_off", + "y": 450 + }, + "powered=true,left=true,right=false,facing=east": { + "model": "automobility:block/dash_panel_left_off", + "y": 450 + }, + "powered=true,left=true,right=false,facing=south": { + "model": "automobility:block/dash_panel_left_off", + "y": 180 + }, + "powered=true,left=false,right=false,facing=south": { + "model": "automobility:block/dash_panel_single_off", + "y": 180 + }, + "powered=true,left=true,right=true,facing=east": { + "model": "automobility:block/dash_panel_center_off", + "y": 450 + }, + "powered=true,left=false,right=true,facing=north": { + "model": "automobility:block/dash_panel_right_off", + "y": 360 + }, + "powered=true,left=true,right=false,facing=north": { + "model": "automobility:block/dash_panel_left_off", + "y": 360 + }, + "powered=true,left=true,right=true,facing=south": { + "model": "automobility:block/dash_panel_center_off", + "y": 180 + } + } +} \ No newline at end of file diff --git a/common/src/main/resources/assets/automobility/blockstates/dirt_off_road.json b/common/src/main/resources/assets/automobility/blockstates/dirt_off_road.json new file mode 100644 index 0000000..04154b7 --- /dev/null +++ b/common/src/main/resources/assets/automobility/blockstates/dirt_off_road.json @@ -0,0 +1,13 @@ +{ + "variants": { + "layers=3": { + "model": "automobility:block/dirt_off_road_2" + }, + "layers=1": { + "model": "automobility:block/dirt_off_road_0" + }, + "layers=2": { + "model": "automobility:block/dirt_off_road_1" + } + } +} \ No newline at end of file diff --git a/common/src/main/resources/assets/automobility/blockstates/grass_off_road.json b/common/src/main/resources/assets/automobility/blockstates/grass_off_road.json new file mode 100644 index 0000000..ff44ed4 --- /dev/null +++ b/common/src/main/resources/assets/automobility/blockstates/grass_off_road.json @@ -0,0 +1,13 @@ +{ + "variants": { + "layers=3": { + "model": "automobility:block/grass_off_road_2" + }, + "layers=1": { + "model": "automobility:block/grass_off_road_0" + }, + "layers=2": { + "model": "automobility:block/grass_off_road_1" + } + } +} \ No newline at end of file diff --git a/common/src/main/resources/assets/automobility/blockstates/launch_gel.json b/common/src/main/resources/assets/automobility/blockstates/launch_gel.json new file mode 100644 index 0000000..75e61f0 --- /dev/null +++ b/common/src/main/resources/assets/automobility/blockstates/launch_gel.json @@ -0,0 +1,7 @@ +{ + "variants": { + "": { + "model": "automobility:block/launch_gel" + } + } +} \ No newline at end of file diff --git a/common/src/main/resources/assets/automobility/blockstates/sand_off_road.json b/common/src/main/resources/assets/automobility/blockstates/sand_off_road.json new file mode 100644 index 0000000..5412711 --- /dev/null +++ b/common/src/main/resources/assets/automobility/blockstates/sand_off_road.json @@ -0,0 +1,13 @@ +{ + "variants": { + "layers=3": { + "model": "automobility:block/sand_off_road_2" + }, + "layers=1": { + "model": "automobility:block/sand_off_road_0" + }, + "layers=2": { + "model": "automobility:block/sand_off_road_1" + } + } +} \ No newline at end of file diff --git a/common/src/main/resources/assets/automobility/blockstates/slope.json b/common/src/main/resources/assets/automobility/blockstates/slope.json new file mode 100644 index 0000000..5f3eb16 --- /dev/null +++ b/common/src/main/resources/assets/automobility/blockstates/slope.json @@ -0,0 +1,36 @@ +{ + "variants": { + "half=bottom,facing=west": { + "model": "automobility:block/slope_bottom", + "y": 270 + }, + "half=bottom,facing=east": { + "model": "automobility:block/slope_bottom", + "y": 90 + }, + "half=bottom,facing=south": { + "model": "automobility:block/slope_bottom", + "y": 180 + }, + "half=bottom,facing=north": { + "model": "automobility:block/slope_bottom", + "y": 0 + }, + "half=top,facing=west": { + "model": "automobility:block/slope_top", + "y": 270 + }, + "half=top,facing=east": { + "model": "automobility:block/slope_top", + "y": 90 + }, + "half=top,facing=south": { + "model": "automobility:block/slope_top", + "y": 180 + }, + "half=top,facing=north": { + "model": "automobility:block/slope_top", + "y": 0 + } + } +} \ No newline at end of file diff --git a/common/src/main/resources/assets/automobility/blockstates/slope_with_dash_panel.json b/common/src/main/resources/assets/automobility/blockstates/slope_with_dash_panel.json new file mode 100644 index 0000000..95d3700 --- /dev/null +++ b/common/src/main/resources/assets/automobility/blockstates/slope_with_dash_panel.json @@ -0,0 +1,69 @@ +{ + "variants": { + "powered=false,half=bottom,facing=west": { + "model": "automobility:block/slope_bottom_dash_panel", + "y": 270 + }, + "powered=false,half=bottom,facing=east": { + "model": "automobility:block/slope_bottom_dash_panel", + "y": 90 + }, + "powered=false,half=bottom,facing=south": { + "model": "automobility:block/slope_bottom_dash_panel", + "y": 180 + }, + "powered=false,half=bottom,facing=north": { + "model": "automobility:block/slope_bottom_dash_panel", + "y": 0 + }, + "powered=false,half=top,facing=west": { + "model": "automobility:block/slope_top_dash_panel", + "y": 270 + }, + "powered=false,half=top,facing=east": { + "model": "automobility:block/slope_top_dash_panel", + "y": 90 + }, + "powered=false,half=top,facing=south": { + "model": "automobility:block/slope_top_dash_panel", + "y": 180 + }, + "powered=false,half=top,facing=north": { + "model": "automobility:block/slope_top_dash_panel", + "y": 0 + }, + + "powered=true,half=bottom,facing=west": { + "model": "automobility:block/slope_bottom_dash_panel_off", + "y": 270 + }, + "powered=true,half=bottom,facing=east": { + "model": "automobility:block/slope_bottom_dash_panel_off", + "y": 90 + }, + "powered=true,half=bottom,facing=south": { + "model": "automobility:block/slope_bottom_dash_panel_off", + "y": 180 + }, + "powered=true,half=bottom,facing=north": { + "model": "automobility:block/slope_bottom_dash_panel_off", + "y": 0 + }, + "powered=true,half=top,facing=west": { + "model": "automobility:block/slope_top_dash_panel_off", + "y": 270 + }, + "powered=true,half=top,facing=east": { + "model": "automobility:block/slope_top_dash_panel_off", + "y": 90 + }, + "powered=true,half=top,facing=south": { + "model": "automobility:block/slope_top_dash_panel_off", + "y": 180 + }, + "powered=true,half=top,facing=north": { + "model": "automobility:block/slope_top_dash_panel_off", + "y": 0 + } + } +} \ No newline at end of file diff --git a/common/src/main/resources/assets/automobility/blockstates/snow_off_road.json b/common/src/main/resources/assets/automobility/blockstates/snow_off_road.json new file mode 100644 index 0000000..7107291 --- /dev/null +++ b/common/src/main/resources/assets/automobility/blockstates/snow_off_road.json @@ -0,0 +1,13 @@ +{ + "variants": { + "layers=3": { + "model": "automobility:block/snow_off_road_2" + }, + "layers=1": { + "model": "automobility:block/snow_off_road_0" + }, + "layers=2": { + "model": "automobility:block/snow_off_road_1" + } + } +} \ No newline at end of file diff --git a/common/src/main/resources/assets/automobility/blockstates/steep_slope.json b/common/src/main/resources/assets/automobility/blockstates/steep_slope.json new file mode 100644 index 0000000..9f4e597 --- /dev/null +++ b/common/src/main/resources/assets/automobility/blockstates/steep_slope.json @@ -0,0 +1,20 @@ +{ + "variants": { + "facing=west": { + "model": "automobility:block/steep_slope", + "y": 270 + }, + "facing=east": { + "model": "automobility:block/steep_slope", + "y": 90 + }, + "facing=south": { + "model": "automobility:block/steep_slope", + "y": 180 + }, + "facing=north": { + "model": "automobility:block/steep_slope", + "y": 0 + } + } +} \ No newline at end of file diff --git a/common/src/main/resources/assets/automobility/blockstates/steep_slope_with_dash_panel.json b/common/src/main/resources/assets/automobility/blockstates/steep_slope_with_dash_panel.json new file mode 100644 index 0000000..defcceb --- /dev/null +++ b/common/src/main/resources/assets/automobility/blockstates/steep_slope_with_dash_panel.json @@ -0,0 +1,36 @@ +{ + "variants": { + "powered=false,facing=west": { + "model": "automobility:block/steep_slope_dash_panel", + "y": 270 + }, + "powered=false,facing=east": { + "model": "automobility:block/steep_slope_dash_panel", + "y": 90 + }, + "powered=false,facing=south": { + "model": "automobility:block/steep_slope_dash_panel", + "y": 180 + }, + "powered=false,facing=north": { + "model": "automobility:block/steep_slope_dash_panel", + "y": 0 + }, + "powered=true,facing=west": { + "model": "automobility:block/steep_slope_dash_panel_off", + "y": 270 + }, + "powered=true,facing=east": { + "model": "automobility:block/steep_slope_dash_panel_off", + "y": 90 + }, + "powered=true,facing=south": { + "model": "automobility:block/steep_slope_dash_panel_off", + "y": 180 + }, + "powered=true,facing=north": { + "model": "automobility:block/steep_slope_dash_panel_off", + "y": 0 + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/automobility/lang/en_us.json b/common/src/main/resources/assets/automobility/lang/en_us.json similarity index 99% rename from src/main/resources/assets/automobility/lang/en_us.json rename to common/src/main/resources/assets/automobility/lang/en_us.json index 948c91c..820b257 100644 --- a/src/main/resources/assets/automobility/lang/en_us.json +++ b/common/src/main/resources/assets/automobility/lang/en_us.json @@ -2,7 +2,6 @@ "entity.automobility.automobile": "Automobile", "itemGroup.automobility.automobility": "Automobility", - "itemGroup.automobility.automobility_course_elements": "Automobility: Course Elements", "itemGroup.automobility.automobility_prefabs": "Automobility: Prefabs", "automobility.automobility": "Automobility", @@ -20,6 +19,7 @@ "tooltip.item.automobility.crowbar": "Use on Automobile to remove", "tooltip.block.automobility.allow": "Let Adventure drivers harvest/plow", + "tooltip.block.automobility.dash_panel": "Can be placed on slopes", "container.automobility.auto_mechanic_table": "Auto Parts", "container.automobility.banner_post": "Banner", diff --git a/common/src/main/resources/assets/automobility/lang/ko_kr.json b/common/src/main/resources/assets/automobility/lang/ko_kr.json new file mode 100644 index 0000000..b892860 --- /dev/null +++ b/common/src/main/resources/assets/automobility/lang/ko_kr.json @@ -0,0 +1,193 @@ +{ + "entity.automobility.automobile": "자동차", + + "itemGroup.automobility.automobility": "자동차", + "itemGroup.automobility.automobility_prefabs": "자동차: 프리셋", + + "automobility.automobility": "자동차", + "midnightcontrols.action.automobility.accelerate_automobile": "가속", + "midnightcontrols.action.automobility.brake_automobile": "감속/후진", + "midnightcontrols.action.automobility.drift_automobile": "드리프트", + + "item.automobility.automobile": "자동차", + "item.automobility.crowbar": "빠루", + "item.automobility.rear_attachment": "후면 부착물", + "item.automobility.front_attachment": "앞면 부착물", + "item.automobility.automobile_frame": "자동차 프레임", + "item.automobility.automobile_wheel": "자동차 바퀴", + "item.automobility.automobile_engine": "자동차 엔진", + + "tooltip.item.automobility.crowbar": "제거하려면 자동차에 사용하십시오", + "tooltip.block.automobility.allow": "어드벤처 운전자가 수확/쟁기질 하도록 하십시오", + "tooltip.block.automobility.dash_panel": "경사에 설치할 수 있습니다", + + "container.automobility.auto_mechanic_table": "자동차 부품", + "container.automobility.banner_post": "배너", + + "part_category.automobility.frames": "프레임", + "part_category.automobility.engines": "엔진", + "part_category.automobility.wheels": "바퀴", + "part_category.automobility.attachments": "부착물", + + "block.automobility.grass_off_road": "잔디 오프로드", + "block.automobility.dirt_off_road": "흙 오프로드", + "block.automobility.sand_off_road": "모래 오프로드", + "block.automobility.snow_off_road": "눈 오프로드", + "block.automobility.launch_gel": "발사 젤", + "block.automobility.dash_panel": "부스터 판넬", + "block.automobility.sloped_dash_panel": "경사 진 대시 판넬", + "block.automobility.steep_sloped_dash_panel": "가파른 대시 판넬", + "block.automobility.auto_mechanic_table": "자동차 제작대", + "block.automobility.automobile_assembler": "자동차 조립대", + "block.automobility.allow": "Allow", + + "block.automobility.slope": "경사", + "block.automobility.steep_slope": "가파른 경사", + + "death.attack.automobile": "%1$이 로드킬 되었습니다.", + "death.attack.automobile.player": "%1$s 님이 %2$s을 피하려다가 움직이는 차량에 치였습니다.", + + "subtitles.automobility.automobile_engine": "자동차 엔진 소리", + "subtitles.automobility.collision": "자동차가 쿵하고 부딪히는 소리", + "subtitles.automobility.landing": "자동차가 쾅하고 부딪히는 소리", + "subtitles.automobility.skid": "자동차 스키드 소리", + + "dialog.automobility.use_crowbar": "파츠 제거를 위해 빠루를 사용하세요.", + "dialog.automobility.incomplete_automobile": "자동차가 완성되지 않았습니다.", + + "automobile_control.accelerate": "가속", + "automobile_control.brake": "감속/후진", + "automobile_control.steer_left": "좌로 돌림", + "automobile_control.steer_right": "우로 돌림", + "automobile_control.drift": "드리프트", + + "prefab.automobility.wooden_motorcar": "나무 자동차", + "prefab.automobility.copper_motorcar": "구리 자동차", + "prefab.automobility.steel_motorcar": "철 자동차", + "prefab.automobility.golden_motorcar": "황금 자동차", + "prefab.automobility.bejeweled_motorcar": "보석 자동차", + "prefab.automobility.standard_white": "표준 하얀색", + "prefab.automobility.standard_orange": "표준 주황색", + "prefab.automobility.standard_magenta": "표준 자홍색", + "prefab.automobility.standard_light_blue": "표준 하늘색", + "prefab.automobility.standard_yellow": "표준 노란색", + "prefab.automobility.standard_lime": "표준 연두색", + "prefab.automobility.standard_pink": "표준 핑크색", + "prefab.automobility.standard_gray": "표준 회색", + "prefab.automobility.standard_light_gray": "표준 회백색", + "prefab.automobility.standard_cyan": "표준 청록색", + "prefab.automobility.standard_purple": "표준 보라색", + "prefab.automobility.standard_blue": "표준 파란색", + "prefab.automobility.standard_brown": "표준 갈색", + "prefab.automobility.standard_green": "표준 초록색", + "prefab.automobility.standard_red": "표준 빨간색", + "prefab.automobility.standard_black": "표준 검은색", + "prefab.automobility.amethyst_rickshaw": "자수정 인력거", + "prefab.automobility.quartz_rickshaw": "석영 인력거", + "prefab.automobility.prismarine_rickshaw": "프리즈머린 인력거", + "prefab.automobility.echo_rickshaw": "에코 트랙터", + "prefab.automobility.red_tractor": "빨간색 트랙터", + "prefab.automobility.yellow_tractor": "노란색 트랙터", + "prefab.automobility.green_tractor": "초록색 트랙터", + "prefab.automobility.blue_tractor": "파란색 트랙터", + "prefab.automobility.shopping_cart": "쇼핑 카트", + "prefab.automobility.c_arr": "c:arr:", + "prefab.automobility.pineapple": "호박마차", + + "tooltip.automobility.frameLabel": "프레임: ", + "tooltip.automobility.wheelLabel": "바퀴: ", + "tooltip.automobility.engineLabel": "엔진: ", + "tooltip.automobility.shiftForStats": "[Shift를 눌러 스탯 보기]", + + "char.automobility.statSeparator": ": ", + + "stat.automobility.automobile.acceleration": "가속도", + "stat.automobility.automobile.acceleration.readout": "%s", + "stat.automobility.automobile.comfortable_speed": "일반 속도", + "stat.automobility.automobile.comfortable_speed.readout": "%s m/s", + "stat.automobility.automobile.handling": "핸들링", + "stat.automobility.automobile.handling.readout": "%s", + "stat.automobility.automobile.grip": "Grip", + "stat.automobility.automobile.grip.readout": "%s", + "stat.automobility.frame.weight": "무게", + "stat.automobility.frame.weight.readout": "%s", + "stat.automobility.wheel.size": "크기", + "stat.automobility.wheel.size.readout": "%s", + "stat.automobility.wheel.grip": "Grip", + "stat.automobility.wheel.grip.readout": "%s", + "stat.automobility.engine.torque": "토크", + "stat.automobility.engine.torque.readout": "%s", + "stat.automobility.engine.speed": "속도", + "stat.automobility.engine.speed.readout": "%s", + + "frame.automobility.wooden_motorcar": "나무", + "frame.automobility.copper_motorcar": "구리", + "frame.automobility.steel_motorcar": "철", + "frame.automobility.golden_motorcar": "황금", + "frame.automobility.bejeweled_motorcar": "보석", + "frame.automobility.standard_white": "표준 하얀색", + "frame.automobility.standard_orange": "표준 주황색", + "frame.automobility.standard_magenta": "표준 자홍색", + "frame.automobility.standard_light_blue": "표준 하늘색", + "frame.automobility.standard_yellow": "표준 노란색", + "frame.automobility.standard_lime": "표준 연두색", + "frame.automobility.standard_pink": "표준 분홍색", + "frame.automobility.standard_gray": "표준 회색", + "frame.automobility.standard_light_gray": "표준 회백색", + "frame.automobility.standard_cyan": "표준 청록색", + "frame.automobility.standard_purple": "표준 보라색", + "frame.automobility.standard_blue": "표준 파란색", + "frame.automobility.standard_brown": "표준 갈색", + "frame.automobility.standard_green": "표준 초록색", + "frame.automobility.standard_red": "표준 빨간색", + "frame.automobility.standard_black": "표준 검은색", + "frame.automobility.amethyst_rickshaw": "자수정 인력거", + "frame.automobility.quartz_rickshaw": "석영 인력거", + "frame.automobility.prismarine_rickshaw": "프리즈머린 인력거", + "frame.automobility.echo_rickshaw": "에코 인력거", + "frame.automobility.red_tractor": "빨간색 트랙터", + "frame.automobility.yellow_tractor": "노란색 트랙터", + "frame.automobility.green_tractor": "초록색 트랙터", + "frame.automobility.blue_tractor": "파란색 트랙터", + "frame.automobility.shopping_cart": "쇼핑 카트", + "frame.automobility.c_arr": "c:arr:", + "frame.automobility.dababy": "DaBaby", + "frame.automobility.pineapple": "호박마차", + + "wheel.automobility.standard": "표준", + "wheel.automobility.carriage": "마차", + "wheel.automobility.plated": "도금", + "wheel.automobility.street": "일반", + "wheel.automobility.gilded": "금 도금", + "wheel.automobility.bejeweled": "보석", + "wheel.automobility.off_road": "오프로드", + "wheel.automobility.tractor": "트랙터", + "wheel.automobility.steel": "철", + "wheel.automobility.convertible": "편안한", + + "engine.automobility.stone": "돌", + "engine.automobility.copper": "구리", + "engine.automobility.iron": "철", + "engine.automobility.gold": "금", + "engine.automobility.diamond": "다이아몬드", + "engine.automobility.creative": "크리에이티브", + + "attachment.rear.automobility.passenger_seat": "좌석", + "attachment.rear.automobility.crafting_table": "제작대", + "attachment.rear.automobility.loom": "베틀", + "attachment.rear.automobility.cartography_table": "지도 제작대", + "attachment.rear.automobility.smithing_table": "대장장이 작업대", + "attachment.rear.automobility.grindstone": "숫돌", + "attachment.rear.automobility.stonecutter": "석재 절단기", + "attachment.rear.automobility.auto_mechanic_table": "자동차 제작대", + "attachment.rear.automobility.chest": "상자", + "attachment.rear.automobility.ender_chest": "엔더 상자", + "attachment.rear.automobility.saddled_barrel": "통", + "attachment.rear.automobility.banner_post": "배너대", + "attachment.rear.automobility.backhoe": "백호", + "attachment.rear.automobility.paver": "페이버", + + "attachment.front.automobility.mob_controller": "몹 컨트롤러", + "attachment.front.automobility.crop_harvester": "작물 수확기", + "attachment.front.automobility.grass_cutter": "예초기" +} \ No newline at end of file diff --git a/src/main/resources/assets/automobility/lang/zh_cn.json b/common/src/main/resources/assets/automobility/lang/zh_cn.json similarity index 100% rename from src/main/resources/assets/automobility/lang/zh_cn.json rename to common/src/main/resources/assets/automobility/lang/zh_cn.json diff --git a/src/main/resources/assets/automobility/models/block/allow.json b/common/src/main/resources/assets/automobility/models/block/allow.json similarity index 100% rename from src/main/resources/assets/automobility/models/block/allow.json rename to common/src/main/resources/assets/automobility/models/block/allow.json diff --git a/src/main/resources/assets/automobility/models/block/auto_mechanic_table.json b/common/src/main/resources/assets/automobility/models/block/auto_mechanic_table.json similarity index 100% rename from src/main/resources/assets/automobility/models/block/auto_mechanic_table.json rename to common/src/main/resources/assets/automobility/models/block/auto_mechanic_table.json diff --git a/src/main/resources/assets/automobility/models/block/automobile_assembler.json b/common/src/main/resources/assets/automobility/models/block/automobile_assembler.json similarity index 99% rename from src/main/resources/assets/automobility/models/block/automobile_assembler.json rename to common/src/main/resources/assets/automobility/models/block/automobile_assembler.json index 56be927..03c1b1b 100644 --- a/src/main/resources/assets/automobility/models/block/automobile_assembler.json +++ b/common/src/main/resources/assets/automobility/models/block/automobile_assembler.json @@ -1,4 +1,5 @@ { + "render_type": "cutout", "parent": "block/block", "textures": { "0": "automobility:block/automobile_assembler_bottom", diff --git a/src/main/resources/assets/automobility/models/block/dash_panel_center.json b/common/src/main/resources/assets/automobility/models/block/dash_panel_center.json similarity index 100% rename from src/main/resources/assets/automobility/models/block/dash_panel_center.json rename to common/src/main/resources/assets/automobility/models/block/dash_panel_center.json diff --git a/common/src/main/resources/assets/automobility/models/block/dash_panel_center_off.json b/common/src/main/resources/assets/automobility/models/block/dash_panel_center_off.json new file mode 100644 index 0000000..0303358 --- /dev/null +++ b/common/src/main/resources/assets/automobility/models/block/dash_panel_center_off.json @@ -0,0 +1,47 @@ +{ + "parent": "minecraft:block/thin_block", + "ambientocclusion": false, + "textures": { + "0": "automobility:block/dash_panel_off", + "1": "automobility:block/dash_panel_frame", + "particle": "automobility:block/dash_panel_off" + }, + "elements": [ + { + "from": [0, 0, 1], + "to": [16, 1, 15], + "faces": { + "north": {"uv": [1, 0, 15, 1], "texture": "#0"}, + "east": {"uv": [1, 15, 15, 16], "texture": "#0"}, + "south": {"uv": [1, 15, 15, 16], "texture": "#0"}, + "west": {"uv": [1, 0, 15, 1], "texture": "#0"}, + "up": {"uv": [0, 1, 16, 15], "texture": "#0"}, + "down": {"uv": [0, 1, 16, 15], "texture": "#0"} + } + }, + { + "from": [0, 0, 0], + "to": [16, 1, 1], + "faces": { + "north": {"uv": [0, 0, 16, 1], "texture": "#1"}, + "east": {"uv": [15, 0, 16, 1], "texture": "#1"}, + "south": {"uv": [0, 0, 16, 1], "texture": "#1"}, + "west": {"uv": [0, 0, 1, 1], "texture": "#1"}, + "up": {"uv": [0, 0, 16, 1], "texture": "#1"}, + "down": {"uv": [0, 0, 16, 1], "texture": "#1"} + } + }, + { + "from": [0, 0, 15], + "to": [16, 1, 16], + "faces": { + "north": {"uv": [0, 0, 16, 1], "texture": "#1"}, + "east": {"uv": [15, 15, 16, 16], "texture": "#1"}, + "south": {"uv": [0, 15, 16, 16], "texture": "#1"}, + "west": {"uv": [0, 15, 1, 16], "texture": "#1"}, + "up": {"uv": [0, 15, 16, 16], "texture": "#1"}, + "down": {"uv": [0, 0, 16, 1], "texture": "#1"} + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/automobility/models/block/dash_panel_left.json b/common/src/main/resources/assets/automobility/models/block/dash_panel_left.json similarity index 100% rename from src/main/resources/assets/automobility/models/block/dash_panel_left.json rename to common/src/main/resources/assets/automobility/models/block/dash_panel_left.json diff --git a/common/src/main/resources/assets/automobility/models/block/dash_panel_left_off.json b/common/src/main/resources/assets/automobility/models/block/dash_panel_left_off.json new file mode 100644 index 0000000..1c8ad94 --- /dev/null +++ b/common/src/main/resources/assets/automobility/models/block/dash_panel_left_off.json @@ -0,0 +1,59 @@ +{ + "parent": "minecraft:block/thin_block", + "ambientocclusion": false, + "textures": { + "0": "automobility:block/dash_panel_off", + "1": "automobility:block/dash_panel_frame", + "particle": "automobility:block/dash_panel_off" + }, + "elements": [ + { + "from": [0, 0, 1], + "to": [15, 1, 15], + "faces": { + "north": {"uv": [1, 0, 15, 1], "texture": "#0"}, + "east": {"uv": [1, 15, 15, 16], "texture": "#0"}, + "south": {"uv": [1, 15, 15, 16], "texture": "#0"}, + "west": {"uv": [1, 0, 15, 1], "texture": "#0"}, + "up": {"uv": [0, 1, 15, 15], "texture": "#0"}, + "down": {"uv": [0, 1, 15, 15], "texture": "#0"} + } + }, + { + "from": [0, 0, 0], + "to": [16, 1, 1], + "faces": { + "north": {"uv": [0, 0, 16, 1], "texture": "#1"}, + "east": {"uv": [15, 0, 16, 1], "texture": "#1"}, + "south": {"uv": [0, 0, 16, 1], "texture": "#1"}, + "west": {"uv": [0, 0, 1, 1], "texture": "#1"}, + "up": {"uv": [0, 0, 16, 1], "texture": "#1"}, + "down": {"uv": [0, 0, 16, 1], "texture": "#1"} + } + }, + { + "from": [0, 0, 15], + "to": [16, 1, 16], + "faces": { + "north": {"uv": [0, 0, 16, 1], "texture": "#1"}, + "east": {"uv": [15, 15, 16, 16], "texture": "#1"}, + "south": {"uv": [0, 15, 16, 16], "texture": "#1"}, + "west": {"uv": [0, 15, 1, 16], "texture": "#1"}, + "up": {"uv": [0, 15, 16, 16], "texture": "#1"}, + "down": {"uv": [0, 0, 16, 1], "texture": "#1"} + } + }, + { + "from": [15, 0, 1], + "to": [16, 1, 15], + "faces": { + "north": {"uv": [0, 0, 1, 1], "texture": "#1"}, + "east": {"uv": [15, 1, 16, 15], "rotation": 90, "texture": "#1"}, + "south": {"uv": [0, 0, 1, 1], "texture": "#1"}, + "west": {"uv": [0, 0, 14, 1], "texture": "#1"}, + "up": {"uv": [15, 1, 16, 15], "texture": "#1"}, + "down": {"uv": [0, 0, 1, 14], "texture": "#1"} + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/automobility/models/block/dash_panel_right.json b/common/src/main/resources/assets/automobility/models/block/dash_panel_right.json similarity index 100% rename from src/main/resources/assets/automobility/models/block/dash_panel_right.json rename to common/src/main/resources/assets/automobility/models/block/dash_panel_right.json diff --git a/common/src/main/resources/assets/automobility/models/block/dash_panel_right_off.json b/common/src/main/resources/assets/automobility/models/block/dash_panel_right_off.json new file mode 100644 index 0000000..5af6fba --- /dev/null +++ b/common/src/main/resources/assets/automobility/models/block/dash_panel_right_off.json @@ -0,0 +1,59 @@ +{ + "parent": "minecraft:block/thin_block", + "ambientocclusion": false, + "textures": { + "0": "automobility:block/dash_panel_off", + "1": "automobility:block/dash_panel_frame", + "particle": "automobility:block/dash_panel_off" + }, + "elements": [ + { + "from": [1, 0, 1], + "to": [16, 1, 15], + "faces": { + "north": {"uv": [1, 0, 15, 1], "texture": "#0"}, + "east": {"uv": [1, 15, 15, 16], "texture": "#0"}, + "south": {"uv": [1, 15, 15, 16], "texture": "#0"}, + "west": {"uv": [1, 0, 15, 1], "texture": "#0"}, + "up": {"uv": [1, 1, 16, 15], "texture": "#0"}, + "down": {"uv": [1, 1, 16, 15], "texture": "#0"} + } + }, + { + "from": [0, 0, 0], + "to": [16, 1, 1], + "faces": { + "north": {"uv": [0, 0, 16, 1], "texture": "#1"}, + "east": {"uv": [15, 0, 16, 1], "texture": "#1"}, + "south": {"uv": [0, 0, 16, 1], "texture": "#1"}, + "west": {"uv": [0, 0, 1, 1], "texture": "#1"}, + "up": {"uv": [0, 0, 16, 1], "texture": "#1"}, + "down": {"uv": [0, 0, 16, 1], "texture": "#1"} + } + }, + { + "from": [0, 0, 15], + "to": [16, 1, 16], + "faces": { + "north": {"uv": [0, 0, 16, 1], "texture": "#1"}, + "east": {"uv": [15, 15, 16, 16], "texture": "#1"}, + "south": {"uv": [0, 15, 16, 16], "texture": "#1"}, + "west": {"uv": [0, 15, 1, 16], "texture": "#1"}, + "up": {"uv": [0, 15, 16, 16], "texture": "#1"}, + "down": {"uv": [0, 0, 16, 1], "texture": "#1"} + } + }, + { + "from": [0, 0, 1], + "to": [1, 1, 15], + "faces": { + "north": {"uv": [0, 0, 1, 1], "texture": "#1"}, + "east": {"uv": [0, 0, 14, 1], "texture": "#1"}, + "south": {"uv": [0, 0, 1, 1], "texture": "#1"}, + "west": {"uv": [0, 1, 1, 15], "rotation": 270, "texture": "#1"}, + "up": {"uv": [0, 1, 1, 15], "texture": "#1"}, + "down": {"uv": [0, 0, 1, 14], "texture": "#1"} + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/automobility/models/block/dash_panel_single.json b/common/src/main/resources/assets/automobility/models/block/dash_panel_single.json similarity index 100% rename from src/main/resources/assets/automobility/models/block/dash_panel_single.json rename to common/src/main/resources/assets/automobility/models/block/dash_panel_single.json diff --git a/common/src/main/resources/assets/automobility/models/block/dash_panel_single_off.json b/common/src/main/resources/assets/automobility/models/block/dash_panel_single_off.json new file mode 100644 index 0000000..c6435c8 --- /dev/null +++ b/common/src/main/resources/assets/automobility/models/block/dash_panel_single_off.json @@ -0,0 +1,78 @@ +{ + "parent": "minecraft:block/thin_block", + "ambientocclusion": false, + "textures": { + "0": "automobility:block/dash_panel_off", + "1": "automobility:block/dash_panel_frame", + "particle": "automobility:block/dash_panel_off" + }, + "elements": [ + { + "from": [1, 0, 1], + "to": [15, 1, 15], + "faces": { + "north": {"uv": [1, 0, 15, 1], "texture": "#0"}, + "east": {"uv": [1, 15, 15, 16], "texture": "#0"}, + "south": {"uv": [1, 15, 15, 16], "texture": "#0"}, + "west": {"uv": [1, 0, 15, 1], "texture": "#0"}, + "up": {"uv": [1, 1, 15, 15], "texture": "#0"}, + "down": {"uv": [1, 1, 15, 15], "texture": "#0"} + } + }, + { + "from": [0, 0, 0], + "to": [16, 1, 1], + "faces": { + "north": {"uv": [0, 0, 16, 1], "texture": "#1"}, + "east": {"uv": [15, 0, 16, 1], "texture": "#1"}, + "south": {"uv": [0, 0, 16, 1], "texture": "#1"}, + "west": {"uv": [0, 0, 1, 1], "texture": "#1"}, + "up": {"uv": [0, 0, 16, 1], "texture": "#1"}, + "down": {"uv": [0, 0, 16, 1], "texture": "#1"} + } + }, + { + "from": [0, 0, 15], + "to": [16, 1, 16], + "faces": { + "north": {"uv": [0, 0, 16, 1], "texture": "#1"}, + "east": {"uv": [15, 15, 16, 16], "texture": "#1"}, + "south": {"uv": [0, 15, 16, 16], "texture": "#1"}, + "west": {"uv": [0, 15, 1, 16], "texture": "#1"}, + "up": {"uv": [0, 15, 16, 16], "texture": "#1"}, + "down": {"uv": [0, 0, 16, 1], "texture": "#1"} + } + }, + { + "from": [0, 0, 1], + "to": [1, 1, 15], + "faces": { + "north": {"uv": [0, 0, 1, 1], "texture": "#1"}, + "east": {"uv": [0, 0, 14, 1], "texture": "#1"}, + "south": {"uv": [0, 0, 1, 1], "texture": "#1"}, + "west": {"uv": [0, 1, 1, 15], "rotation": 270, "texture": "#1"}, + "up": {"uv": [0, 1, 1, 15], "texture": "#1"}, + "down": {"uv": [0, 0, 1, 14], "texture": "#1"} + } + }, + { + "from": [15, 0, 1], + "to": [16, 1, 15], + "faces": { + "north": {"uv": [0, 0, 1, 1], "texture": "#1"}, + "east": {"uv": [15, 1, 16, 15], "rotation": 90, "texture": "#1"}, + "south": {"uv": [0, 0, 1, 1], "texture": "#1"}, + "west": {"uv": [0, 0, 14, 1], "texture": "#1"}, + "up": {"uv": [15, 1, 16, 15], "texture": "#1"}, + "down": {"uv": [0, 0, 1, 14], "texture": "#1"} + } + } + ], + "display": { + "gui": { + "rotation": [ 30, 315, 0 ], + "translation": [ 0, 0, 0], + "scale":[ 0.625, 0.625, 0.625 ] + } + } +} \ No newline at end of file diff --git a/common/src/main/resources/assets/automobility/models/block/dirt_off_road_0.json b/common/src/main/resources/assets/automobility/models/block/dirt_off_road_0.json new file mode 100644 index 0000000..f29eed7 --- /dev/null +++ b/common/src/main/resources/assets/automobility/models/block/dirt_off_road_0.json @@ -0,0 +1,7 @@ +{ + "parent": "automobility:block/template_off_road_0", + "textures": { + "off_road": "automobility:block/dirt_off_road" + }, + "elements": [] +} \ No newline at end of file diff --git a/common/src/main/resources/assets/automobility/models/block/dirt_off_road_1.json b/common/src/main/resources/assets/automobility/models/block/dirt_off_road_1.json new file mode 100644 index 0000000..8b0c1fc --- /dev/null +++ b/common/src/main/resources/assets/automobility/models/block/dirt_off_road_1.json @@ -0,0 +1,7 @@ +{ + "parent": "automobility:block/template_off_road_1", + "textures": { + "off_road": "automobility:block/dirt_off_road" + }, + "elements": [] +} \ No newline at end of file diff --git a/common/src/main/resources/assets/automobility/models/block/dirt_off_road_2.json b/common/src/main/resources/assets/automobility/models/block/dirt_off_road_2.json new file mode 100644 index 0000000..1d7ffc9 --- /dev/null +++ b/common/src/main/resources/assets/automobility/models/block/dirt_off_road_2.json @@ -0,0 +1,7 @@ +{ + "parent": "automobility:block/template_off_road_2", + "textures": { + "off_road": "automobility:block/dirt_off_road" + }, + "elements": [] +} \ No newline at end of file diff --git a/common/src/main/resources/assets/automobility/models/block/grass_off_road_0.json b/common/src/main/resources/assets/automobility/models/block/grass_off_road_0.json new file mode 100644 index 0000000..ff607ad --- /dev/null +++ b/common/src/main/resources/assets/automobility/models/block/grass_off_road_0.json @@ -0,0 +1,7 @@ +{ + "parent": "automobility:block/template_off_road_0", + "textures": { + "off_road": "automobility:block/grass_off_road" + }, + "elements": [] +} \ No newline at end of file diff --git a/common/src/main/resources/assets/automobility/models/block/grass_off_road_1.json b/common/src/main/resources/assets/automobility/models/block/grass_off_road_1.json new file mode 100644 index 0000000..608514b --- /dev/null +++ b/common/src/main/resources/assets/automobility/models/block/grass_off_road_1.json @@ -0,0 +1,7 @@ +{ + "parent": "automobility:block/template_off_road_1", + "textures": { + "off_road": "automobility:block/grass_off_road" + }, + "elements": [] +} \ No newline at end of file diff --git a/common/src/main/resources/assets/automobility/models/block/grass_off_road_2.json b/common/src/main/resources/assets/automobility/models/block/grass_off_road_2.json new file mode 100644 index 0000000..7e7d721 --- /dev/null +++ b/common/src/main/resources/assets/automobility/models/block/grass_off_road_2.json @@ -0,0 +1,7 @@ +{ + "parent": "automobility:block/template_off_road_2", + "textures": { + "off_road": "automobility:block/grass_off_road" + }, + "elements": [] +} \ No newline at end of file diff --git a/src/main/resources/assets/automobility/models/block/launch_gel.json b/common/src/main/resources/assets/automobility/models/block/launch_gel.json similarity index 92% rename from src/main/resources/assets/automobility/models/block/launch_gel.json rename to common/src/main/resources/assets/automobility/models/block/launch_gel.json index 4cd4314..a674296 100644 --- a/src/main/resources/assets/automobility/models/block/launch_gel.json +++ b/common/src/main/resources/assets/automobility/models/block/launch_gel.json @@ -1,5 +1,6 @@ { "ambientocclusion": false, + "render_type": "translucent", "textures": { "particle": "automobility:block/launch_gel", "gel": "automobility:block/launch_gel" diff --git a/common/src/main/resources/assets/automobility/models/block/sand_off_road_0.json b/common/src/main/resources/assets/automobility/models/block/sand_off_road_0.json new file mode 100644 index 0000000..4147677 --- /dev/null +++ b/common/src/main/resources/assets/automobility/models/block/sand_off_road_0.json @@ -0,0 +1,7 @@ +{ + "parent": "automobility:block/template_off_road_0", + "textures": { + "off_road": "automobility:block/sand_off_road" + }, + "elements": [] +} \ No newline at end of file diff --git a/common/src/main/resources/assets/automobility/models/block/sand_off_road_1.json b/common/src/main/resources/assets/automobility/models/block/sand_off_road_1.json new file mode 100644 index 0000000..1413beb --- /dev/null +++ b/common/src/main/resources/assets/automobility/models/block/sand_off_road_1.json @@ -0,0 +1,7 @@ +{ + "parent": "automobility:block/template_off_road_1", + "textures": { + "off_road": "automobility:block/sand_off_road" + }, + "elements": [] +} \ No newline at end of file diff --git a/common/src/main/resources/assets/automobility/models/block/sand_off_road_2.json b/common/src/main/resources/assets/automobility/models/block/sand_off_road_2.json new file mode 100644 index 0000000..5859061 --- /dev/null +++ b/common/src/main/resources/assets/automobility/models/block/sand_off_road_2.json @@ -0,0 +1,7 @@ +{ + "parent": "automobility:block/template_off_road_2", + "textures": { + "off_road": "automobility:block/sand_off_road" + }, + "elements": [] +} \ No newline at end of file diff --git a/common/src/main/resources/assets/automobility/models/block/snow_off_road_0.json b/common/src/main/resources/assets/automobility/models/block/snow_off_road_0.json new file mode 100644 index 0000000..a07102a --- /dev/null +++ b/common/src/main/resources/assets/automobility/models/block/snow_off_road_0.json @@ -0,0 +1,7 @@ +{ + "parent": "automobility:block/template_off_road_0", + "textures": { + "off_road": "automobility:block/snow_off_road" + }, + "elements": [] +} \ No newline at end of file diff --git a/common/src/main/resources/assets/automobility/models/block/snow_off_road_1.json b/common/src/main/resources/assets/automobility/models/block/snow_off_road_1.json new file mode 100644 index 0000000..76f32ae --- /dev/null +++ b/common/src/main/resources/assets/automobility/models/block/snow_off_road_1.json @@ -0,0 +1,7 @@ +{ + "parent": "automobility:block/template_off_road_1", + "textures": { + "off_road": "automobility:block/snow_off_road" + }, + "elements": [] +} \ No newline at end of file diff --git a/common/src/main/resources/assets/automobility/models/block/snow_off_road_2.json b/common/src/main/resources/assets/automobility/models/block/snow_off_road_2.json new file mode 100644 index 0000000..0f9da0c --- /dev/null +++ b/common/src/main/resources/assets/automobility/models/block/snow_off_road_2.json @@ -0,0 +1,7 @@ +{ + "parent": "automobility:block/template_off_road_2", + "textures": { + "off_road": "automobility:block/snow_off_road" + }, + "elements": [] +} \ No newline at end of file diff --git a/src/main/resources/assets/automobility/models/block/template_off_road_0.json b/common/src/main/resources/assets/automobility/models/block/template_off_road_0.json similarity index 100% rename from src/main/resources/assets/automobility/models/block/template_off_road_0.json rename to common/src/main/resources/assets/automobility/models/block/template_off_road_0.json diff --git a/src/main/resources/assets/automobility/models/block/template_off_road_1.json b/common/src/main/resources/assets/automobility/models/block/template_off_road_1.json similarity index 100% rename from src/main/resources/assets/automobility/models/block/template_off_road_1.json rename to common/src/main/resources/assets/automobility/models/block/template_off_road_1.json diff --git a/src/main/resources/assets/automobility/models/block/template_off_road_2.json b/common/src/main/resources/assets/automobility/models/block/template_off_road_2.json similarity index 100% rename from src/main/resources/assets/automobility/models/block/template_off_road_2.json rename to common/src/main/resources/assets/automobility/models/block/template_off_road_2.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile/engine/copper/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile/engine/copper/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile/engine/copper/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile/engine/copper/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile/engine/creative/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile/engine/creative/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile/engine/creative/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile/engine/creative/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile/engine/diamond/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile/engine/diamond/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile/engine/diamond/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile/engine/diamond/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile/engine/gold/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile/engine/gold/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile/engine/gold/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile/engine/gold/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile/engine/iron/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile/engine/iron/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile/engine/iron/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile/engine/iron/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile/engine/stone/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile/engine/stone/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile/engine/stone/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile/engine/stone/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile/frame/c_arr/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile/frame/c_arr/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile/frame/c_arr/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile/frame/c_arr/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile/frame/cruiser/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile/frame/cruiser/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile/frame/cruiser/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile/frame/cruiser/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile/frame/motorcar/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile/frame/motorcar/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile/frame/motorcar/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile/frame/motorcar/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile/frame/pineapple/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile/frame/pineapple/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile/frame/pineapple/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile/frame/pineapple/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile/frame/rickshaw/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile/frame/rickshaw/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile/frame/rickshaw/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile/frame/rickshaw/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile/frame/shopping_cart/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile/frame/shopping_cart/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile/frame/shopping_cart/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile/frame/shopping_cart/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile/frame/standard/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile/frame/standard/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile/frame/standard/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile/frame/standard/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile/frame/tractor/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile/frame/tractor/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile/frame/tractor/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile/frame/tractor/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile/front_attachment/harvester/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile/front_attachment/harvester/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile/front_attachment/harvester/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile/front_attachment/harvester/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile/front_attachment/mob_controller/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile/front_attachment/mob_controller/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile/front_attachment/mob_controller/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile/front_attachment/mob_controller/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile/rear_attachment/banner_post/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile/rear_attachment/banner_post/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile/rear_attachment/banner_post/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile/rear_attachment/banner_post/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile/rear_attachment/block/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile/rear_attachment/block/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile/rear_attachment/block/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile/rear_attachment/block/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile/rear_attachment/chest/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile/rear_attachment/chest/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile/rear_attachment/chest/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile/rear_attachment/chest/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile/rear_attachment/grindstone/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile/rear_attachment/grindstone/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile/rear_attachment/grindstone/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile/rear_attachment/grindstone/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile/rear_attachment/passenger_seat/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile/rear_attachment/passenger_seat/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile/rear_attachment/passenger_seat/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile/rear_attachment/passenger_seat/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile/rear_attachment/plow/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile/rear_attachment/plow/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile/rear_attachment/plow/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile/rear_attachment/plow/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile/rear_attachment/stonecutter/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile/rear_attachment/stonecutter/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile/rear_attachment/stonecutter/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile/rear_attachment/stonecutter/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile/wheel/carriage/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile/wheel/carriage/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile/wheel/carriage/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile/wheel/carriage/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile/wheel/off_road/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile/wheel/off_road/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile/wheel/off_road/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile/wheel/off_road/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile/wheel/standard/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile/wheel/standard/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile/wheel/standard/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile/wheel/standard/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile/wheel/steel/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile/wheel/steel/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile/wheel/steel/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile/wheel/steel/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile/wheel/tractor/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile/wheel/tractor/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile/wheel/tractor/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile/wheel/tractor/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile_exhaust_fumes/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile_exhaust_fumes/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile_exhaust_fumes/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile_exhaust_fumes/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile_skid_effect/main.json b/common/src/main/resources/assets/automobility/models/entity/automobile_skid_effect/main.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile_skid_effect/main.json rename to common/src/main/resources/assets/automobility/models/entity/automobile_skid_effect/main.json diff --git a/src/main/resources/assets/automobility/models/entity/automobile_skid_effect/old.json b/common/src/main/resources/assets/automobility/models/entity/automobile_skid_effect/old.json similarity index 100% rename from src/main/resources/assets/automobility/models/entity/automobile_skid_effect/old.json rename to common/src/main/resources/assets/automobility/models/entity/automobile_skid_effect/old.json diff --git a/src/main/resources/assets/automobility/models/item/allow.json b/common/src/main/resources/assets/automobility/models/item/allow.json similarity index 100% rename from src/main/resources/assets/automobility/models/item/allow.json rename to common/src/main/resources/assets/automobility/models/item/allow.json diff --git a/src/main/resources/assets/automobility/models/item/auto_mechanic_table.json b/common/src/main/resources/assets/automobility/models/item/auto_mechanic_table.json similarity index 100% rename from src/main/resources/assets/automobility/models/item/auto_mechanic_table.json rename to common/src/main/resources/assets/automobility/models/item/auto_mechanic_table.json diff --git a/src/main/resources/assets/automobility/models/item/automobile.json b/common/src/main/resources/assets/automobility/models/item/automobile.json similarity index 100% rename from src/main/resources/assets/automobility/models/item/automobile.json rename to common/src/main/resources/assets/automobility/models/item/automobile.json diff --git a/src/main/resources/assets/automobility/models/item/automobile_assembler.json b/common/src/main/resources/assets/automobility/models/item/automobile_assembler.json similarity index 100% rename from src/main/resources/assets/automobility/models/item/automobile_assembler.json rename to common/src/main/resources/assets/automobility/models/item/automobile_assembler.json diff --git a/src/main/resources/assets/automobility/models/item/automobile_engine.json b/common/src/main/resources/assets/automobility/models/item/automobile_engine.json similarity index 100% rename from src/main/resources/assets/automobility/models/item/automobile_engine.json rename to common/src/main/resources/assets/automobility/models/item/automobile_engine.json diff --git a/src/main/resources/assets/automobility/models/item/automobile_frame.json b/common/src/main/resources/assets/automobility/models/item/automobile_frame.json similarity index 100% rename from src/main/resources/assets/automobility/models/item/automobile_frame.json rename to common/src/main/resources/assets/automobility/models/item/automobile_frame.json diff --git a/src/main/resources/assets/automobility/models/item/automobile_wheel.json b/common/src/main/resources/assets/automobility/models/item/automobile_wheel.json similarity index 100% rename from src/main/resources/assets/automobility/models/item/automobile_wheel.json rename to common/src/main/resources/assets/automobility/models/item/automobile_wheel.json diff --git a/src/main/resources/assets/automobility/models/item/crowbar.json b/common/src/main/resources/assets/automobility/models/item/crowbar.json similarity index 100% rename from src/main/resources/assets/automobility/models/item/crowbar.json rename to common/src/main/resources/assets/automobility/models/item/crowbar.json diff --git a/src/main/resources/assets/automobility/models/item/dash_panel.json b/common/src/main/resources/assets/automobility/models/item/dash_panel.json similarity index 100% rename from src/main/resources/assets/automobility/models/item/dash_panel.json rename to common/src/main/resources/assets/automobility/models/item/dash_panel.json diff --git a/common/src/main/resources/assets/automobility/models/item/dirt_off_road.json b/common/src/main/resources/assets/automobility/models/item/dirt_off_road.json new file mode 100644 index 0000000..56878b3 --- /dev/null +++ b/common/src/main/resources/assets/automobility/models/item/dirt_off_road.json @@ -0,0 +1,4 @@ +{ + "parent": "automobility:block/dirt_off_road_0", + "elements": [] +} \ No newline at end of file diff --git a/src/main/resources/assets/automobility/models/item/front_attachment.json b/common/src/main/resources/assets/automobility/models/item/front_attachment.json similarity index 100% rename from src/main/resources/assets/automobility/models/item/front_attachment.json rename to common/src/main/resources/assets/automobility/models/item/front_attachment.json diff --git a/common/src/main/resources/assets/automobility/models/item/grass_off_road.json b/common/src/main/resources/assets/automobility/models/item/grass_off_road.json new file mode 100644 index 0000000..402c016 --- /dev/null +++ b/common/src/main/resources/assets/automobility/models/item/grass_off_road.json @@ -0,0 +1,4 @@ +{ + "parent": "automobility:block/grass_off_road_0", + "elements": [] +} \ No newline at end of file diff --git a/src/main/resources/assets/automobility/models/item/launch_gel.json b/common/src/main/resources/assets/automobility/models/item/launch_gel.json similarity index 100% rename from src/main/resources/assets/automobility/models/item/launch_gel.json rename to common/src/main/resources/assets/automobility/models/item/launch_gel.json diff --git a/src/main/resources/assets/automobility/models/item/rear_attachment.json b/common/src/main/resources/assets/automobility/models/item/rear_attachment.json similarity index 100% rename from src/main/resources/assets/automobility/models/item/rear_attachment.json rename to common/src/main/resources/assets/automobility/models/item/rear_attachment.json diff --git a/common/src/main/resources/assets/automobility/models/item/sand_off_road.json b/common/src/main/resources/assets/automobility/models/item/sand_off_road.json new file mode 100644 index 0000000..d8c9d49 --- /dev/null +++ b/common/src/main/resources/assets/automobility/models/item/sand_off_road.json @@ -0,0 +1,4 @@ +{ + "parent": "automobility:block/sand_off_road_0", + "elements": [] +} \ No newline at end of file diff --git a/common/src/main/resources/assets/automobility/models/item/slope.json b/common/src/main/resources/assets/automobility/models/item/slope.json new file mode 100644 index 0000000..a40ab58 --- /dev/null +++ b/common/src/main/resources/assets/automobility/models/item/slope.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "automobility:item/slope" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/automobility/models/item/sloped_dash_panel.json b/common/src/main/resources/assets/automobility/models/item/sloped_dash_panel.json similarity index 100% rename from src/main/resources/assets/automobility/models/item/sloped_dash_panel.json rename to common/src/main/resources/assets/automobility/models/item/sloped_dash_panel.json diff --git a/common/src/main/resources/assets/automobility/models/item/snow_off_road.json b/common/src/main/resources/assets/automobility/models/item/snow_off_road.json new file mode 100644 index 0000000..18aea1a --- /dev/null +++ b/common/src/main/resources/assets/automobility/models/item/snow_off_road.json @@ -0,0 +1,4 @@ +{ + "parent": "automobility:block/snow_off_road_0", + "elements": [] +} \ No newline at end of file diff --git a/common/src/main/resources/assets/automobility/models/item/steep_slope.json b/common/src/main/resources/assets/automobility/models/item/steep_slope.json new file mode 100644 index 0000000..1ea9f9c --- /dev/null +++ b/common/src/main/resources/assets/automobility/models/item/steep_slope.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "automobility:item/steep_slope" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/automobility/models/item/steep_sloped_dash_panel.json b/common/src/main/resources/assets/automobility/models/item/steep_sloped_dash_panel.json similarity index 100% rename from src/main/resources/assets/automobility/models/item/steep_sloped_dash_panel.json rename to common/src/main/resources/assets/automobility/models/item/steep_sloped_dash_panel.json diff --git a/common/src/main/resources/assets/automobility/particles/drift_smoke.json b/common/src/main/resources/assets/automobility/particles/drift_smoke.json new file mode 100644 index 0000000..6aa43ef --- /dev/null +++ b/common/src/main/resources/assets/automobility/particles/drift_smoke.json @@ -0,0 +1,5 @@ +{ + "textures": [ + "automobility:small_smoke_cloud" + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/automobility/sounds.json b/common/src/main/resources/assets/automobility/sounds.json similarity index 100% rename from src/main/resources/assets/automobility/sounds.json rename to common/src/main/resources/assets/automobility/sounds.json diff --git a/src/main/resources/assets/automobility/sounds/collision.ogg b/common/src/main/resources/assets/automobility/sounds/collision.ogg similarity index 100% rename from src/main/resources/assets/automobility/sounds/collision.ogg rename to common/src/main/resources/assets/automobility/sounds/collision.ogg diff --git a/src/main/resources/assets/automobility/sounds/copper_engine.ogg b/common/src/main/resources/assets/automobility/sounds/copper_engine.ogg similarity index 100% rename from src/main/resources/assets/automobility/sounds/copper_engine.ogg rename to common/src/main/resources/assets/automobility/sounds/copper_engine.ogg diff --git a/src/main/resources/assets/automobility/sounds/creative_engine.ogg b/common/src/main/resources/assets/automobility/sounds/creative_engine.ogg similarity index 100% rename from src/main/resources/assets/automobility/sounds/creative_engine.ogg rename to common/src/main/resources/assets/automobility/sounds/creative_engine.ogg diff --git a/src/main/resources/assets/automobility/sounds/diamond_engine.ogg b/common/src/main/resources/assets/automobility/sounds/diamond_engine.ogg similarity index 100% rename from src/main/resources/assets/automobility/sounds/diamond_engine.ogg rename to common/src/main/resources/assets/automobility/sounds/diamond_engine.ogg diff --git a/src/main/resources/assets/automobility/sounds/gold_engine.ogg b/common/src/main/resources/assets/automobility/sounds/gold_engine.ogg similarity index 100% rename from src/main/resources/assets/automobility/sounds/gold_engine.ogg rename to common/src/main/resources/assets/automobility/sounds/gold_engine.ogg diff --git a/src/main/resources/assets/automobility/sounds/iron_engine.ogg b/common/src/main/resources/assets/automobility/sounds/iron_engine.ogg similarity index 100% rename from src/main/resources/assets/automobility/sounds/iron_engine.ogg rename to common/src/main/resources/assets/automobility/sounds/iron_engine.ogg diff --git a/src/main/resources/assets/automobility/sounds/landing.ogg b/common/src/main/resources/assets/automobility/sounds/landing.ogg similarity index 100% rename from src/main/resources/assets/automobility/sounds/landing.ogg rename to common/src/main/resources/assets/automobility/sounds/landing.ogg diff --git a/src/main/resources/assets/automobility/sounds/skid.ogg b/common/src/main/resources/assets/automobility/sounds/skid.ogg similarity index 100% rename from src/main/resources/assets/automobility/sounds/skid.ogg rename to common/src/main/resources/assets/automobility/sounds/skid.ogg diff --git a/src/main/resources/assets/automobility/sounds/stone_engine.ogg b/common/src/main/resources/assets/automobility/sounds/stone_engine.ogg similarity index 100% rename from src/main/resources/assets/automobility/sounds/stone_engine.ogg rename to common/src/main/resources/assets/automobility/sounds/stone_engine.ogg diff --git a/src/main/resources/assets/automobility/textures/block/allow.png b/common/src/main/resources/assets/automobility/textures/block/allow.png similarity index 100% rename from src/main/resources/assets/automobility/textures/block/allow.png rename to common/src/main/resources/assets/automobility/textures/block/allow.png diff --git a/src/main/resources/assets/automobility/textures/block/auto_mechanic_table.png b/common/src/main/resources/assets/automobility/textures/block/auto_mechanic_table.png similarity index 100% rename from src/main/resources/assets/automobility/textures/block/auto_mechanic_table.png rename to common/src/main/resources/assets/automobility/textures/block/auto_mechanic_table.png diff --git a/src/main/resources/assets/automobility/textures/block/auto_mechanic_table_bottom.png b/common/src/main/resources/assets/automobility/textures/block/auto_mechanic_table_bottom.png similarity index 100% rename from src/main/resources/assets/automobility/textures/block/auto_mechanic_table_bottom.png rename to common/src/main/resources/assets/automobility/textures/block/auto_mechanic_table_bottom.png diff --git a/src/main/resources/assets/automobility/textures/block/automobile_assembler_bottom.png b/common/src/main/resources/assets/automobility/textures/block/automobile_assembler_bottom.png similarity index 100% rename from src/main/resources/assets/automobility/textures/block/automobile_assembler_bottom.png rename to common/src/main/resources/assets/automobility/textures/block/automobile_assembler_bottom.png diff --git a/src/main/resources/assets/automobility/textures/block/automobile_assembler_side.png b/common/src/main/resources/assets/automobility/textures/block/automobile_assembler_side.png similarity index 100% rename from src/main/resources/assets/automobility/textures/block/automobile_assembler_side.png rename to common/src/main/resources/assets/automobility/textures/block/automobile_assembler_side.png diff --git a/src/main/resources/assets/automobility/textures/block/automobile_assembler_top.png b/common/src/main/resources/assets/automobility/textures/block/automobile_assembler_top.png similarity index 100% rename from src/main/resources/assets/automobility/textures/block/automobile_assembler_top.png rename to common/src/main/resources/assets/automobility/textures/block/automobile_assembler_top.png diff --git a/src/main/resources/assets/automobility/textures/block/dash_panel.png b/common/src/main/resources/assets/automobility/textures/block/dash_panel.png similarity index 100% rename from src/main/resources/assets/automobility/textures/block/dash_panel.png rename to common/src/main/resources/assets/automobility/textures/block/dash_panel.png diff --git a/src/main/resources/assets/automobility/textures/block/dash_panel.png.mcmeta b/common/src/main/resources/assets/automobility/textures/block/dash_panel.png.mcmeta similarity index 100% rename from src/main/resources/assets/automobility/textures/block/dash_panel.png.mcmeta rename to common/src/main/resources/assets/automobility/textures/block/dash_panel.png.mcmeta diff --git a/src/main/resources/assets/automobility/textures/block/dash_panel_frame.png b/common/src/main/resources/assets/automobility/textures/block/dash_panel_frame.png similarity index 100% rename from src/main/resources/assets/automobility/textures/block/dash_panel_frame.png rename to common/src/main/resources/assets/automobility/textures/block/dash_panel_frame.png diff --git a/common/src/main/resources/assets/automobility/textures/block/dash_panel_off.png b/common/src/main/resources/assets/automobility/textures/block/dash_panel_off.png new file mode 100644 index 0000000..5528992 Binary files /dev/null and b/common/src/main/resources/assets/automobility/textures/block/dash_panel_off.png differ diff --git a/common/src/main/resources/assets/automobility/textures/block/dash_panel_off.png.mcmeta b/common/src/main/resources/assets/automobility/textures/block/dash_panel_off.png.mcmeta new file mode 100644 index 0000000..7d911f7 --- /dev/null +++ b/common/src/main/resources/assets/automobility/textures/block/dash_panel_off.png.mcmeta @@ -0,0 +1,24 @@ +{ + "animation": { + "frametime": 6, + "interpolate": true, + "frames": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15 + ] + } +} diff --git a/src/main/resources/assets/automobility/textures/block/dirt_off_road.png b/common/src/main/resources/assets/automobility/textures/block/dirt_off_road.png similarity index 100% rename from src/main/resources/assets/automobility/textures/block/dirt_off_road.png rename to common/src/main/resources/assets/automobility/textures/block/dirt_off_road.png diff --git a/src/main/resources/assets/automobility/textures/block/grass_off_road.png b/common/src/main/resources/assets/automobility/textures/block/grass_off_road.png similarity index 100% rename from src/main/resources/assets/automobility/textures/block/grass_off_road.png rename to common/src/main/resources/assets/automobility/textures/block/grass_off_road.png diff --git a/src/main/resources/assets/automobility/textures/block/launch_gel.png b/common/src/main/resources/assets/automobility/textures/block/launch_gel.png similarity index 100% rename from src/main/resources/assets/automobility/textures/block/launch_gel.png rename to common/src/main/resources/assets/automobility/textures/block/launch_gel.png diff --git a/src/main/resources/assets/automobility/textures/block/sand_off_road.png b/common/src/main/resources/assets/automobility/textures/block/sand_off_road.png similarity index 100% rename from src/main/resources/assets/automobility/textures/block/sand_off_road.png rename to common/src/main/resources/assets/automobility/textures/block/sand_off_road.png diff --git a/common/src/main/resources/assets/automobility/textures/block/slope_frame.png b/common/src/main/resources/assets/automobility/textures/block/slope_frame.png new file mode 100644 index 0000000..902a511 Binary files /dev/null and b/common/src/main/resources/assets/automobility/textures/block/slope_frame.png differ diff --git a/common/src/main/resources/assets/automobility/textures/block/snow_off_road.png b/common/src/main/resources/assets/automobility/textures/block/snow_off_road.png new file mode 100644 index 0000000..b6a9058 Binary files /dev/null and b/common/src/main/resources/assets/automobility/textures/block/snow_off_road.png differ diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/engine/copper.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/engine/copper.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/engine/copper.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/engine/copper.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/engine/creative.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/engine/creative.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/engine/creative.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/engine/creative.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/engine/diamond.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/engine/diamond.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/engine/diamond.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/engine/diamond.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/engine/gold.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/engine/gold.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/engine/gold.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/engine/gold.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/engine/iron.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/engine/iron.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/engine/iron.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/engine/iron.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/engine/stone.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/engine/stone.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/engine/stone.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/engine/stone.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_flames_0.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_flames_0.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_flames_0.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_flames_0.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_flames_1.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_flames_1.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_flames_1.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_flames_1.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_flames_2.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_flames_2.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_flames_2.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_flames_2.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_flames_3.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_flames_3.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_flames_3.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_flames_3.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_smoke_0.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_smoke_0.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_smoke_0.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_smoke_0.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_smoke_1.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_smoke_1.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_smoke_1.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_smoke_1.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_smoke_2.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_smoke_2.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_smoke_2.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_smoke_2.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_smoke_3.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_smoke_3.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_smoke_3.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/exhaust/exhaust_smoke_3.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/amethyst_rickshaw.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/amethyst_rickshaw.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/amethyst_rickshaw.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/amethyst_rickshaw.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/bejeweled_motorcar.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/bejeweled_motorcar.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/bejeweled_motorcar.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/bejeweled_motorcar.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/blue_tractor.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/blue_tractor.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/blue_tractor.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/blue_tractor.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/c_arr.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/c_arr.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/c_arr.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/c_arr.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/copper_motorcar.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/copper_motorcar.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/copper_motorcar.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/copper_motorcar.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/echo_rickshaw.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/echo_rickshaw.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/echo_rickshaw.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/echo_rickshaw.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/golden_motorcar.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/golden_motorcar.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/golden_motorcar.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/golden_motorcar.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/green_tractor.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/green_tractor.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/green_tractor.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/green_tractor.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/pineapple.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/pineapple.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/pineapple.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/pineapple.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/pineapple_src.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/pineapple_src.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/pineapple_src.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/pineapple_src.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/prismarine_rickshaw.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/prismarine_rickshaw.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/prismarine_rickshaw.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/prismarine_rickshaw.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/quartz_rickshaw.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/quartz_rickshaw.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/quartz_rickshaw.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/quartz_rickshaw.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/red_tractor.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/red_tractor.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/red_tractor.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/red_tractor.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/shopping_cart.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/shopping_cart.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/shopping_cart.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/shopping_cart.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_black.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_black.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_black.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_black.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_blue.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_blue.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_blue.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_blue.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_brown.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_brown.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_brown.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_brown.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_cyan.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_cyan.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_cyan.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_cyan.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_gray.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_gray.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_gray.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_gray.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_green.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_green.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_green.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_green.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_light_blue.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_light_blue.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_light_blue.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_light_blue.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_light_gray.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_light_gray.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_light_gray.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_light_gray.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_lime.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_lime.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_lime.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_lime.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_magenta.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_magenta.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_magenta.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_magenta.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_orange.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_orange.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_orange.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_orange.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_pink.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_pink.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_pink.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_pink.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_purple.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_purple.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_purple.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_purple.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_red.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_red.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_red.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_red.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_white.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_white.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_white.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_white.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_yellow.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_yellow.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_yellow.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/standard_yellow.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/steel_motorcar.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/steel_motorcar.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/steel_motorcar.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/steel_motorcar.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/wooden_motorcar.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/wooden_motorcar.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/wooden_motorcar.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/wooden_motorcar.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/wooden_motorcar_old.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/wooden_motorcar_old.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/wooden_motorcar_old.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/wooden_motorcar_old.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/frame/yellow_tractor.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/frame/yellow_tractor.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/frame/yellow_tractor.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/frame/yellow_tractor.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/front_attachment/crop_harvester.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/front_attachment/crop_harvester.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/front_attachment/crop_harvester.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/front_attachment/crop_harvester.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/front_attachment/grass_cutter.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/front_attachment/grass_cutter.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/front_attachment/grass_cutter.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/front_attachment/grass_cutter.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/front_attachment/mob_controller.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/front_attachment/mob_controller.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/front_attachment/mob_controller.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/front_attachment/mob_controller.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/auto_mechanic_table.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/auto_mechanic_table.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/auto_mechanic_table.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/auto_mechanic_table.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/backhoe.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/backhoe.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/backhoe.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/backhoe.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/banner_post.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/banner_post.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/banner_post.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/banner_post.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/cartography_table.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/cartography_table.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/cartography_table.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/cartography_table.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/chest.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/chest.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/chest.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/chest.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/crafting_table.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/crafting_table.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/crafting_table.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/crafting_table.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/ender_chest.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/ender_chest.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/ender_chest.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/ender_chest.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/grindstone.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/grindstone.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/grindstone.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/grindstone.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/loom.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/loom.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/loom.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/loom.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/painter.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/painter.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/painter.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/painter.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/passenger_seat.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/passenger_seat.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/passenger_seat.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/passenger_seat.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/paver.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/paver.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/paver.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/paver.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/saddled_barrel.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/saddled_barrel.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/saddled_barrel.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/saddled_barrel.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/smithing_table.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/smithing_table.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/smithing_table.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/smithing_table.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/stonecutter.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/stonecutter.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/stonecutter.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/rear_attachment/stonecutter.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/old/skid_smoke_0.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/old/skid_smoke_0.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/old/skid_smoke_0.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/old/skid_smoke_0.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/old/skid_smoke_1.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/old/skid_smoke_1.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/old/skid_smoke_1.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/old/skid_smoke_1.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/old/skid_smoke_2.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/old/skid_smoke_2.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/old/skid_smoke_2.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/old/skid_smoke_2.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/old/skid_sparks_0.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/old/skid_sparks_0.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/old/skid_sparks_0.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/old/skid_sparks_0.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/old/skid_sparks_1.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/old/skid_sparks_1.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/old/skid_sparks_1.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/old/skid_sparks_1.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/old/skid_sparks_2.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/old/skid_sparks_2.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/old/skid_sparks_2.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/old/skid_sparks_2.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_cool_sparks_0.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_cool_sparks_0.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_cool_sparks_0.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_cool_sparks_0.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_cool_sparks_1.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_cool_sparks_1.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_cool_sparks_1.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_cool_sparks_1.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_cool_sparks_2.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_cool_sparks_2.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_cool_sparks_2.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_cool_sparks_2.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_debris_0.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_debris_0.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_debris_0.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_debris_0.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_debris_1.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_debris_1.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_debris_1.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_debris_1.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_debris_2.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_debris_2.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_debris_2.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_debris_2.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_flames_0.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_flames_0.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_flames_0.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_flames_0.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_flames_1.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_flames_1.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_flames_1.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_flames_1.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_flames_2.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_flames_2.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_flames_2.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_flames_2.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_hot_sparks_0.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_hot_sparks_0.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_hot_sparks_0.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_hot_sparks_0.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_hot_sparks_1.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_hot_sparks_1.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_hot_sparks_1.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_hot_sparks_1.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_hot_sparks_2.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_hot_sparks_2.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_hot_sparks_2.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/skid_effect/skid_hot_sparks_2.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/wheel/bejeweled.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/wheel/bejeweled.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/wheel/bejeweled.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/wheel/bejeweled.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/wheel/carriage.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/wheel/carriage.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/wheel/carriage.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/wheel/carriage.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/wheel/gilded.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/wheel/gilded.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/wheel/gilded.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/wheel/gilded.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/wheel/off_road.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/wheel/off_road.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/wheel/off_road.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/wheel/off_road.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/wheel/plated.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/wheel/plated.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/wheel/plated.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/wheel/plated.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/wheel/standard.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/wheel/standard.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/wheel/standard.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/wheel/standard.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/wheel/steel.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/wheel/steel.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/wheel/steel.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/wheel/steel.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/wheel/street.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/wheel/street.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/wheel/street.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/wheel/street.png diff --git a/src/main/resources/assets/automobility/textures/entity/automobile/wheel/tractor.png b/common/src/main/resources/assets/automobility/textures/entity/automobile/wheel/tractor.png similarity index 100% rename from src/main/resources/assets/automobility/textures/entity/automobile/wheel/tractor.png rename to common/src/main/resources/assets/automobility/textures/entity/automobile/wheel/tractor.png diff --git a/src/main/resources/assets/automobility/textures/gui/container/auto_mechanic_table.png b/common/src/main/resources/assets/automobility/textures/gui/container/auto_mechanic_table.png similarity index 100% rename from src/main/resources/assets/automobility/textures/gui/container/auto_mechanic_table.png rename to common/src/main/resources/assets/automobility/textures/gui/container/auto_mechanic_table.png diff --git a/src/main/resources/assets/automobility/textures/gui/container/single_slot.png b/common/src/main/resources/assets/automobility/textures/gui/container/single_slot.png similarity index 100% rename from src/main/resources/assets/automobility/textures/gui/container/single_slot.png rename to common/src/main/resources/assets/automobility/textures/gui/container/single_slot.png diff --git a/src/main/resources/assets/automobility/textures/item/crowbar.png b/common/src/main/resources/assets/automobility/textures/item/crowbar.png similarity index 100% rename from src/main/resources/assets/automobility/textures/item/crowbar.png rename to common/src/main/resources/assets/automobility/textures/item/crowbar.png diff --git a/src/main/resources/assets/automobility/textures/item/launch_gel.png b/common/src/main/resources/assets/automobility/textures/item/launch_gel.png similarity index 100% rename from src/main/resources/assets/automobility/textures/item/launch_gel.png rename to common/src/main/resources/assets/automobility/textures/item/launch_gel.png diff --git a/common/src/main/resources/assets/automobility/textures/item/slope.png b/common/src/main/resources/assets/automobility/textures/item/slope.png new file mode 100644 index 0000000..3d5fffb Binary files /dev/null and b/common/src/main/resources/assets/automobility/textures/item/slope.png differ diff --git a/common/src/main/resources/assets/automobility/textures/item/steep_slope.png b/common/src/main/resources/assets/automobility/textures/item/steep_slope.png new file mode 100644 index 0000000..0008f29 Binary files /dev/null and b/common/src/main/resources/assets/automobility/textures/item/steep_slope.png differ diff --git a/src/main/resources/assets/automobility/textures/particle/drift_smoke.png b/common/src/main/resources/assets/automobility/textures/particle/small_smoke_cloud.png similarity index 100% rename from src/main/resources/assets/automobility/textures/particle/drift_smoke.png rename to common/src/main/resources/assets/automobility/textures/particle/small_smoke_cloud.png diff --git a/common/src/main/resources/automobility.mixins.json b/common/src/main/resources/automobility.mixins.json new file mode 100644 index 0000000..794b9ea --- /dev/null +++ b/common/src/main/resources/automobility.mixins.json @@ -0,0 +1,24 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "io.github.foundationgames.automobility.mixin", + "compatibilityLevel": "JAVA_17", + "refmap": "automobility-refmap.json", + "mixins": [ + "AABBMixin", + "PlayerEnderChestContainerMixin", + "EntityMixin", + "ItemCombinerMenuMixin", + "AbstractContainerMenuMixin", + "ServerGamePacketListenerImplMixin", + "ShovelItemAccess" + ], + "client": [ + "LocalPlayerMixin", + "MultiPlayerGameModeMixin", + "EntityRenderersMixin" + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/src/main/resources/assets/automobility/icon.png b/common/src/main/resources/automobility.png similarity index 100% rename from src/main/resources/assets/automobility/icon.png rename to common/src/main/resources/automobility.png diff --git a/src/main/resources/data/automobility/loot_tables/blocks/auto_mechanic_table.json b/common/src/main/resources/data/automobility/loot_tables/blocks/auto_mechanic_table.json similarity index 100% rename from src/main/resources/data/automobility/loot_tables/blocks/auto_mechanic_table.json rename to common/src/main/resources/data/automobility/loot_tables/blocks/auto_mechanic_table.json diff --git a/src/main/resources/data/automobility/loot_tables/blocks/automobile_assembler.json b/common/src/main/resources/data/automobility/loot_tables/blocks/automobile_assembler.json similarity index 100% rename from src/main/resources/data/automobility/loot_tables/blocks/automobile_assembler.json rename to common/src/main/resources/data/automobility/loot_tables/blocks/automobile_assembler.json diff --git a/common/src/main/resources/data/automobility/loot_tables/blocks/dash_panel.json b/common/src/main/resources/data/automobility/loot_tables/blocks/dash_panel.json new file mode 100644 index 0000000..7f8a955 --- /dev/null +++ b/common/src/main/resources/data/automobility/loot_tables/blocks/dash_panel.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "automobility:dash_panel" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} \ No newline at end of file diff --git a/common/src/main/resources/data/automobility/loot_tables/blocks/dirt_off_road.json b/common/src/main/resources/data/automobility/loot_tables/blocks/dirt_off_road.json new file mode 100644 index 0000000..e268270 --- /dev/null +++ b/common/src/main/resources/data/automobility/loot_tables/blocks/dirt_off_road.json @@ -0,0 +1,47 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "automobility:dirt_off_road", + "functions": [ + { + "function": "minecraft:set_count", + "conditions": [ + { + "block": "automobility:dirt_off_road", + "condition": "minecraft:block_state_property", + "properties": { + "layers": "2" + } + } + ], + "count": 2 + }, + { + "function": "minecraft:set_count", + "conditions": [ + { + "block": "automobility:dirt_off_road", + "condition": "minecraft:block_state_property", + "properties": { + "layers": "3" + } + } + ], + "count": 3 + } + ] + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} \ No newline at end of file diff --git a/common/src/main/resources/data/automobility/loot_tables/blocks/grass_off_road.json b/common/src/main/resources/data/automobility/loot_tables/blocks/grass_off_road.json new file mode 100644 index 0000000..443da9f --- /dev/null +++ b/common/src/main/resources/data/automobility/loot_tables/blocks/grass_off_road.json @@ -0,0 +1,47 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "automobility:grass_off_road", + "functions": [ + { + "function": "minecraft:set_count", + "conditions": [ + { + "block": "automobility:grass_off_road", + "condition": "minecraft:block_state_property", + "properties": { + "layers": "2" + } + } + ], + "count": 2 + }, + { + "function": "minecraft:set_count", + "conditions": [ + { + "block": "automobility:grass_off_road", + "condition": "minecraft:block_state_property", + "properties": { + "layers": "3" + } + } + ], + "count": 3 + } + ] + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} \ No newline at end of file diff --git a/common/src/main/resources/data/automobility/loot_tables/blocks/launch_gel.json b/common/src/main/resources/data/automobility/loot_tables/blocks/launch_gel.json new file mode 100644 index 0000000..7a423ff --- /dev/null +++ b/common/src/main/resources/data/automobility/loot_tables/blocks/launch_gel.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "automobility:launch_gel" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} \ No newline at end of file diff --git a/common/src/main/resources/data/automobility/loot_tables/blocks/sand_off_road.json b/common/src/main/resources/data/automobility/loot_tables/blocks/sand_off_road.json new file mode 100644 index 0000000..9c0b3a4 --- /dev/null +++ b/common/src/main/resources/data/automobility/loot_tables/blocks/sand_off_road.json @@ -0,0 +1,47 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "automobility:sand_off_road", + "functions": [ + { + "function": "minecraft:set_count", + "conditions": [ + { + "block": "automobility:sand_off_road", + "condition": "minecraft:block_state_property", + "properties": { + "layers": "2" + } + } + ], + "count": 2 + }, + { + "function": "minecraft:set_count", + "conditions": [ + { + "block": "automobility:sand_off_road", + "condition": "minecraft:block_state_property", + "properties": { + "layers": "3" + } + } + ], + "count": 3 + } + ] + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} \ No newline at end of file diff --git a/common/src/main/resources/data/automobility/loot_tables/blocks/slope.json b/common/src/main/resources/data/automobility/loot_tables/blocks/slope.json new file mode 100644 index 0000000..7a2ae22 --- /dev/null +++ b/common/src/main/resources/data/automobility/loot_tables/blocks/slope.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "automobility:slope" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} \ No newline at end of file diff --git a/common/src/main/resources/data/automobility/loot_tables/blocks/slope_with_dash_panel.json b/common/src/main/resources/data/automobility/loot_tables/blocks/slope_with_dash_panel.json new file mode 100644 index 0000000..ed0ae77 --- /dev/null +++ b/common/src/main/resources/data/automobility/loot_tables/blocks/slope_with_dash_panel.json @@ -0,0 +1,33 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "automobility:dash_panel" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + }, + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "automobility:slope" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} \ No newline at end of file diff --git a/common/src/main/resources/data/automobility/loot_tables/blocks/snow_off_road.json b/common/src/main/resources/data/automobility/loot_tables/blocks/snow_off_road.json new file mode 100644 index 0000000..cd562c0 --- /dev/null +++ b/common/src/main/resources/data/automobility/loot_tables/blocks/snow_off_road.json @@ -0,0 +1,47 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "automobility:snow_off_road", + "functions": [ + { + "function": "minecraft:set_count", + "conditions": [ + { + "block": "automobility:snow_off_road", + "condition": "minecraft:block_state_property", + "properties": { + "layers": "2" + } + } + ], + "count": 2 + }, + { + "function": "minecraft:set_count", + "conditions": [ + { + "block": "automobility:snow_off_road", + "condition": "minecraft:block_state_property", + "properties": { + "layers": "3" + } + } + ], + "count": 3 + } + ] + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} \ No newline at end of file diff --git a/common/src/main/resources/data/automobility/loot_tables/blocks/steep_slope.json b/common/src/main/resources/data/automobility/loot_tables/blocks/steep_slope.json new file mode 100644 index 0000000..643b5d7 --- /dev/null +++ b/common/src/main/resources/data/automobility/loot_tables/blocks/steep_slope.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "automobility:steep_slope" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} \ No newline at end of file diff --git a/common/src/main/resources/data/automobility/loot_tables/blocks/steep_slope_with_dash_panel.json b/common/src/main/resources/data/automobility/loot_tables/blocks/steep_slope_with_dash_panel.json new file mode 100644 index 0000000..d80b0c0 --- /dev/null +++ b/common/src/main/resources/data/automobility/loot_tables/blocks/steep_slope_with_dash_panel.json @@ -0,0 +1,33 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "automobility:dash_panel" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + }, + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "automobility:steep_slope" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/automobility/recipes/attachment/front/crop_harvester.json b/common/src/main/resources/data/automobility/recipes/attachment/front/crop_harvester.json similarity index 100% rename from src/main/resources/data/automobility/recipes/attachment/front/crop_harvester.json rename to common/src/main/resources/data/automobility/recipes/attachment/front/crop_harvester.json diff --git a/src/main/resources/data/automobility/recipes/attachment/front/grass_cutter.json b/common/src/main/resources/data/automobility/recipes/attachment/front/grass_cutter.json similarity index 100% rename from src/main/resources/data/automobility/recipes/attachment/front/grass_cutter.json rename to common/src/main/resources/data/automobility/recipes/attachment/front/grass_cutter.json diff --git a/src/main/resources/data/automobility/recipes/attachment/front/mob_controller.json b/common/src/main/resources/data/automobility/recipes/attachment/front/mob_controller.json similarity index 100% rename from src/main/resources/data/automobility/recipes/attachment/front/mob_controller.json rename to common/src/main/resources/data/automobility/recipes/attachment/front/mob_controller.json diff --git a/src/main/resources/data/automobility/recipes/attachment/rear/auto_mechanic_table.json b/common/src/main/resources/data/automobility/recipes/attachment/rear/auto_mechanic_table.json similarity index 100% rename from src/main/resources/data/automobility/recipes/attachment/rear/auto_mechanic_table.json rename to common/src/main/resources/data/automobility/recipes/attachment/rear/auto_mechanic_table.json diff --git a/src/main/resources/data/automobility/recipes/attachment/rear/backhoe.json b/common/src/main/resources/data/automobility/recipes/attachment/rear/backhoe.json similarity index 100% rename from src/main/resources/data/automobility/recipes/attachment/rear/backhoe.json rename to common/src/main/resources/data/automobility/recipes/attachment/rear/backhoe.json diff --git a/src/main/resources/data/automobility/recipes/attachment/rear/banner_post.json b/common/src/main/resources/data/automobility/recipes/attachment/rear/banner_post.json similarity index 100% rename from src/main/resources/data/automobility/recipes/attachment/rear/banner_post.json rename to common/src/main/resources/data/automobility/recipes/attachment/rear/banner_post.json diff --git a/src/main/resources/data/automobility/recipes/attachment/rear/cartography_table.json b/common/src/main/resources/data/automobility/recipes/attachment/rear/cartography_table.json similarity index 100% rename from src/main/resources/data/automobility/recipes/attachment/rear/cartography_table.json rename to common/src/main/resources/data/automobility/recipes/attachment/rear/cartography_table.json diff --git a/src/main/resources/data/automobility/recipes/attachment/rear/chest.json b/common/src/main/resources/data/automobility/recipes/attachment/rear/chest.json similarity index 100% rename from src/main/resources/data/automobility/recipes/attachment/rear/chest.json rename to common/src/main/resources/data/automobility/recipes/attachment/rear/chest.json diff --git a/src/main/resources/data/automobility/recipes/attachment/rear/crafting_table.json b/common/src/main/resources/data/automobility/recipes/attachment/rear/crafting_table.json similarity index 100% rename from src/main/resources/data/automobility/recipes/attachment/rear/crafting_table.json rename to common/src/main/resources/data/automobility/recipes/attachment/rear/crafting_table.json diff --git a/src/main/resources/data/automobility/recipes/attachment/rear/ender_chest.json b/common/src/main/resources/data/automobility/recipes/attachment/rear/ender_chest.json similarity index 100% rename from src/main/resources/data/automobility/recipes/attachment/rear/ender_chest.json rename to common/src/main/resources/data/automobility/recipes/attachment/rear/ender_chest.json diff --git a/src/main/resources/data/automobility/recipes/attachment/rear/grindstone.json b/common/src/main/resources/data/automobility/recipes/attachment/rear/grindstone.json similarity index 100% rename from src/main/resources/data/automobility/recipes/attachment/rear/grindstone.json rename to common/src/main/resources/data/automobility/recipes/attachment/rear/grindstone.json diff --git a/src/main/resources/data/automobility/recipes/attachment/rear/loom.json b/common/src/main/resources/data/automobility/recipes/attachment/rear/loom.json similarity index 100% rename from src/main/resources/data/automobility/recipes/attachment/rear/loom.json rename to common/src/main/resources/data/automobility/recipes/attachment/rear/loom.json diff --git a/src/main/resources/data/automobility/recipes/attachment/rear/passenger_seat.json b/common/src/main/resources/data/automobility/recipes/attachment/rear/passenger_seat.json similarity index 100% rename from src/main/resources/data/automobility/recipes/attachment/rear/passenger_seat.json rename to common/src/main/resources/data/automobility/recipes/attachment/rear/passenger_seat.json diff --git a/src/main/resources/data/automobility/recipes/attachment/rear/paver.json b/common/src/main/resources/data/automobility/recipes/attachment/rear/paver.json similarity index 100% rename from src/main/resources/data/automobility/recipes/attachment/rear/paver.json rename to common/src/main/resources/data/automobility/recipes/attachment/rear/paver.json diff --git a/src/main/resources/data/automobility/recipes/attachment/rear/saddled_barrel.json b/common/src/main/resources/data/automobility/recipes/attachment/rear/saddled_barrel.json similarity index 100% rename from src/main/resources/data/automobility/recipes/attachment/rear/saddled_barrel.json rename to common/src/main/resources/data/automobility/recipes/attachment/rear/saddled_barrel.json diff --git a/src/main/resources/data/automobility/recipes/attachment/rear/smithing_table.json b/common/src/main/resources/data/automobility/recipes/attachment/rear/smithing_table.json similarity index 100% rename from src/main/resources/data/automobility/recipes/attachment/rear/smithing_table.json rename to common/src/main/resources/data/automobility/recipes/attachment/rear/smithing_table.json diff --git a/src/main/resources/data/automobility/recipes/attachment/rear/stonecutter.json b/common/src/main/resources/data/automobility/recipes/attachment/rear/stonecutter.json similarity index 100% rename from src/main/resources/data/automobility/recipes/attachment/rear/stonecutter.json rename to common/src/main/resources/data/automobility/recipes/attachment/rear/stonecutter.json diff --git a/src/main/resources/data/automobility/recipes/auto_mechanic_table.json b/common/src/main/resources/data/automobility/recipes/auto_mechanic_table.json similarity index 100% rename from src/main/resources/data/automobility/recipes/auto_mechanic_table.json rename to common/src/main/resources/data/automobility/recipes/auto_mechanic_table.json diff --git a/src/main/resources/data/automobility/recipes/automobile_assembler.json b/common/src/main/resources/data/automobility/recipes/automobile_assembler.json similarity index 100% rename from src/main/resources/data/automobility/recipes/automobile_assembler.json rename to common/src/main/resources/data/automobility/recipes/automobile_assembler.json diff --git a/src/main/resources/data/automobility/recipes/crowbar.json b/common/src/main/resources/data/automobility/recipes/crowbar.json similarity index 100% rename from src/main/resources/data/automobility/recipes/crowbar.json rename to common/src/main/resources/data/automobility/recipes/crowbar.json diff --git a/common/src/main/resources/data/automobility/recipes/dash_panel.json b/common/src/main/resources/data/automobility/recipes/dash_panel.json new file mode 100644 index 0000000..e46925a --- /dev/null +++ b/common/src/main/resources/data/automobility/recipes/dash_panel.json @@ -0,0 +1,26 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "ABA", + "ACA", + "ADA" + ], + "key": { + "A": { + "item": "minecraft:iron_ingot" + }, + "B": { + "item": "minecraft:glow_ink_sac" + }, + "C": { + "item": "minecraft:redstone" + }, + "D": { + "item": "minecraft:blaze_powder" + } + }, + "result": { + "item": "automobility:dash_panel", + "count": 2 + } +} \ No newline at end of file diff --git a/common/src/main/resources/data/automobility/recipes/dirt_off_road.json b/common/src/main/resources/data/automobility/recipes/dirt_off_road.json new file mode 100644 index 0000000..3dd8a61 --- /dev/null +++ b/common/src/main/resources/data/automobility/recipes/dirt_off_road.json @@ -0,0 +1,18 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "ABA" + ], + "key": { + "A": { + "item": "minecraft:dirt" + }, + "B": { + "item": "minecraft:gravel" + } + }, + "result": { + "item": "automobility:dirt_off_road", + "count": 6 + } +} \ No newline at end of file diff --git a/src/main/resources/data/automobility/recipes/engine/copper_engine.json b/common/src/main/resources/data/automobility/recipes/engine/copper_engine.json similarity index 100% rename from src/main/resources/data/automobility/recipes/engine/copper_engine.json rename to common/src/main/resources/data/automobility/recipes/engine/copper_engine.json diff --git a/src/main/resources/data/automobility/recipes/engine/diamond_engine.json b/common/src/main/resources/data/automobility/recipes/engine/diamond_engine.json similarity index 100% rename from src/main/resources/data/automobility/recipes/engine/diamond_engine.json rename to common/src/main/resources/data/automobility/recipes/engine/diamond_engine.json diff --git a/src/main/resources/data/automobility/recipes/engine/gold_engine.json b/common/src/main/resources/data/automobility/recipes/engine/gold_engine.json similarity index 100% rename from src/main/resources/data/automobility/recipes/engine/gold_engine.json rename to common/src/main/resources/data/automobility/recipes/engine/gold_engine.json diff --git a/src/main/resources/data/automobility/recipes/engine/iron_engine.json b/common/src/main/resources/data/automobility/recipes/engine/iron_engine.json similarity index 100% rename from src/main/resources/data/automobility/recipes/engine/iron_engine.json rename to common/src/main/resources/data/automobility/recipes/engine/iron_engine.json diff --git a/src/main/resources/data/automobility/recipes/engine/stone_engine.json b/common/src/main/resources/data/automobility/recipes/engine/stone_engine.json similarity index 100% rename from src/main/resources/data/automobility/recipes/engine/stone_engine.json rename to common/src/main/resources/data/automobility/recipes/engine/stone_engine.json diff --git a/src/main/resources/data/automobility/recipes/frame/amethyst_rickshaw.json b/common/src/main/resources/data/automobility/recipes/frame/amethyst_rickshaw.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/amethyst_rickshaw.json rename to common/src/main/resources/data/automobility/recipes/frame/amethyst_rickshaw.json diff --git a/src/main/resources/data/automobility/recipes/frame/bejeweled_motorcar.json b/common/src/main/resources/data/automobility/recipes/frame/bejeweled_motorcar.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/bejeweled_motorcar.json rename to common/src/main/resources/data/automobility/recipes/frame/bejeweled_motorcar.json diff --git a/src/main/resources/data/automobility/recipes/frame/blue_tractor.json b/common/src/main/resources/data/automobility/recipes/frame/blue_tractor.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/blue_tractor.json rename to common/src/main/resources/data/automobility/recipes/frame/blue_tractor.json diff --git a/src/main/resources/data/automobility/recipes/frame/copper_motorcar.json b/common/src/main/resources/data/automobility/recipes/frame/copper_motorcar.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/copper_motorcar.json rename to common/src/main/resources/data/automobility/recipes/frame/copper_motorcar.json diff --git a/src/main/resources/data/automobility/recipes/frame/echo_rickshaw.json b/common/src/main/resources/data/automobility/recipes/frame/echo_rickshaw.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/echo_rickshaw.json rename to common/src/main/resources/data/automobility/recipes/frame/echo_rickshaw.json diff --git a/src/main/resources/data/automobility/recipes/frame/golden_motorcar.json b/common/src/main/resources/data/automobility/recipes/frame/golden_motorcar.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/golden_motorcar.json rename to common/src/main/resources/data/automobility/recipes/frame/golden_motorcar.json diff --git a/src/main/resources/data/automobility/recipes/frame/green_tractor.json b/common/src/main/resources/data/automobility/recipes/frame/green_tractor.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/green_tractor.json rename to common/src/main/resources/data/automobility/recipes/frame/green_tractor.json diff --git a/src/main/resources/data/automobility/recipes/frame/pineapple.json b/common/src/main/resources/data/automobility/recipes/frame/pineapple.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/pineapple.json rename to common/src/main/resources/data/automobility/recipes/frame/pineapple.json diff --git a/src/main/resources/data/automobility/recipes/frame/prismarine_rickshaw.json b/common/src/main/resources/data/automobility/recipes/frame/prismarine_rickshaw.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/prismarine_rickshaw.json rename to common/src/main/resources/data/automobility/recipes/frame/prismarine_rickshaw.json diff --git a/src/main/resources/data/automobility/recipes/frame/quartz_rickshaw.json b/common/src/main/resources/data/automobility/recipes/frame/quartz_rickshaw.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/quartz_rickshaw.json rename to common/src/main/resources/data/automobility/recipes/frame/quartz_rickshaw.json diff --git a/src/main/resources/data/automobility/recipes/frame/red_tractor.json b/common/src/main/resources/data/automobility/recipes/frame/red_tractor.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/red_tractor.json rename to common/src/main/resources/data/automobility/recipes/frame/red_tractor.json diff --git a/src/main/resources/data/automobility/recipes/frame/shopping_cart.json b/common/src/main/resources/data/automobility/recipes/frame/shopping_cart.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/shopping_cart.json rename to common/src/main/resources/data/automobility/recipes/frame/shopping_cart.json diff --git a/src/main/resources/data/automobility/recipes/frame/standard_black.json b/common/src/main/resources/data/automobility/recipes/frame/standard_black.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/standard_black.json rename to common/src/main/resources/data/automobility/recipes/frame/standard_black.json diff --git a/src/main/resources/data/automobility/recipes/frame/standard_blue.json b/common/src/main/resources/data/automobility/recipes/frame/standard_blue.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/standard_blue.json rename to common/src/main/resources/data/automobility/recipes/frame/standard_blue.json diff --git a/src/main/resources/data/automobility/recipes/frame/standard_brown.json b/common/src/main/resources/data/automobility/recipes/frame/standard_brown.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/standard_brown.json rename to common/src/main/resources/data/automobility/recipes/frame/standard_brown.json diff --git a/src/main/resources/data/automobility/recipes/frame/standard_cyan.json b/common/src/main/resources/data/automobility/recipes/frame/standard_cyan.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/standard_cyan.json rename to common/src/main/resources/data/automobility/recipes/frame/standard_cyan.json diff --git a/src/main/resources/data/automobility/recipes/frame/standard_gray.json b/common/src/main/resources/data/automobility/recipes/frame/standard_gray.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/standard_gray.json rename to common/src/main/resources/data/automobility/recipes/frame/standard_gray.json diff --git a/src/main/resources/data/automobility/recipes/frame/standard_green.json b/common/src/main/resources/data/automobility/recipes/frame/standard_green.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/standard_green.json rename to common/src/main/resources/data/automobility/recipes/frame/standard_green.json diff --git a/src/main/resources/data/automobility/recipes/frame/standard_light_blue.json b/common/src/main/resources/data/automobility/recipes/frame/standard_light_blue.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/standard_light_blue.json rename to common/src/main/resources/data/automobility/recipes/frame/standard_light_blue.json diff --git a/src/main/resources/data/automobility/recipes/frame/standard_light_gray.json b/common/src/main/resources/data/automobility/recipes/frame/standard_light_gray.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/standard_light_gray.json rename to common/src/main/resources/data/automobility/recipes/frame/standard_light_gray.json diff --git a/src/main/resources/data/automobility/recipes/frame/standard_lime.json b/common/src/main/resources/data/automobility/recipes/frame/standard_lime.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/standard_lime.json rename to common/src/main/resources/data/automobility/recipes/frame/standard_lime.json diff --git a/src/main/resources/data/automobility/recipes/frame/standard_magenta.json b/common/src/main/resources/data/automobility/recipes/frame/standard_magenta.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/standard_magenta.json rename to common/src/main/resources/data/automobility/recipes/frame/standard_magenta.json diff --git a/src/main/resources/data/automobility/recipes/frame/standard_orange.json b/common/src/main/resources/data/automobility/recipes/frame/standard_orange.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/standard_orange.json rename to common/src/main/resources/data/automobility/recipes/frame/standard_orange.json diff --git a/src/main/resources/data/automobility/recipes/frame/standard_pink.json b/common/src/main/resources/data/automobility/recipes/frame/standard_pink.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/standard_pink.json rename to common/src/main/resources/data/automobility/recipes/frame/standard_pink.json diff --git a/src/main/resources/data/automobility/recipes/frame/standard_purple.json b/common/src/main/resources/data/automobility/recipes/frame/standard_purple.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/standard_purple.json rename to common/src/main/resources/data/automobility/recipes/frame/standard_purple.json diff --git a/src/main/resources/data/automobility/recipes/frame/standard_red.json b/common/src/main/resources/data/automobility/recipes/frame/standard_red.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/standard_red.json rename to common/src/main/resources/data/automobility/recipes/frame/standard_red.json diff --git a/src/main/resources/data/automobility/recipes/frame/standard_white.json b/common/src/main/resources/data/automobility/recipes/frame/standard_white.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/standard_white.json rename to common/src/main/resources/data/automobility/recipes/frame/standard_white.json diff --git a/src/main/resources/data/automobility/recipes/frame/standard_yellow.json b/common/src/main/resources/data/automobility/recipes/frame/standard_yellow.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/standard_yellow.json rename to common/src/main/resources/data/automobility/recipes/frame/standard_yellow.json diff --git a/src/main/resources/data/automobility/recipes/frame/steel_motorcar.json b/common/src/main/resources/data/automobility/recipes/frame/steel_motorcar.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/steel_motorcar.json rename to common/src/main/resources/data/automobility/recipes/frame/steel_motorcar.json diff --git a/src/main/resources/data/automobility/recipes/frame/wooden_motorcar.json b/common/src/main/resources/data/automobility/recipes/frame/wooden_motorcar.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/wooden_motorcar.json rename to common/src/main/resources/data/automobility/recipes/frame/wooden_motorcar.json diff --git a/src/main/resources/data/automobility/recipes/frame/yellow_tractor.json b/common/src/main/resources/data/automobility/recipes/frame/yellow_tractor.json similarity index 100% rename from src/main/resources/data/automobility/recipes/frame/yellow_tractor.json rename to common/src/main/resources/data/automobility/recipes/frame/yellow_tractor.json diff --git a/common/src/main/resources/data/automobility/recipes/grass_off_road.json b/common/src/main/resources/data/automobility/recipes/grass_off_road.json new file mode 100644 index 0000000..d61ca56 --- /dev/null +++ b/common/src/main/resources/data/automobility/recipes/grass_off_road.json @@ -0,0 +1,18 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "ABA" + ], + "key": { + "A": { + "item": "minecraft:grass" + }, + "B": { + "item": "minecraft:coarse_dirt" + } + }, + "result": { + "item": "automobility:grass_off_road", + "count": 6 + } +} \ No newline at end of file diff --git a/common/src/main/resources/data/automobility/recipes/launch_gel.json b/common/src/main/resources/data/automobility/recipes/launch_gel.json new file mode 100644 index 0000000..45f3499 --- /dev/null +++ b/common/src/main/resources/data/automobility/recipes/launch_gel.json @@ -0,0 +1,18 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "ABA" + ], + "key": { + "A": { + "item": "minecraft:slime_ball" + }, + "B": { + "item": "minecraft:quartz" + } + }, + "result": { + "item": "automobility:launch_gel", + "count": 3 + } +} \ No newline at end of file diff --git a/common/src/main/resources/data/automobility/recipes/sand_off_road.json b/common/src/main/resources/data/automobility/recipes/sand_off_road.json new file mode 100644 index 0000000..bd2ba41 --- /dev/null +++ b/common/src/main/resources/data/automobility/recipes/sand_off_road.json @@ -0,0 +1,18 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "ABA" + ], + "key": { + "A": { + "item": "minecraft:sand" + }, + "B": { + "item": "minecraft:gravel" + } + }, + "result": { + "item": "automobility:sand_off_road", + "count": 6 + } +} \ No newline at end of file diff --git a/common/src/main/resources/data/automobility/recipes/slope.json b/common/src/main/resources/data/automobility/recipes/slope.json new file mode 100644 index 0000000..d4bd57c --- /dev/null +++ b/common/src/main/resources/data/automobility/recipes/slope.json @@ -0,0 +1,22 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + " AA", + "ABC" + ], + "key": { + "A": { + "item": "minecraft:iron_ingot" + }, + "B": { + "item": "minecraft:glow_ink_sac" + }, + "C": { + "item": "minecraft:slime_ball" + } + }, + "result": { + "item": "automobility:slope", + "count": 6 + } +} \ No newline at end of file diff --git a/common/src/main/resources/data/automobility/recipes/snow_off_road.json b/common/src/main/resources/data/automobility/recipes/snow_off_road.json new file mode 100644 index 0000000..e1eea4f --- /dev/null +++ b/common/src/main/resources/data/automobility/recipes/snow_off_road.json @@ -0,0 +1,18 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "ABA" + ], + "key": { + "A": { + "item": "minecraft:snow_block" + }, + "B": { + "item": "minecraft:gravel" + } + }, + "result": { + "item": "automobility:snow_off_road", + "count": 6 + } +} \ No newline at end of file diff --git a/common/src/main/resources/data/automobility/recipes/steep_slope.json b/common/src/main/resources/data/automobility/recipes/steep_slope.json new file mode 100644 index 0000000..5d82f59 --- /dev/null +++ b/common/src/main/resources/data/automobility/recipes/steep_slope.json @@ -0,0 +1,23 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + " A", + " AA", + "ABC" + ], + "key": { + "A": { + "item": "minecraft:iron_ingot" + }, + "B": { + "item": "minecraft:glow_ink_sac" + }, + "C": { + "item": "minecraft:slime_ball" + } + }, + "result": { + "item": "automobility:steep_slope", + "count": 3 + } +} \ No newline at end of file diff --git a/src/main/resources/data/automobility/recipes/wheel/bejeweled_wheel.json b/common/src/main/resources/data/automobility/recipes/wheel/bejeweled_wheel.json similarity index 100% rename from src/main/resources/data/automobility/recipes/wheel/bejeweled_wheel.json rename to common/src/main/resources/data/automobility/recipes/wheel/bejeweled_wheel.json diff --git a/src/main/resources/data/automobility/recipes/wheel/carriage_wheel.json b/common/src/main/resources/data/automobility/recipes/wheel/carriage_wheel.json similarity index 100% rename from src/main/resources/data/automobility/recipes/wheel/carriage_wheel.json rename to common/src/main/resources/data/automobility/recipes/wheel/carriage_wheel.json diff --git a/src/main/resources/data/automobility/recipes/wheel/gilded_wheel.json b/common/src/main/resources/data/automobility/recipes/wheel/gilded_wheel.json similarity index 100% rename from src/main/resources/data/automobility/recipes/wheel/gilded_wheel.json rename to common/src/main/resources/data/automobility/recipes/wheel/gilded_wheel.json diff --git a/src/main/resources/data/automobility/recipes/wheel/off_road_wheel.json b/common/src/main/resources/data/automobility/recipes/wheel/off_road_wheel.json similarity index 100% rename from src/main/resources/data/automobility/recipes/wheel/off_road_wheel.json rename to common/src/main/resources/data/automobility/recipes/wheel/off_road_wheel.json diff --git a/src/main/resources/data/automobility/recipes/wheel/plated_wheel.json b/common/src/main/resources/data/automobility/recipes/wheel/plated_wheel.json similarity index 100% rename from src/main/resources/data/automobility/recipes/wheel/plated_wheel.json rename to common/src/main/resources/data/automobility/recipes/wheel/plated_wheel.json diff --git a/src/main/resources/data/automobility/recipes/wheel/standard_wheel.json b/common/src/main/resources/data/automobility/recipes/wheel/standard_wheel.json similarity index 100% rename from src/main/resources/data/automobility/recipes/wheel/standard_wheel.json rename to common/src/main/resources/data/automobility/recipes/wheel/standard_wheel.json diff --git a/src/main/resources/data/automobility/recipes/wheel/steel_wheel.json b/common/src/main/resources/data/automobility/recipes/wheel/steel_wheel.json similarity index 100% rename from src/main/resources/data/automobility/recipes/wheel/steel_wheel.json rename to common/src/main/resources/data/automobility/recipes/wheel/steel_wheel.json diff --git a/src/main/resources/data/automobility/recipes/wheel/street_wheel.json b/common/src/main/resources/data/automobility/recipes/wheel/street_wheel.json similarity index 100% rename from src/main/resources/data/automobility/recipes/wheel/street_wheel.json rename to common/src/main/resources/data/automobility/recipes/wheel/street_wheel.json diff --git a/src/main/resources/data/automobility/recipes/wheel/tractor_wheel.json b/common/src/main/resources/data/automobility/recipes/wheel/tractor_wheel.json similarity index 100% rename from src/main/resources/data/automobility/recipes/wheel/tractor_wheel.json rename to common/src/main/resources/data/automobility/recipes/wheel/tractor_wheel.json diff --git a/src/main/resources/data/automobility/tags/entity_types/dash_panel_boostables.json b/common/src/main/resources/data/automobility/tags/entity_types/dash_panel_boostables.json similarity index 100% rename from src/main/resources/data/automobility/tags/entity_types/dash_panel_boostables.json rename to common/src/main/resources/data/automobility/tags/entity_types/dash_panel_boostables.json diff --git a/common/src/main/resources/data/minecraft/tags/blocks/mineable/pickaxe.json b/common/src/main/resources/data/minecraft/tags/blocks/mineable/pickaxe.json new file mode 100644 index 0000000..43ef48a --- /dev/null +++ b/common/src/main/resources/data/minecraft/tags/blocks/mineable/pickaxe.json @@ -0,0 +1,12 @@ +{ + "replace": false, + "values": [ + "automobility:auto_mechanic_table", + "automobility:automobile_assembler", + "automobility:dash_panel", + "automobility:slope", + "automobility:steep_slope", + "automobility:slope_with_dash_panel", + "automobility:steep_slope_with_dash_panel" + ] +} \ No newline at end of file diff --git a/common/src/main/resources/data/minecraft/tags/blocks/mineable/shovel.json b/common/src/main/resources/data/minecraft/tags/blocks/mineable/shovel.json new file mode 100644 index 0000000..497fe11 --- /dev/null +++ b/common/src/main/resources/data/minecraft/tags/blocks/mineable/shovel.json @@ -0,0 +1,9 @@ +{ + "replace": false, + "values": [ + "automobility:grass_off_road", + "automobility:dirt_off_road", + "automobility:sand_off_road", + "automobility:snow_off_road" + ] +} \ No newline at end of file diff --git a/fabric/build.gradle b/fabric/build.gradle new file mode 100644 index 0000000..133a5e0 --- /dev/null +++ b/fabric/build.gradle @@ -0,0 +1,98 @@ +plugins { + id 'fabric-loom' version '0.11-SNAPSHOT' + id 'maven-publish' +} + +version = "${project.mod_version}+${project.minecraft_version}-fabric" as Object + +repositories { + 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://api.modrinth.com/maven' } +} + +dependencies { + minecraft "com.mojang:minecraft:${project.minecraft_version}" + mappings loom.officialMojangMappings() + modImplementation "net.fabricmc:fabric-loader:${project.fabric_version}" + + // Fabric API + modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}" + + // Controller Support + modImplementation "dev.lambdaurora:spruceui:${project.spruceui_version}" + modImplementation "maven.modrinth:midnightlib:${project.midnightlib_version}" + modImplementation "maven.modrinth:midnightcontrols:${project.midnightcontrols_version}" + api('org.aperlambda:lambdajcommon:1.8.1') { + exclude group: 'com.google.code.gson' + exclude group: 'com.google.guava' + } + + // OBJ loader TODO: Update + // modImplementation "dev.monarkhes:myron:${project.myron_version}" + // include "dev.monarkhes:myron:${project.myron_version}" + + // Json't + modImplementation "net.devtech:arrp:${project.arrp_version}" + include "net.devtech:arrp:${project.arrp_version}" + + // Json entity models + modImplementation "maven.modrinth:jsonem:${project.jsonem_version}" + include "maven.modrinth:jsonem:${project.jsonem_version}" + + implementation project(':common') +} + +processResources { + from project(":common").sourceSets.main.resources + + inputs.property 'version', project.version + filesMatching('fabric.mod.json') { + expand 'version': project.version + } +} + +tasks.withType(JavaCompile) { + source(project(':common').sourceSets.main.allSource) +} + +tasks.withType(JavaCompile).configureEach { + it.options.encoding = 'UTF-8' + it.options.release = 17 +} + +loom { + runs { + client { + setConfigName('(Fabric) Client') + ideConfigGenerated(true) + runDir('run') + client() + } + server { + setConfigName('(Fabric) Server') + ideConfigGenerated(true) + runDir('run') + server() + } + } +} + +publishing { + publications { + mavenJava(MavenPublication) { + artifact(remapJar) { + builtBy remapJar + } + artifact(sourcesJar) { + builtBy remapSourcesJar + } + } + } + + repositories { + } +} diff --git a/fabric/src/main/java/io/github/foundationgames/automobility/fabric/AutomobilityClientFabric.java b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/AutomobilityClientFabric.java new file mode 100644 index 0000000..9c1bc90 --- /dev/null +++ b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/AutomobilityClientFabric.java @@ -0,0 +1,53 @@ +package io.github.foundationgames.automobility.fabric; + +import io.github.foundationgames.automobility.AutomobilityClient; +import io.github.foundationgames.automobility.block.AutomobilityBlocks; +import io.github.foundationgames.automobility.block.model.SlopeBakedModel; +import io.github.foundationgames.automobility.block.model.SlopeUnbakedModel; +import io.github.foundationgames.automobility.entity.AutomobileEntity; +import io.github.foundationgames.automobility.fabric.block.render.FabricSlopeBakedModel; +import io.github.foundationgames.automobility.fabric.resource.AutomobilityAssets; +import io.github.foundationgames.automobility.particle.AutomobilityParticles; +import io.github.foundationgames.automobility.particle.DriftSmokeParticle; +import io.github.foundationgames.automobility.screen.AutomobileHud; +import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; +import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry; +import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry; +import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry; +import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.RenderType; + +public class AutomobilityClientFabric implements ClientModInitializer { + @Override + public void onInitializeClient() { + FabricPlatform.init(); + + AutomobilityClient.init(); + AutomobilityAssets.setup(); + + ParticleFactoryRegistry.getInstance().register(AutomobilityParticles.DRIFT_SMOKE.require(), DriftSmokeParticle.Factory::new); + HudRenderCallback.EVENT.register((pose, tickDelta) -> { + var player = Minecraft.getInstance().player; + if (player.getVehicle() instanceof AutomobileEntity auto) { + AutomobileHud.render(pose, player, auto, tickDelta); + } + }); + + ColorProviderRegistry.BLOCK.register(AutomobilityClient.GRASS_COLOR, AutomobilityBlocks.GRASS_OFF_ROAD.require()); + ColorProviderRegistry.ITEM.register(AutomobilityClient.GRASS_ITEM_COLOR, AutomobilityBlocks.GRASS_OFF_ROAD.require()); + + SlopeBakedModel.impl = FabricSlopeBakedModel::new; + + ModelLoadingRegistry.INSTANCE.registerResourceProvider(manager -> (location, context) -> + SlopeUnbakedModel.DEFAULT_MODELS.containsKey(location) ? SlopeUnbakedModel.DEFAULT_MODELS.get(location).get() : null); + + BlockRenderLayerMap.INSTANCE.putBlock(AutomobilityBlocks.LAUNCH_GEL.require(), RenderType.translucent()); + BlockRenderLayerMap.INSTANCE.putBlock(AutomobilityBlocks.AUTOMOBILE_ASSEMBLER.require(), RenderType.cutout()); + BlockRenderLayerMap.INSTANCE.putBlock(AutomobilityBlocks.SLOPE.require(), RenderType.translucent()); + BlockRenderLayerMap.INSTANCE.putBlock(AutomobilityBlocks.STEEP_SLOPE.require(), RenderType.translucent()); + BlockRenderLayerMap.INSTANCE.putBlock(AutomobilityBlocks.SLOPE_WITH_DASH_PANEL.require(), RenderType.translucent()); + BlockRenderLayerMap.INSTANCE.putBlock(AutomobilityBlocks.STEEP_SLOPE_WITH_DASH_PANEL.require(), RenderType.translucent()); + } +} 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 new file mode 100644 index 0000000..1d815e3 --- /dev/null +++ b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/AutomobilityFabric.java @@ -0,0 +1,33 @@ +package io.github.foundationgames.automobility.fabric; + +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.util.RegistryQueue; +import net.fabricmc.api.ModInitializer; +import net.minecraft.core.Registry; + +public class AutomobilityFabric implements ModInitializer { + @Override + 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); + + AutomobilityData.setup(); + AutomobilityFabricBlocks.init(); + } + + public static void register(Registry registry) { + RegistryQueue.getQueue(registry).forEach(e -> Registry.register(registry, e.rl(), e.entry().create())); + } +} 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 new file mode 100644 index 0000000..7b0a88b --- /dev/null +++ b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/FabricPlatform.java @@ -0,0 +1,164 @@ +package io.github.foundationgames.automobility.fabric; + +import com.mojang.blaze3d.vertex.PoseStack; +import io.github.foundationgames.automobility.fabric.util.midnightcontrols.ControllerUtils; +import io.github.foundationgames.automobility.platform.Platform; +import io.github.foundationgames.automobility.util.HexCons; +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; +import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry; +import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +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.minecraft.client.Minecraft; +import net.minecraft.client.color.block.BlockColor; +import net.minecraft.client.gui.screens.MenuScreens; +import net.minecraft.client.gui.screens.Screen; +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; +import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.core.BlockPos; +import net.minecraft.core.particles.SimpleParticleType; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityDimensions; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.MobCategory; +import net.minecraft.world.entity.player.Inventory; +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.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.Nullable; + +import java.util.function.BiConsumer; +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.function.Supplier; + +public class FabricPlatform implements Platform { + private static final FabricPlatform INSTANCE = new FabricPlatform(); + + public static void init() { + Platform.init(INSTANCE); + } + + @Override + public CreativeModeTab creativeTab(ResourceLocation rl, Supplier icon) { + return FabricItemGroupBuilder.build(rl, icon); + } + + @Override + public void builtinItemRenderer(Item item, HexCons renderer) { + BuiltinItemRendererRegistry.INSTANCE.register(item, renderer::accept); + } + + @Override + public MenuType menuType(BiFunction factory) { + return new MenuType<>(factory::apply); + } + + @Override + public > void registerMenuScreen(MenuType type, TriFunc factory) { + MenuScreens.register(type, factory::apply); + } + + @Override + public @Nullable BlockColor blockColor(BlockState state) { + return ColorProviderRegistry.BLOCK.get(state.getBlock()); + } + + @Override + public BlockEntityType blockEntity(BiFunction factory, Block... blocks) { + return FabricBlockEntityTypeBuilder.create(factory::apply, blocks).build(); + } + + @Override + public void blockEntityRenderer(BlockEntityType type, Function> provider) { + BlockEntityRendererRegistry.register(type, provider::apply); + } + + @Override + public void serverSendPacket(ServerPlayer player, ResourceLocation rl, FriendlyByteBuf buf) { + ServerPlayNetworking.send(player, rl, buf); + } + + @Override + public void clientSendPacket(ResourceLocation rl, FriendlyByteBuf buf) { + ClientPlayNetworking.send(rl, buf); + } + + @Override + public void serverReceivePacket(ResourceLocation rl, TriCons run) { + ServerPlayNetworking.registerGlobalReceiver(rl, (server, player, handler, buf, responseSender) -> + run.accept(server, player, buf)); + } + + @Override + public void clientReceivePacket(ResourceLocation rl, BiConsumer run) { + ClientPlayNetworking.registerGlobalReceiver(rl, (client, handler, buf, responseSender) -> + run.accept(client, buf)); + } + + @Override + public EntityType entityType(MobCategory category, BiFunction, Level, T> factory, EntityDimensions size, int updateRate, int updateRange) { + return FabricEntityTypeBuilder.create(category, factory::apply).dimensions(size).trackedUpdateRate(updateRate).trackRangeChunks(updateRange).build(); + } + + @Override + public void entityRenderer(EntityType entity, Function> factory) { + EntityRendererRegistry.register(entity, factory::apply); + } + + @Override + public void modelLayer(ModelLayerLocation layer) { + JsonEM.registerModelLayer(layer); + } + + @Override + public SimpleParticleType simpleParticleType(boolean z) { + return FabricParticleTypes.simple(z); + } + + @Override + public boolean controllerAccel() { + return ControllerUtils.accelerating(); + } + + @Override + public boolean controllerBrake() { + return ControllerUtils.braking(); + } + + @Override + public boolean controllerDrift() { + return ControllerUtils.drifting(); + } + + @Override + public boolean inControllerMode() { + return ControllerUtils.inControllerMode(); + } +} 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 new file mode 100644 index 0000000..891737d --- /dev/null +++ b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/block/AutomobilityFabricBlocks.java @@ -0,0 +1,72 @@ +package io.github.foundationgames.automobility.fabric.block; + +import io.github.foundationgames.automobility.Automobility; +import io.github.foundationgames.automobility.block.SlopeBlock; +import io.github.foundationgames.automobility.block.SteepSlopeBlock; +import io.github.foundationgames.automobility.fabric.block.old.SlopedDashPanelBlock; +import io.github.foundationgames.automobility.fabric.block.old.SteepSlopedDashPanelBlock; +import io.github.foundationgames.automobility.fabric.resource.AutomobilityAssets; +import io.github.foundationgames.automobility.fabric.resource.AutomobilityData; +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.resources.ResourceLocation; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.StairBlock; +import net.minecraft.world.level.block.state.BlockBehaviour; + +import java.util.function.Function; + +public class AutomobilityFabricBlocks { + public static final Block SLOPED_DASH_PANEL = register("sloped_dash_panel", new SlopedDashPanelBlock(BlockBehaviour.Properties.copy(Blocks.IRON_BLOCK).lightLevel(s -> 1).emissiveRendering((state, world, pos) -> true))); + public static final Block STEEP_SLOPED_DASH_PANEL = register("steep_sloped_dash_panel", new SteepSlopedDashPanelBlock(BlockBehaviour.Properties.copy(Blocks.IRON_BLOCK).lightLevel(s -> 1).emissiveRendering((state, world, pos) -> true))); + + public static void init() { + registerSlopes("minecraft"); + } + + public static Block register(String name, Block block) { + return Registry.register(Registry.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)); + return register(name, block); + } + + private static void makeStairsSticky(Block candidate, ResourceLocation id) { + if (candidate instanceof StairBlock) { + AutomobilityData.STICKY_SLOPE_TAG_CANDIDATES.add(id); + AutomobilityData.STICKY_SLOPE_TAG_CANDIDATES.add(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) { + if (base.getClass().equals(Block.class)) { + var id = Registry.BLOCK.getKey(base); + if (id.getNamespace().equals(namespace)) { + var path = id.getPath()+"_slope"; + var steepPath = "steep_"+path; + register(path, new SlopeBlock(FabricBlockSettings.copyOf(base), true)); + var normalId = Automobility.rl(path); + var steepId = Automobility.rl(steepPath); + register(steepPath, new SteepSlopeBlock(FabricBlockSettings.copyOf(base), true)); + AutomobilityAssets.addProcessor(pack -> AutomobilityAssets.addMinecraftSlope(path, id.getPath())); + AutomobilityData.NON_STEEP_SLOPE_TAG_CANDIDATES.add(normalId); + AutomobilityData.STEEP_SLOPE_TAG_CANDIDATES.add(steepId); + } + } + + makeStairsSticky(base, Registry.BLOCK.getKey(base)); + } + + RegistryEntryAddedCallback.event(Registry.BLOCK).register((raw, id, block) -> { + makeStairsSticky(block, id); + }); + } +} diff --git a/fabric/src/main/java/io/github/foundationgames/automobility/fabric/block/old/SlopedDashPanelBlock.java b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/block/old/SlopedDashPanelBlock.java new file mode 100644 index 0000000..682f5d2 --- /dev/null +++ b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/block/old/SlopedDashPanelBlock.java @@ -0,0 +1,43 @@ +package io.github.foundationgames.automobility.fabric.block.old; + +import io.github.foundationgames.automobility.block.DashPanelBlock; +import io.github.foundationgames.automobility.block.SlopeBlock; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BooleanProperty; + +public class SlopedDashPanelBlock extends SlopeBlock { + public static final BooleanProperty LEFT = BooleanProperty.create("left"); + public static final BooleanProperty RIGHT = BooleanProperty.create("right"); + + public SlopedDashPanelBlock(Properties settings) { + super(settings, true); + + registerDefaultState(defaultBlockState().setValue(LEFT, false).setValue(RIGHT, false)); + } + + @Override + protected void createBlockStateDefinition(StateDefinition.Builder builder) { + super.createBlockStateDefinition(builder); + builder.add(LEFT, RIGHT); + } + + @Override + public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) { + super.entityInside(state, world, pos, entity); + DashPanelBlock.onCollideWithDashPanel(null, entity); + } + + @Override + public BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { + boolean left = world.getBlockState(pos.relative(state.getValue(FACING).getCounterClockWise(Direction.Axis.Y))).is(this); + boolean right = world.getBlockState(pos.relative(state.getValue(FACING).getClockWise(Direction.Axis.Y))).is(this); + return state.setValue(LEFT, left).setValue(RIGHT, right); + } +} diff --git a/fabric/src/main/java/io/github/foundationgames/automobility/fabric/block/old/SteepSlopedDashPanelBlock.java b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/block/old/SteepSlopedDashPanelBlock.java new file mode 100644 index 0000000..e44f783 --- /dev/null +++ b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/block/old/SteepSlopedDashPanelBlock.java @@ -0,0 +1,42 @@ +package io.github.foundationgames.automobility.fabric.block.old; + +import io.github.foundationgames.automobility.block.DashPanelBlock; +import io.github.foundationgames.automobility.block.SteepSlopeBlock; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BooleanProperty; + +public class SteepSlopedDashPanelBlock extends SteepSlopeBlock { + public static final BooleanProperty LEFT = BooleanProperty.create("left"); + public static final BooleanProperty RIGHT = BooleanProperty.create("right"); + + public SteepSlopedDashPanelBlock(Properties settings) { + super(settings, true); + registerDefaultState(defaultBlockState().setValue(LEFT, false).setValue(RIGHT, false)); + } + + @Override + protected void createBlockStateDefinition(StateDefinition.Builder builder) { + super.createBlockStateDefinition(builder); + builder.add(LEFT, RIGHT); + } + + @Override + public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) { + super.entityInside(state, world, pos, entity); + DashPanelBlock.onCollideWithDashPanel(null, entity); + } + + @Override + public BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { + boolean left = world.getBlockState(pos.relative(state.getValue(FACING).getCounterClockWise(Direction.Axis.Y))).is(this); + boolean right = world.getBlockState(pos.relative(state.getValue(FACING).getClockWise(Direction.Axis.Y))).is(this); + return state.setValue(LEFT, left).setValue(RIGHT, right); + } +} 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 new file mode 100644 index 0000000..0ebf492 --- /dev/null +++ b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/block/render/FabricGeometryBuilder.java @@ -0,0 +1,59 @@ +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; + +public class FabricGeometryBuilder implements GeometryBuilder { + private final QuadEmitter quads; + private final Matrix4f transform; + + private int index = 0; + + public FabricGeometryBuilder(QuadEmitter quads, Matrix4f transform) { + this.quads = quads; + this.transform = transform; + } + + @Override + public GeometryBuilder vertex(float x, float y, float z, @Nullable Direction face, float nx, float ny, float nz, TextureAtlasSprite sprite, float u, float v) { + return this.vertex(x, y, z, face, nx, ny, nz, sprite, u, v, 0xFFFFFFFF); + } + + @Override + 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 + + var normal = new Vector3f(tNormal.x(), tNormal.y(), tNormal.z()); + normal.normalize(); + + quads.pos(index, pos.x() + 0.5f, pos.y(), pos.z() + 0.5f); + if (face != null) { + face = Direction.rotate(this.transform, face); + quads.cullFace(face); + } + quads.normal(index, normal.x(), normal.y(), normal.z()); + + float u0 = sprite.getU0(); + float u1 = sprite.getU1(); + float v0 = sprite.getV0(); + float v1 = sprite.getV1(); + quads.spriteColor(index, 0, color); + quads.sprite(index, 0, u0 + ((u1 - u0) * u), v0 + ((v1 - v0) * v)); + + if (++index >= 4) { + quads.emit(); + index = 0; + } + + return this; + } +} diff --git a/fabric/src/main/java/io/github/foundationgames/automobility/fabric/block/render/FabricSlopeBakedModel.java b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/block/render/FabricSlopeBakedModel.java new file mode 100644 index 0000000..5f1d727 --- /dev/null +++ b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/block/render/FabricSlopeBakedModel.java @@ -0,0 +1,56 @@ +package io.github.foundationgames.automobility.fabric.block.render; + +import io.github.foundationgames.automobility.block.model.SlopeBakedModel; +import io.github.foundationgames.automobility.block.model.SlopeUnbakedModel; +import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel; +import net.fabricmc.fabric.api.renderer.v1.render.RenderContext; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.resources.model.ModelState; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.util.RandomSource; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.BlockAndTintGetter; +import net.minecraft.world.level.block.HorizontalDirectionalBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import org.jetbrains.annotations.Nullable; + +import java.util.Map; +import java.util.function.Supplier; + +public class FabricSlopeBakedModel extends SlopeBakedModel implements FabricBakedModel { + public FabricSlopeBakedModel(TextureAtlasSprite frame, Map frameTexOverrides, @Nullable TextureAtlasSprite plateInner, + @Nullable TextureAtlasSprite plateOuter, ModelState settings, SlopeUnbakedModel.Type type) { + super(frame, frameTexOverrides, plateInner, plateOuter, settings, type); + } + + @Override + public boolean isVanillaAdapter() { + return false; + } + + @Override + public void emitBlockQuads(BlockAndTintGetter level, BlockState state, BlockPos pos, Supplier randomSupplier, RenderContext context) { + var geo = new FabricGeometryBuilder(context.getEmitter(), this.settings.getRotation().getMatrix()); + var frameSprite = this.getFrameSprite(level, pos); + int frameColor = this.getFrameColor(level, pos); + + if (state.getBlock() instanceof HorizontalDirectionalBlock) { + var dir = state.getValue(BlockStateProperties.HORIZONTAL_FACING); + this.buildSlopeGeometry(frameSprite, geo, frameColor, + level.getBlockState(pos.relative(dir.getCounterClockWise(Direction.Axis.Y))) == state, + level.getBlockState(pos.relative(dir.getClockWise(Direction.Axis.Y))) == state); + } else { + this.buildSlopeGeometry(frameSprite, geo, frameColor, false, false); + } + } + + @Override + public void emitItemQuads(ItemStack stack, Supplier randomSupplier, RenderContext context) { + var geo = new FabricGeometryBuilder(context.getEmitter(), this.settings.getRotation().getMatrix()); + + this.buildSlopeGeometry(this.getFrameSprite(null, null), geo, + this.getFrameColor(null, null), false, false); + } +} diff --git a/src/main/java/io/github/foundationgames/automobility/mixin/ModelElementDeserializerMixin.java b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/mixin/BlockElementDeserializerMixin.java similarity index 51% rename from src/main/java/io/github/foundationgames/automobility/mixin/ModelElementDeserializerMixin.java rename to fabric/src/main/java/io/github/foundationgames/automobility/fabric/mixin/BlockElementDeserializerMixin.java index 5dd8abd..b1328f4 100644 --- a/src/main/java/io/github/foundationgames/automobility/mixin/ModelElementDeserializerMixin.java +++ b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/mixin/BlockElementDeserializerMixin.java @@ -1,20 +1,17 @@ -package io.github.foundationgames.automobility.mixin; +package io.github.foundationgames.automobility.fabric.mixin; import com.google.gson.JsonObject; -import net.minecraft.util.JsonHelper; +import net.minecraft.util.GsonHelper; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(targets = "net/minecraft/client/render/model/json/ModelElement$Deserializer") -public class ModelElementDeserializerMixin { - /* - i am inevitable - */ - @Inject(method = "deserializeRotationAngle(Lcom/google/gson/JsonObject;)F", at = @At("HEAD"), cancellable = true) +@Mixin(targets = "net/minecraft/client/renderer/block/model/BlockElement$Deserializer") +public class BlockElementDeserializerMixin { + @Inject(method = "getAngle(Lcom/google/gson/JsonObject;)F", at = @At("HEAD"), cancellable = true) private void automobility$letAtanOfZeroPointFiveBeAValidBlockModelCuboidRotationAngle(JsonObject object, CallbackInfoReturnable cir) { - float f = JsonHelper.getFloat(object, "angle"); + float f = GsonHelper.getAsFloat(object, "angle"); if (f >= 26.5 && f <= 26.6) cir.setReturnValue(f); } } diff --git a/src/main/java/io/github/foundationgames/automobility/mixin/GameRendererMixin.java b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/mixin/GameRendererMixin.java similarity index 61% rename from src/main/java/io/github/foundationgames/automobility/mixin/GameRendererMixin.java rename to fabric/src/main/java/io/github/foundationgames/automobility/fabric/mixin/GameRendererMixin.java index c5dbdfa..05cbc03 100644 --- a/src/main/java/io/github/foundationgames/automobility/mixin/GameRendererMixin.java +++ b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/mixin/GameRendererMixin.java @@ -1,9 +1,9 @@ -package io.github.foundationgames.automobility.mixin; +package io.github.foundationgames.automobility.fabric.mixin; -import io.github.foundationgames.automobility.entity.AutomobileEntity; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.render.Camera; -import net.minecraft.client.render.GameRenderer; +import io.github.foundationgames.automobility.AutomobilityClient; +import net.minecraft.client.Camera; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GameRenderer; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -14,7 +14,7 @@ @Mixin(GameRenderer.class) public class GameRendererMixin { - @Shadow @Final private MinecraftClient client; + @Shadow @Final private Minecraft minecraft; private float tickDelta = 0f; @@ -25,10 +25,6 @@ public class GameRendererMixin { @ModifyVariable(method = "getFov", at = @At(value = "RETURN", ordinal = 1, shift = At.Shift.BEFORE), index = 4) private double automobility$applyBoostFovEffect(double old) { - var player = client.player; - if (player.getVehicle() instanceof AutomobileEntity auto) { - return old + ((auto.getBoostSpeed(tickDelta) * 18) * client.options.getFovEffectScale().getValue()); - } - return old; + return AutomobilityClient.modifyBoostFov(minecraft, old, tickDelta); } } diff --git a/src/main/java/io/github/foundationgames/automobility/mixin/midnightcontrols/InputHandlersMixin.java b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/mixin/midnightcontrols/InputHandlersMixin.java similarity index 77% rename from src/main/java/io/github/foundationgames/automobility/mixin/midnightcontrols/InputHandlersMixin.java rename to fabric/src/main/java/io/github/foundationgames/automobility/fabric/mixin/midnightcontrols/InputHandlersMixin.java index 7be09f9..7f4127b 100644 --- a/src/main/java/io/github/foundationgames/automobility/mixin/midnightcontrols/InputHandlersMixin.java +++ b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/mixin/midnightcontrols/InputHandlersMixin.java @@ -1,10 +1,10 @@ -package io.github.foundationgames.automobility.mixin.midnightcontrols; +package io.github.foundationgames.automobility.fabric.mixin.midnightcontrols; import eu.midnightdust.midnightcontrols.client.controller.ButtonBinding; import eu.midnightdust.midnightcontrols.client.controller.InputHandlers; import io.github.foundationgames.automobility.entity.AutomobileEntity; -import io.github.foundationgames.automobility.util.midnightcontrols.AutomobilityMidnightControls; -import net.minecraft.client.MinecraftClient; +import io.github.foundationgames.automobility.fabric.util.midnightcontrols.AutomobilityMidnightControls; +import net.minecraft.client.Minecraft; import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Pseudo; @@ -18,7 +18,7 @@ @Mixin(value = InputHandlers.class, remap = false) public class InputHandlersMixin { @Inject(method = "inGame", at = @At("HEAD"), cancellable = true) - private static void automobility$makeAutomobileInputsWork(@NotNull MinecraftClient client, @NotNull ButtonBinding binding, CallbackInfoReturnable cir) { + private static void automobility$makeAutomobileInputsWork(@NotNull Minecraft client, @NotNull ButtonBinding binding, CallbackInfoReturnable cir) { var player = client.player; if (!(player == null || !(player.getVehicle() instanceof AutomobileEntity))) { for (ButtonBinding ab : AutomobilityMidnightControls.AUTOMOBILITY_BINDINGS) { diff --git a/src/main/java/io/github/foundationgames/automobility/mixin/myron/AbstractObjLoaderMixin.java b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/mixin/myron/AbstractObjLoaderMixin.java similarity index 50% rename from src/main/java/io/github/foundationgames/automobility/mixin/myron/AbstractObjLoaderMixin.java rename to fabric/src/main/java/io/github/foundationgames/automobility/fabric/mixin/myron/AbstractObjLoaderMixin.java index f369b48..fcdc115 100644 --- a/src/main/java/io/github/foundationgames/automobility/mixin/myron/AbstractObjLoaderMixin.java +++ b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/mixin/myron/AbstractObjLoaderMixin.java @@ -1,16 +1,4 @@ -package io.github.foundationgames.automobility.mixin.myron; - -// import dev.monarkhes.myron.impl.client.obj.AbstractObjLoader; -import net.minecraft.client.render.model.UnbakedModel; -import net.minecraft.client.render.model.json.ModelTransformation; -import net.minecraft.resource.ResourceManager; -import net.minecraft.util.Identifier; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Pseudo; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +package io.github.foundationgames.automobility.fabric.mixin.myron; //@Pseudo //@Mixin(value = AbstractObjLoader.class, remap = false) diff --git a/fabric/src/main/java/io/github/foundationgames/automobility/fabric/resource/AutomobilityAssets.java b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/resource/AutomobilityAssets.java new file mode 100644 index 0000000..806323e --- /dev/null +++ b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/resource/AutomobilityAssets.java @@ -0,0 +1,73 @@ +package io.github.foundationgames.automobility.fabric.resource; + +import io.github.foundationgames.automobility.Automobility; +import io.github.foundationgames.automobility.util.AUtils; +import net.devtech.arrp.api.RRPCallback; +import net.devtech.arrp.api.RuntimeResourcePack; +import net.devtech.arrp.json.blockstate.JState; +import net.devtech.arrp.json.models.JModel; +import net.minecraft.core.Direction; + +import java.util.HashSet; +import java.util.Set; +import java.util.function.Consumer; + +public enum AutomobilityAssets {; + public static final RuntimeResourcePack PACK = RuntimeResourcePack.create("automobility:assets"); + private static final Set> PROCESSORS = new HashSet<>(); + + public static void setup() { + for (var p : PROCESSORS) { + p.accept(PACK); + } + + RRPCallback.AFTER_VANILLA.register(a -> a.add(PACK)); + } + + public static void addSlope(String name, String texture) { + { + var path = "block/"+name; + PACK.addModel(new JModel().parent("automobility:block/template_slope_bottom").textures(JModel.textures().var("slope", texture)), Automobility.rl(path+"_bottom")); + PACK.addModel(new JModel().parent("automobility:block/template_slope_top").textures(JModel.textures().var("slope", texture)), Automobility.rl(path+"_top")); + var variants = JState.variant(); + for (Direction dir : AUtils.HORIZONTAL_DIRS) { + variants.put("half=bottom,facing="+ dir, JState.model(Automobility.rl(path)+"_bottom").y((int)dir.toYRot())); + variants.put("half=top,facing="+ dir, JState.model(Automobility.rl(path)+"_top").y((int)dir.toYRot())); + } + PACK.addBlockState(new JState().add(variants), Automobility.rl(name)); + } + { + name = "steep_"+name; + var path = "block/"+name; + PACK.addModel(new JModel().parent("automobility:block/template_steep_slope").textures(JModel.textures().var("slope", texture)), Automobility.rl(path)); + var variants = JState.variant(); + for (Direction dir : AUtils.HORIZONTAL_DIRS) { + variants.put("facing="+ dir, JState.model(Automobility.rl(path)).y((int)dir.toYRot())); + } + PACK.addBlockState(new JState().add(variants), Automobility.rl(name)); + } + } + + public static void addMinecraftSlope(String name, String base) { + base = switch (base) { + case "snow_block" -> "snow"; + case "quartz_block" -> "quartz_block_side"; + case "smooth_sandstone" -> "sandstone_top"; + case "smooth_quartz" -> "quartz_block_top"; + case "smooth_red_sandstone" -> "red_sandstone_top"; + case "dried_kelp_block" -> "dried_kelp_side"; + case "ancient_debris" -> "ancient_debris_side"; + case "lodestone" -> "lodestone_top"; + default -> base; + }; + if (base.startsWith("waxed_") && base.contains("copper")) { + base = base.replaceFirst("waxed_", ""); + } + var tex = "minecraft:block/"+base; + addSlope(name, tex); + } + + public static void addProcessor(Consumer processor) { + PROCESSORS.add(processor); + } +} diff --git a/src/main/java/io/github/foundationgames/automobility/resource/AutomobilityData.java b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/resource/AutomobilityData.java similarity index 60% rename from src/main/java/io/github/foundationgames/automobility/resource/AutomobilityData.java rename to fabric/src/main/java/io/github/foundationgames/automobility/fabric/resource/AutomobilityData.java index 9c5cd57..3669d94 100644 --- a/src/main/java/io/github/foundationgames/automobility/resource/AutomobilityData.java +++ b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/resource/AutomobilityData.java @@ -1,10 +1,10 @@ -package io.github.foundationgames.automobility.resource; +package io.github.foundationgames.automobility.fabric.resource; import io.github.foundationgames.automobility.Automobility; import net.devtech.arrp.api.RRPCallback; import net.devtech.arrp.api.RuntimeResourcePack; import net.devtech.arrp.json.tags.JTag; -import net.minecraft.util.Identifier; +import net.minecraft.resources.ResourceLocation; import java.util.ArrayList; import java.util.HashSet; @@ -16,28 +16,28 @@ public enum AutomobilityData {; public static final RuntimeResourcePack PACK = RuntimeResourcePack.create("automobility:data"); private static final Set> PROCESSORS = new HashSet<>(); - public static final List STEEP_SLOPE_TAG_CANDIDATES = new ArrayList<>(); - public static final List NON_STEEP_SLOPE_TAG_CANDIDATES = new ArrayList<>(); - public static final List STICKY_SLOPE_TAG_CANDIDATES = new ArrayList<>(); + public static final List STEEP_SLOPE_TAG_CANDIDATES = new ArrayList<>(); + public static final List NON_STEEP_SLOPE_TAG_CANDIDATES = new ArrayList<>(); + public static final List STICKY_SLOPE_TAG_CANDIDATES = new ArrayList<>(); public static void setup() { var steepSlopesTag = new JTag(); for (var id : STEEP_SLOPE_TAG_CANDIDATES) steepSlopesTag.add(id); - PACK.addTag(Automobility.id("blocks/steep_slopes"), steepSlopesTag); + PACK.addTag(Automobility.rl("blocks/steep_slopes"), steepSlopesTag); var nonSteepSlopesTag = new JTag(); for (var id : NON_STEEP_SLOPE_TAG_CANDIDATES) nonSteepSlopesTag.add(id); - PACK.addTag(Automobility.id("blocks/non_steep_slopes"), nonSteepSlopesTag); + PACK.addTag(Automobility.rl("blocks/non_steep_slopes"), nonSteepSlopesTag); var slopesTag = new JTag(); - slopesTag.tag(Automobility.id("blocks/steep_slopes")); - slopesTag.tag(Automobility.id("blocks/non_steep_slopes")); - PACK.addTag(Automobility.id("blocks/slopes"), slopesTag); + slopesTag.tag(Automobility.rl("blocks/steep_slopes")); + slopesTag.tag(Automobility.rl("blocks/non_steep_slopes")); + PACK.addTag(Automobility.rl("blocks/slopes"), slopesTag); var stickySlopesTag = new JTag(); - stickySlopesTag.tag(Automobility.id("blocks/slopes")); + stickySlopesTag.tag(Automobility.rl("blocks/slopes")); for (var id : STICKY_SLOPE_TAG_CANDIDATES) stickySlopesTag.add(id); - PACK.addTag(Automobility.id("blocks/sticky_slopes"), stickySlopesTag); + PACK.addTag(Automobility.rl("blocks/sticky_slopes"), stickySlopesTag); for (var p : PROCESSORS) { p.accept(PACK); diff --git a/src/main/java/io/github/foundationgames/automobility/util/midnightcontrols/AutomobilityMidnightControls.java b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/util/midnightcontrols/AutomobilityMidnightControls.java similarity index 78% rename from src/main/java/io/github/foundationgames/automobility/util/midnightcontrols/AutomobilityMidnightControls.java rename to fabric/src/main/java/io/github/foundationgames/automobility/fabric/util/midnightcontrols/AutomobilityMidnightControls.java index 762a0e8..7dd3978 100644 --- a/src/main/java/io/github/foundationgames/automobility/util/midnightcontrols/AutomobilityMidnightControls.java +++ b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/util/midnightcontrols/AutomobilityMidnightControls.java @@ -1,4 +1,4 @@ -package io.github.foundationgames.automobility.util.midnightcontrols; +package io.github.foundationgames.automobility.fabric.util.midnightcontrols; import eu.midnightdust.midnightcontrols.ControlsMode; import eu.midnightdust.midnightcontrols.client.MidnightControlsClient; @@ -10,7 +10,7 @@ import eu.midnightdust.midnightcontrols.client.controller.InputManager; import io.github.foundationgames.automobility.Automobility; import io.github.foundationgames.automobility.entity.AutomobileEntity; -import net.minecraft.client.MinecraftClient; +import net.minecraft.client.Minecraft; import org.aperlambda.lambdacommon.Identifier; import org.aperlambda.lambdacommon.utils.function.PairPredicate; import org.jetbrains.annotations.NotNull; @@ -19,23 +19,24 @@ import java.util.Set; import java.util.function.Supplier; -import static org.lwjgl.glfw.GLFW.*; +import static org.lwjgl.glfw.GLFW.GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER; +import static org.lwjgl.glfw.GLFW.GLFW_GAMEPAD_BUTTON_A; +import static org.lwjgl.glfw.GLFW.GLFW_GAMEPAD_BUTTON_B; public class AutomobilityMidnightControls implements CompatHandler { - public static final PairPredicate ON_AUTOMOBILE = (client, button) -> client.player != null && client.player.getVehicle() instanceof AutomobileEntity; + public static final PairPredicate ON_AUTOMOBILE = (client, button) -> client.player != null && client.player.getVehicle() instanceof AutomobileEntity; public static final Set AUTOMOBILITY_BINDINGS = new HashSet<>(); - public static final ButtonBinding ACCELERATE = binding(new ButtonBinding.Builder(Automobility.id("accelerate_automobile")) + public static final ButtonBinding ACCELERATE = binding(new ButtonBinding.Builder(Automobility.rl("accelerate_automobile")) .buttons(GLFW_GAMEPAD_BUTTON_A).filter(ON_AUTOMOBILE).register()); - public static final ButtonBinding BRAKE = binding(new ButtonBinding.Builder(Automobility.id("brake_automobile")) + public static final ButtonBinding BRAKE = binding(new ButtonBinding.Builder(Automobility.rl("brake_automobile")) .buttons(GLFW_GAMEPAD_BUTTON_B).filter(ON_AUTOMOBILE).register()); - public static final ButtonBinding DRIFT = binding(new ButtonBinding.Builder(Automobility.id("drift_automobile")) + public static final ButtonBinding DRIFT = binding(new ButtonBinding.Builder(Automobility.rl("drift_automobile")) .buttons(ButtonBinding.axisAsButton(GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER, true)).filter(ON_AUTOMOBILE).register()); - // There is 1 impostor among us public static final ButtonCategory AUTOMOBILITY_CATEGORY = InputManager.registerCategory(new Identifier(Automobility.MOD_ID, "automobility")); public static Supplier IN_CONTROLLER_MODE = () -> false; diff --git a/src/main/java/io/github/foundationgames/automobility/util/midnightcontrols/ControllerUtils.java b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/util/midnightcontrols/ControllerUtils.java similarity index 92% rename from src/main/java/io/github/foundationgames/automobility/util/midnightcontrols/ControllerUtils.java rename to fabric/src/main/java/io/github/foundationgames/automobility/fabric/util/midnightcontrols/ControllerUtils.java index 26f02e7..29fb7ff 100644 --- a/src/main/java/io/github/foundationgames/automobility/util/midnightcontrols/ControllerUtils.java +++ b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/util/midnightcontrols/ControllerUtils.java @@ -1,4 +1,4 @@ -package io.github.foundationgames.automobility.util.midnightcontrols; +package io.github.foundationgames.automobility.fabric.util.midnightcontrols; import net.fabricmc.loader.api.FabricLoader; diff --git a/fabric/src/main/resources/assets/automobility/blockstates/sloped_dash_panel.json b/fabric/src/main/resources/assets/automobility/blockstates/sloped_dash_panel.json new file mode 100644 index 0000000..c4fde71 --- /dev/null +++ b/fabric/src/main/resources/assets/automobility/blockstates/sloped_dash_panel.json @@ -0,0 +1,132 @@ +{ + "variants": { + "half=top,left=false,right=true,facing=south": { + "model": "automobility:block/sloped_dash_panel_right_top", + "y": 0 + }, + "half=top,left=false,right=true,facing=north": { + "model": "automobility:block/sloped_dash_panel_right_top", + "y": 180 + }, + "half=bottom,left=false,right=true,facing=west": { + "model": "automobility:block/sloped_dash_panel_right_bottom", + "y": 90 + }, + "half=bottom,left=false,right=false,facing=west": { + "model": "automobility:block/sloped_dash_panel_single_bottom", + "y": 90 + }, + "half=top,left=true,right=false,facing=south": { + "model": "automobility:block/sloped_dash_panel_left_top", + "y": 0 + }, + "half=top,left=true,right=true,facing=north": { + "model": "automobility:block/sloped_dash_panel_center_top", + "y": 180 + }, + "half=bottom,left=true,right=false,facing=west": { + "model": "automobility:block/sloped_dash_panel_left_bottom", + "y": 90 + }, + "half=bottom,left=false,right=false,facing=east": { + "model": "automobility:block/sloped_dash_panel_single_bottom", + "y": 270 + }, + "half=top,left=true,right=true,facing=west": { + "model": "automobility:block/sloped_dash_panel_center_top", + "y": 90 + }, + "half=top,left=true,right=false,facing=east": { + "model": "automobility:block/sloped_dash_panel_left_top", + "y": 270 + }, + "half=top,left=false,right=true,facing=east": { + "model": "automobility:block/sloped_dash_panel_right_top", + "y": 270 + }, + "half=bottom,left=false,right=true,facing=south": { + "model": "automobility:block/sloped_dash_panel_right_bottom", + "y": 0 + }, + "half=bottom,left=true,right=true,facing=north": { + "model": "automobility:block/sloped_dash_panel_center_bottom", + "y": 180 + }, + "half=top,left=true,right=false,facing=north": { + "model": "automobility:block/sloped_dash_panel_left_top", + "y": 180 + }, + "half=bottom,left=true,right=true,facing=west": { + "model": "automobility:block/sloped_dash_panel_center_bottom", + "y": 90 + }, + "half=top,left=true,right=false,facing=west": { + "model": "automobility:block/sloped_dash_panel_left_top", + "y": 90 + }, + "half=bottom,left=true,right=false,facing=south": { + "model": "automobility:block/sloped_dash_panel_left_bottom", + "y": 0 + }, + "half=top,left=false,right=false,facing=south": { + "model": "automobility:block/sloped_dash_panel_single_top", + "y": 0 + }, + "half=bottom,left=true,right=true,facing=east": { + "model": "automobility:block/sloped_dash_panel_center_bottom", + "y": 270 + }, + "half=top,left=false,right=false,facing=west": { + "model": "automobility:block/sloped_dash_panel_single_top", + "y": 90 + }, + "half=bottom,left=true,right=false,facing=north": { + "model": "automobility:block/sloped_dash_panel_left_bottom", + "y": 180 + }, + "half=top,left=false,right=false,facing=north": { + "model": "automobility:block/sloped_dash_panel_single_top", + "y": 180 + }, + "half=bottom,left=false,right=true,facing=north": { + "model": "automobility:block/sloped_dash_panel_right_bottom", + "y": 180 + }, + "half=bottom,left=true,right=true,facing=south": { + "model": "automobility:block/sloped_dash_panel_center_bottom", + "y": 0 + }, + "half=top,left=false,right=true,facing=west": { + "model": "automobility:block/sloped_dash_panel_right_top", + "y": 90 + }, + "half=bottom,left=true,right=false,facing=east": { + "model": "automobility:block/sloped_dash_panel_left_bottom", + "y": 270 + }, + "half=top,left=true,right=true,facing=east": { + "model": "automobility:block/sloped_dash_panel_center_top", + "y": 270 + }, + "half=bottom,left=false,right=false,facing=south": { + "model": "automobility:block/sloped_dash_panel_single_bottom", + "y": 0 + }, + "half=bottom,left=false,right=false,facing=north": { + "model": "automobility:block/sloped_dash_panel_single_bottom", + "y": 180 + }, + "half=bottom,left=false,right=true,facing=east": { + "model": "automobility:block/sloped_dash_panel_right_bottom", + "y": 270 + }, + "half=top,left=false,right=false,facing=east": { + "model": "automobility:block/sloped_dash_panel_single_top", + "y": 270 + }, + "half=top,left=true,right=true,facing=south": { + "model": "automobility:block/sloped_dash_panel_center_top", + "y": 0 + } + } +} \ No newline at end of file diff --git a/fabric/src/main/resources/assets/automobility/blockstates/steep_sloped_dash_panel.json b/fabric/src/main/resources/assets/automobility/blockstates/steep_sloped_dash_panel.json new file mode 100644 index 0000000..8c8b82b --- /dev/null +++ b/fabric/src/main/resources/assets/automobility/blockstates/steep_sloped_dash_panel.json @@ -0,0 +1,68 @@ +{ + "variants": { + "left=true,right=false,facing=west": { + "model": "automobility:block/steep_sloped_dash_panel_left", + "y": 90 + }, + "left=true,right=true,facing=west": { + "model": "automobility:block/steep_sloped_dash_panel_center", + "y": 90 + }, + "left=false,right=false,facing=east": { + "model": "automobility:block/steep_sloped_dash_panel_single", + "y": 270 + }, + "left=false,right=true,facing=south": { + "model": "automobility:block/steep_sloped_dash_panel_right", + "y": 0 + }, + "left=true,right=true,facing=north": { + "model": "automobility:block/steep_sloped_dash_panel_center", + "y": 180 + }, + "left=false,right=false,facing=north": { + "model": "automobility:block/steep_sloped_dash_panel_single", + "y": 180 + }, + "left=false,right=true,facing=west": { + "model": "automobility:block/steep_sloped_dash_panel_right", + "y": 90 + }, + "left=false,right=false,facing=west": { + "model": "automobility:block/steep_sloped_dash_panel_single", + "y": 90 + }, + "left=false,right=true,facing=east": { + "model": "automobility:block/steep_sloped_dash_panel_right", + "y": 270 + }, + "left=true,right=false,facing=east": { + "model": "automobility:block/steep_sloped_dash_panel_left", + "y": 270 + }, + "left=true,right=false,facing=south": { + "model": "automobility:block/steep_sloped_dash_panel_left", + "y": 0 + }, + "left=false,right=false,facing=south": { + "model": "automobility:block/steep_sloped_dash_panel_single", + "y": 0 + }, + "left=true,right=true,facing=east": { + "model": "automobility:block/steep_sloped_dash_panel_center", + "y": 270 + }, + "left=false,right=true,facing=north": { + "model": "automobility:block/steep_sloped_dash_panel_right", + "y": 180 + }, + "left=true,right=false,facing=north": { + "model": "automobility:block/steep_sloped_dash_panel_left", + "y": 180 + }, + "left=true,right=true,facing=south": { + "model": "automobility:block/steep_sloped_dash_panel_center", + "y": 0 + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/automobility/models/block/sloped_dash_panel_center_bottom.json b/fabric/src/main/resources/assets/automobility/models/block/sloped_dash_panel_center_bottom.json similarity index 100% rename from src/main/resources/assets/automobility/models/block/sloped_dash_panel_center_bottom.json rename to fabric/src/main/resources/assets/automobility/models/block/sloped_dash_panel_center_bottom.json diff --git a/src/main/resources/assets/automobility/models/block/sloped_dash_panel_center_top.json b/fabric/src/main/resources/assets/automobility/models/block/sloped_dash_panel_center_top.json similarity index 100% rename from src/main/resources/assets/automobility/models/block/sloped_dash_panel_center_top.json rename to fabric/src/main/resources/assets/automobility/models/block/sloped_dash_panel_center_top.json diff --git a/src/main/resources/assets/automobility/models/block/sloped_dash_panel_left_bottom.json b/fabric/src/main/resources/assets/automobility/models/block/sloped_dash_panel_left_bottom.json similarity index 100% rename from src/main/resources/assets/automobility/models/block/sloped_dash_panel_left_bottom.json rename to fabric/src/main/resources/assets/automobility/models/block/sloped_dash_panel_left_bottom.json diff --git a/src/main/resources/assets/automobility/models/block/sloped_dash_panel_left_top.json b/fabric/src/main/resources/assets/automobility/models/block/sloped_dash_panel_left_top.json similarity index 100% rename from src/main/resources/assets/automobility/models/block/sloped_dash_panel_left_top.json rename to fabric/src/main/resources/assets/automobility/models/block/sloped_dash_panel_left_top.json diff --git a/src/main/resources/assets/automobility/models/block/sloped_dash_panel_right_bottom.json b/fabric/src/main/resources/assets/automobility/models/block/sloped_dash_panel_right_bottom.json similarity index 100% rename from src/main/resources/assets/automobility/models/block/sloped_dash_panel_right_bottom.json rename to fabric/src/main/resources/assets/automobility/models/block/sloped_dash_panel_right_bottom.json diff --git a/src/main/resources/assets/automobility/models/block/sloped_dash_panel_right_top.json b/fabric/src/main/resources/assets/automobility/models/block/sloped_dash_panel_right_top.json similarity index 100% rename from src/main/resources/assets/automobility/models/block/sloped_dash_panel_right_top.json rename to fabric/src/main/resources/assets/automobility/models/block/sloped_dash_panel_right_top.json diff --git a/src/main/resources/assets/automobility/models/block/sloped_dash_panel_single_bottom.json b/fabric/src/main/resources/assets/automobility/models/block/sloped_dash_panel_single_bottom.json similarity index 100% rename from src/main/resources/assets/automobility/models/block/sloped_dash_panel_single_bottom.json rename to fabric/src/main/resources/assets/automobility/models/block/sloped_dash_panel_single_bottom.json diff --git a/src/main/resources/assets/automobility/models/block/sloped_dash_panel_single_top.json b/fabric/src/main/resources/assets/automobility/models/block/sloped_dash_panel_single_top.json similarity index 100% rename from src/main/resources/assets/automobility/models/block/sloped_dash_panel_single_top.json rename to fabric/src/main/resources/assets/automobility/models/block/sloped_dash_panel_single_top.json diff --git a/src/main/resources/assets/automobility/models/block/steep_sloped_dash_panel_center.json b/fabric/src/main/resources/assets/automobility/models/block/steep_sloped_dash_panel_center.json similarity index 100% rename from src/main/resources/assets/automobility/models/block/steep_sloped_dash_panel_center.json rename to fabric/src/main/resources/assets/automobility/models/block/steep_sloped_dash_panel_center.json diff --git a/src/main/resources/assets/automobility/models/block/steep_sloped_dash_panel_left.json b/fabric/src/main/resources/assets/automobility/models/block/steep_sloped_dash_panel_left.json similarity index 100% rename from src/main/resources/assets/automobility/models/block/steep_sloped_dash_panel_left.json rename to fabric/src/main/resources/assets/automobility/models/block/steep_sloped_dash_panel_left.json diff --git a/src/main/resources/assets/automobility/models/block/steep_sloped_dash_panel_right.json b/fabric/src/main/resources/assets/automobility/models/block/steep_sloped_dash_panel_right.json similarity index 100% rename from src/main/resources/assets/automobility/models/block/steep_sloped_dash_panel_right.json rename to fabric/src/main/resources/assets/automobility/models/block/steep_sloped_dash_panel_right.json diff --git a/src/main/resources/assets/automobility/models/block/steep_sloped_dash_panel_single.json b/fabric/src/main/resources/assets/automobility/models/block/steep_sloped_dash_panel_single.json similarity index 100% rename from src/main/resources/assets/automobility/models/block/steep_sloped_dash_panel_single.json rename to fabric/src/main/resources/assets/automobility/models/block/steep_sloped_dash_panel_single.json diff --git a/src/main/resources/assets/automobility/models/block/template_slope_bottom.json b/fabric/src/main/resources/assets/automobility/models/block/template_slope_bottom.json similarity index 100% rename from src/main/resources/assets/automobility/models/block/template_slope_bottom.json rename to fabric/src/main/resources/assets/automobility/models/block/template_slope_bottom.json diff --git a/src/main/resources/assets/automobility/models/block/template_slope_top.json b/fabric/src/main/resources/assets/automobility/models/block/template_slope_top.json similarity index 100% rename from src/main/resources/assets/automobility/models/block/template_slope_top.json rename to fabric/src/main/resources/assets/automobility/models/block/template_slope_top.json diff --git a/src/main/resources/assets/automobility/models/block/template_steep_slope.json b/fabric/src/main/resources/assets/automobility/models/block/template_steep_slope.json similarity index 100% rename from src/main/resources/assets/automobility/models/block/template_steep_slope.json rename to fabric/src/main/resources/assets/automobility/models/block/template_steep_slope.json diff --git a/fabric/src/main/resources/automobility_fabric.mixins.json b/fabric/src/main/resources/automobility_fabric.mixins.json new file mode 100644 index 0000000..1744ff2 --- /dev/null +++ b/fabric/src/main/resources/automobility_fabric.mixins.json @@ -0,0 +1,17 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "io.github.foundationgames.automobility.fabric.mixin", + "compatibilityLevel": "JAVA_17", + "refmap": "automobility-refmap.json", + "mixins": [ + ], + "client": [ + "BlockElementDeserializerMixin", + "GameRendererMixin", + "midnightcontrols.InputHandlersMixin" + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json similarity index 67% rename from src/main/resources/fabric.mod.json rename to fabric/src/main/resources/fabric.mod.json index e87b6fb..440a2e6 100644 --- a/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -12,18 +12,19 @@ "sources": "" }, "license": "MIT", - "icon": "assets/automobility/icon.png", + "icon": "automobility.png", "environment": "*", "entrypoints": { "main": [ - "io.github.foundationgames.automobility.Automobility" + "io.github.foundationgames.automobility.fabric.AutomobilityFabric" ], "client": [ - "io.github.foundationgames.automobility.AutomobilityClient" + "io.github.foundationgames.automobility.fabric.AutomobilityClientFabric" ] }, "mixins": [ - "automobility.mixins.json" + "automobility.mixins.json", + "automobility_fabric.mixins.json" ], "depends": { "fabricloader": ">=0.11.3", diff --git a/forge/build.gradle b/forge/build.gradle new file mode 100644 index 0000000..1462f0e --- /dev/null +++ b/forge/build.gradle @@ -0,0 +1,99 @@ +buildscript { + repositories { + maven { url = 'https://maven.minecraftforge.net' } + mavenCentral() + } + + dependencies { + classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true + classpath 'org.spongepowered:mixingradle:0.7.+' + } +} + +apply plugin: 'java' +apply plugin: 'net.minecraftforge.gradle' +apply plugin: 'eclipse' +apply plugin: 'maven-publish' +apply plugin: 'org.spongepowered.mixin' + +version = "${project.mod_version}+${project.minecraft_version}-forge" as Object + +minecraft { + mappings channel: 'official', version: minecraft_version + + runs { + client { + workingDirectory project.file('run') + ideaModule "${rootProject.name}.${project.name}.main" + taskName '(Forge) Client' + property 'mixin.env.remapRefMap', 'true' + property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg" + mods { + modClientRun { + source sourceSets.main + source project(':common').sourceSets.main + } + } + } + + server { + workingDirectory project.file('run') + ideaModule "${rootProject.name}.${project.name}.main" + taskName '(Forge) Server' + property 'mixin.env.remapRefMap', 'true' + property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg" + + mods { + modServerRun { + source sourceSets.main + source project(':common').sourceSets.main + } + } + } + } +} + +sourceSets.main.resources.srcDir 'src/generated/resources' + +dependencies { + minecraft "net.minecraftforge:forge:${project.minecraft_version}-${project.forge_version}" + annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' + + compileOnly project(':common') +} + +mixin { + add sourceSets.main, "automobility-refmap.json" + + config 'automobility.mixins.json' + config 'automobility_forge.mixins.json' +} + +tasks.withType(JavaCompile) { + source(project(':common').sourceSets.main.allSource) +} + +processResources { + from project(":common").sourceSets.main.resources + + inputs.property 'version', project.version + filesMatching('META-INF/mods.toml') { + expand 'version': project.version + } +} + +jar.finalizedBy('reobfJar') + +publishing { + publications { + mavenJava(MavenPublication) { + groupId project.group + artifactId project.archivesBaseName + version project.version + artifact jar + } + } + + repositories { + } +} \ No newline at end of file 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 new file mode 100644 index 0000000..13e417b --- /dev/null +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/AutomobilityClientForge.java @@ -0,0 +1,58 @@ +package io.github.foundationgames.automobility.forge; + +import io.github.foundationgames.automobility.AutomobilityClient; +import io.github.foundationgames.automobility.block.AutomobilityBlocks; +import io.github.foundationgames.automobility.block.model.SlopeBakedModel; +import io.github.foundationgames.automobility.entity.AutomobileEntity; +import io.github.foundationgames.automobility.forge.block.render.ForgeSlopeBakedModel; +import io.github.foundationgames.automobility.particle.AutomobilityParticles; +import io.github.foundationgames.automobility.particle.DriftSmokeParticle; +import io.github.foundationgames.automobility.screen.AutomobileHud; +import io.github.foundationgames.automobility.util.InitlessConstants; +import net.minecraft.client.Minecraft; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.client.event.RegisterColorHandlersEvent; +import net.minecraftforge.client.event.RegisterParticleProvidersEvent; +import net.minecraftforge.client.event.RenderGuiEvent; +import net.minecraftforge.client.event.ViewportEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; + +@Mod.EventBusSubscriber(value = Dist.CLIENT, modid = InitlessConstants.AUTOMOBILITY, bus = Mod.EventBusSubscriber.Bus.MOD) +public class AutomobilityClientForge { + @SubscribeEvent + public static void initClient(FMLClientSetupEvent setup) { + ForgePlatform.init(); + + AutomobilityClient.init(); + + SlopeBakedModel.impl = ForgeSlopeBakedModel::new; + + MinecraftForge.EVENT_BUS.addListener(evt -> { + var player = Minecraft.getInstance().player; + if (player.getVehicle() instanceof AutomobileEntity auto) { + AutomobileHud.render(evt.getPoseStack(), player, auto, evt.getPartialTick()); + } + }); + + MinecraftForge.EVENT_BUS.addListener(evt -> + evt.setFOV(AutomobilityClient.modifyBoostFov(Minecraft.getInstance(), evt.getFOV(), (float) evt.getPartialTick()))); + } + + @SubscribeEvent + public static void registerParticleProviders(RegisterParticleProvidersEvent evt) { + evt.register(AutomobilityParticles.DRIFT_SMOKE.require(), DriftSmokeParticle.Factory::new); + } + + @SubscribeEvent + public static void registerBlockColors(RegisterColorHandlersEvent.Block evt) { + evt.register(AutomobilityClient.GRASS_COLOR, AutomobilityBlocks.GRASS_OFF_ROAD.require()); + } + + @SubscribeEvent + public static void registerItemColors(RegisterColorHandlersEvent.Item evt) { + evt.register(AutomobilityClient.GRASS_ITEM_COLOR, AutomobilityBlocks.GRASS_OFF_ROAD.require()); + } +} 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 new file mode 100644 index 0000000..784b8c5 --- /dev/null +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/AutomobilityForge.java @@ -0,0 +1,52 @@ +package io.github.foundationgames.automobility.forge; + +import io.github.foundationgames.automobility.Automobility; +import io.github.foundationgames.automobility.forge.network.AutomobilityPacketHandler; +import io.github.foundationgames.automobility.util.InitlessConstants; +import io.github.foundationgames.automobility.util.RegistryQueue; +import net.minecraft.core.Registry; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.registries.RegisterEvent; + +@Mod(InitlessConstants.AUTOMOBILITY) +@Mod.EventBusSubscriber(modid = InitlessConstants.AUTOMOBILITY, bus = Mod.EventBusSubscriber.Bus.MOD) +public class AutomobilityForge { + public AutomobilityForge() { + ForgePlatform.init(); + + Automobility.init(); + AutomobilityPacketHandler.init(); + } + + @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); + } + + public static void register(Registry registry, RegisterEvent evt) { + if (registry == evt.getVanillaRegistry()) { + + if (evt.getForgeRegistry() != null) { + evt.register(evt.getForgeRegistry().getRegistryKey(), helper -> { + for (var entry : RegistryQueue.getQueue(registry)) { + helper.register(entry.rl(), entry.entry().create()); + } + }); + } else { + for (var entry : RegistryQueue.getQueue(registry)) { + evt.register(registry.key(), entry.rl(), entry.entry()::create); + } + } + } + } +} 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 new file mode 100644 index 0000000..f2a0161 --- /dev/null +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/ForgePlatform.java @@ -0,0 +1,163 @@ +package io.github.foundationgames.automobility.forge; + +import com.mojang.blaze3d.vertex.PoseStack; +import io.github.foundationgames.automobility.forge.client.BEWLRs; +import io.github.foundationgames.automobility.forge.mixin.BlockColorsAccess; +import io.github.foundationgames.automobility.forge.network.AutomobilityPacketHandler; +import io.github.foundationgames.automobility.forge.vendored.jsonem.JsonEM; +import io.github.foundationgames.automobility.platform.Platform; +import io.github.foundationgames.automobility.util.HexCons; +import io.github.foundationgames.automobility.util.TriCons; +import io.github.foundationgames.automobility.util.TriFunc; +import net.minecraft.client.Minecraft; +import net.minecraft.client.color.block.BlockColor; +import net.minecraft.client.gui.screens.MenuScreens; +import net.minecraft.client.gui.screens.Screen; +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; +import net.minecraft.client.renderer.entity.EntityRenderer; +import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.client.renderer.entity.EntityRenderers; +import net.minecraft.core.BlockPos; +import net.minecraft.core.particles.SimpleParticleType; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityDimensions; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.MobCategory; +import net.minecraft.world.entity.player.Inventory; +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.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.registries.ForgeRegistries; +import org.jetbrains.annotations.Nullable; + +import java.util.function.BiConsumer; +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.function.Supplier; + +public class ForgePlatform implements Platform { + private static final ForgePlatform INSTANCE = new ForgePlatform(); + + public static void init() { + Platform.init(INSTANCE); + } + + @Override + public CreativeModeTab creativeTab(ResourceLocation rl, Supplier icon) { + return new CreativeModeTab(rl.getNamespace()+"."+rl.getPath()) { + @Override + public ItemStack makeIcon() { + return icon.get(); + } + }; + } + + @Override + public void builtinItemRenderer(Item item, HexCons renderer) { + BEWLRs.add(item, renderer); + } + + @Override + public MenuType menuType(BiFunction factory) { + return new MenuType<>(factory::apply); + } + + @Override + public > void registerMenuScreen(MenuType type, TriFunc factory) { + MenuScreens.register(type, factory::apply); + } + + @Override + public @Nullable BlockColor blockColor(BlockState state) { + return ((BlockColorsAccess)Minecraft.getInstance().getBlockColors()).automobility$getForgeColorMap() + .get(ForgeRegistries.BLOCKS.getDelegateOrThrow(state.getBlock())); + } + + @Override + public BlockEntityType blockEntity(BiFunction factory, Block... blocks) { + return BlockEntityType.Builder.of(factory::apply, blocks).build(null); + } + + @Override + public void blockEntityRenderer(BlockEntityType type, Function> provider) { + BlockEntityRenderers.register(type, provider::apply); + } + + @Override + public void serverSendPacket(ServerPlayer player, ResourceLocation rl, FriendlyByteBuf buf) { + AutomobilityPacketHandler.serverToClient(player, rl, buf); + } + + @Override + public void clientSendPacket(ResourceLocation rl, FriendlyByteBuf buf) { + AutomobilityPacketHandler.clientToServer(rl, buf); + } + + @Override + public void serverReceivePacket(ResourceLocation rl, TriCons run) { + AutomobilityPacketHandler.addServerReceiver(rl, run); + } + + @Override + public void clientReceivePacket(ResourceLocation rl, BiConsumer run) { + AutomobilityPacketHandler.addClientReceiver(rl, run); + } + + @Override + public EntityType entityType(MobCategory category, BiFunction, Level, T> factory, EntityDimensions size, int updateRate, int updateRange) { + return EntityType.Builder.of(factory::apply, category).sized(size.width, size.height).updateInterval(updateRate).clientTrackingRange(updateRange).build(""); + } + + @Override + public void entityRenderer(EntityType entity, Function> factory) { + EntityRenderers.register(entity, factory::apply); + } + + @Override + public void modelLayer(ModelLayerLocation layer) { + JsonEM.registerModelLayer(layer); + } + + @Override + public SimpleParticleType simpleParticleType(boolean z) { + return new SimpleParticleType(z); + } + + @Override + public boolean controllerAccel() { + return false; + } + + @Override + public boolean controllerBrake() { + return false; + } + + @Override + public boolean controllerDrift() { + return false; + } + + @Override + public boolean inControllerMode() { + return false; + } +} 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 new file mode 100644 index 0000000..d013e5b --- /dev/null +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/block/render/ForgeGeometryBuilder.java @@ -0,0 +1,63 @@ +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; +import net.minecraft.core.Direction; +import net.minecraftforge.client.model.pipeline.QuadBakingVertexConsumer; +import net.minecraftforge.common.ForgeConfig; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class ForgeGeometryBuilder implements GeometryBuilder { + private final Matrix4f transform; + private final @Nullable Direction filter; + private final QuadBakingVertexConsumer quads; + + public ForgeGeometryBuilder(Matrix4f transform, @Nullable Direction filter, List quadPool) { + this.transform = transform; + this.filter = filter; + + this.quads = new QuadBakingVertexConsumer(quadPool::add); + this.quads.setShade(true); + this.quads.setHasAmbientOcclusion(ForgeConfig.CLIENT.experimentalForgeLightPipelineEnabled.get()); + } + + @Override + public GeometryBuilder vertex(float x, float y, float z, @Nullable Direction face, float nx, float ny, float nz, TextureAtlasSprite sprite, float u, float v) { + return this.vertex(x, y, z, face, nx, ny, nz, sprite, u, v, 0xFFFFFFFF); + } + + @Override + 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) { + if (face != null) { + face = Direction.rotate(this.transform, face); + } + if (face != this.filter) { + return this; + } + + 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 + + var normal = new Vector3f(tNormal.x(), tNormal.y(), tNormal.z()); + normal.normalize(); + + float u0 = sprite.getU0(); + float u1 = sprite.getU1(); + float v0 = sprite.getV0(); + float v1 = sprite.getV1(); + + quads.setDirection(face != null ? face : Direction.UP); + quads.setSprite(sprite); + quads.vertex(pos.x() + 0.5f, pos.y(), pos.z() + 0.5f).color(color).uv(u0 + ((u1 - u0) * u), v0 + ((v1 - v0) * v)).normal(normal.x(), normal.y(), normal.z()).endVertex(); + + return this; + } +} diff --git a/forge/src/main/java/io/github/foundationgames/automobility/forge/block/render/ForgeSlopeBakedModel.java b/forge/src/main/java/io/github/foundationgames/automobility/forge/block/render/ForgeSlopeBakedModel.java new file mode 100644 index 0000000..ada43bd --- /dev/null +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/block/render/ForgeSlopeBakedModel.java @@ -0,0 +1,95 @@ +package io.github.foundationgames.automobility.forge.block.render; + +import io.github.foundationgames.automobility.block.model.SlopeBakedModel; +import io.github.foundationgames.automobility.block.model.SlopeUnbakedModel; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.resources.model.ModelState; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.util.RandomSource; +import net.minecraft.world.level.BlockAndTintGetter; +import net.minecraft.world.level.block.HorizontalDirectionalBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraftforge.client.ChunkRenderTypeSet; +import net.minecraftforge.client.model.data.ModelData; +import net.minecraftforge.client.model.data.ModelProperty; +import net.minecraftforge.common.ForgeConfig; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +public class ForgeSlopeBakedModel extends SlopeBakedModel { + private static final ChunkRenderTypeSet RENDER_TYPES = ChunkRenderTypeSet.of(RenderType.translucent()); + private static final ModelProperty FRAME_SPRITE = new ModelProperty<>(); + private static final ModelProperty BORDERED_LEFT = new ModelProperty<>(); + private static final ModelProperty BORDERED_RIGHT = new ModelProperty<>(); + private static final ModelProperty FRAME_COLOR = new ModelProperty<>(); + + public ForgeSlopeBakedModel(TextureAtlasSprite frame, Map frameTexOverrides, @Nullable TextureAtlasSprite plateInner, + @Nullable TextureAtlasSprite plateOuter, ModelState settings, SlopeUnbakedModel.Type type) { + super(frame, frameTexOverrides, plateInner, plateOuter, settings, type); + } + + @Override + public ChunkRenderTypeSet getRenderTypes(@NotNull BlockState state, @NotNull RandomSource rand, @NotNull ModelData data) { + return RENDER_TYPES; + } + + @Override + public @NotNull ModelData getModelData(@NotNull BlockAndTintGetter level, @NotNull BlockPos pos, @NotNull BlockState state, @NotNull ModelData modelData) { + var builder = modelData.derive().with(FRAME_SPRITE, this.getFrameSprite(level, pos)) + .with(FRAME_COLOR, this.getFrameColor(level, pos)); + + if (state.getBlock() instanceof HorizontalDirectionalBlock) { + var dir = state.getValue(BlockStateProperties.HORIZONTAL_FACING); + builder.with(BORDERED_LEFT, level.getBlockState(pos.relative(dir.getCounterClockWise(Direction.Axis.Y))) == state) + .with(BORDERED_RIGHT, level.getBlockState(pos.relative(dir.getClockWise(Direction.Axis.Y))) == state); + } else { + builder.with(BORDERED_LEFT, false).with(BORDERED_RIGHT, false); + } + + return builder.build(); + } + + private boolean unwrap(Boolean box) { + if (box == null) { + return false; + } + + return box; + } + + private int unwrap(Integer box) { + if (box == null) { + return 0xFFFFFFFF; + } + + return box; + } + + @Override + public @NotNull List getQuads(@Nullable BlockState state, @Nullable Direction side, @NotNull RandomSource rand, @NotNull ModelData data, @Nullable RenderType renderType) { + if (renderType == null || this.getRenderTypes(state, rand, data).contains(renderType)) { + var quads = new ArrayList(); + var geo = new ForgeGeometryBuilder(this.settings.getRotation().getMatrix(), side, quads); + + this.buildSlopeGeometry(data.get(FRAME_SPRITE), geo, unwrap(data.get(FRAME_COLOR)), unwrap(data.get(BORDERED_LEFT)), unwrap(data.get(BORDERED_RIGHT))); + + return quads; + } + + return Collections.emptyList(); + } + + @Override + public boolean useAmbientOcclusion() { + return ForgeConfig.CLIENT.experimentalForgeLightPipelineEnabled.get(); + } +} 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 new file mode 100644 index 0000000..ccafde0 --- /dev/null +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/client/BEWLRs.java @@ -0,0 +1,32 @@ +package io.github.foundationgames.automobility.forge.client; + +import com.mojang.blaze3d.vertex.PoseStack; +import io.github.foundationgames.automobility.util.HexCons; +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.ItemStack; + +import java.util.HashMap; +import java.util.Map; + +public class BEWLRs { + private static final Map> BEWLRS = new HashMap<>(); + + 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) { + var item = stack.getItem(); + if (BEWLRS.containsKey(item)) { + BEWLRS.get(item).accept(stack, transform, pose, buffers, light, overlay); + return true; + } + + return false; + } +} diff --git a/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/BlockColorsAccess.java b/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/BlockColorsAccess.java new file mode 100644 index 0000000..e3e6849 --- /dev/null +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/BlockColorsAccess.java @@ -0,0 +1,16 @@ +package io.github.foundationgames.automobility.forge.mixin; + +import net.minecraft.client.color.block.BlockColor; +import net.minecraft.client.color.block.BlockColors; +import net.minecraft.core.Holder; +import net.minecraft.world.level.block.Block; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.Map; + +@Mixin(BlockColors.class) +public interface BlockColorsAccess { + @Accessor("blockColors") + Map, BlockColor> automobility$getForgeColorMap(); +} 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 new file mode 100644 index 0000000..1a9578f --- /dev/null +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/BlockEntityWithoutLevelRendererMixin.java @@ -0,0 +1,22 @@ +package io.github.foundationgames.automobility.forge.mixin; + +import com.mojang.blaze3d.vertex.PoseStack; +import io.github.foundationgames.automobility.forge.client.BEWLRs; +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.ItemStack; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@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) { + if (BEWLRs.tryRender(stack, transform, pose, buffers, light, overlay)) { + ci.cancel(); + } + } +} diff --git a/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/ModelBakeryMixin.java b/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/ModelBakeryMixin.java new file mode 100644 index 0000000..8f36373 --- /dev/null +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/ModelBakeryMixin.java @@ -0,0 +1,32 @@ +package io.github.foundationgames.automobility.forge.mixin; + +import io.github.foundationgames.automobility.block.model.SlopeUnbakedModel; +import net.minecraft.client.resources.model.ModelBakery; +import net.minecraft.client.resources.model.UnbakedModel; +import net.minecraft.resources.ResourceLocation; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.Map; + +@Mixin(ModelBakery.class) +public abstract class ModelBakeryMixin { + @Shadow @Final private Map unbakedCache; + + @Shadow @Final private Map topLevelModels; + + @Inject(method = "loadModel", at = @At("HEAD"), cancellable = true) + private void automobility$addUnbakedSlopeModels(ResourceLocation location, CallbackInfo ci) { + if (SlopeUnbakedModel.DEFAULT_MODELS.containsKey(location)) { + var model = SlopeUnbakedModel.DEFAULT_MODELS.get(location).get(); + this.unbakedCache.put(location, model); + this.topLevelModels.put(location, model); + + 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 new file mode 100644 index 0000000..243e041 --- /dev/null +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/jsonem/CubeDefinitionAccess.java @@ -0,0 +1,39 @@ +package io.github.foundationgames.automobility.forge.mixin.jsonem; + +import com.mojang.math.Vector3f; +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 org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(CubeDefinition.class) +public interface CubeDefinitionAccess { + @Accessor("comment") + String automobility$name(); + + @Accessor("origin") + Vector3f automobility$offset(); + + @Accessor("dimensions") + Vector3f automobility$dimensions(); + + @Accessor("grow") + CubeDeformation automobility$dilation(); + + @Accessor("mirror") + boolean automobility$mirror(); + + @Accessor("texCoord") + UVPair automobility$uv(); + + @Accessor("texScale") + 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) { + throw new AssertionError(); + } +} diff --git a/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/jsonem/CubeDeformationAccess.java b/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/jsonem/CubeDeformationAccess.java new file mode 100644 index 0000000..50003d8 --- /dev/null +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/jsonem/CubeDeformationAccess.java @@ -0,0 +1,17 @@ +package io.github.foundationgames.automobility.forge.mixin.jsonem; + +import net.minecraft.client.model.geom.builders.CubeDeformation; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(CubeDeformation.class) +public interface CubeDeformationAccess { + @Accessor("growX") + float automobility$radiusX(); + + @Accessor("growY") + float automobility$radiusY(); + + @Accessor("growZ") + float automobility$radiusZ(); +} diff --git a/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/jsonem/EntityModelSetMixin.java b/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/jsonem/EntityModelSetMixin.java new file mode 100644 index 0000000..fc3ac15 --- /dev/null +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/jsonem/EntityModelSetMixin.java @@ -0,0 +1,31 @@ +package io.github.foundationgames.automobility.forge.mixin.jsonem; + +import io.github.foundationgames.automobility.forge.vendored.jsonem.util.JsonEntityModelUtil; +import net.minecraft.client.model.geom.EntityModelSet; +import net.minecraft.client.model.geom.LayerDefinitions; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.model.geom.builders.LayerDefinition; +import net.minecraft.server.packs.resources.ResourceManager; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.HashMap; +import java.util.Map; + +@Mixin(EntityModelSet.class) +public class EntityModelSetMixin { + @Shadow private Map roots; + + @Inject(method = "onResourceManagerReload", at = @At("HEAD"), cancellable = true) + private void jsonem$loadJsonEntityModels(ResourceManager manager, CallbackInfo ci) { + roots = new HashMap<>(); + roots.putAll(LayerDefinitions.createRoots()); + + JsonEntityModelUtil.loadModels(manager, roots); + + ci.cancel(); + } +} diff --git a/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/jsonem/LayerDefinitionAccess.java b/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/jsonem/LayerDefinitionAccess.java new file mode 100644 index 0000000..a27cbfc --- /dev/null +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/jsonem/LayerDefinitionAccess.java @@ -0,0 +1,22 @@ +package io.github.foundationgames.automobility.forge.mixin.jsonem; + +import net.minecraft.client.model.geom.builders.LayerDefinition; +import net.minecraft.client.model.geom.builders.MaterialDefinition; +import net.minecraft.client.model.geom.builders.MeshDefinition; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(LayerDefinition.class) +public interface LayerDefinitionAccess { + @Accessor("mesh") + MeshDefinition automobility$root(); + + @Accessor("material") + MaterialDefinition automobility$texture(); + + @Invoker("") + static LayerDefinition automobility$create(MeshDefinition data, MaterialDefinition dimensions) { + throw new AssertionError(); + } +} diff --git a/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/jsonem/MaterialDefinitionAccess.java b/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/jsonem/MaterialDefinitionAccess.java new file mode 100644 index 0000000..39b1092 --- /dev/null +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/jsonem/MaterialDefinitionAccess.java @@ -0,0 +1,14 @@ +package io.github.foundationgames.automobility.forge.mixin.jsonem; + +import net.minecraft.client.model.geom.builders.MaterialDefinition; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(MaterialDefinition.class) +public interface MaterialDefinitionAccess { + @Accessor("xTexSize") + int automobility$width(); + + @Accessor("yTexSize") + int automobility$height(); +} diff --git a/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/jsonem/PartDefinitionAccess.java b/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/jsonem/PartDefinitionAccess.java new file mode 100644 index 0000000..c16bc0b --- /dev/null +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/mixin/jsonem/PartDefinitionAccess.java @@ -0,0 +1,28 @@ +package io.github.foundationgames.automobility.forge.mixin.jsonem; + +import net.minecraft.client.model.geom.PartPose; +import net.minecraft.client.model.geom.builders.CubeDefinition; +import net.minecraft.client.model.geom.builders.PartDefinition; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; +import org.spongepowered.asm.mixin.gen.Invoker; + +import java.util.List; +import java.util.Map; + +@Mixin(PartDefinition.class) +public interface PartDefinitionAccess { + @Accessor("cubes") + List automobility$cuboids(); + + @Accessor("partPose") + PartPose automobility$transform(); + + @Accessor("children") + Map automobility$children(); + + @Invoker("") + static PartDefinition automobility$create(List cuboids, PartPose rotation) { + throw new AssertionError(); + } +} diff --git a/forge/src/main/java/io/github/foundationgames/automobility/forge/network/AutomobilityPacketHandler.java b/forge/src/main/java/io/github/foundationgames/automobility/forge/network/AutomobilityPacketHandler.java new file mode 100644 index 0000000..964ae68 --- /dev/null +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/network/AutomobilityPacketHandler.java @@ -0,0 +1,86 @@ +package io.github.foundationgames.automobility.forge.network; + +import io.github.foundationgames.automobility.Automobility; +import io.github.foundationgames.automobility.util.TriCons; +import net.minecraft.client.Minecraft; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; +import net.minecraftforge.fml.LogicalSide; +import net.minecraftforge.network.NetworkEvent; +import net.minecraftforge.network.NetworkRegistry; +import net.minecraftforge.network.PacketDistributor; +import net.minecraftforge.network.simple.SimpleChannel; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.BiConsumer; +import java.util.function.Supplier; + +public class AutomobilityPacketHandler { + private static final String PROTOCOL_VERSION = "0.3"; + public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel( + Automobility.rl("main"), + () -> PROTOCOL_VERSION, + PROTOCOL_VERSION::equals, + PROTOCOL_VERSION::equals + ); + + private static final Map> CLIENT_RECEIVERS = new HashMap<>(); + private static final Map> SERVER_RECEIVERS = new HashMap<>(); + + public static void addClientReceiver(ResourceLocation rl, BiConsumer receiver) { + CLIENT_RECEIVERS.put(rl, receiver); + } + + public static void addServerReceiver(ResourceLocation rl, TriCons receiver) { + SERVER_RECEIVERS.put(rl, receiver); + } + + public static void clientToServer(ResourceLocation rl, FriendlyByteBuf buf) { + INSTANCE.sendToServer(new PayloadMessage(rl, buf)); + } + + public static void serverToClient(ServerPlayer player, ResourceLocation rl, FriendlyByteBuf buf) { + INSTANCE.send(PacketDistributor.PLAYER.with(() -> player), new PayloadMessage(rl, buf)); + } + + public static void init() { + INSTANCE.registerMessage(0, PayloadMessage.class, PayloadMessage::encode, PayloadMessage::decode, PayloadMessage::handle); + } + + public static class PayloadMessage { + private final ResourceLocation id; + private final FriendlyByteBuf payload; + + public PayloadMessage(ResourceLocation id, FriendlyByteBuf payload) { + this.id = id; + this.payload = payload; + } + + public static PayloadMessage decode(FriendlyByteBuf buf) { + return new PayloadMessage(buf.readResourceLocation(), new FriendlyByteBuf(buf.readBytes(buf.readableBytes()))); + } + + private void encode(FriendlyByteBuf buf) { + buf.writeResourceLocation(this.id); + buf.writeBytes(this.payload); + } + + private void handle(Supplier ctxProvider) { + var ctx = ctxProvider.get(); + + if (ctx.getDirection().getReceptionSide() == LogicalSide.CLIENT) { + CLIENT_RECEIVERS.get(this.id).accept(Minecraft.getInstance(), this.payload); + } else if (ctx.getDirection().getReceptionSide() == LogicalSide.SERVER) { + var player = ctx.getSender(); + if (player != null) { + SERVER_RECEIVERS.get(this.id).accept(player.server, player, this.payload); + } + } + + ctx.setPacketHandled(true); + } + } +} diff --git a/forge/src/main/java/io/github/foundationgames/automobility/forge/vendored/jsonem/JsonEM.java b/forge/src/main/java/io/github/foundationgames/automobility/forge/vendored/jsonem/JsonEM.java new file mode 100644 index 0000000..3d15313 --- /dev/null +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/vendored/jsonem/JsonEM.java @@ -0,0 +1,16 @@ +package io.github.foundationgames.automobility.forge.vendored.jsonem; + +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.model.geom.builders.LayerDefinition; +import net.minecraft.client.model.geom.builders.MeshDefinition; +import net.minecraftforge.client.ForgeHooksClient; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +public class JsonEM { + public static final Logger LOG = LogManager.getLogger("Automobility Vendored | Json Entity Models"); + + public static void registerModelLayer(ModelLayerLocation layer) { + ForgeHooksClient.registerLayerDefinition(layer, () -> LayerDefinition.create(new MeshDefinition(), 32, 32)); + } +} 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 new file mode 100644 index 0000000..f05de0c --- /dev/null +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/vendored/jsonem/serialization/JsonEMCodecs.java @@ -0,0 +1,98 @@ +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; +import io.github.foundationgames.automobility.forge.mixin.jsonem.CubeDeformationAccess; +import io.github.foundationgames.automobility.forge.mixin.jsonem.LayerDefinitionAccess; +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 net.minecraft.Util; +import net.minecraft.client.model.geom.PartPose; +import net.minecraft.client.model.geom.builders.CubeDefinition; +import net.minecraft.client.model.geom.builders.CubeDeformation; +import net.minecraft.client.model.geom.builders.LayerDefinition; +import net.minecraft.client.model.geom.builders.MaterialDefinition; +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 java.util.HashMap; +import java.util.Optional; + +public class JsonEMCodecs { + public static final Codec MATERIAL_DEFINITION = RecordCodecBuilder.create((instance) -> + instance.group( + Codec.INT.fieldOf("width").forGetter(obj -> ((MaterialDefinitionAccess) obj).automobility$width()), + Codec.INT.fieldOf("height").forGetter(obj -> ((MaterialDefinitionAccess) obj).automobility$height()) + ).apply(instance, MaterialDefinition::new) + ); + + 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)) + ).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( + vec -> new CubeDeformation(vec.x(), vec.y(), vec.z()), + dil -> new Vector3f( + ((CubeDeformationAccess) dil).automobility$radiusX(), + ((CubeDeformationAccess) dil).automobility$radiusY(), + ((CubeDeformationAccess) dil).automobility$radiusZ()) + ); + + public static final Codec UV_PAIR = Codec.FLOAT.listOf().comapFlatMap((vec) -> + Util.fixedSize(vec, 2).map((arr) -> new UVPairComparable(arr.get(0), arr.get(1))), + (vec) -> ImmutableList.of(vec.u(), vec.v()) + ); + + 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()); + } + + private static final UVPair DEFAULT_UV_SCALE = new UVPairComparable(1.0f, 1.0f); + + 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()), + 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()), + UV_PAIR.optionalFieldOf("uv_scale", DEFAULT_UV_SCALE).forGetter(obj -> UVPairComparable.of(((CubeDefinitionAccess)(Object)obj).automobility$uvScale())) + ).apply(instance, JsonEMCodecs::createCuboidData) + ); + + private static Codec createPartDefinitionCodec() { + return RecordCodecBuilder.create((instance) -> + instance.group( + PART_POSE.optionalFieldOf("transform", PartPose.ZERO).forGetter(obj -> ((PartDefinitionAccess)obj).automobility$transform()), + Codec.list(CUBE_DEFINITION).fieldOf("cuboids").forGetter(obj -> ((PartDefinitionAccess)obj).automobility$cuboids()), + LazyTypeUnboundedMapCodec.of(Codec.STRING, JsonEMCodecs::createPartDefinitionCodec).optionalFieldOf("children", new HashMap<>()).forGetter(obj -> ((PartDefinitionAccess)obj).automobility$children()) + ).apply(instance, (transform, cuboids, children) -> { + var data = PartDefinitionAccess.automobility$create(cuboids, transform); + ((PartDefinitionAccess) data).automobility$children().putAll(children); + return data; + }) + ); + } + + public static final Codec PART_DEFINITION = createPartDefinitionCodec(); + + public static final Codec LAYER_DEFINITION = RecordCodecBuilder.create((instance) -> + instance.group( + MATERIAL_DEFINITION.fieldOf("texture").forGetter(obj -> ((LayerDefinitionAccess) obj).automobility$texture()), + Codec.unboundedMap(Codec.STRING, PART_DEFINITION).fieldOf("bones").forGetter(obj -> ((PartDefinitionAccess) ((LayerDefinitionAccess) obj).automobility$root().getRoot()).automobility$children()) + ).apply(instance, (texture, bones) -> { + var data = new MeshDefinition(); + ((PartDefinitionAccess) data.getRoot()).automobility$children().putAll(bones); + return LayerDefinitionAccess.automobility$create(data, texture); + }) + ); +} diff --git a/forge/src/main/java/io/github/foundationgames/automobility/forge/vendored/jsonem/serialization/LazyTypeUnboundedMapCodec.java b/forge/src/main/java/io/github/foundationgames/automobility/forge/vendored/jsonem/serialization/LazyTypeUnboundedMapCodec.java new file mode 100644 index 0000000..c80c7a1 --- /dev/null +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/vendored/jsonem/serialization/LazyTypeUnboundedMapCodec.java @@ -0,0 +1,51 @@ +package io.github.foundationgames.automobility.forge.vendored.jsonem.serialization; + +import com.mojang.datafixers.util.Pair; +import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.DynamicOps; +import com.mojang.serialization.Lifecycle; +import com.mojang.serialization.codecs.BaseMapCodec; + +import java.util.Map; +import java.util.function.Supplier; + +public class LazyTypeUnboundedMapCodec implements BaseMapCodec, Codec> { + private final Codec keyCodec; + private final Supplier> elementCodecProvider; + + private Codec elementCodec; + + public LazyTypeUnboundedMapCodec(Codec keyCodec, Supplier> elementCodecProvider) { + this.keyCodec = keyCodec; + this.elementCodecProvider = elementCodecProvider; + } + + public static LazyTypeUnboundedMapCodec of(Codec keyCodec, Supplier> elementCodecProvider) { + return new LazyTypeUnboundedMapCodec<>(keyCodec, elementCodecProvider); + } + + @Override + public DataResult, T>> decode(DynamicOps ops, T input) { + return ops.getMap(input).setLifecycle(Lifecycle.stable()).flatMap(map -> decode(ops, map)).map(r -> Pair.of(r, input)); + } + + @Override + public DataResult encode(Map input, DynamicOps ops, T prefix) { + return encode(input, ops, ops.mapBuilder()).build(prefix); + } + + @Override + public Codec keyCodec() { + return keyCodec; + } + + @Override + public Codec elementCodec() { + if (elementCodec == null) { + elementCodec = elementCodecProvider.get(); + } + + return elementCodec; + } +} \ No newline at end of file diff --git a/forge/src/main/java/io/github/foundationgames/automobility/forge/vendored/jsonem/util/JsonEntityModelUtil.java b/forge/src/main/java/io/github/foundationgames/automobility/forge/vendored/jsonem/util/JsonEntityModelUtil.java new file mode 100644 index 0000000..f4782b3 --- /dev/null +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/vendored/jsonem/util/JsonEntityModelUtil.java @@ -0,0 +1,64 @@ +package io.github.foundationgames.automobility.forge.vendored.jsonem.util; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Streams; +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.mojang.datafixers.util.Pair; +import com.mojang.serialization.JsonOps; +import io.github.foundationgames.automobility.forge.vendored.jsonem.JsonEM; +import io.github.foundationgames.automobility.forge.vendored.jsonem.serialization.JsonEMCodecs; +import io.github.foundationgames.automobility.util.InitlessConstants; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.model.geom.ModelLayers; +import net.minecraft.client.model.geom.builders.LayerDefinition; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.resources.ResourceManager; +import net.minecraftforge.client.ForgeHooksClient; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Map; +import java.util.Optional; + +public final class JsonEntityModelUtil { + public static final Gson GSON = new Gson(); + + private JsonEntityModelUtil() {} + + public static Optional readJson(InputStream data) { + JsonElement json = GSON.fromJson(GSON.newJsonReader(new InputStreamReader(data)), JsonObject.class); + + return JsonEMCodecs.LAYER_DEFINITION.decode(JsonOps.INSTANCE, json).result().map(Pair::getFirst); + } + + public static void loadModels(ResourceManager manager, Map models) { + var tempMap = new ImmutableMap.Builder(); + ForgeHooksClient.loadLayerDefinitions(tempMap); + + // Only load Automobility models, don't mess with other mods (or the vanilla game) + var layers = Streams.concat( + ModelLayers.getKnownLocations(), + tempMap.build().keySet().stream() + .filter(ml -> InitlessConstants.AUTOMOBILITY.equals(ml.getModel().getNamespace())) + ); + layers.forEach(layer -> { + var modelLoc = new ResourceLocation(layer.getModel().getNamespace(), "models/entity/"+layer.getModel().getPath()+"/"+layer.getLayer()+".json"); + + var res = manager.getResource(modelLoc); + + if (res.isPresent()) { + try { + try (var in = res.get().open()) { + var data = JsonEntityModelUtil.readJson(in); + data.ifPresent(model -> models.put(layer, model)); + } + } catch (IOException e) { + JsonEM.LOG.error(e); + } + } + }); + } +} diff --git a/forge/src/main/java/io/github/foundationgames/automobility/forge/vendored/jsonem/util/UVPairComparable.java b/forge/src/main/java/io/github/foundationgames/automobility/forge/vendored/jsonem/util/UVPairComparable.java new file mode 100644 index 0000000..a5d1289 --- /dev/null +++ b/forge/src/main/java/io/github/foundationgames/automobility/forge/vendored/jsonem/util/UVPairComparable.java @@ -0,0 +1,24 @@ +package io.github.foundationgames.automobility.forge.vendored.jsonem.util; + +import net.minecraft.client.model.geom.builders.UVPair; + +/** + * Implementation of {@code equals()} on {@link UVPair} + */ +public class UVPairComparable extends UVPair { + public UVPairComparable(float x, float y) { + super(x, y); + } + + public static UVPairComparable of(UVPair vec) { + return new UVPairComparable(vec.u(), vec.v()); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof UVPair vec) { + return this.u() == vec.u() && this.v() == vec.v(); + } + return super.equals(obj); + } +} diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml new file mode 100644 index 0000000..d8cf8bd --- /dev/null +++ b/forge/src/main/resources/META-INF/mods.toml @@ -0,0 +1,27 @@ +modLoader="javafml" +loaderVersion="[43,)" +license="MIT" + +[[mods]] +modId="automobility" +version="${version}" +displayName="Automobility" +logoFile="automobility.png" +authors="FoundationGames" #optional +description=''' +Vehicles and whatnot +''' + +[[dependencies.automobility]] +modId="forge" +mandatory=true +versionRange="[43,)" +ordering="NONE" +side="BOTH" + +[[dependencies.automobility]] +modId="minecraft" +mandatory=true +versionRange="[1.19.2,1.20)" +ordering="NONE" +side="BOTH" diff --git a/forge/src/main/resources/automobility_forge.mixins.json b/forge/src/main/resources/automobility_forge.mixins.json new file mode 100644 index 0000000..060bf93 --- /dev/null +++ b/forge/src/main/resources/automobility_forge.mixins.json @@ -0,0 +1,23 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "io.github.foundationgames.automobility.forge.mixin", + "compatibilityLevel": "JAVA_17", + "refmap": "automobility-refmap.json", + "mixins": [ + ], + "client": [ + "BlockColorsAccess", + "BlockEntityWithoutLevelRendererMixin", + "ModelBakeryMixin", + "jsonem.CubeDefinitionAccess", + "jsonem.CubeDeformationAccess", + "jsonem.EntityModelSetMixin", + "jsonem.LayerDefinitionAccess", + "jsonem.MaterialDefinitionAccess", + "jsonem.PartDefinitionAccess" + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/forge/src/main/resources/pack.mcmeta b/forge/src/main/resources/pack.mcmeta new file mode 100644 index 0000000..723abe2 --- /dev/null +++ b/forge/src/main/resources/pack.mcmeta @@ -0,0 +1,6 @@ +{ + "pack": { + "pack_format": 9, + "description": "Automobilty Mod Resources" + } +} diff --git a/gradle.properties b/gradle.properties index b6cc9aa..453b51a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,12 +2,11 @@ org.gradle.jvmargs=-Xmx1G minecraft_version=1.19.2 yarn_mappings=1.19.2+build.4 -loader_version=0.14.9 +fabric_version=0.14.9 +forge_version=43.1.30 -#Fabric api -fabric_version=0.60.0+1.19.2 - -# Other Dependencies +# 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 @@ -15,6 +14,6 @@ myron_version=1.6.5+22w14a arrp_version=0.6.2 jsonem_version=0.1.2+1.19 -mod_version = 0.3+1.19.2 +mod_version = 0.4.1 maven_group = io.github.foundationgames archives_base_name = automobility diff --git a/settings.gradle b/settings.gradle index f91a4fe..87f0651 100644 --- a/settings.gradle +++ b/settings.gradle @@ -4,6 +4,12 @@ pluginManagement { name = 'Fabric' url = 'https://maven.fabricmc.net/' } + maven { + url = 'https://repo.spongepowered.org/repository/maven-public/' + } gradlePluginPortal() } } + +rootProject.name = "Automobility" +include("common", "fabric", "forge") diff --git a/src/main/java/io/github/foundationgames/automobility/Automobility.java b/src/main/java/io/github/foundationgames/automobility/Automobility.java deleted file mode 100644 index 7b896a0..0000000 --- a/src/main/java/io/github/foundationgames/automobility/Automobility.java +++ /dev/null @@ -1,64 +0,0 @@ -package io.github.foundationgames.automobility; - -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.particle.AutomobilityParticles; -import io.github.foundationgames.automobility.recipe.AutoMechanicTableRecipe; -import io.github.foundationgames.automobility.recipe.AutoMechanicTableRecipeSerializer; -import io.github.foundationgames.automobility.resource.AutomobilityData; -import io.github.foundationgames.automobility.screen.AutoMechanicTableScreenHandler; -import io.github.foundationgames.automobility.screen.SingleSlotScreenHandler; -import io.github.foundationgames.automobility.sound.AutomobilitySounds; -import io.github.foundationgames.automobility.util.AUtils; -import io.github.foundationgames.automobility.util.midnightcontrols.ControllerUtils; -import io.github.foundationgames.automobility.util.network.PayloadPackets; -import net.fabricmc.api.ModInitializer; -import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder; -import net.minecraft.block.Block; -import net.minecraft.item.ItemGroup; -import net.minecraft.screen.ScreenHandlerType; -import net.minecraft.tag.TagKey; -import net.minecraft.util.Identifier; -import net.minecraft.util.registry.Registry; - -public class Automobility implements ModInitializer { - public static final String MOD_ID = "automobility"; - - public static final ItemGroup GROUP = FabricItemGroupBuilder.build(id("automobility"), AUtils::createGroupIcon); - public static final ItemGroup COURSE_ELEMENTS = FabricItemGroupBuilder.build(id("automobility_course_elements"), AUtils::createCourseElementsIcon); - public static final ItemGroup PREFABS = FabricItemGroupBuilder.build(id("automobility_prefabs"), AUtils::createPrefabsIcon); - - public static final TagKey SLOPES = TagKey.of(Registry.BLOCK_KEY, id("slopes")); - public static final TagKey STEEP_SLOPES = TagKey.of(Registry.BLOCK_KEY, id("steep_slopes")); - public static final TagKey NON_STEEP_SLOPES = TagKey.of(Registry.BLOCK_KEY, id("non_steep_slopes")); - public static final TagKey STICKY_SLOPES = TagKey.of(Registry.BLOCK_KEY, id("sticky_slopes")); - - public static final ScreenHandlerType AUTO_MECHANIC_SCREEN = - Registry.register(Registry.SCREEN_HANDLER, Automobility.id("auto_mechanic_table"), new ScreenHandlerType<>(AutoMechanicTableScreenHandler::new)); - public static final ScreenHandlerType SINGLE_SLOT_SCREEN = - Registry.register(Registry.SCREEN_HANDLER, Automobility.id("single_slot"), new ScreenHandlerType<>(SingleSlotScreenHandler::new)); - - @Override - public void onInitialize() { - AutomobilityBlocks.init(); - AutomobilityItems.init(); - AutomobilityEntities.init(); - AutomobilityParticles.init(); - AutomobilitySounds.init(); - initOther(); - - PayloadPackets.init(); - AutomobilityData.setup(); - ControllerUtils.initMidnightControlsHandler(); - } - - public static void initOther() { - Registry.register(Registry.RECIPE_TYPE, AutoMechanicTableRecipe.ID, AutoMechanicTableRecipe.TYPE); - Registry.register(Registry.RECIPE_SERIALIZER, AutoMechanicTableRecipe.ID, AutoMechanicTableRecipeSerializer.INSTANCE); - } - - public static Identifier id(String path) { - return new Identifier(MOD_ID, path); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/AutomobilityClient.java b/src/main/java/io/github/foundationgames/automobility/AutomobilityClient.java deleted file mode 100644 index 8949b8d..0000000 --- a/src/main/java/io/github/foundationgames/automobility/AutomobilityClient.java +++ /dev/null @@ -1,49 +0,0 @@ -package io.github.foundationgames.automobility; - -import io.github.foundationgames.automobility.block.AutomobilityBlocks; -import io.github.foundationgames.automobility.block.entity.render.AutomobileAssemblerBlockEntityRenderer; -import io.github.foundationgames.automobility.entity.AutomobileEntity; -import io.github.foundationgames.automobility.entity.AutomobilityEntities; -import io.github.foundationgames.automobility.item.AutomobilityItems; -import io.github.foundationgames.automobility.particle.AutomobilityParticles; -import io.github.foundationgames.automobility.render.AutomobilityModels; -import io.github.foundationgames.automobility.resource.AutomobilityAssets; -import io.github.foundationgames.automobility.screen.AutoMechanicTableScreen; -import io.github.foundationgames.automobility.screen.AutomobileHud; -import io.github.foundationgames.automobility.screen.SingleSlotScreen; -import io.github.foundationgames.automobility.util.network.PayloadPackets; -import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; -import net.fabricmc.fabric.api.client.rendering.v1.BlockEntityRendererRegistry; -import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.ingame.HandledScreens; -import net.minecraft.client.render.RenderLayer; - -public class AutomobilityClient implements ClientModInitializer { - @Override - public void onInitializeClient() { - AutomobilityModels.init(); - AutomobilityBlocks.initClient(); - AutomobilityItems.initClient(); - AutomobilityEntities.initClient(); - AutomobilityParticles.initClient(); - PayloadPackets.initClient(); - - AutomobilityAssets.setup(); - - HandledScreens.register(Automobility.AUTO_MECHANIC_SCREEN, AutoMechanicTableScreen::new); - HandledScreens.register(Automobility.SINGLE_SLOT_SCREEN, SingleSlotScreen::new); - - HudRenderCallback.EVENT.register((matrices, delta) -> { - var player = MinecraftClient.getInstance().player; - if (player.getVehicle() instanceof AutomobileEntity auto) { - AutomobileHud.render(matrices, player, auto, delta); - } - }); - - BlockRenderLayerMap.INSTANCE.putBlock(AutomobilityBlocks.AUTOMOBILE_ASSEMBLER, RenderLayer.getCutout()); - - BlockEntityRendererRegistry.register(AutomobilityBlocks.AUTOMOBILE_ASSEMBLER_ENTITY, AutomobileAssemblerBlockEntityRenderer::new); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BaseChestRearAttachment.java b/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BaseChestRearAttachment.java deleted file mode 100644 index 2be9844..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BaseChestRearAttachment.java +++ /dev/null @@ -1,127 +0,0 @@ -package io.github.foundationgames.automobility.automobile.attachment.rear; - -import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType; -import io.github.foundationgames.automobility.entity.AutomobileEntity; -import io.github.foundationgames.automobility.util.duck.EnderChestInventoryDuck; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.entity.ChestLidAnimator; -import net.minecraft.block.entity.ViewerCountManager; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.screen.GenericContainerScreenHandler; -import net.minecraft.screen.NamedScreenHandlerFactory; -import net.minecraft.screen.ScreenHandlerContext; -import net.minecraft.screen.SimpleNamedScreenHandlerFactory; -import net.minecraft.sound.SoundCategory; -import net.minecraft.sound.SoundEvent; -import net.minecraft.sound.SoundEvents; -import net.minecraft.text.Text; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.jetbrains.annotations.Nullable; - -import java.util.function.BiFunction; - -public class BaseChestRearAttachment extends BlockRearAttachment { - public static final Text TITLE_CHEST = Text.translatable("container.chest"); - public static final Text TITLE_ENDER_CHEST = Text.translatable("container.enderchest"); - public static final Text TITLE_BARREL = Text.translatable("container.barrel"); - - private final ViewerCountManager viewerManager; - public final ChestLidAnimator lidAnimator; - - public BaseChestRearAttachment(RearAttachmentType type, AutomobileEntity entity, BlockState block, @Nullable BiFunction screenProvider) { - super(type, entity, block, screenProvider); - this.viewerManager = new ViewerCountManager() { - protected void onContainerOpen(World world, BlockPos pos, BlockState state) { - sound(world, pos, BaseChestRearAttachment.this.getOpenSound()); - } - - protected void onContainerClose(World world, BlockPos pos, BlockState state) { - sound(world, pos, BaseChestRearAttachment.this.getCloseSound()); - } - - protected void onViewerCountUpdate(World world, BlockPos pos, BlockState state, int oldViewerCount, int newViewerCount) { - if (!world.isClient()) { - BaseChestRearAttachment.this.updateTrackedAnimation(newViewerCount); - } - } - - protected boolean isPlayerViewing(PlayerEntity player) { - if (!(player.currentScreenHandler instanceof GenericContainerScreenHandler)) { - return false; - } else { - var inventory = ((GenericContainerScreenHandler)player.currentScreenHandler).getInventory(); - return inventory == BaseChestRearAttachment.this; - } - } - }; - this.lidAnimator = new ChestLidAnimator(); - } - - public void open(PlayerEntity player) { - if (!player.isSpectator()) { - this.viewerManager.openContainer(player, this.world(), this.automobile.getBlockPos(), Blocks.AIR.getDefaultState()); - } - } - - public void close(PlayerEntity player) { - if (!player.isSpectator()) { - this.viewerManager.closeContainer(player, this.world(), this.automobile.getBlockPos(), Blocks.AIR.getDefaultState()); - } - } - - @Override - public void onTrackedAnimationUpdated(float animation) { - super.onTrackedAnimationUpdated(animation); - - this.lidAnimator.setOpen(animation > 0); - } - - @Override - public void tick() { - super.tick(); - - if (world().isClient()) { - this.lidAnimator.step(); - } - } - - protected SoundEvent getOpenSound() { - return SoundEvents.BLOCK_ENDER_CHEST_OPEN; - } - - protected SoundEvent getCloseSound() { - return SoundEvents.BLOCK_ENDER_CHEST_CLOSE; - } - - private static void sound(World world, BlockPos pos, SoundEvent soundEvent) { - world.playSound(null, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, soundEvent, SoundCategory.BLOCKS, 0.5F, world.random.nextFloat() * 0.1F + 0.9F); - } - - public static BaseChestRearAttachment chest(RearAttachmentType type, AutomobileEntity entity) { - return new ChestRearAttachment(type, entity, - Blocks.ENDER_CHEST.getDefaultState(), - (ctx, att) -> att instanceof ChestRearAttachment chest ? chest : null); - } - - public static BaseChestRearAttachment enderChest(RearAttachmentType type, AutomobileEntity entity) { - return new BaseChestRearAttachment(type, entity, - Blocks.ENDER_CHEST.getDefaultState(), - (ctx, att) -> new SimpleNamedScreenHandlerFactory((syncId, inventory, player) -> { - var enderChest = player.getEnderChestInventory(); - if (att instanceof BaseChestRearAttachment chest) { - EnderChestInventoryDuck.of(enderChest).automobility$setActiveAttachment(chest); - } - return GenericContainerScreenHandler.createGeneric9x3(syncId, inventory, enderChest); - }, TITLE_ENDER_CHEST) - ); - } - - public static BaseChestRearAttachment saddledBarrel(RearAttachmentType type, AutomobileEntity entity) { - return new SaddledBarrelRearAttachment(type, entity, - Blocks.BARREL.getDefaultState(), - (ctx, att) -> att instanceof SaddledBarrelRearAttachment barrel ? barrel : null); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BlockRearAttachment.java b/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BlockRearAttachment.java deleted file mode 100644 index 4e0c7b0..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BlockRearAttachment.java +++ /dev/null @@ -1,108 +0,0 @@ -package io.github.foundationgames.automobility.automobile.attachment.rear; - -import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType; -import io.github.foundationgames.automobility.block.AutoMechanicTableBlock; -import io.github.foundationgames.automobility.block.AutomobilityBlocks; -import io.github.foundationgames.automobility.entity.AutomobileEntity; -import io.github.foundationgames.automobility.screen.AutoMechanicTableScreenHandler; -import io.github.foundationgames.automobility.util.duck.EnderChestInventoryDuck; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.screen.CartographyTableScreenHandler; -import net.minecraft.screen.CraftingScreenHandler; -import net.minecraft.screen.GenericContainerScreenHandler; -import net.minecraft.screen.GrindstoneScreenHandler; -import net.minecraft.screen.LoomScreenHandler; -import net.minecraft.screen.NamedScreenHandlerFactory; -import net.minecraft.screen.ScreenHandlerContext; -import net.minecraft.screen.SimpleNamedScreenHandlerFactory; -import net.minecraft.screen.SmithingScreenHandler; -import net.minecraft.screen.StonecutterScreenHandler; -import net.minecraft.text.Text; -import org.jetbrains.annotations.Nullable; - -import java.util.function.BiFunction; - -public class BlockRearAttachment extends RearAttachment { - public static final Text TITLE_CRAFTING = Text.translatable("container.crafting"); - public static final Text TITLE_LOOM = Text.translatable("container.loom"); - public static final Text TITLE_CARTOGRAPHY = Text.translatable("container.cartography_table"); - public static final Text TITLE_SMITHING = Text.translatable("container.upgrade"); - public static final Text TITLE_GRINDSTONE = Text.translatable("container.grindstone_title"); - public static final Text TITLE_STONECUTTER = Text.translatable("container.stonecutter"); - - public final BlockState block; - private final @Nullable BiFunction screenProvider; - - public BlockRearAttachment(RearAttachmentType type, AutomobileEntity entity, BlockState block, @Nullable BiFunction screenProvider) { - super(type, entity); - this.block = block; - this.screenProvider = screenProvider; - } - - @Override - public boolean hasMenu() { - return this.screenProvider != null; - } - - @Override - public @Nullable NamedScreenHandlerFactory createMenu(ScreenHandlerContext ctx) { - return this.screenProvider != null ? this.screenProvider.apply(ctx, this) : null; - } - - public static BlockRearAttachment craftingTable(RearAttachmentType type, AutomobileEntity entity) { - return new BlockRearAttachment(type, entity, - Blocks.CRAFTING_TABLE.getDefaultState(), - (ctx, att) -> new SimpleNamedScreenHandlerFactory((syncId, inventory, player) -> - new CraftingScreenHandler(syncId, inventory, ctx), TITLE_CRAFTING) - ); - } - - public static BlockRearAttachment loom(RearAttachmentType type, AutomobileEntity entity) { - return new BlockRearAttachment(type, entity, - Blocks.LOOM.getDefaultState(), - (ctx, att) -> new SimpleNamedScreenHandlerFactory((syncId, inventory, player) -> - new LoomScreenHandler(syncId, inventory, ctx), TITLE_LOOM) - ); - } - - public static BlockRearAttachment cartographyTable(RearAttachmentType type, AutomobileEntity entity) { - return new BlockRearAttachment(type, entity, - Blocks.CARTOGRAPHY_TABLE.getDefaultState(), - (ctx, att) -> new SimpleNamedScreenHandlerFactory((syncId, inventory, player) -> - new CartographyTableScreenHandler(syncId, inventory, ctx), TITLE_CARTOGRAPHY) - ); - } - - public static BlockRearAttachment smithingTable(RearAttachmentType type, AutomobileEntity entity) { - return new BlockRearAttachment(type, entity, - Blocks.SMITHING_TABLE.getDefaultState(), - (ctx, att) -> new SimpleNamedScreenHandlerFactory((syncId, inventory, player) -> - new SmithingScreenHandler(syncId, inventory, ctx), TITLE_SMITHING) - ); - } - - public static BlockRearAttachment grindstone(RearAttachmentType type, AutomobileEntity entity) { - return new BlockRearAttachment(type, entity, - Blocks.GRINDSTONE.getDefaultState(), - (ctx, att) -> new SimpleNamedScreenHandlerFactory((syncId, inventory, player) -> - new GrindstoneScreenHandler(syncId, inventory, ctx), TITLE_GRINDSTONE) - ); - } - - public static BlockRearAttachment stonecutter(RearAttachmentType type, AutomobileEntity entity) { - return new BlockRearAttachment(type, entity, - Blocks.STONECUTTER.getDefaultState(), - (ctx, att) -> new SimpleNamedScreenHandlerFactory((syncId, inventory, player) -> - new StonecutterScreenHandler(syncId, inventory, ctx), TITLE_STONECUTTER) - ); - } - - public static BlockRearAttachment autoMechanicTable(RearAttachmentType type, AutomobileEntity entity) { - return new BlockRearAttachment(type, entity, - AutomobilityBlocks.AUTO_MECHANIC_TABLE.getDefaultState(), - (ctx, att) -> new SimpleNamedScreenHandlerFactory((syncId, inventory, player) -> - new AutoMechanicTableScreenHandler(syncId, inventory, ctx), AutoMechanicTableBlock.UI_TITLE) - ); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/ChestRearAttachment.java b/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/ChestRearAttachment.java deleted file mode 100644 index 8c0ba77..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/ChestRearAttachment.java +++ /dev/null @@ -1,130 +0,0 @@ -package io.github.foundationgames.automobility.automobile.attachment.rear; - -import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType; -import io.github.foundationgames.automobility.entity.AutomobileEntity; -import net.minecraft.block.BlockState; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.Inventories; -import net.minecraft.inventory.Inventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.screen.GenericContainerScreenHandler; -import net.minecraft.screen.NamedScreenHandlerFactory; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.screen.ScreenHandlerContext; -import net.minecraft.sound.SoundEvent; -import net.minecraft.sound.SoundEvents; -import net.minecraft.text.Text; -import net.minecraft.util.ItemScatterer; -import net.minecraft.util.collection.DefaultedList; -import org.jetbrains.annotations.Nullable; - -import java.util.function.BiFunction; - -public class ChestRearAttachment extends BaseChestRearAttachment implements Inventory, NamedScreenHandlerFactory { - private DefaultedList inventory; - - public ChestRearAttachment(RearAttachmentType type, AutomobileEntity entity, BlockState block, @Nullable BiFunction screenProvider) { - super(type, entity, block, screenProvider); - this.inventory = DefaultedList.ofSize(27, ItemStack.EMPTY); - } - - @Override - public void onRemoved() { - super.onRemoved(); - - var pos = this.pos(); - this.inventory.forEach(s -> ItemScatterer.spawn(this.world(), pos.x, pos.y, pos.z, s)); - } - - @Override - public int size() { - return this.inventory.size(); - } - - @Override - public boolean isEmpty() { - return this.inventory.stream().allMatch(ItemStack::isEmpty); - } - - @Override - public ItemStack getStack(int slot) { - return this.inventory.get(slot); - } - - @Override - public ItemStack removeStack(int slot, int amount) { - return Inventories.splitStack(this.inventory, slot, amount); - } - - @Override - public ItemStack removeStack(int slot) { - return Inventories.removeStack(this.inventory, slot); - } - - @Override - public void setStack(int slot, ItemStack stack) { - this.inventory.set(slot, stack); - } - - @Override - public void markDirty() { - this.automobile.markDirty(); - } - - @Override - public boolean canPlayerUse(PlayerEntity player) { - return true; - } - - @Override - public Text getDisplayName() { - return BaseChestRearAttachment.TITLE_CHEST; - } - - @Nullable - @Override - public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) { - return GenericContainerScreenHandler.createGeneric9x3(syncId, inv, this); - } - - @Override - public void clear() { - this.inventory.clear(); - } - - @Override - public void onOpen(PlayerEntity player) { - this.open(player); - } - - @Override - public void onClose(PlayerEntity player) { - this.close(player); - } - - @Override - protected SoundEvent getOpenSound() { - return SoundEvents.BLOCK_CHEST_OPEN; - } - - @Override - protected SoundEvent getCloseSound() { - return SoundEvents.BLOCK_CHEST_CLOSE; - } - - @Override - public void writeNbt(NbtCompound nbt) { - super.writeNbt(nbt); - - nbt.put("Items", Inventories.writeNbt(new NbtCompound(), this.inventory)); - } - - @Override - public void readNbt(NbtCompound nbt) { - super.readNbt(nbt); - - Inventories.readNbt(nbt.getCompound("Items"), this.inventory); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/AutomobileRenderer.java b/src/main/java/io/github/foundationgames/automobility/automobile/render/AutomobileRenderer.java deleted file mode 100644 index 1fc4b5a..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/AutomobileRenderer.java +++ /dev/null @@ -1,215 +0,0 @@ -package io.github.foundationgames.automobility.automobile.render; - -import io.github.foundationgames.automobility.automobile.AutomobileEngine; -import io.github.foundationgames.automobility.automobile.WheelBase; -import io.github.foundationgames.automobility.automobile.render.attachment.front.FrontAttachmentRenderModel; -import io.github.foundationgames.automobility.automobile.render.attachment.rear.RearAttachmentRenderModel; -import io.github.foundationgames.automobility.automobile.render.wheel.WheelContextReceiver; -import io.github.foundationgames.automobility.entity.AutomobileEntity; -import net.minecraft.client.model.Model; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.Identifier; -import net.minecraft.util.math.Vec3f; - -public enum AutomobileRenderer {; - private static Model skidEffectModel; - private static Model exhaustFumesModel; - - public static void render( - MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, float tickDelta, - EntityRendererFactory.Context ctx, RenderableAutomobile automobile - ) { - var frame = automobile.getFrame(); - var wheels = automobile.getWheels(); - var engine = automobile.getEngine(); - - if (skidEffectModel == null || exhaustFumesModel == null) { - skidEffectModel = new SkidEffectModel(ctx); - exhaustFumesModel = new ExhaustFumesModel(ctx); - } - - matrices.push(); - - matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(180)); - matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(automobile.getAutomobileYaw(tickDelta) + 180)); - - float chassisRaise = wheels.model().radius() / 16; - float bounce = automobile.getSuspensionBounce(tickDelta) * 0.048f; - - var frameModel = automobile.getFrameModel(ctx); - var wheelModel = automobile.getWheelModel(ctx); - var engineModel = automobile.getEngineModel(ctx); - var rearAttachmentModel = automobile.getRearAttachmentModel(ctx); - var frontAttachmentModel = automobile.getFrontAttachmentModel(ctx); - - matrices.translate(0, -chassisRaise, 0); - - // Frame, engine, exhaust - matrices.push(); - - matrices.translate(0, bounce + (automobile.engineRunning() ? (Math.cos((automobile.getTime() + tickDelta) * 2.7) / 156) : 0), 0); - var frameTexture = frame.model().texture(); - var engineTexture = engine.model().texture(); - if (!frame.isEmpty() && frameModel != null) { - frameModel.render(matrices, vertexConsumers.getBuffer(frameModel.getLayer(frameTexture)), light, overlay, 1, 1, 1, 1); - if (frameModel instanceof BaseModel base) { - base.doOtherLayerRender(matrices, vertexConsumers, light, overlay); - } - } - - float eBack = frame.model().enginePosBack() / 16; - float eUp = frame.model().enginePosUp() / 16; - matrices.translate(0, -eUp, eBack); - matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(180)); - if (!engine.isEmpty() && engineModel != null) { - engineModel.render(matrices, vertexConsumers.getBuffer(engineModel.getLayer(engineTexture)), light, overlay, 1, 1, 1, 1); - if (engineModel instanceof BaseModel base) { - base.doOtherLayerRender(matrices, vertexConsumers, light, overlay); - } - } - - VertexConsumer exhaustBuffer = null; - Identifier[] exhaustTexes; - if (automobile.getBoostTimer() > 0) { - exhaustTexes = ExhaustFumesModel.FLAME_TEXTURES; - int index = (int)(automobile.getTime() % exhaustTexes.length); - exhaustBuffer = vertexConsumers.getBuffer(RenderLayer.getEyes(exhaustTexes[index])); - } else if (automobile.engineRunning()) { - exhaustTexes = ExhaustFumesModel.SMOKE_TEXTURES; - int index = (int)Math.floor(((automobile.getTime() + tickDelta) / 1.5f) % exhaustTexes.length); - exhaustBuffer = vertexConsumers.getBuffer(RenderLayer.getEntityTranslucent(exhaustTexes[index])); - } - if (exhaustBuffer != null) { - for (AutomobileEngine.ExhaustPos exhaust : engine.model().exhausts()) { - matrices.push(); - - matrices.translate(exhaust.x() / 16, -exhaust.y() / 16, exhaust.z() / 16); - matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(exhaust.yaw())); - matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(exhaust.pitch())); - exhaustFumesModel.render(matrices, exhaustBuffer, light, overlay, 1, 1, 1, 1); - - matrices.pop(); - } - } - matrices.pop(); - - // Rear Attachment - var rearAtt = automobile.getRearAttachmentType(); - if (!rearAtt.isEmpty()) { - matrices.push(); - matrices.translate(0, chassisRaise, frame.model().rearAttachmentPos() / 16); - matrices.multiply(Vec3f.NEGATIVE_Y.getDegreesQuaternion(automobile.getAutomobileYaw(tickDelta) - automobile.getRearAttachmentYaw(tickDelta))); - - matrices.translate(0, 0, rearAtt.model().pivotDistPx() / 16); - if (rearAttachmentModel instanceof RearAttachmentRenderModel rm) { - rm.setRenderState(automobile.getRearAttachment(), (float) Math.toRadians(automobile.getWheelAngle(tickDelta)), tickDelta); - } - rearAttachmentModel.render(matrices, vertexConsumers.getBuffer(rearAttachmentModel.getLayer(rearAtt.model().texture())), light, overlay, 1, 1, 1, 1); - if (rearAttachmentModel instanceof BaseModel base) { - base.doOtherLayerRender(matrices, vertexConsumers, light, overlay); - } - matrices.pop(); - } - - // Front Attachment - var frontAtt = automobile.getFrontAttachmentType(); - if (!frontAtt.isEmpty()) { - matrices.push(); - matrices.translate(0, 0, frame.model().frontAttachmentPos() / -16); - - if (frontAttachmentModel instanceof FrontAttachmentRenderModel fm) { - fm.setRenderState(automobile.getFrontAttachment(), chassisRaise, tickDelta); - } - frontAttachmentModel.render(matrices, vertexConsumers.getBuffer(frontAttachmentModel.getLayer(frontAtt.model().texture())), light, overlay, 1, 1, 1, 1); - if (frontAttachmentModel instanceof BaseModel base) { - base.doOtherLayerRender(matrices, vertexConsumers, light, overlay); - } - matrices.pop(); - } - - // WHEELS ---------------------------------------- - var wPoses = frame.model().wheelBase().wheels; - - if (!wheels.isEmpty()) { - var wheelBuffer = vertexConsumers.getBuffer(wheelModel.getLayer(wheels.model().texture())); - float wheelAngle = automobile.getWheelAngle(tickDelta); - int wheelCount = automobile.getWheelCount(); - - for (var pos : wPoses) { - if (wheelCount <= 0) { - break; - } - - if (wheelModel instanceof WheelContextReceiver receiver) { - receiver.provideContext(pos); - } - float scale = pos.scale(); - float wheelRadius = wheels.model().radius() - (wheels.model().radius() * (scale - 1)); - matrices.push(); - - matrices.translate(pos.right() / 16, wheelRadius / 16, -pos.forward() / 16); - - if (pos.end() == WheelBase.WheelEnd.FRONT) matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(automobile.getSteering(tickDelta) * 27)); - matrices.translate(0, -chassisRaise, 0); - matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(wheelAngle)); - matrices.scale(scale, scale, scale); - - matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(180 + pos.yaw())); - - wheelModel.render(matrices, wheelBuffer, light, overlay, 1, 1, 1, 1); - if (wheelModel instanceof BaseModel base) { - base.doOtherLayerRender(matrices, vertexConsumers, light, overlay); - } - - matrices.pop(); - - wheelCount--; - } - } - - // Skid effects - if ((automobile.getTurboCharge() > AutomobileEntity.SMALL_TURBO_TIME || automobile.debris()) && automobile.automobileOnGround()) { - var skidTexes = SkidEffectModel.COOL_SPARK_TEXTURES; - boolean bright = true; - float r = 1; - float g = 1; - float b = 1; - if (automobile.getTurboCharge() > AutomobileEntity.LARGE_TURBO_TIME) { - skidTexes = SkidEffectModel.FLAME_TEXTURES; - } else if (automobile.getTurboCharge() > AutomobileEntity.MEDIUM_TURBO_TIME) { - skidTexes = SkidEffectModel.HOT_SPARK_TEXTURES; - } else if (automobile.debris()) { - skidTexes = SkidEffectModel.DEBRIS_TEXTURES; - var c = automobile.debrisColor(); - r = c.getX() * 0.85f; - g = c.getY() * 0.85f; - b = c.getZ() * 0.85f; - bright = false; - } - int index = (int)Math.floor(((automobile.getTime() + tickDelta) / 1.5f) % skidTexes.length); - var skidEffectBuffer = vertexConsumers.getBuffer(bright ? RenderLayer.getEyes(skidTexes[index]) : RenderLayer.getEntitySmoothCutout(skidTexes[index])); - - for (var pos : wPoses) { - if (pos.end() == WheelBase.WheelEnd.BACK) { - float scale = pos.scale(); - float heightOffset = wheels.model().radius(); - float wheelRadius = wheels.model().radius() * scale; - float wheelWidth = (wheels.model().width() / 16) * scale; - float back = (wheelRadius > 2) ? (float) (Math.sqrt((wheelRadius * wheelRadius) - Math.pow(wheelRadius - 2, 2)) - 0.85) / 16 : 0.08f; - matrices.push(); - matrices.translate((pos.right() / 16) + (wheelWidth * (pos.side() == WheelBase.WheelSide.RIGHT ? 1 : -1)), heightOffset / 16, (-pos.forward() / 16) + back); - matrices.scale(pos.side() == WheelBase.WheelSide.LEFT ? -1 : 1, 1, -1); - skidEffectModel.render(matrices, skidEffectBuffer, light, overlay, r, g, b, 0.6f); - matrices.pop(); - } - } - } - // ----------------------------------------------- - - matrices.pop(); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/BaseModel.java b/src/main/java/io/github/foundationgames/automobility/automobile/render/BaseModel.java deleted file mode 100644 index acb42e8..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/BaseModel.java +++ /dev/null @@ -1,47 +0,0 @@ -package io.github.foundationgames.automobility.automobile.render; - -import net.minecraft.client.model.Model; -import net.minecraft.client.model.ModelPart; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.Identifier; - -import java.util.function.Function; - -public class BaseModel extends Model { - protected final ModelPart root; - - public BaseModel(Function layerFactory, EntityRendererFactory.Context ctx, EntityModelLayer layer) { - super(layerFactory); - this.root = ctx.getPart(layer).getChild("main"); - } - - protected void prepare(MatrixStack matrices) { - } - - @Override - public final void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) { - matrices.push(); - this.prepare(matrices); - this.root.render(matrices, vertices, light, overlay, red, green, blue, alpha); - renderExtra(matrices, vertices, light, overlay, red, green, blue, alpha); - matrices.pop(); - } - - public final void doOtherLayerRender(MatrixStack matrices, VertexConsumerProvider consumers, int light, int overlay) { - matrices.push(); - this.prepare(matrices); - this.renderOtherLayer(matrices, consumers, light, overlay); - matrices.pop(); - } - - public void renderExtra(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) { - } - - public void renderOtherLayer(MatrixStack matrices, VertexConsumerProvider consumers, int light, int overlay) { - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/EmptyModel.java b/src/main/java/io/github/foundationgames/automobility/automobile/render/EmptyModel.java deleted file mode 100644 index 80ccb89..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/EmptyModel.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.github.foundationgames.automobility.automobile.render; - -import net.minecraft.client.model.Model; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.util.math.MatrixStack; - -public class EmptyModel extends Model { - public EmptyModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntitySolid); - } - - @Override - public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) { - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/ExhaustFumesModel.java b/src/main/java/io/github/foundationgames/automobility/automobile/render/ExhaustFumesModel.java deleted file mode 100644 index 7759f38..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/ExhaustFumesModel.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.github.foundationgames.automobility.automobile.render; - -import io.github.foundationgames.automobility.Automobility; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; -import net.minecraft.util.Identifier; - -public class ExhaustFumesModel extends BaseModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile_exhaust_fumes"), "main"); - - public static final Identifier[] SMOKE_TEXTURES = new Identifier[] { - Automobility.id("textures/entity/automobile/exhaust/exhaust_smoke_0.png"), - Automobility.id("textures/entity/automobile/exhaust/exhaust_smoke_1.png"), - Automobility.id("textures/entity/automobile/exhaust/exhaust_smoke_2.png"), - Automobility.id("textures/entity/automobile/exhaust/exhaust_smoke_3.png") - }; - public static final Identifier[] FLAME_TEXTURES = new Identifier[] { - Automobility.id("textures/entity/automobile/exhaust/exhaust_flames_0.png"), - Automobility.id("textures/entity/automobile/exhaust/exhaust_flames_1.png"), - Automobility.id("textures/entity/automobile/exhaust/exhaust_flames_2.png"), - Automobility.id("textures/entity/automobile/exhaust/exhaust_flames_3.png") - }; - - public ExhaustFumesModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityCutout, ctx, MODEL_LAYER); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/SkidEffectModel.java b/src/main/java/io/github/foundationgames/automobility/automobile/render/SkidEffectModel.java deleted file mode 100644 index 2123a7b..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/SkidEffectModel.java +++ /dev/null @@ -1,40 +0,0 @@ -package io.github.foundationgames.automobility.automobile.render; - -import io.github.foundationgames.automobility.Automobility; -import net.minecraft.client.model.*; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.Identifier; -import net.minecraft.util.math.Vec3f; - -public class SkidEffectModel extends BaseModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile_skid_effect"), "main"); - - public static final Identifier[] COOL_SPARK_TEXTURES = new Identifier[] { - Automobility.id("textures/entity/automobile/skid_effect/skid_cool_sparks_0.png"), - Automobility.id("textures/entity/automobile/skid_effect/skid_cool_sparks_1.png"), - Automobility.id("textures/entity/automobile/skid_effect/skid_cool_sparks_2.png") - }; - public static final Identifier[] HOT_SPARK_TEXTURES = new Identifier[] { - Automobility.id("textures/entity/automobile/skid_effect/skid_hot_sparks_0.png"), - Automobility.id("textures/entity/automobile/skid_effect/skid_hot_sparks_1.png"), - Automobility.id("textures/entity/automobile/skid_effect/skid_hot_sparks_2.png") - }; - public static final Identifier[] FLAME_TEXTURES = new Identifier[] { - Automobility.id("textures/entity/automobile/skid_effect/skid_flames_0.png"), - Automobility.id("textures/entity/automobile/skid_effect/skid_flames_1.png"), - Automobility.id("textures/entity/automobile/skid_effect/skid_flames_2.png") - }; - public static final Identifier[] DEBRIS_TEXTURES = new Identifier[] { - Automobility.id("textures/entity/automobile/skid_effect/skid_debris_0.png"), - Automobility.id("textures/entity/automobile/skid_effect/skid_debris_1.png"), - Automobility.id("textures/entity/automobile/skid_effect/skid_debris_2.png") - }; - - public SkidEffectModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityCutout, ctx, MODEL_LAYER); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/MobControllerFrontAttachmentModel.java b/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/MobControllerFrontAttachmentModel.java deleted file mode 100644 index 089f300..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/MobControllerFrontAttachmentModel.java +++ /dev/null @@ -1,14 +0,0 @@ -package io.github.foundationgames.automobility.automobile.render.attachment.front; - -import io.github.foundationgames.automobility.Automobility; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; - -public class MobControllerFrontAttachmentModel extends FrontAttachmentRenderModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/front_attachment/mob_controller"), "main"); - - public MobControllerFrontAttachmentModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityCutout, ctx, MODEL_LAYER); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/BlockRearAttachmentModel.java b/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/BlockRearAttachmentModel.java deleted file mode 100644 index 0e36163..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/BlockRearAttachmentModel.java +++ /dev/null @@ -1,14 +0,0 @@ -package io.github.foundationgames.automobility.automobile.render.attachment.rear; - -import io.github.foundationgames.automobility.Automobility; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; - -public class BlockRearAttachmentModel extends RearAttachmentRenderModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/rear_attachment/block"), "main"); - - public BlockRearAttachmentModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityCutoutNoCull, ctx, MODEL_LAYER); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/PassengerSeatRearAttachmentModel.java b/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/PassengerSeatRearAttachmentModel.java deleted file mode 100644 index c929f0f..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/PassengerSeatRearAttachmentModel.java +++ /dev/null @@ -1,14 +0,0 @@ -package io.github.foundationgames.automobility.automobile.render.attachment.rear; - -import io.github.foundationgames.automobility.Automobility; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; - -public class PassengerSeatRearAttachmentModel extends RearAttachmentRenderModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/rear_attachment/passenger_seat"), "main"); - - public PassengerSeatRearAttachmentModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityCutoutNoCull, ctx, MODEL_LAYER); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/CopperEngineModel.java b/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/CopperEngineModel.java deleted file mode 100644 index 11fa481..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/CopperEngineModel.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.github.foundationgames.automobility.automobile.render.engine; - -import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.automobile.render.BaseModel; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.math.Vec3f; - -public class CopperEngineModel extends BaseModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/engine/copper"), "main"); - - public CopperEngineModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityCutout, ctx, MODEL_LAYER); - } - - @Override - protected void prepare(MatrixStack matrices) { - matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(180)); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/CreativeEngineModel.java b/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/CreativeEngineModel.java deleted file mode 100644 index 42b8fc5..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/CreativeEngineModel.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.github.foundationgames.automobility.automobile.render.engine; - -import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.automobile.render.BaseModel; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.math.Vec3f; - -public class CreativeEngineModel extends BaseModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/engine/creative"), "main"); - - public CreativeEngineModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityCutout, ctx, MODEL_LAYER); - } - - @Override - protected void prepare(MatrixStack matrices) { - matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(180)); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/DiamondEngineModel.java b/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/DiamondEngineModel.java deleted file mode 100644 index f3e460f..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/DiamondEngineModel.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.github.foundationgames.automobility.automobile.render.engine; - -import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.automobile.render.BaseModel; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; - -public class DiamondEngineModel extends BaseModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/engine/diamond"), "main"); - - public DiamondEngineModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityCutout, ctx, MODEL_LAYER); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/GoldEngineModel.java b/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/GoldEngineModel.java deleted file mode 100644 index 9f1d7a8..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/GoldEngineModel.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.github.foundationgames.automobility.automobile.render.engine; - -import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.automobile.render.BaseModel; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; - -public class GoldEngineModel extends BaseModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/engine/gold"), "main"); - - public GoldEngineModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityCutout, ctx, MODEL_LAYER); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/IronEngineModel.java b/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/IronEngineModel.java deleted file mode 100644 index dec6642..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/IronEngineModel.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.github.foundationgames.automobility.automobile.render.engine; - -import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.automobile.render.BaseModel; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; - -public class IronEngineModel extends BaseModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/engine/iron"), "main"); - - public IronEngineModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityCutout, ctx, MODEL_LAYER); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/StoneEngineModel.java b/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/StoneEngineModel.java deleted file mode 100644 index 93456f1..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/StoneEngineModel.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.github.foundationgames.automobility.automobile.render.engine; - -import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.automobile.render.BaseModel; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; - -public class StoneEngineModel extends BaseModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/engine/stone"), "main"); - - public StoneEngineModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityCutout, ctx, MODEL_LAYER); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/CARRFrameModel.java b/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/CARRFrameModel.java deleted file mode 100644 index daadf98..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/CARRFrameModel.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.github.foundationgames.automobility.automobile.render.frame; - -import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.automobile.render.BaseModel; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.math.Vec3f; - -public class CARRFrameModel extends BaseModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/frame/c_arr"), "main"); - - public CARRFrameModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityCutoutNoCull, ctx, MODEL_LAYER); - } - - @Override - protected void prepare(MatrixStack matrices) { - matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(-90)); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/DaBabyFrameModel.java b/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/DaBabyFrameModel.java deleted file mode 100644 index af5ebc7..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/DaBabyFrameModel.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.github.foundationgames.automobility.automobile.render.frame; - -// import dev.monarkhes.myron.api.Myron; -import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.util.AUtils; -import net.minecraft.client.model.Model; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.RenderLayers; -import net.minecraft.client.render.TexturedRenderLayers; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.model.BakedModel; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.math.Vec3f; - -public class DaBabyFrameModel extends Model { - // Credit to https://github.com/Sk3leCreeper for model - // private final BakedModel model = Myron.getModel(Automobility.id("models/misc/automobile/frame/dababy")); - - public DaBabyFrameModel(EntityRendererFactory.Context ctx) { - super(id -> TexturedRenderLayers.getEntitySolid()); - } - - @Override - public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) { - /* - if (model == null) return; - matrices.push(); - matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(180)); - matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(90)); - matrices.translate(0.1, 0.04, 0); - AUtils.renderMyronObj(model, vertices, matrices, light, overlay); - matrices.pop(); - */ - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/MotorcarFrameModel.java b/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/MotorcarFrameModel.java deleted file mode 100644 index 602f469..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/MotorcarFrameModel.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.github.foundationgames.automobility.automobile.render.frame; - -import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.automobile.render.BaseModel; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; - -public class MotorcarFrameModel extends BaseModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/frame/motorcar"), "main"); - - public MotorcarFrameModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityTranslucentCull, ctx, MODEL_LAYER); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/PineappleFrameModel.java b/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/PineappleFrameModel.java deleted file mode 100644 index 753bada..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/PineappleFrameModel.java +++ /dev/null @@ -1,21 +0,0 @@ -package io.github.foundationgames.automobility.automobile.render.frame; - -import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.automobile.render.BaseModel; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; -import net.minecraft.client.util.math.MatrixStack; - -public class PineappleFrameModel extends BaseModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/frame/pineapple"), "main"); - - public PineappleFrameModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityCutout, ctx, MODEL_LAYER); - } - - @Override - protected void prepare(MatrixStack matrices) { - matrices.scale(2, 2, 2); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/RickshawFrameModel.java b/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/RickshawFrameModel.java deleted file mode 100644 index 9046587..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/RickshawFrameModel.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.github.foundationgames.automobility.automobile.render.frame; - -import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.automobile.render.BaseModel; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; - -public class RickshawFrameModel extends BaseModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/frame/rickshaw"), "main"); - - public RickshawFrameModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityCutoutNoCull, ctx, MODEL_LAYER); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/ShoppingCartFrameModel.java b/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/ShoppingCartFrameModel.java deleted file mode 100644 index ad9b4d2..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/ShoppingCartFrameModel.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.github.foundationgames.automobility.automobile.render.frame; - -import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.automobile.render.BaseModel; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; - -public class ShoppingCartFrameModel extends BaseModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/frame/shopping_cart"), "main"); - - public ShoppingCartFrameModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityCutoutNoCull, ctx, MODEL_LAYER); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/StandardFrameModel.java b/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/StandardFrameModel.java deleted file mode 100644 index a73b930..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/StandardFrameModel.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.github.foundationgames.automobility.automobile.render.frame; - -import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.automobile.render.BaseModel; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.math.Vec3f; - -public class StandardFrameModel extends BaseModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/frame/standard"), "main"); - - public StandardFrameModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityCutout, ctx, MODEL_LAYER); - } - - @Override - protected void prepare(MatrixStack matrices) { - matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(-90)); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/TractorFrameModel.java b/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/TractorFrameModel.java deleted file mode 100644 index 79d5fb0..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/TractorFrameModel.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.github.foundationgames.automobility.automobile.render.frame; - -import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.automobile.render.BaseModel; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; - -public class TractorFrameModel extends BaseModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/frame/tractor"), "main"); - - public TractorFrameModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityCutout, ctx, MODEL_LAYER); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/item/ItemRenderableAutomobile.java b/src/main/java/io/github/foundationgames/automobility/automobile/render/item/ItemRenderableAutomobile.java deleted file mode 100644 index e384661..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/item/ItemRenderableAutomobile.java +++ /dev/null @@ -1,155 +0,0 @@ -package io.github.foundationgames.automobility.automobile.render.item; - -import io.github.foundationgames.automobility.automobile.AutomobileData; -import io.github.foundationgames.automobility.automobile.AutomobileEngine; -import io.github.foundationgames.automobility.automobile.AutomobileFrame; -import io.github.foundationgames.automobility.automobile.AutomobileWheel; -import io.github.foundationgames.automobility.automobile.attachment.FrontAttachmentType; -import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType; -import io.github.foundationgames.automobility.automobile.attachment.front.FrontAttachment; -import io.github.foundationgames.automobility.automobile.attachment.rear.RearAttachment; -import io.github.foundationgames.automobility.automobile.render.RenderableAutomobile; -import io.github.foundationgames.automobility.util.EntityRenderHelper; -import net.minecraft.client.model.Model; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.util.Identifier; -import net.minecraft.util.math.Vec3f; -import org.jetbrains.annotations.Nullable; - -import java.util.HashMap; -import java.util.Map; - -public class ItemRenderableAutomobile implements RenderableAutomobile { - private final AutomobileData reader; - private final Map frameModelCache = new HashMap<>(); - private final Map wheelModelCache = new HashMap<>(); - private final Map engineModelCache = new HashMap<>(); - private Model emptyRearAttModel; - private Model emptyFrontAttModel; - - public ItemRenderableAutomobile(AutomobileData reader) { - this.reader = reader; - EntityRenderHelper.registerContextListener(ctx -> { - frameModelCache.clear(); - wheelModelCache.clear(); - engineModelCache.clear(); - emptyRearAttModel = null; - emptyFrontAttModel = null; - }); - } - - @Override - public AutomobileFrame getFrame() { - return reader.getFrame(); - } - - @Override - public AutomobileEngine getEngine() { - return reader.getEngine(); - } - - @Override - public AutomobileWheel getWheels() { - return reader.getWheel(); - } - - @Override - public @Nullable RearAttachment getRearAttachment() { - return null; - } - - @Override - public @Nullable FrontAttachment getFrontAttachment() { - return null; - } - - @Override - public Model getFrameModel(EntityRendererFactory.Context ctx) { - if (!frameModelCache.containsKey(reader.getFrame().getId())) frameModelCache.put(reader.getFrame().getId(), reader.getFrame().model().model().apply(ctx)); - return frameModelCache.get(reader.getFrame().getId()); - } - - @Override - public Model getWheelModel(EntityRendererFactory.Context ctx) { - if (!wheelModelCache.containsKey(reader.getWheel().getId())) wheelModelCache.put(reader.getWheel().getId(), reader.getWheel().model().model().apply(ctx)); - return wheelModelCache.get(reader.getWheel().getId()); - } - - @Override - public Model getEngineModel(EntityRendererFactory.Context ctx) { - if (!engineModelCache.containsKey(reader.getEngine().getId())) engineModelCache.put(reader.getEngine().getId(), reader.getEngine().model().model().apply(ctx)); - return engineModelCache.get(reader.getEngine().getId()); - } - - @Override - public Model getRearAttachmentModel(EntityRendererFactory.Context ctx) { - if (emptyRearAttModel == null) emptyRearAttModel = RearAttachmentType.EMPTY.model().model().apply(ctx); - return emptyRearAttModel; - } - - @Override - public Model getFrontAttachmentModel(EntityRendererFactory.Context ctx) { - if (emptyFrontAttModel == null) emptyFrontAttModel = FrontAttachmentType.EMPTY.model().model().apply(ctx); - return emptyFrontAttModel; - } - - @Override - public float getAutomobileYaw(float tickDelta) { - return 0; - } - - @Override - public float getRearAttachmentYaw(float tickDelta) { - return 0; - } - - @Override - public float getWheelAngle(float tickDelta) { - return 0; - } - - @Override - public float getSteering(float tickDelta) { - return 0; - } - - @Override - public float getSuspensionBounce(float tickDelta) { - return 0; - } - - @Override - public boolean engineRunning() { - return false; - } - - @Override - public int getBoostTimer() { - return 0; - } - - @Override - public int getTurboCharge() { - return 0; - } - - @Override - public long getTime() { - return 0; - } - - @Override - public boolean automobileOnGround() { - return true; - } - - @Override - public boolean debris() { - return false; - } - - @Override - public Vec3f debrisColor() { - return new Vec3f(); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/CarriageWheelModel.java b/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/CarriageWheelModel.java deleted file mode 100644 index d543bcd..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/CarriageWheelModel.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.github.foundationgames.automobility.automobile.render.wheel; - -import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.automobile.render.BaseModel; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; - -public class CarriageWheelModel extends BaseModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/wheel/carriage"), "main"); - - public CarriageWheelModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityCutoutNoCull, ctx, MODEL_LAYER); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/OffRoadWheelModel.java b/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/OffRoadWheelModel.java deleted file mode 100644 index fd4a40b..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/OffRoadWheelModel.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.github.foundationgames.automobility.automobile.render.wheel; - -import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.automobile.render.BaseModel; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.math.Vec3f; - -public class OffRoadWheelModel extends BaseModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/wheel/off_road"), "main"); - - public OffRoadWheelModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityCutout, ctx, MODEL_LAYER); - } - - @Override - protected void prepare(MatrixStack matrices) { - matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(-90)); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/StandardWheelModel.java b/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/StandardWheelModel.java deleted file mode 100644 index c1ea04d..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/StandardWheelModel.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.github.foundationgames.automobility.automobile.render.wheel; - -import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.automobile.render.BaseModel; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.math.Vec3f; - -public class StandardWheelModel extends BaseModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/wheel/standard"), "main"); - - public StandardWheelModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityCutout, ctx, MODEL_LAYER); - } - - @Override - protected void prepare(MatrixStack matrices) { - matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(-90)); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/SteelWheelModel.java b/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/SteelWheelModel.java deleted file mode 100644 index a801584..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/SteelWheelModel.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.github.foundationgames.automobility.automobile.render.wheel; - -import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.automobile.render.BaseModel; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; - -public class SteelWheelModel extends BaseModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/wheel/steel"), "main"); - - public SteelWheelModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityCutout, ctx, MODEL_LAYER); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/TractorWheelModel.java b/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/TractorWheelModel.java deleted file mode 100644 index d547b36..0000000 --- a/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/TractorWheelModel.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.github.foundationgames.automobility.automobile.render.wheel; - -import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.automobile.render.BaseModel; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.model.EntityModelLayer; - -public class TractorWheelModel extends BaseModel { - public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/wheel/tractor"), "main"); - - public TractorWheelModel(EntityRendererFactory.Context ctx) { - super(RenderLayer::getEntityCutout, ctx, MODEL_LAYER); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/block/AutoMechanicTableBlock.java b/src/main/java/io/github/foundationgames/automobility/block/AutoMechanicTableBlock.java deleted file mode 100644 index d7889cf..0000000 --- a/src/main/java/io/github/foundationgames/automobility/block/AutoMechanicTableBlock.java +++ /dev/null @@ -1,40 +0,0 @@ -package io.github.foundationgames.automobility.block; - -import io.github.foundationgames.automobility.screen.AutoMechanicTableScreenHandler; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.screen.NamedScreenHandlerFactory; -import net.minecraft.screen.ScreenHandlerContext; -import net.minecraft.screen.SimpleNamedScreenHandlerFactory; -import net.minecraft.text.Text; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.jetbrains.annotations.Nullable; - -public class AutoMechanicTableBlock extends Block { - public static final Text UI_TITLE = Text.translatable("container.automobility.auto_mechanic_table"); - - public AutoMechanicTableBlock(Settings settings) { - super(settings); - } - - @Override - public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { - if (world.isClient()) { - return ActionResult.SUCCESS; - } else { - player.openHandledScreen(state.createScreenHandlerFactory(world, pos)); - return ActionResult.CONSUME; - } - } - - @Override - public @Nullable NamedScreenHandlerFactory createScreenHandlerFactory(BlockState state, World world, BlockPos pos) { - return new SimpleNamedScreenHandlerFactory((syncId, playerInventory, player) -> - new AutoMechanicTableScreenHandler(syncId, playerInventory, ScreenHandlerContext.create(world, pos)), UI_TITLE); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/block/AutomobileAssemblerBlock.java b/src/main/java/io/github/foundationgames/automobility/block/AutomobileAssemblerBlock.java deleted file mode 100644 index 1ca79b0..0000000 --- a/src/main/java/io/github/foundationgames/automobility/block/AutomobileAssemblerBlock.java +++ /dev/null @@ -1,112 +0,0 @@ -package io.github.foundationgames.automobility.block; - -import io.github.foundationgames.automobility.block.entity.AutomobileAssemblerBlockEntity; -import net.minecraft.block.Block; -import net.minecraft.block.BlockEntityProvider; -import net.minecraft.block.BlockState; -import net.minecraft.block.HorizontalFacingBlock; -import net.minecraft.block.ShapeContext; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemPlacementContext; -import net.minecraft.item.ItemStack; -import net.minecraft.state.StateManager; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.state.property.Properties; -import net.minecraft.text.Text; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Formatting; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.util.shape.VoxelShapes; -import net.minecraft.world.BlockView; -import net.minecraft.world.World; -import org.jetbrains.annotations.Nullable; - -public class AutomobileAssemblerBlock extends HorizontalFacingBlock implements BlockEntityProvider { - public static final Text USE_CROWBAR_DIALOG = Text.translatable("dialog.automobility.use_crowbar").formatted(Formatting.GOLD); - public static final Text INCOMPLETE_AUTOMOBILE_DIALOG = Text.translatable("dialog.automobility.incomplete_automobile").formatted(Formatting.RED); - - public static final BooleanProperty POWERED = Properties.POWERED; - - private static final VoxelShape BASE = VoxelShapes.union( - Block.createCuboidShape(0, 0, 0, 16, 4, 16), - Block.createCuboidShape(5, 4, 5, 11, 12, 11)); - - private static final VoxelShape NORTH_SOUTH = VoxelShapes.union(BASE, - Block.createCuboidShape(0, 8, 6, 16, 12, 10)); - private static final VoxelShape EAST_WEST = VoxelShapes.union(BASE, - Block.createCuboidShape(6, 8, 0, 10, 12, 16)); - - public AutomobileAssemblerBlock(Settings settings) { - super(settings); - this.setDefaultState(this.getDefaultState().with(FACING, Direction.NORTH).with(POWERED, false)); - } - - @Override - public void neighborUpdate(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos, boolean notify) { - super.neighborUpdate(state, world, pos, block, fromPos, notify); - - boolean power = world.isReceivingRedstonePower(pos); - if (power != state.get(POWERED)) { - world.setBlockState(pos, state.with(POWERED, power)); - } - } - - @Override - public void onPlaced(World world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack itemStack) { - if (!world.isClient() && placer instanceof PlayerEntity player) { - player.sendMessage(USE_CROWBAR_DIALOG, true); - } - - super.onPlaced(world, pos, state, placer, itemStack); - } - - @Override - public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { - if (world.getBlockEntity(pos) instanceof AutomobileAssemblerBlockEntity assembler) { - return assembler.interact(player, hand); - } - - return super.onUse(state, world, pos, player, hand, hit); - } - - @Override - public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) { - if (!newState.isOf(this) && world.getBlockEntity(pos) instanceof AutomobileAssemblerBlockEntity assembler) { - assembler.dropParts(); - } - - super.onStateReplaced(state, world, pos, newState, moved); - } - - @Override - public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { - return switch (state.get(FACING)) { - case EAST, WEST -> EAST_WEST; - default -> NORTH_SOUTH; - }; - } - - @Nullable - @Override - public BlockState getPlacementState(ItemPlacementContext ctx) { - return super.getPlacementState(ctx).with(FACING, ctx.getPlayerFacing().getOpposite()); - } - - @Override - protected void appendProperties(StateManager.Builder builder) { - super.appendProperties(builder); - builder.add(FACING, POWERED); - } - - @Nullable - @Override - public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { - return new AutomobileAssemblerBlockEntity(pos, state); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/block/AutomobilityBlocks.java b/src/main/java/io/github/foundationgames/automobility/block/AutomobilityBlocks.java deleted file mode 100644 index 7651070..0000000 --- a/src/main/java/io/github/foundationgames/automobility/block/AutomobilityBlocks.java +++ /dev/null @@ -1,118 +0,0 @@ -package io.github.foundationgames.automobility.block; - -import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.block.entity.AutomobileAssemblerBlockEntity; -import io.github.foundationgames.automobility.item.SlopeBlockItem; -import io.github.foundationgames.automobility.item.SteepSlopeBlockItem; -import io.github.foundationgames.automobility.item.TooltipBlockItem; -import io.github.foundationgames.automobility.resource.AutomobilityAssets; -import io.github.foundationgames.automobility.resource.AutomobilityData; -import io.github.foundationgames.automobility.util.AUtils; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; -import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry; -import net.fabricmc.fabric.api.event.registry.RegistryEntryAddedCallback; -import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder; -import net.minecraft.block.Block; -import net.minecraft.block.Blocks; -import net.minecraft.block.StairsBlock; -import net.minecraft.block.entity.BlockEntityType; -import net.minecraft.client.color.world.BiomeColors; -import net.minecraft.client.color.world.GrassColors; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; -import net.minecraft.item.ItemGroup; -import net.minecraft.sound.BlockSoundGroup; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import net.minecraft.util.Identifier; -import net.minecraft.util.registry.Registry; - -import java.util.function.Function; - -public enum AutomobilityBlocks {; - public static final Block AUTO_MECHANIC_TABLE = register("auto_mechanic_table", new AutoMechanicTableBlock(FabricBlockSettings.copyOf(Blocks.COPPER_BLOCK)), Automobility.GROUP); - public static final Block AUTOMOBILE_ASSEMBLER = register("automobile_assembler", new AutomobileAssemblerBlock(FabricBlockSettings.copyOf(Blocks.ANVIL)), Automobility.GROUP); - - public static final Block LAUNCH_GEL = register("launch_gel", new LaunchGelBlock(FabricBlockSettings.copyOf(Blocks.GLOW_LICHEN).sounds(BlockSoundGroup.HONEY).noCollision()), Automobility.COURSE_ELEMENTS); - public static final Block ALLOW = register("allow", new Block(FabricBlockSettings.copyOf(Blocks.BARRIER).sounds(BlockSoundGroup.METAL)), - b -> new TooltipBlockItem(b, Text.translatable("tooltip.block.automobility.allow").formatted(Formatting.AQUA), new Item.Settings().group(Automobility.COURSE_ELEMENTS))); - - public static final Block GRASS_OFF_ROAD = register("grass_off_road", new OffRoadBlock(FabricBlockSettings.copyOf(Blocks.GRASS_BLOCK).noCollision(), AUtils.colorFromInt(0x406918)), Automobility.COURSE_ELEMENTS); - public static final Block DIRT_OFF_ROAD = register("dirt_off_road", new OffRoadBlock(FabricBlockSettings.copyOf(Blocks.DIRT).noCollision(), AUtils.colorFromInt(0x594227)), Automobility.COURSE_ELEMENTS); - public static final Block SAND_OFF_ROAD = register("sand_off_road", new OffRoadBlock(FabricBlockSettings.copyOf(Blocks.SAND).noCollision(), AUtils.colorFromInt(0xC2B185)), Automobility.COURSE_ELEMENTS); - public static final Block SNOW_OFF_ROAD = register("snow_off_road", new OffRoadBlock(FabricBlockSettings.copyOf(Blocks.SNOW).noCollision(), AUtils.colorFromInt(0xD0E7ED)), Automobility.COURSE_ELEMENTS); - - public static final Block DASH_PANEL = register("dash_panel", new DashPanelBlock(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).luminance(1).emissiveLighting((state, world, pos) -> true).noCollision()), Automobility.COURSE_ELEMENTS); - public static final Block SLOPED_DASH_PANEL = register("sloped_dash_panel", new SlopedDashPanelBlock(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).luminance(1).emissiveLighting((state, world, pos) -> true))); - public static final Block STEEP_SLOPED_DASH_PANEL = register("steep_sloped_dash_panel", new SteepSlopedDashPanelBlock(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).luminance(1).emissiveLighting((state, world, pos) -> true))); - - public static final BlockEntityType AUTOMOBILE_ASSEMBLER_ENTITY = Registry.register(Registry.BLOCK_ENTITY_TYPE, - Automobility.id("automobile_assembler"), FabricBlockEntityTypeBuilder.create(AutomobileAssemblerBlockEntity::new, AUTOMOBILE_ASSEMBLER).build()); - - public static void init() { - Registry.register(Registry.ITEM, Automobility.id("sloped_dash_panel"), new SlopeBlockItem(null, SLOPED_DASH_PANEL, new Item.Settings().group(Automobility.COURSE_ELEMENTS))); - Registry.register(Registry.ITEM, Automobility.id("steep_sloped_dash_panel"), new SteepSlopeBlockItem(null, STEEP_SLOPED_DASH_PANEL, new Item.Settings().group(Automobility.COURSE_ELEMENTS))); - registerSlopes("minecraft"); - } - - @Environment(EnvType.CLIENT) - public static void initClient() { - ColorProviderRegistry.BLOCK.register((state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getGrassColor(world, pos) : GrassColors.getColor(0.5D, 1.0D), GRASS_OFF_ROAD); - ColorProviderRegistry.ITEM.register((stack, tintIndex) -> GrassColors.getColor(0.5D, 1.0D), GRASS_OFF_ROAD.asItem()); - - BlockRenderLayerMap.INSTANCE.putBlock(LAUNCH_GEL, RenderLayer.getTranslucent()); - } - - public static Block register(String name, Block block) { - return Registry.register(Registry.BLOCK, Automobility.id(name), block); - } - - public static Block register(String name, Block block, ItemGroup group) { - return register(name, block, b -> new BlockItem(b, new Item.Settings().group(group))); - } - - public static Block register(String name, Block block, Function item) { - Registry.register(Registry.ITEM, Automobility.id(name), item.apply(block)); - return register(name, block); - } - - private static void makeStairsSticky(Block candidate, Identifier id) { - if (candidate instanceof StairsBlock) { - AutomobilityData.STICKY_SLOPE_TAG_CANDIDATES.add(id); - AutomobilityData.STICKY_SLOPE_TAG_CANDIDATES.add(id); - } - } - - public static void registerSlopes(String namespace) { - AutomobilityData.NON_STEEP_SLOPE_TAG_CANDIDATES.add(Automobility.id("sloped_dash_panel")); - AutomobilityData.STEEP_SLOPE_TAG_CANDIDATES.add(Automobility.id("steep_sloped_dash_panel")); - for (var base : Registry.BLOCK) { - if (base.getClass().equals(Block.class)) { - var id = Registry.BLOCK.getId(base); - if (id.getNamespace().equals(namespace)) { - var path = id.getPath()+"_slope"; - var steepPath = "steep_"+path; - var block = register(path, new SlopeBlock(FabricBlockSettings.copyOf(base))); - var normalId = Automobility.id(path); - var steepId = Automobility.id(steepPath); - Registry.register(Registry.ITEM, normalId, new SlopeBlockItem(base, block, new Item.Settings().group(Automobility.COURSE_ELEMENTS))); - block = register(steepPath, new SteepSlopeBlock(FabricBlockSettings.copyOf(base))); - Registry.register(Registry.ITEM, steepId, new SteepSlopeBlockItem(base, block, new Item.Settings().group(Automobility.COURSE_ELEMENTS))); - AutomobilityAssets.addProcessor(pack -> AutomobilityAssets.addMinecraftSlope(path, id.getPath())); - AutomobilityData.NON_STEEP_SLOPE_TAG_CANDIDATES.add(normalId); - AutomobilityData.STEEP_SLOPE_TAG_CANDIDATES.add(steepId); - } - } - - makeStairsSticky(base, Registry.BLOCK.getId(base)); - } - - RegistryEntryAddedCallback.event(Registry.BLOCK).register((raw, id, block) -> { - makeStairsSticky(block, id); - }); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/block/DashPanelBlock.java b/src/main/java/io/github/foundationgames/automobility/block/DashPanelBlock.java deleted file mode 100644 index 231b65c..0000000 --- a/src/main/java/io/github/foundationgames/automobility/block/DashPanelBlock.java +++ /dev/null @@ -1,94 +0,0 @@ -package io.github.foundationgames.automobility.block; - -import io.github.foundationgames.automobility.entity.AutomobileEntity; -import io.github.foundationgames.automobility.entity.AutomobilityEntities; -import net.minecraft.block.*; -import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.effect.StatusEffect; -import net.minecraft.entity.effect.StatusEffectInstance; -import net.minecraft.entity.effect.StatusEffects; -import net.minecraft.fluid.FluidState; -import net.minecraft.fluid.Fluids; -import net.minecraft.item.ItemPlacementContext; -import net.minecraft.state.StateManager; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.state.property.Properties; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.util.math.Vec3d; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.world.BlockView; -import net.minecraft.world.World; -import net.minecraft.world.WorldAccess; -import org.jetbrains.annotations.Nullable; - -public class DashPanelBlock extends HorizontalFacingBlock implements Waterloggable { - public static final BooleanProperty LEFT = BooleanProperty.of("left"); - public static final BooleanProperty RIGHT = BooleanProperty.of("right"); - public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED; - - public static final VoxelShape SHAPE = createCuboidShape(0, 0, 0, 16, 1, 16); - - public DashPanelBlock(Settings settings) { - super(settings); - setDefaultState(getDefaultState().with(FACING, Direction.NORTH).with(LEFT, false).with(RIGHT, false).with(WATERLOGGED, false)); - } - - @Override - protected void appendProperties(StateManager.Builder builder) { - super.appendProperties(builder); - builder.add(FACING, LEFT, RIGHT, WATERLOGGED); - } - - @Nullable - @Override - public BlockState getPlacementState(ItemPlacementContext ctx) { - return super.getPlacementState(ctx).with(FACING, ctx.getPlayerFacing()).with(WATERLOGGED, ctx.getWorld().getBlockState(ctx.getBlockPos()).isOf(Blocks.WATER)); - } - - @Override - public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) { - boolean left = world.getBlockState(pos.offset(state.get(FACING).rotateCounterclockwise(Direction.Axis.Y))).isOf(this); - boolean right = world.getBlockState(pos.offset(state.get(FACING).rotateClockwise(Direction.Axis.Y))).isOf(this); - return state.with(LEFT, left).with(RIGHT, right); - } - - @Override - public void neighborUpdate(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos, boolean notify) { - super.neighborUpdate(state, world, pos, block, fromPos, notify); - if (!world.getBlockState(pos.down()).isSideSolidFullSquare(world, pos.down(), Direction.UP)) { - world.breakBlock(pos, true); - } - } - - @Override - public FluidState getFluidState(BlockState state) { - return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state); - } - - @Override - public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) { - super.onEntityCollision(state, world, pos, entity); - onCollideWithDashPanel(entity); - } - - @Override - public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { - return SHAPE; - } - - public static void onCollideWithDashPanel(Entity entity) { - if (entity instanceof AutomobileEntity auto) { - auto.boost(0.45f, 50); - } else if (entity.getType().isIn(AutomobilityEntities.DASH_PANEL_BOOSTABLES)) { - if (entity instanceof LivingEntity living) { - living.addStatusEffect(new StatusEffectInstance(StatusEffects.SPEED, 50, 20, true, false, false)); - } - Vec3d vel; - double yaw = Math.toRadians(entity.getYaw() + 180); - vel = new Vec3d(Math.sin(yaw), 0, Math.cos(yaw)); - entity.addVelocity(vel.x, vel.y, vel.z); - } - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/block/LaunchGelBlock.java b/src/main/java/io/github/foundationgames/automobility/block/LaunchGelBlock.java deleted file mode 100644 index 1b72ef3..0000000 --- a/src/main/java/io/github/foundationgames/automobility/block/LaunchGelBlock.java +++ /dev/null @@ -1,53 +0,0 @@ -package io.github.foundationgames.automobility.block; - -import io.github.foundationgames.automobility.entity.AutomobileEntity; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.ShapeContext; -import net.minecraft.entity.Entity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.world.BlockView; -import net.minecraft.world.World; -import net.minecraft.world.WorldView; - -public class LaunchGelBlock extends Block { - public static final VoxelShape SHAPE = createCuboidShape(0, 0, 0, 16, 1, 16); - - public LaunchGelBlock(Settings settings) { - super(settings); - } - - public boolean canExistAt(WorldView world, BlockPos pos) { - return world.getBlockState(pos.down()).isSideSolidFullSquare(world, pos, Direction.UP); - } - - @Override - public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) { - super.onEntityCollision(state, world, pos, entity); - - if (entity instanceof AutomobileEntity automobile && automobile.automobileOnGround()) { - automobile.boost(0.14f, 7); - } - } - - @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { - return canExistAt(world, pos); - } - - @Override - public void neighborUpdate(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos, boolean notify) { - super.neighborUpdate(state, world, pos, block, fromPos, notify); - - if (!canExistAt(world, pos)) { - world.breakBlock(pos, true); - } - } - - @Override - public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { - return SHAPE; - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/block/OffRoadBlock.java b/src/main/java/io/github/foundationgames/automobility/block/OffRoadBlock.java deleted file mode 100644 index c3f6343..0000000 --- a/src/main/java/io/github/foundationgames/automobility/block/OffRoadBlock.java +++ /dev/null @@ -1,81 +0,0 @@ -package io.github.foundationgames.automobility.block; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.ShapeContext; -import net.minecraft.block.piston.PistonBehavior; -import net.minecraft.item.ItemPlacementContext; -import net.minecraft.state.StateManager; -import net.minecraft.state.property.IntProperty; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.util.math.Vec3f; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.world.BlockView; -import net.minecraft.world.World; -import net.minecraft.world.WorldView; -import org.jetbrains.annotations.Nullable; - -public class OffRoadBlock extends Block { - public static final VoxelShape ONE_LAYER_SHAPE = createCuboidShape(0, 0, 0, 16, 2, 16); - public static final VoxelShape TWO_LAYER_SHAPE = createCuboidShape(0, 0, 0, 16, 4, 16); - public static final VoxelShape THREE_LAYER_SHAPE = createCuboidShape(0, 0, 0, 16, 6, 16); - - public static final IntProperty LAYERS = IntProperty.of("layers", 1, 3); - - public final Vec3f color; - - public OffRoadBlock(Settings settings, Vec3f color) { - super(settings); - setDefaultState(getDefaultState().with(LAYERS, 1)); - this.color = color; - } - - @Nullable - @Override - public BlockState getPlacementState(ItemPlacementContext ctx) { - var state = ctx.getWorld().getBlockState(ctx.getBlockPos()); - if (state.isOf(this) && state.get(LAYERS) < 3) { - return state.with(LAYERS, state.get(LAYERS) + 1); - } - return super.getPlacementState(ctx); - } - - @Override - public boolean canReplace(BlockState state, ItemPlacementContext context) { - return state.get(LAYERS) < 3; - } - - @Override - public void neighborUpdate(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos, boolean notify) { - super.neighborUpdate(state, world, pos, block, fromPos, notify); - if (!canPlaceAt(state, world, pos)) { - world.breakBlock(pos, true); - } - } - - @Override - public PistonBehavior getPistonBehavior(BlockState state) { - return PistonBehavior.DESTROY; - } - - @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { - return world.getBlockState(pos.down()).isSideSolidFullSquare(world, pos.down(), Direction.UP); - } - - @Override - public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { - return switch (state.get(LAYERS)) { - case 2 -> TWO_LAYER_SHAPE; - case 3 -> THREE_LAYER_SHAPE; - default -> ONE_LAYER_SHAPE; - }; - } - - @Override - protected void appendProperties(StateManager.Builder builder) { - super.appendProperties(builder); - builder.add(LAYERS); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/block/SlopeBlock.java b/src/main/java/io/github/foundationgames/automobility/block/SlopeBlock.java deleted file mode 100644 index 0056635..0000000 --- a/src/main/java/io/github/foundationgames/automobility/block/SlopeBlock.java +++ /dev/null @@ -1,127 +0,0 @@ -package io.github.foundationgames.automobility.block; - -import io.github.foundationgames.automobility.item.SlopePlacementContext; -import io.github.foundationgames.automobility.util.AUtils; -import net.minecraft.block.*; -import net.minecraft.block.enums.BlockHalf; -import net.minecraft.fluid.FluidState; -import net.minecraft.fluid.Fluids; -import net.minecraft.item.ItemPlacementContext; -import net.minecraft.state.StateManager; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.state.property.EnumProperty; -import net.minecraft.state.property.Properties; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.util.shape.VoxelShapes; -import net.minecraft.world.BlockView; -import net.minecraft.world.World; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; - -public class SlopeBlock extends HorizontalFacingBlock implements Waterloggable { - public static final VoxelShape NORTH_BOTTOM_SHAPE; - public static final VoxelShape SOUTH_BOTTOM_SHAPE; - public static final VoxelShape EAST_BOTTOM_SHAPE; - public static final VoxelShape WEST_BOTTOM_SHAPE; - public static final VoxelShape NORTH_TOP_SHAPE; - public static final VoxelShape SOUTH_TOP_SHAPE; - public static final VoxelShape EAST_TOP_SHAPE; - public static final VoxelShape WEST_TOP_SHAPE; - - public static final EnumProperty HALF = Properties.BLOCK_HALF; - public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED; - - public SlopeBlock(Settings settings) { - super(settings); - setDefaultState(getDefaultState().with(FACING, Direction.NORTH).with(HALF, BlockHalf.BOTTOM).with(WATERLOGGED, false)); - } - - @Nullable - @Override - public BlockState getPlacementState(ItemPlacementContext ctx) { - return ctx instanceof SlopePlacementContext slopeCtx ? - super.getPlacementState(ctx) - .with(FACING, slopeCtx.getSlopeFacing()) - .with(WATERLOGGED, ctx.getWorld().getBlockState(ctx.getBlockPos()).isOf(Blocks.WATER)) - .with(HALF, slopeCtx.getSlopeHalf()) - : - super.getPlacementState(ctx) - .with(FACING, ctx.getPlayerFacing().getOpposite()) - .with(WATERLOGGED, ctx.getWorld().getBlockState(ctx.getBlockPos()).isOf(Blocks.WATER)) - .with(HALF, ctx.getHitPos().y - ctx.getBlockPos().getY() > 0.5 ? BlockHalf.TOP : BlockHalf.BOTTOM); - } - - @Override - protected void appendProperties(StateManager.Builder builder) { - super.appendProperties(builder); - builder.add(FACING, HALF, WATERLOGGED); - } - - @Override - public FluidState getFluidState(BlockState state) { - return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state); - } - - @Override - public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { - return switch (state.get(HALF)) { - case BOTTOM -> switch (state.get(FACING)) { - case NORTH -> NORTH_BOTTOM_SHAPE; - case SOUTH -> SOUTH_BOTTOM_SHAPE; - case WEST -> WEST_BOTTOM_SHAPE; - case EAST -> EAST_BOTTOM_SHAPE; - default -> VoxelShapes.empty(); - }; - case TOP -> switch (state.get(FACING)) { - case NORTH -> NORTH_TOP_SHAPE; - case SOUTH -> SOUTH_TOP_SHAPE; - case WEST -> WEST_TOP_SHAPE; - case EAST -> EAST_TOP_SHAPE; - default -> VoxelShapes.empty(); - }; - default -> VoxelShapes.empty(); - }; - } - - static { - var shapes = new ArrayList(); - for (var dir : AUtils.HORIZONTAL_DIRS) { - for (int i = 0; i < 2; i++) { - double ox = switch (dir) { - case WEST -> 0.5; - case EAST -> -0.5; - default -> 0; - }; - double oz = switch (dir) { - case NORTH -> 0.5; - case SOUTH -> -0.5; - default -> 0; - }; - var shape = switch (dir) { - case NORTH -> Block.createCuboidShape(0, -1.5, 0, 16, 0.5, 0.5); - case SOUTH -> Block.createCuboidShape(0, -1.5, 15.5, 16, 0.5, 16); - case EAST -> Block.createCuboidShape(15.5, -1.5, 0, 16, 0.5, 16); - case WEST -> Block.createCuboidShape(0, -1.5, 0, 0.5, 0.5, 16); - default -> VoxelShapes.empty(); - }; - shape = shape.offset(0, i * 0.5, 0); - var finalShape = shape; - for (int j = 1; j < 32; j++) { - finalShape = VoxelShapes.union(finalShape, shape.offset((ox * j) / 16, (0.25 * j) / 16, (oz * j) / 16)); - } - shapes.add(finalShape); - } - } - NORTH_BOTTOM_SHAPE = shapes.get(0); - NORTH_TOP_SHAPE = shapes.get(1); - SOUTH_BOTTOM_SHAPE = shapes.get(2); - SOUTH_TOP_SHAPE = shapes.get(3); - EAST_BOTTOM_SHAPE = shapes.get(4); - EAST_TOP_SHAPE = shapes.get(5); - WEST_BOTTOM_SHAPE = shapes.get(6); - WEST_TOP_SHAPE = shapes.get(7); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/block/SlopedDashPanelBlock.java b/src/main/java/io/github/foundationgames/automobility/block/SlopedDashPanelBlock.java deleted file mode 100644 index 189622e..0000000 --- a/src/main/java/io/github/foundationgames/automobility/block/SlopedDashPanelBlock.java +++ /dev/null @@ -1,40 +0,0 @@ -package io.github.foundationgames.automobility.block; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.entity.Entity; -import net.minecraft.state.StateManager; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.World; -import net.minecraft.world.WorldAccess; - -public class SlopedDashPanelBlock extends SlopeBlock { - public static final BooleanProperty LEFT = BooleanProperty.of("left"); - public static final BooleanProperty RIGHT = BooleanProperty.of("right"); - - public SlopedDashPanelBlock(Settings settings) { - super(settings); - setDefaultState(getDefaultState().with(LEFT, false).with(RIGHT, false)); - } - - @Override - protected void appendProperties(StateManager.Builder builder) { - super.appendProperties(builder); - builder.add(LEFT, RIGHT); - } - - @Override - public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) { - super.onEntityCollision(state, world, pos, entity); - DashPanelBlock.onCollideWithDashPanel(entity); - } - - @Override - public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) { - boolean left = world.getBlockState(pos.offset(state.get(FACING).rotateCounterclockwise(Direction.Axis.Y))).isOf(this); - boolean right = world.getBlockState(pos.offset(state.get(FACING).rotateClockwise(Direction.Axis.Y))).isOf(this); - return state.with(LEFT, left).with(RIGHT, right); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/block/SteepSlopeBlock.java b/src/main/java/io/github/foundationgames/automobility/block/SteepSlopeBlock.java deleted file mode 100644 index ee29157..0000000 --- a/src/main/java/io/github/foundationgames/automobility/block/SteepSlopeBlock.java +++ /dev/null @@ -1,101 +0,0 @@ -package io.github.foundationgames.automobility.block; - -import io.github.foundationgames.automobility.item.SlopePlacementContext; -import io.github.foundationgames.automobility.util.AUtils; -import net.minecraft.block.*; -import net.minecraft.fluid.FluidState; -import net.minecraft.fluid.Fluids; -import net.minecraft.item.ItemPlacementContext; -import net.minecraft.state.StateManager; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.state.property.Properties; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.util.shape.VoxelShapes; -import net.minecraft.world.BlockView; -import net.minecraft.world.World; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; - -public class SteepSlopeBlock extends HorizontalFacingBlock implements Waterloggable { - public static final VoxelShape NORTH_SHAPE; - public static final VoxelShape SOUTH_SHAPE; - public static final VoxelShape EAST_SHAPE; - public static final VoxelShape WEST_SHAPE; - - public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED; - - public SteepSlopeBlock(Settings settings) { - super(settings.nonOpaque()); - setDefaultState(getDefaultState().with(FACING, Direction.NORTH).with(WATERLOGGED, false)); - } - - @Nullable - @Override - public BlockState getPlacementState(ItemPlacementContext ctx) { - return ctx instanceof SlopePlacementContext slopeCtx ? - super.getPlacementState(ctx) - .with(FACING, slopeCtx.getSlopeFacing()) - .with(WATERLOGGED, ctx.getWorld().getBlockState(ctx.getBlockPos()).isOf(Blocks.WATER)) - : - super.getPlacementState(ctx) - .with(FACING, ctx.getPlayerFacing().getOpposite()) - .with(WATERLOGGED, ctx.getWorld().getBlockState(ctx.getBlockPos()).isOf(Blocks.WATER)); - } - - @Override - protected void appendProperties(StateManager.Builder builder) { - super.appendProperties(builder); - builder.add(FACING, WATERLOGGED); - } - - @Override - public FluidState getFluidState(BlockState state) { - return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state); - } - - @Override - public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { - return switch (state.get(FACING)) { - case NORTH -> NORTH_SHAPE; - case SOUTH -> SOUTH_SHAPE; - case WEST -> WEST_SHAPE; - case EAST -> EAST_SHAPE; - default -> VoxelShapes.empty(); - }; - } - - static { - var shapes = new ArrayList(); - for (var dir : AUtils.HORIZONTAL_DIRS) { - double ox = switch (dir) { - case WEST -> 0.5; - case EAST -> -0.5; - default -> 0; - }; - double oz = switch (dir) { - case NORTH -> 0.5; - case SOUTH -> -0.5; - default -> 0; - }; - var shape = switch (dir) { - case NORTH -> Block.createCuboidShape(0, -1.5, 0, 16, 0.5, 0.5); - case SOUTH -> Block.createCuboidShape(0, -1.5, 15.5, 16, 0.5, 16); - case EAST -> Block.createCuboidShape(15.5, -1.5, 0, 16, 0.5, 16); - case WEST -> Block.createCuboidShape(0, -1.5, 0, 0.5, 0.5, 16); - default -> VoxelShapes.empty(); - }; - var finalShape = shape; - for (int i = 1; i < 32; i++) { - finalShape = VoxelShapes.union(finalShape, shape.offset((ox * i) / 16, (0.5 * i) / 16, (oz * i) / 16)); - } - shapes.add(finalShape); - } - NORTH_SHAPE = shapes.get(0); - SOUTH_SHAPE = shapes.get(1); - EAST_SHAPE = shapes.get(2); - WEST_SHAPE = shapes.get(3); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/block/SteepSlopedDashPanelBlock.java b/src/main/java/io/github/foundationgames/automobility/block/SteepSlopedDashPanelBlock.java deleted file mode 100644 index b411591..0000000 --- a/src/main/java/io/github/foundationgames/automobility/block/SteepSlopedDashPanelBlock.java +++ /dev/null @@ -1,40 +0,0 @@ -package io.github.foundationgames.automobility.block; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.entity.Entity; -import net.minecraft.state.StateManager; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.World; -import net.minecraft.world.WorldAccess; - -public class SteepSlopedDashPanelBlock extends SteepSlopeBlock { - public static final BooleanProperty LEFT = BooleanProperty.of("left"); - public static final BooleanProperty RIGHT = BooleanProperty.of("right"); - - public SteepSlopedDashPanelBlock(Settings settings) { - super(settings); - setDefaultState(getDefaultState().with(LEFT, false).with(RIGHT, false)); - } - - @Override - protected void appendProperties(StateManager.Builder builder) { - super.appendProperties(builder); - builder.add(LEFT, RIGHT); - } - - @Override - public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) { - super.onEntityCollision(state, world, pos, entity); - DashPanelBlock.onCollideWithDashPanel(entity); - } - - @Override - public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) { - boolean left = world.getBlockState(pos.offset(state.get(FACING).rotateCounterclockwise(Direction.Axis.Y))).isOf(this); - boolean right = world.getBlockState(pos.offset(state.get(FACING).rotateClockwise(Direction.Axis.Y))).isOf(this); - return state.with(LEFT, left).with(RIGHT, right); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/block/entity/AutomobileAssemblerBlockEntity.java b/src/main/java/io/github/foundationgames/automobility/block/entity/AutomobileAssemblerBlockEntity.java deleted file mode 100644 index ea62ab3..0000000 --- a/src/main/java/io/github/foundationgames/automobility/block/entity/AutomobileAssemblerBlockEntity.java +++ /dev/null @@ -1,390 +0,0 @@ -package io.github.foundationgames.automobility.block.entity; - -import io.github.foundationgames.automobility.automobile.AutomobileEngine; -import io.github.foundationgames.automobility.automobile.AutomobileFrame; -import io.github.foundationgames.automobility.automobile.AutomobileStats; -import io.github.foundationgames.automobility.automobile.AutomobileWheel; -import io.github.foundationgames.automobility.automobile.attachment.FrontAttachmentType; -import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType; -import io.github.foundationgames.automobility.automobile.attachment.front.FrontAttachment; -import io.github.foundationgames.automobility.automobile.attachment.rear.RearAttachment; -import io.github.foundationgames.automobility.automobile.render.RenderableAutomobile; -import io.github.foundationgames.automobility.block.AutomobileAssemblerBlock; -import io.github.foundationgames.automobility.block.AutomobilityBlocks; -import io.github.foundationgames.automobility.entity.AutomobileEntity; -import io.github.foundationgames.automobility.item.AutomobileEngineItem; -import io.github.foundationgames.automobility.item.AutomobileFrameItem; -import io.github.foundationgames.automobility.item.AutomobileWheelItem; -import io.github.foundationgames.automobility.item.AutomobilityItems; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.block.BlockState; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.client.model.Model; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.entity.ItemEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.network.Packet; -import net.minecraft.network.listener.ClientPlayPacketListener; -import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket; -import net.minecraft.network.packet.s2c.play.ParticleS2CPacket; -import net.minecraft.particle.ParticleTypes; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.sound.SoundCategory; -import net.minecraft.sound.SoundEvents; -import net.minecraft.text.Text; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.Identifier; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3d; -import net.minecraft.util.math.Vec3f; -import net.minecraft.world.event.GameEvent; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.List; - -public class AutomobileAssemblerBlockEntity extends BlockEntity implements RenderableAutomobile { - @Environment(EnvType.CLIENT) private Model frameModel = null; - @Environment(EnvType.CLIENT) private Model engineModel = null; - @Environment(EnvType.CLIENT) private Model wheelModel = null; - @Environment(EnvType.CLIENT) private Model emptyRearAttModel = null; - @Environment(EnvType.CLIENT) private Model emptyFrontAttModel = null; - private boolean componentsUpdated = true; - - protected AutomobileFrame frame = AutomobileFrame.EMPTY; - protected AutomobileEngine engine = AutomobileEngine.EMPTY; - protected AutomobileWheel wheel = AutomobileWheel.EMPTY; - protected int wheelCount = 0; - - public final List label = new ArrayList<>(); - protected final AutomobileStats stats = new AutomobileStats(); - - public AutomobileAssemblerBlockEntity(BlockPos pos, BlockState state) { - super(AutomobilityBlocks.AUTOMOBILE_ASSEMBLER_ENTITY, pos, state); - } - - @Override - public AutomobileFrame getFrame() { - return frame; - } - - @Override - public AutomobileWheel getWheels() { - return wheel; - } - - @Override - public AutomobileEngine getEngine() { - return engine; - } - - @Override - public @Nullable RearAttachment getRearAttachment() { - return null; - } - - @Override - public @Nullable FrontAttachment getFrontAttachment() { - return null; - } - - @Override - public Model getFrameModel(EntityRendererFactory.Context ctx) { - if (this.componentsUpdated) this.frameModel = this.frame.model().model().apply(ctx); - return this.frameModel; - } - - @Override - public Model getWheelModel(EntityRendererFactory.Context ctx) { - if (this.componentsUpdated) this.wheelModel = this.wheel.model().model().apply(ctx); - return this.wheelModel; - } - - @Override - public Model getEngineModel(EntityRendererFactory.Context ctx) { - if (this.componentsUpdated) this.engineModel = this.engine.model().model().apply(ctx); - return this.engineModel; - } - - @Override - public Model getRearAttachmentModel(EntityRendererFactory.Context ctx) { - if (this.componentsUpdated) this.emptyRearAttModel = RearAttachmentType.EMPTY.model().model().apply(ctx); - return this.emptyRearAttModel; - } - - @Override - public Model getFrontAttachmentModel(EntityRendererFactory.Context ctx) { - if (this.componentsUpdated) this.emptyFrontAttModel = FrontAttachmentType.EMPTY.model().model().apply(ctx); - return this.emptyFrontAttModel; - } - - private void partChanged() { - this.sync(); - this.markDirty(); - this.world.emitGameEvent(GameEvent.BLOCK_CHANGE, this.getPos(), new GameEvent.Emitter(null, this.getCachedState())); - } - - protected ActionResult handleItemInteract(PlayerEntity player, ItemStack stack) { - // Returns success on the server since the client is never 100% confident that the action was valid - // Subsequent handling is performed with the action result - - if (stack.isOf(AutomobilityItems.CROWBAR)) { - if (!world.isClient()) { - this.dropParts(); - this.partChanged(); - return ActionResult.SUCCESS; - } - return ActionResult.PASS; - } - if (this.frame.isEmpty() && stack.getItem() instanceof AutomobileFrameItem frameItem) { - if (!world.isClient()) { - this.frame = frameItem.getComponent(stack); - if (!player.isCreative()) { - stack.decrement(1); - } - this.partChanged(); - return ActionResult.SUCCESS; - } - return ActionResult.PASS; - } - if (!this.frame.isEmpty()) { - if (this.engine.isEmpty() && stack.getItem() instanceof AutomobileEngineItem engineItem) { - if (!world.isClient()) { - this.engine = engineItem.getComponent(stack); - if (!player.isCreative()) { - stack.decrement(1); - } - this.partChanged(); - return ActionResult.SUCCESS; - } - return ActionResult.PASS; - } - if (stack.getItem() instanceof AutomobileWheelItem wheelItem) { - if (!world.isClient()) { - var wheelType = wheelItem.getComponent(stack); - if (this.wheel.isEmpty()) { - this.wheel = wheelType; - this.wheelCount = 0; // Fix wheel count if ever invalid - } - if (this.wheel == wheelType && this.wheelCount < this.frame.model().wheelBase().wheelCount) { - this.wheelCount++; - if (!player.isCreative()) { - stack.decrement(1); - } - this.partChanged(); - return ActionResult.SUCCESS; - } - } else { - return ActionResult.PASS; - } - } - } - if (!this.world.isClient() && stack.isOf(AutomobilityItems.FRONT_ATTACHMENT) || stack.isOf(AutomobilityItems.REAR_ATTACHMENT)) { - player.sendMessage(AutomobileAssemblerBlock.INCOMPLETE_AUTOMOBILE_DIALOG, true); - } - - return ActionResult.FAIL; - } - - public ActionResult interact(PlayerEntity player, Hand hand) { - var stack = player.getStackInHand(hand); - var result = this.handleItemInteract(player, stack); - - if (!this.world.isClient() && result == ActionResult.SUCCESS) { - if (!isComplete()) { - world.playSound(null, this.pos, SoundEvents.BLOCK_COPPER_PLACE, SoundCategory.BLOCKS, 0.7f, 0.6f + (this.world.random.nextFloat() * 0.15f)); - } - - tryConstructAutomobile(); - return ActionResult.SUCCESS; - } - return result; - } - - protected Vec3d centerPos() { - return new Vec3d(this.pos.getX() + 0.5, this.pos.getY() + 0.75, this.pos.getZ() + 0.5); - } - - public boolean isComplete() { - return !this.frame.isEmpty() && - !this.engine.isEmpty() && - ((!this.wheel.isEmpty()) && (this.wheelCount >= this.frame.model().wheelBase().wheelCount)); - } - - public void tryConstructAutomobile() { - if (this.isComplete()) { - var pos = this.centerPos(); - var auto = new AutomobileEntity(this.world); - auto.refreshPositionAndAngles(pos.x, pos.y, pos.z, this.getAutomobileYaw(0), 0); - auto.setComponents(this.frame, this.wheel, this.engine); - world.spawnEntity(auto); - - world.getPlayers().forEach(p -> { - if (p instanceof ServerPlayerEntity player && p.getBlockPos().getSquaredDistance(this.pos) < 80000) { - player.networkHandler.sendPacket(new ParticleS2CPacket(ParticleTypes.EXPLOSION, false, pos.x, pos.y + 0.47, pos.z, 0, 0, 0, 0, 1)); - } - }); - world.playSound(null, this.pos, SoundEvents.BLOCK_ANVIL_PLACE, SoundCategory.BLOCKS, 0.23f, 0.5f); - - this.clear(); - } - } - - public void dropParts() { - var pos = this.centerPos(); - - this.world.spawnEntity(new ItemEntity(world, pos.x, pos.y, pos.z, AutomobilityItems.AUTOMOBILE_FRAME.createStack(this.getFrame()))); - this.world.spawnEntity(new ItemEntity(world, pos.x, pos.y, pos.z, AutomobilityItems.AUTOMOBILE_ENGINE.createStack(this.getEngine()))); - - var wheelStack = AutomobilityItems.AUTOMOBILE_WHEEL.createStack(this.getWheels()); - wheelStack.setCount(this.wheelCount); - this.world.spawnEntity(new ItemEntity(world, pos.x, pos.y, pos.z, wheelStack)); - - this.clear(); - } - - public void clear() { - this.frame = AutomobileFrame.EMPTY; - this.wheel = AutomobileWheel.EMPTY; - this.engine = AutomobileEngine.EMPTY; - this.wheelCount = 0; - } - - private boolean hasAllParts() { - return !this.frame.isEmpty() && !this.wheel.isEmpty() && !this.engine.isEmpty(); - } - - private void onComponentsUpdated() { - this.componentsUpdated = true; - - if (world == null || world.isClient()) { - this.label.clear(); - if (this.hasAllParts()) { - this.stats.from(this.frame, this.wheel, this.engine); - this.stats.appendTexts(this.label, this.stats); - } - } - } - - private void sync() { - if (this.world instanceof ServerWorld sWorld) { - sWorld.getChunkManager().markForUpdate(this.pos); - } - } - - @Override - public void readNbt(NbtCompound nbt) { - super.readNbt(nbt); - - this.frame = AutomobileFrame.REGISTRY.getOrDefault(Identifier.tryParse(nbt.getString("frame"))); - this.engine = AutomobileEngine.REGISTRY.getOrDefault(Identifier.tryParse(nbt.getString("engine"))); - - var wheelNbt = nbt.getCompound("wheels"); - this.wheel = AutomobileWheel.REGISTRY.getOrDefault(Identifier.tryParse(wheelNbt.getString("type"))); - this.wheelCount = wheelNbt.getInt("count"); - - onComponentsUpdated(); - } - - @Override - protected void writeNbt(NbtCompound nbt) { - super.writeNbt(nbt); - - nbt.putString("frame", this.frame.getId().toString()); - nbt.putString("engine", this.engine.getId().toString()); - - var wheelNbt = new NbtCompound(); - wheelNbt.putString("type", this.wheel.getId().toString()); - wheelNbt.putInt("count", this.wheelCount); - nbt.put("wheels", wheelNbt); - } - - @Nullable - @Override - public Packet toUpdatePacket() { - return BlockEntityUpdateS2CPacket.create(this); - } - - @Override - public NbtCompound toInitialChunkDataNbt() { - var nbt = new NbtCompound(); - this.writeNbt(nbt); - return nbt; - } - - protected boolean powered() { - var state = this.world.getBlockState(this.pos); - return state.contains(AutomobileAssemblerBlock.POWERED) && state.get(AutomobileAssemblerBlock.POWERED); - } - - @Override - public float getAutomobileYaw(float tickDelta) { - var state = this.world.getBlockState(this.pos); - return state.contains(AutomobileAssemblerBlock.FACING) ? (state.get(AutomobileAssemblerBlock.FACING).asRotation() - 90) : 0; - } - - @Override - public int getWheelCount() { - return this.wheelCount; - } - - @Override - public float getRearAttachmentYaw(float tickDelta) { - return 0; - } - - @Override - public float getWheelAngle(float tickDelta) { - return this.powered() ? (this.getTime() + tickDelta) * 36 : 0; - } - - @Override - public float getSteering(float tickDelta) { - return 0; - } - - @Override - public float getSuspensionBounce(float tickDelta) { - return 0; - } - - @Override - public boolean engineRunning() { - return this.powered(); - } - - @Override - public int getBoostTimer() { - return this.powered() ? 1 : 0; - } - - @Override - public int getTurboCharge() { - return 0; - } - - @Override - public long getTime() { - return this.world.getTime(); - } - - @Override - public boolean automobileOnGround() { - return false; - } - - @Override - public boolean debris() { - return false; - } - - @Override - public Vec3f debrisColor() { - return null; - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/block/entity/render/AutomobileAssemblerBlockEntityRenderer.java b/src/main/java/io/github/foundationgames/automobility/block/entity/render/AutomobileAssemblerBlockEntityRenderer.java deleted file mode 100644 index 182e819..0000000 --- a/src/main/java/io/github/foundationgames/automobility/block/entity/render/AutomobileAssemblerBlockEntityRenderer.java +++ /dev/null @@ -1,54 +0,0 @@ -package io.github.foundationgames.automobility.block.entity.render; - -import io.github.foundationgames.automobility.automobile.render.AutomobileRenderer; -import io.github.foundationgames.automobility.block.entity.AutomobileAssemblerBlockEntity; -import io.github.foundationgames.automobility.util.EntityRenderHelper; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.render.block.entity.BlockEntityRenderer; -import net.minecraft.client.render.block.entity.BlockEntityRendererFactory; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.state.property.Properties; -import net.minecraft.util.math.Vec3f; - -public class AutomobileAssemblerBlockEntityRenderer implements BlockEntityRenderer { - private final TextRenderer textRenderer; - private EntityRendererFactory.Context context = null; - - public AutomobileAssemblerBlockEntityRenderer(BlockEntityRendererFactory.Context blockEntityCtx) { - EntityRenderHelper.registerContextListener(this::setContext); - - this.textRenderer = blockEntityCtx.getTextRenderer(); - } - - public void setContext(EntityRendererFactory.Context context) { - this.context = context; - } - - @Override - public void render(AutomobileAssemblerBlockEntity entity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) { - if (this.context != null) { - matrices.push(); - matrices.translate(0.5, 0.75 - (entity.getWheels().model().radius() / 16), 0.5); - AutomobileRenderer.render(matrices, vertexConsumers, light, overlay, tickDelta, this.context, entity); - matrices.pop(); - - matrices.push(); - matrices.translate(0.5, 0, 0.5); - matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(-entity.getCachedState().get(Properties.HORIZONTAL_FACING).asRotation())); - matrices.translate(0, 0.372, 0.501); - matrices.scale(0.008f, -0.008f, -0.008f); - - for (var text : entity.label) { - matrices.push(); - matrices.translate(-0.5 * textRenderer.getWidth(text), 0, 0); - textRenderer.drawWithShadow(matrices, text, 0, 0, 0xFFFFFF); - matrices.pop(); - matrices.translate(0, 12, 0); - } - - matrices.pop(); - } - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/entity/AutomobilityEntities.java b/src/main/java/io/github/foundationgames/automobility/entity/AutomobilityEntities.java deleted file mode 100644 index c76d316..0000000 --- a/src/main/java/io/github/foundationgames/automobility/entity/AutomobilityEntities.java +++ /dev/null @@ -1,99 +0,0 @@ -package io.github.foundationgames.automobility.entity; - -import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.automobile.render.ExhaustFumesModel; -import io.github.foundationgames.automobility.automobile.render.SkidEffectModel; -import io.github.foundationgames.automobility.automobile.render.attachment.front.HarvesterFrontAttachmentModel; -import io.github.foundationgames.automobility.automobile.render.attachment.front.MobControllerFrontAttachmentModel; -import io.github.foundationgames.automobility.automobile.render.attachment.rear.BannerPostRearAttachmentModel; -import io.github.foundationgames.automobility.automobile.render.attachment.rear.BlockRearAttachmentModel; -import io.github.foundationgames.automobility.automobile.render.attachment.rear.ChestRearAttachmentModel; -import io.github.foundationgames.automobility.automobile.render.attachment.rear.GrindstoneRearAttachmentModel; -import io.github.foundationgames.automobility.automobile.render.attachment.rear.PassengerSeatRearAttachmentModel; -import io.github.foundationgames.automobility.automobile.render.attachment.rear.PlowRearAttachmentModel; -import io.github.foundationgames.automobility.automobile.render.attachment.rear.StonecutterRearAttachmentModel; -import io.github.foundationgames.automobility.automobile.render.engine.CopperEngineModel; -import io.github.foundationgames.automobility.automobile.render.engine.CreativeEngineModel; -import io.github.foundationgames.automobility.automobile.render.engine.DiamondEngineModel; -import io.github.foundationgames.automobility.automobile.render.engine.GoldEngineModel; -import io.github.foundationgames.automobility.automobile.render.engine.IronEngineModel; -import io.github.foundationgames.automobility.automobile.render.engine.StoneEngineModel; -import io.github.foundationgames.automobility.automobile.render.frame.CARRFrameModel; -import io.github.foundationgames.automobility.automobile.render.frame.MotorcarFrameModel; -import io.github.foundationgames.automobility.automobile.render.frame.PineappleFrameModel; -import io.github.foundationgames.automobility.automobile.render.frame.RickshawFrameModel; -import io.github.foundationgames.automobility.automobile.render.frame.ShoppingCartFrameModel; -import io.github.foundationgames.automobility.automobile.render.frame.StandardFrameModel; -import io.github.foundationgames.automobility.automobile.render.frame.TractorFrameModel; -import io.github.foundationgames.automobility.automobile.render.wheel.CarriageWheelModel; -import io.github.foundationgames.automobility.automobile.render.wheel.OffRoadWheelModel; -import io.github.foundationgames.automobility.automobile.render.wheel.StandardWheelModel; -import io.github.foundationgames.automobility.automobile.render.wheel.SteelWheelModel; -import io.github.foundationgames.automobility.automobile.render.wheel.TractorWheelModel; -import io.github.foundationgames.automobility.entity.render.AutomobileEntityRenderer; -import io.github.foundationgames.jsonem.JsonEM; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry; -import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder; -import net.minecraft.entity.EntityDimensions; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.SpawnGroup; -import net.minecraft.entity.damage.DamageSource; -import net.minecraft.tag.TagKey; -import net.minecraft.util.registry.Registry; - -public enum AutomobilityEntities {; - public static final EntityType AUTOMOBILE = Registry.register( - Registry.ENTITY_TYPE, - Automobility.id("automobile"), - FabricEntityTypeBuilder.create(SpawnGroup.MISC, AutomobileEntity::new).dimensions(new EntityDimensions(1f, 0.66f, true)).trackedUpdateRate(3).trackRangeChunks(10).build() - ); - - public static final TagKey> DASH_PANEL_BOOSTABLES = TagKey.of(Registry.ENTITY_TYPE_KEY, Automobility.id("dash_panel_boostables")); - - public static final DamageSource AUTOMOBILE_DAMAGE_SOURCE = new AutomobileDamageSource("automobile"); - - public static void init() { - } - - @Environment(EnvType.CLIENT) - public static void initClient() { - EntityRendererRegistry.register(AUTOMOBILE, AutomobileEntityRenderer::new); - - JsonEM.registerModelLayer(StandardFrameModel.MODEL_LAYER); - JsonEM.registerModelLayer(TractorFrameModel.MODEL_LAYER); - JsonEM.registerModelLayer(MotorcarFrameModel.MODEL_LAYER); - JsonEM.registerModelLayer(ShoppingCartFrameModel.MODEL_LAYER); - JsonEM.registerModelLayer(CARRFrameModel.MODEL_LAYER); - JsonEM.registerModelLayer(PineappleFrameModel.MODEL_LAYER); - JsonEM.registerModelLayer(RickshawFrameModel.MODEL_LAYER); - - JsonEM.registerModelLayer(StandardWheelModel.MODEL_LAYER); - JsonEM.registerModelLayer(OffRoadWheelModel.MODEL_LAYER); - JsonEM.registerModelLayer(TractorWheelModel.MODEL_LAYER); - JsonEM.registerModelLayer(CarriageWheelModel.MODEL_LAYER); - JsonEM.registerModelLayer(SteelWheelModel.MODEL_LAYER); - - JsonEM.registerModelLayer(StoneEngineModel.MODEL_LAYER); - JsonEM.registerModelLayer(IronEngineModel.MODEL_LAYER); - JsonEM.registerModelLayer(CopperEngineModel.MODEL_LAYER); - JsonEM.registerModelLayer(GoldEngineModel.MODEL_LAYER); - JsonEM.registerModelLayer(DiamondEngineModel.MODEL_LAYER); - JsonEM.registerModelLayer(CreativeEngineModel.MODEL_LAYER); - - JsonEM.registerModelLayer(PassengerSeatRearAttachmentModel.MODEL_LAYER); - JsonEM.registerModelLayer(BlockRearAttachmentModel.MODEL_LAYER); - JsonEM.registerModelLayer(GrindstoneRearAttachmentModel.MODEL_LAYER); - JsonEM.registerModelLayer(StonecutterRearAttachmentModel.MODEL_LAYER); - JsonEM.registerModelLayer(ChestRearAttachmentModel.MODEL_LAYER); - JsonEM.registerModelLayer(BannerPostRearAttachmentModel.MODEL_LAYER); - JsonEM.registerModelLayer(PlowRearAttachmentModel.MODEL_LAYER); - - JsonEM.registerModelLayer(MobControllerFrontAttachmentModel.MODEL_LAYER); - JsonEM.registerModelLayer(HarvesterFrontAttachmentModel.MODEL_LAYER); - - JsonEM.registerModelLayer(SkidEffectModel.MODEL_LAYER); - JsonEM.registerModelLayer(ExhaustFumesModel.MODEL_LAYER); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/entity/render/AutomobileEntityRenderer.java b/src/main/java/io/github/foundationgames/automobility/entity/render/AutomobileEntityRenderer.java deleted file mode 100644 index 24eeb55..0000000 --- a/src/main/java/io/github/foundationgames/automobility/entity/render/AutomobileEntityRenderer.java +++ /dev/null @@ -1,40 +0,0 @@ -package io.github.foundationgames.automobility.entity.render; - -import io.github.foundationgames.automobility.automobile.render.AutomobileRenderer; -import io.github.foundationgames.automobility.entity.AutomobileEntity; -import net.minecraft.client.render.OverlayTexture; -import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.render.entity.EntityRenderer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.Identifier; -import net.minecraft.util.math.Quaternion; -import net.minecraft.util.math.Vec3f; - -public class AutomobileEntityRenderer extends EntityRenderer { - private final EntityRendererFactory.Context ctx; - - public AutomobileEntityRenderer(EntityRendererFactory.Context ctx) { - super(ctx); - this.ctx = ctx; - } - - @Override - public Identifier getTexture(AutomobileEntity entity) { - return null; - } - - @Override - public void render(AutomobileEntity entity, float yaw, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light) { - matrices.push(); - float angX = entity.getDisplacement().getAngularX(tickDelta); - float angZ = entity.getDisplacement().getAngularZ(tickDelta); - float offsetY = entity.getDisplacement().getVertical(tickDelta); - - matrices.translate(0, offsetY, 0); - matrices.multiply(Quaternion.fromEulerXyz((float) Math.toRadians(angX), 0, (float) Math.toRadians(angZ))); - - AutomobileRenderer.render(matrices, vertexConsumers, light, OverlayTexture.DEFAULT_UV, tickDelta, ctx, entity); - matrices.pop(); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/item/AutomobileComponentItem.java b/src/main/java/io/github/foundationgames/automobility/item/AutomobileComponentItem.java deleted file mode 100644 index d4c26f3..0000000 --- a/src/main/java/io/github/foundationgames/automobility/item/AutomobileComponentItem.java +++ /dev/null @@ -1,100 +0,0 @@ -package io.github.foundationgames.automobility.item; - -import io.github.foundationgames.automobility.automobile.AutomobileComponent; -import io.github.foundationgames.automobility.util.FloatFunc; -import io.github.foundationgames.automobility.util.SimpleMapContentRegistry; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry; -import net.minecraft.client.item.TooltipContext; -import net.minecraft.client.model.Model; -import net.minecraft.item.Item; -import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemStack; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import net.minecraft.util.Identifier; -import net.minecraft.util.collection.DefaultedList; -import net.minecraft.util.function.ToFloatFunction; -import net.minecraft.world.World; -import org.jetbrains.annotations.Nullable; - -import java.util.List; -import java.util.function.Function; - -public class AutomobileComponentItem> extends Item { - protected final String nbtKey; - protected final String translationKey; - protected final SimpleMapContentRegistry registry; - - public AutomobileComponentItem(Settings settings, String nbtKey, String translationKey, SimpleMapContentRegistry registry) { - super(settings); - this.nbtKey = nbtKey; - this.translationKey = translationKey; - this.registry = registry; - } - - public ItemStack createStack(T component) { - if (component.isEmpty()) { - return ItemStack.EMPTY; - } - - var stack = new ItemStack(this); - this.setComponent(stack, component.getId()); - return stack; - } - - public void setComponent(ItemStack stack, Identifier component) { - stack.getOrCreateNbt().putString(this.nbtKey, component.toString()); - } - - public T getComponent(ItemStack stack) { - if (stack.hasNbt() && stack.getNbt().contains(this.nbtKey)) { - return this.registry.getOrDefault(Identifier.tryParse(stack.getNbt().getString(this.nbtKey))); - } - return this.registry.getOrDefault(null); - } - - @Override - public void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context) { - super.appendTooltip(stack, world, tooltip, context); - var component = this.getComponent(stack); - var id = component.getId(); - var compKey = id.getNamespace()+"."+id.getPath(); - tooltip.add(Text.translatable(this.translationKey+"."+compKey).formatted(Formatting.BLUE)); - - component.appendTexts(tooltip, component); - } - - @Override - public void appendStacks(ItemGroup group, DefaultedList stacks) { - if (this.isIn(group)) { - this.registry.forEach(component -> { - if (addToCreative(component)) stacks.add(this.createStack(component)); - }); - } - } - - @Environment(EnvType.CLIENT) - protected boolean renders(T component) { - return !component.isEmpty(); - } - - protected boolean addToCreative(T component) { - return !component.isEmpty(); - } - - @Environment(EnvType.CLIENT) - public void registerItemRenderer(Function modelProvider, Function textureProvider, FloatFunc scaleProvider) { - BuiltinItemRendererRegistry.INSTANCE.register(this, (stack, mode, matrices, vertexConsumers, light, overlay) -> { - var component = this.getComponent(stack); - if (this.renders(component)) { - var model = modelProvider.apply(component); - float scale = scaleProvider.apply(component); - matrices.translate(0.5, 0, 0.5); - matrices.scale(scale, -scale, -scale); - model.render(matrices, vertexConsumers.getBuffer(model.getLayer(textureProvider.apply(component))), light, overlay, 1, 1, 1, 1); - } - }); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/item/AutomobileInteractable.java b/src/main/java/io/github/foundationgames/automobility/item/AutomobileInteractable.java deleted file mode 100644 index 39f0614..0000000 --- a/src/main/java/io/github/foundationgames/automobility/item/AutomobileInteractable.java +++ /dev/null @@ -1,11 +0,0 @@ -package io.github.foundationgames.automobility.item; - -import io.github.foundationgames.automobility.entity.AutomobileEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; - -public interface AutomobileInteractable { - ActionResult interactAutomobile(ItemStack stack, PlayerEntity player, Hand hand, AutomobileEntity automobile); -} diff --git a/src/main/java/io/github/foundationgames/automobility/item/AutomobileItem.java b/src/main/java/io/github/foundationgames/automobility/item/AutomobileItem.java deleted file mode 100644 index c0fe4f7..0000000 --- a/src/main/java/io/github/foundationgames/automobility/item/AutomobileItem.java +++ /dev/null @@ -1,88 +0,0 @@ -package io.github.foundationgames.automobility.item; - -import io.github.foundationgames.automobility.automobile.AutomobileData; -import io.github.foundationgames.automobility.automobile.AutomobilePrefab; -import io.github.foundationgames.automobility.automobile.AutomobileStats; -import io.github.foundationgames.automobility.entity.AutomobileEntity; -import io.github.foundationgames.automobility.entity.AutomobilityEntities; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.item.TooltipContext; -import net.minecraft.item.Item; -import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemStack; -import net.minecraft.item.ItemUsageContext; -import net.minecraft.text.Text; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Formatting; -import net.minecraft.util.collection.DefaultedList; -import net.minecraft.world.World; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class AutomobileItem extends Item { - public static final List PREFABS = new ArrayList<>(); - private static final AutomobileData data = new AutomobileData(); - private static final AutomobileStats stats = new AutomobileStats(); - - public AutomobileItem(Settings settings) { - super(settings); - } - - @Override - public ActionResult useOnBlock(ItemUsageContext context) { - if (!context.getWorld().isClient()) { - var stack = context.getStack(); - data.read(stack.getOrCreateSubNbt("Automobile")); - var e = new AutomobileEntity(AutomobilityEntities.AUTOMOBILE, context.getWorld()); - var pos = context.getHitPos(); - e.refreshPositionAndAngles(pos.x, pos.y, pos.z, context.getPlayerFacing().asRotation(), 0); - e.setComponents(data.getFrame(), data.getWheel(), data.getEngine()); - context.getWorld().spawnEntity(e); - stack.decrement(1); - return ActionResult.PASS; - } - return ActionResult.SUCCESS; - } - - @Override - public void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context) { - super.appendTooltip(stack, world, tooltip, context); - data.read(stack.getOrCreateSubNbt("Automobile")); - if (Screen.hasShiftDown()) { - stats.from(data.getFrame(), data.getWheel(), data.getEngine()); - stats.appendTexts(tooltip, stats); - } else { - if (!data.isPrefab()) { - tooltip.add( - Text.translatable("tooltip.automobility.frameLabel").formatted(Formatting.BLUE) - .append(Text.translatable(data.getFrame().getTranslationKey()).formatted(Formatting.DARK_GREEN)) - ); - tooltip.add( - Text.translatable("tooltip.automobility.wheelLabel").formatted(Formatting.BLUE) - .append(Text.translatable(data.getWheel().getTranslationKey()).formatted(Formatting.DARK_GREEN)) - ); - tooltip.add( - Text.translatable("tooltip.automobility.engineLabel").formatted(Formatting.BLUE) - .append(Text.translatable(data.getEngine().getTranslationKey()).formatted(Formatting.DARK_GREEN)) - ); - } - tooltip.add(Text.translatable("tooltip.automobility.shiftForStats").formatted(Formatting.GOLD)); - } - } - - public static void addPrefabs(AutomobilePrefab ... prefabs) { - PREFABS.addAll(Arrays.asList(prefabs)); - } - - @Override - public void appendStacks(ItemGroup group, DefaultedList stacks) { - if (isIn(group) || group == ItemGroup.TRANSPORTATION) { - for (var prefab : PREFABS) { - stacks.add(prefab.toStack()); - } - } - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/item/AutomobilityItems.java b/src/main/java/io/github/foundationgames/automobility/item/AutomobilityItems.java deleted file mode 100644 index e10209f..0000000 --- a/src/main/java/io/github/foundationgames/automobility/item/AutomobilityItems.java +++ /dev/null @@ -1,135 +0,0 @@ -package io.github.foundationgames.automobility.item; - -import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.automobile.*; -import io.github.foundationgames.automobility.automobile.attachment.FrontAttachmentType; -import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType; -import io.github.foundationgames.automobility.automobile.render.AutomobileRenderer; -import io.github.foundationgames.automobility.automobile.render.item.ItemRenderableAutomobile; -import io.github.foundationgames.automobility.util.EntityRenderHelper; -import io.github.foundationgames.automobility.util.SimpleMapContentRegistry; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.model.Model; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.item.Item; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import net.minecraft.util.registry.Registry; - -import java.util.HashMap; -import java.util.Map; -import java.util.function.Function; - -public enum AutomobilityItems {; - public static final Item CROWBAR = register("crowbar", new TooltipItem(Text.translatable("tooltip.item.automobility.crowbar").formatted(Formatting.BLUE), new Item.Settings().maxCount(1).group(Automobility.GROUP))); - public static final Item AUTOMOBILE = register("automobile", new AutomobileItem(new Item.Settings().maxCount(1).group(Automobility.PREFABS))); - public static final AutomobileFrameItem AUTOMOBILE_FRAME = register("automobile_frame", new AutomobileFrameItem(new Item.Settings().maxCount(16).group(Automobility.GROUP))); - public static final AutomobileWheelItem AUTOMOBILE_WHEEL = register("automobile_wheel", new AutomobileWheelItem(new Item.Settings().group(Automobility.GROUP))); - public static final AutomobileEngineItem AUTOMOBILE_ENGINE = register("automobile_engine", new AutomobileEngineItem(new Item.Settings().maxCount(16).group(Automobility.GROUP))); - public static final FrontAttachmentItem FRONT_ATTACHMENT = register("front_attachment", new FrontAttachmentItem(new Item.Settings().maxCount(1).group(Automobility.GROUP))); - public static final RearAttachmentItem REAR_ATTACHMENT = register("rear_attachment", new RearAttachmentItem(new Item.Settings().maxCount(1).group(Automobility.GROUP))); - - public static void init() { - AutomobileItem.addPrefabs( - new AutomobilePrefab(Automobility.id("wooden_motorcar"), AutomobileFrame.WOODEN_MOTORCAR, AutomobileWheel.CARRIAGE, AutomobileEngine.STONE), - new AutomobilePrefab(Automobility.id("copper_motorcar"), AutomobileFrame.COPPER_MOTORCAR, AutomobileWheel.PLATED, AutomobileEngine.COPPER), - new AutomobilePrefab(Automobility.id("steel_motorcar"), AutomobileFrame.STEEL_MOTORCAR, AutomobileWheel.STREET, AutomobileEngine.IRON), - new AutomobilePrefab(Automobility.id("golden_motorcar"), AutomobileFrame.GOLDEN_MOTORCAR, AutomobileWheel.GILDED, AutomobileEngine.GOLD), - new AutomobilePrefab(Automobility.id("bejeweled_motorcar"), AutomobileFrame.BEJEWELED_MOTORCAR, AutomobileWheel.BEJEWELED, AutomobileEngine.DIAMOND), - new AutomobilePrefab(Automobility.id("standard_white"), AutomobileFrame.STANDARD_WHITE, AutomobileWheel.STANDARD, AutomobileEngine.IRON), - new AutomobilePrefab(Automobility.id("standard_orange"), AutomobileFrame.STANDARD_ORANGE, AutomobileWheel.STANDARD, AutomobileEngine.IRON), - new AutomobilePrefab(Automobility.id("standard_magenta"), AutomobileFrame.STANDARD_MAGENTA, AutomobileWheel.STANDARD, AutomobileEngine.IRON), - new AutomobilePrefab(Automobility.id("standard_light_blue"), AutomobileFrame.STANDARD_LIGHT_BLUE, AutomobileWheel.STANDARD, AutomobileEngine.IRON), - new AutomobilePrefab(Automobility.id("standard_yellow"), AutomobileFrame.STANDARD_YELLOW, AutomobileWheel.STANDARD, AutomobileEngine.IRON), - new AutomobilePrefab(Automobility.id("standard_lime"), AutomobileFrame.STANDARD_LIME, AutomobileWheel.STANDARD, AutomobileEngine.IRON), - new AutomobilePrefab(Automobility.id("standard_pink"), AutomobileFrame.STANDARD_PINK, AutomobileWheel.STANDARD, AutomobileEngine.IRON), - new AutomobilePrefab(Automobility.id("standard_gray"), AutomobileFrame.STANDARD_GRAY, AutomobileWheel.STANDARD, AutomobileEngine.IRON), - new AutomobilePrefab(Automobility.id("standard_light_gray"), AutomobileFrame.STANDARD_LIGHT_GRAY, AutomobileWheel.STANDARD, AutomobileEngine.IRON), - new AutomobilePrefab(Automobility.id("standard_cyan"), AutomobileFrame.STANDARD_CYAN, AutomobileWheel.STANDARD, AutomobileEngine.IRON), - new AutomobilePrefab(Automobility.id("standard_purple"), AutomobileFrame.STANDARD_PURPLE, AutomobileWheel.STANDARD, AutomobileEngine.IRON), - new AutomobilePrefab(Automobility.id("standard_blue"), AutomobileFrame.STANDARD_BLUE, AutomobileWheel.STANDARD, AutomobileEngine.IRON), - new AutomobilePrefab(Automobility.id("standard_brown"), AutomobileFrame.STANDARD_BROWN, AutomobileWheel.STANDARD, AutomobileEngine.IRON), - new AutomobilePrefab(Automobility.id("standard_green"), AutomobileFrame.STANDARD_GREEN, AutomobileWheel.STANDARD, AutomobileEngine.IRON), - new AutomobilePrefab(Automobility.id("standard_red"), AutomobileFrame.STANDARD_RED, AutomobileWheel.STANDARD, AutomobileEngine.IRON), - new AutomobilePrefab(Automobility.id("standard_black"), AutomobileFrame.STANDARD_BLACK, AutomobileWheel.STANDARD, AutomobileEngine.IRON), - new AutomobilePrefab(Automobility.id("amethyst_rickshaw"), AutomobileFrame.AMETHYST_RICKSHAW, AutomobileWheel.BEJEWELED, AutomobileEngine.STONE), - new AutomobilePrefab(Automobility.id("quartz_rickshaw"), AutomobileFrame.QUARTZ_RICKSHAW, AutomobileWheel.GILDED, AutomobileEngine.GOLD), - new AutomobilePrefab(Automobility.id("prismarine_rickshaw"), AutomobileFrame.PRISMARINE_RICKSHAW, AutomobileWheel.PLATED, AutomobileEngine.COPPER), - new AutomobilePrefab(Automobility.id("echo_rickshaw"), AutomobileFrame.ECHO_RICKSHAW, AutomobileWheel.STREET, AutomobileEngine.DIAMOND), - new AutomobilePrefab(Automobility.id("red_tractor"), AutomobileFrame.RED_TRACTOR, AutomobileWheel.TRACTOR, AutomobileEngine.COPPER), - new AutomobilePrefab(Automobility.id("yellow_tractor"), AutomobileFrame.YELLOW_TRACTOR, AutomobileWheel.TRACTOR, AutomobileEngine.COPPER), - new AutomobilePrefab(Automobility.id("green_tractor"), AutomobileFrame.GREEN_TRACTOR, AutomobileWheel.TRACTOR, AutomobileEngine.COPPER), - new AutomobilePrefab(Automobility.id("blue_tractor"), AutomobileFrame.BLUE_TRACTOR, AutomobileWheel.TRACTOR, AutomobileEngine.COPPER), - new AutomobilePrefab(Automobility.id("shopping_cart"), AutomobileFrame.SHOPPING_CART, AutomobileWheel.STEEL, AutomobileEngine.STONE), - new AutomobilePrefab(Automobility.id("c_arr"), AutomobileFrame.C_ARR, AutomobileWheel.OFF_ROAD, AutomobileEngine.DIAMOND), - new AutomobilePrefab(Automobility.id("pineapple"), AutomobileFrame.PINEAPPLE, AutomobileWheel.TRACTOR, AutomobileEngine.GOLD) - ); - } - - @Environment(EnvType.CLIENT) private static EntityRendererFactory.Context cachedCtx; - @Environment(EnvType.CLIENT) private static final Map frameModelPool = new HashMap<>(); - @Environment(EnvType.CLIENT) private static final Map wheelModelPool = new HashMap<>(); - @Environment(EnvType.CLIENT) private static final Map engineModelPool = new HashMap<>(); - @Environment(EnvType.CLIENT) private static final Map, Model> rearAttModelPool = new HashMap<>(); - @Environment(EnvType.CLIENT) private static final Map, Model> frontAttModelPool = new HashMap<>(); - - private static final AutomobileData reader = new AutomobileData(); - - @Environment(EnvType.CLIENT) - public static void initClient() { - var itemAutomobile = new ItemRenderableAutomobile(reader); - EntityRenderHelper.registerContextListener(ctx -> { - cachedCtx = ctx; - rearAttModelPool.clear(); - }); - - BuiltinItemRendererRegistry.INSTANCE.register(AUTOMOBILE, (stack, mode, matrices, vertexConsumers, light, overlay) -> { - if (cachedCtx != null) { - reader.read(stack.getOrCreateSubNbt("Automobile")); - float wheelDist = reader.getFrame().model().lengthPx() / 16; - float scale = 1; - scale /= wheelDist * 0.77f; - matrices.scale(scale, scale, scale); - AutomobileRenderer.render(matrices, vertexConsumers, light, overlay, MinecraftClient.getInstance().getTickDelta(), cachedCtx, itemAutomobile); - } - }); - AUTOMOBILE_FRAME.registerItemRenderer( - pooledModelProvider(t -> t.model().model().apply(cachedCtx), frameModelPool), - t -> t.model().texture(), t -> 1 / ((t.model().lengthPx() / 16) * 0.77f) - ); - AUTOMOBILE_WHEEL.registerItemRenderer( - pooledModelProvider(t -> t.model().model().apply(cachedCtx), wheelModelPool), - t -> t.model().texture(), t -> 6 / t.model().radius() - ); - AUTOMOBILE_ENGINE.registerItemRenderer( - pooledModelProvider(t -> t.model().model().apply(cachedCtx), engineModelPool), - t -> t.model().texture(), t -> 1 - ); - REAR_ATTACHMENT.registerItemRenderer( - pooledModelProvider(t -> t.model().model().apply(cachedCtx), rearAttModelPool), - t -> t.model().texture(), t -> 1 - ); - FRONT_ATTACHMENT.registerItemRenderer( - pooledModelProvider(t -> t.model().model().apply(cachedCtx), frontAttModelPool), - t -> t.model().texture(), t -> t.model().scale() - ); - } - - private static Function pooledModelProvider(Function provider, Map pool) { - return t -> { - if (!pool.containsKey(t)) { - var model = provider.apply(t); - pool.put(t, model); - return model; - } - return pool.get(t); - }; - } - - public static T register(String name, T item) { - return Registry.register(Registry.ITEM, Automobility.id(name), item); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/item/SlopeBlockItem.java b/src/main/java/io/github/foundationgames/automobility/item/SlopeBlockItem.java deleted file mode 100644 index b7d0221..0000000 --- a/src/main/java/io/github/foundationgames/automobility/item/SlopeBlockItem.java +++ /dev/null @@ -1,62 +0,0 @@ -package io.github.foundationgames.automobility.item; - -import io.github.foundationgames.automobility.block.SlopeBlock; -import net.minecraft.block.Block; -import net.minecraft.block.Blocks; -import net.minecraft.block.enums.BlockHalf; -import net.minecraft.client.item.TooltipContext; -import net.minecraft.item.BlockItem; -import net.minecraft.item.ItemPlacementContext; -import net.minecraft.item.ItemStack; -import net.minecraft.state.property.Properties; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.World; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -public class SlopeBlockItem extends BlockItem { - private final Block base; - - public SlopeBlockItem(Block base, Block block, Settings settings) { - super(block, settings); - this.base = base; - } - - @Nullable - @Override - public ItemPlacementContext getPlacementContext(ItemPlacementContext context) { - var hitPos = context.getHitPos(); - var pos = new BlockPos(Math.floor(hitPos.x), Math.floor(hitPos.y), Math.floor(hitPos.z)); - var world = context.getWorld(); - if (world.getBlockState(pos).getBlock() instanceof SlopeBlock) { - var facing = world.getBlockState(pos).get(Properties.HORIZONTAL_FACING); - var half = world.getBlockState(pos).get(Properties.BLOCK_HALF); - var playerFacing = context.getPlayerFacing(); - var vOffset = playerFacing == facing && half == BlockHalf.BOTTOM ? Direction.DOWN : playerFacing == facing.getOpposite() && half == BlockHalf.TOP ? Direction.UP : null; - var place = pos.offset(playerFacing); - if (vOffset != null) place = place.offset(vOffset); - var pState = world.getBlockState(place); - var nHalf = half; - if (playerFacing == facing || playerFacing == facing.getOpposite()) nHalf = half == BlockHalf.TOP ? BlockHalf.BOTTOM : BlockHalf.TOP; - if (pState.isAir() || pState.isOf(Blocks.WATER)) { - return new SlopePlacementContext(ItemPlacementContext.offset(context, place, Direction.UP), facing, nHalf); - } - } - return super.getPlacementContext(context); - } - - @Override - public String getTranslationKey() { - return base != null ? "block.automobility.slope" : super.getTranslationKey(); - } - - @Override - public void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context) { - super.appendTooltip(stack, world, tooltip, context); - if (base != null) tooltip.add(Text.translatable(base.getTranslationKey()).formatted(Formatting.BLUE)); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/item/SlopePlacementContext.java b/src/main/java/io/github/foundationgames/automobility/item/SlopePlacementContext.java deleted file mode 100644 index 6af2a40..0000000 --- a/src/main/java/io/github/foundationgames/automobility/item/SlopePlacementContext.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.foundationgames.automobility.item; - -import net.minecraft.block.enums.BlockHalf; -import net.minecraft.item.ItemPlacementContext; -import net.minecraft.item.ItemUsageContext; -import net.minecraft.util.math.Direction; -import org.jetbrains.annotations.Nullable; - -public class SlopePlacementContext extends ItemPlacementContext { - private final Direction slopeFacing; - private final BlockHalf slopeHalf; - - public SlopePlacementContext(ItemUsageContext context, Direction slopeFacing, BlockHalf slopeHalf) { - super(context); - this.slopeFacing = slopeFacing; - this.slopeHalf = slopeHalf; - } - - public SlopePlacementContext(ItemUsageContext context, Direction slopeFacing) { - this(context, slopeFacing, BlockHalf.BOTTOM); - } - - public Direction getSlopeFacing() { - return slopeFacing; - } - - public BlockHalf getSlopeHalf() { - return slopeHalf; - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/item/SteepSlopeBlockItem.java b/src/main/java/io/github/foundationgames/automobility/item/SteepSlopeBlockItem.java deleted file mode 100644 index 061d610..0000000 --- a/src/main/java/io/github/foundationgames/automobility/item/SteepSlopeBlockItem.java +++ /dev/null @@ -1,58 +0,0 @@ -package io.github.foundationgames.automobility.item; - -import io.github.foundationgames.automobility.block.SteepSlopeBlock; -import net.minecraft.block.Block; -import net.minecraft.block.Blocks; -import net.minecraft.client.item.TooltipContext; -import net.minecraft.item.BlockItem; -import net.minecraft.item.ItemPlacementContext; -import net.minecraft.item.ItemStack; -import net.minecraft.state.property.Properties; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.World; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -public class SteepSlopeBlockItem extends BlockItem { - private final Block base; - - public SteepSlopeBlockItem(Block base, Block block, Settings settings) { - super(block, settings); - this.base = base; - } - - @Nullable - @Override - public ItemPlacementContext getPlacementContext(ItemPlacementContext context) { - var hitPos = context.getHitPos(); - var pos = new BlockPos(Math.floor(hitPos.x), Math.floor(hitPos.y), Math.floor(hitPos.z)); - var world = context.getWorld(); - if (world.getBlockState(pos).getBlock() instanceof SteepSlopeBlock) { - var facing = world.getBlockState(pos).get(Properties.HORIZONTAL_FACING); - var playerFacing = context.getPlayerFacing(); - var vOffset = playerFacing == facing ? Direction.DOWN : playerFacing == facing.getOpposite() ? Direction.UP : null; - var place = pos.offset(playerFacing); - if (vOffset != null) place = place.offset(vOffset); - var pState = world.getBlockState(place); - if (pState.isAir() || pState.isOf(Blocks.WATER)) { - return new SlopePlacementContext(ItemPlacementContext.offset(context, place, Direction.UP), facing); - } - } - return super.getPlacementContext(context); - } - - @Override - public String getTranslationKey() { - return base != null ? "block.automobility.steep_slope" : super.getTranslationKey(); - } - - @Override - public void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context) { - super.appendTooltip(stack, world, tooltip, context); - if (base != null) tooltip.add(Text.translatable(base.getTranslationKey()).formatted(Formatting.BLUE)); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/item/TooltipBlockItem.java b/src/main/java/io/github/foundationgames/automobility/item/TooltipBlockItem.java deleted file mode 100644 index 39904ab..0000000 --- a/src/main/java/io/github/foundationgames/automobility/item/TooltipBlockItem.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.github.foundationgames.automobility.item; - -import net.minecraft.block.Block; -import net.minecraft.client.item.TooltipContext; -import net.minecraft.item.BlockItem; -import net.minecraft.item.ItemStack; -import net.minecraft.text.Text; -import net.minecraft.world.World; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -public class TooltipBlockItem extends BlockItem { - private final Text tooltip; - - public TooltipBlockItem(Block block, Text tooltip, Settings settings) { - super(block, settings); - this.tooltip = tooltip; - } - - @Override - public void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context) { - super.appendTooltip(stack, world, tooltip, context); - tooltip.add(this.tooltip); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/item/TooltipItem.java b/src/main/java/io/github/foundationgames/automobility/item/TooltipItem.java deleted file mode 100644 index f33cd61..0000000 --- a/src/main/java/io/github/foundationgames/automobility/item/TooltipItem.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.github.foundationgames.automobility.item; - -import net.minecraft.client.item.TooltipContext; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.text.Text; -import net.minecraft.world.World; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -public class TooltipItem extends Item { - private final Text tooltip; - - public TooltipItem(Text tooltip, Settings settings) { - super(settings); - this.tooltip = tooltip; - } - - @Override - public void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context) { - super.appendTooltip(stack, world, tooltip, context); - tooltip.add(this.tooltip); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/mixin/ClientPlayerEntityMixin.java b/src/main/java/io/github/foundationgames/automobility/mixin/ClientPlayerEntityMixin.java deleted file mode 100644 index d064284..0000000 --- a/src/main/java/io/github/foundationgames/automobility/mixin/ClientPlayerEntityMixin.java +++ /dev/null @@ -1,41 +0,0 @@ -package io.github.foundationgames.automobility.mixin; - -import io.github.foundationgames.automobility.entity.AutomobileEntity; -import io.github.foundationgames.automobility.util.midnightcontrols.ControllerUtils; -import net.minecraft.client.input.Input; -import net.minecraft.client.network.ClientPlayerEntity; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(ClientPlayerEntity.class) -public class ClientPlayerEntityMixin { - @Shadow - public Input input; - - @Inject(method = "tickRiding", at = @At("TAIL")) - public void automobility$setAutomobileInputs(CallbackInfo ci) { - ClientPlayerEntity self = (ClientPlayerEntity)(Object)this; - if (self.getVehicle() instanceof AutomobileEntity vehicle) { - if (ControllerUtils.inControllerMode()) { - vehicle.provideClientInput( - ControllerUtils.accelerating(), - ControllerUtils.braking(), - input.pressingLeft, - input.pressingRight, - ControllerUtils.drifting() - ); - } else { - vehicle.provideClientInput( - input.pressingForward, - input.pressingBack, - input.pressingLeft, - input.pressingRight, - input.jumping - ); - } - } - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/mixin/ForgingScreenHandlerMixin.java b/src/main/java/io/github/foundationgames/automobility/mixin/ForgingScreenHandlerMixin.java deleted file mode 100644 index 3d4475c..0000000 --- a/src/main/java/io/github/foundationgames/automobility/mixin/ForgingScreenHandlerMixin.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.github.foundationgames.automobility.mixin; - -import io.github.foundationgames.automobility.screen.AutomobileScreenHandlerContext; -import net.minecraft.block.BlockState; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.screen.ForgingScreenHandler; -import net.minecraft.screen.ScreenHandlerContext; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(ForgingScreenHandler.class) -public abstract class ForgingScreenHandlerMixin { - @Shadow @Final protected ScreenHandlerContext context; - - @Shadow protected abstract boolean canUse(BlockState state); - - @Inject( - method = "canUse(Lnet/minecraft/entity/player/PlayerEntity;)Z", - at = @At("HEAD"), cancellable = true) - private void automobility$allowForgingScreenAutomobileSpoof(PlayerEntity player, CallbackInfoReturnable cir) { - if (this.context instanceof AutomobileScreenHandlerContext ctx) { - boolean isClose = ctx.get((world, pos) -> (player.getBlockPos().getSquaredDistance(pos) < 64), true); - if (isClose && this.canUse(ctx.getAttachmentBlockState())) { - cir.setReturnValue(true); - } - } - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/mixin/ScreenHandlerMixin.java b/src/main/java/io/github/foundationgames/automobility/mixin/ScreenHandlerMixin.java deleted file mode 100644 index 01631f5..0000000 --- a/src/main/java/io/github/foundationgames/automobility/mixin/ScreenHandlerMixin.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.github.foundationgames.automobility.mixin; - -import io.github.foundationgames.automobility.screen.AutomobileScreenHandlerContext; -import net.minecraft.block.Block; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.screen.ScreenHandlerContext; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(ScreenHandler.class) -public class ScreenHandlerMixin { - @Inject( - method = "canUse(Lnet/minecraft/screen/ScreenHandlerContext;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/block/Block;)Z", - at = @At("HEAD"), cancellable = true) - private static void automobility$spoofAutomobileAttachmentScreens(ScreenHandlerContext context, PlayerEntity player, Block block, CallbackInfoReturnable cir) { - if (context instanceof AutomobileScreenHandlerContext ctx) { - boolean isClose = ctx.get((world, pos) -> (player.getBlockPos().getSquaredDistance(pos) < 64), true); - if (isClose && ctx.getAttachmentBlockState().isOf(block)) { - cir.setReturnValue(true); - } - } - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/mixin/ServerPlayNetworkHandlerMixin.java b/src/main/java/io/github/foundationgames/automobility/mixin/ServerPlayNetworkHandlerMixin.java deleted file mode 100644 index f774bcc..0000000 --- a/src/main/java/io/github/foundationgames/automobility/mixin/ServerPlayNetworkHandlerMixin.java +++ /dev/null @@ -1,27 +0,0 @@ -package io.github.foundationgames.automobility.mixin; - -import io.github.foundationgames.automobility.entity.AutomobileEntity; -import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket; -import net.minecraft.server.network.ServerPlayNetworkHandler; -import net.minecraft.server.network.ServerPlayerEntity; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(ServerPlayNetworkHandler.class) -public class ServerPlayNetworkHandlerMixin { - @Shadow public ServerPlayerEntity player; - - @Inject(method = "onClientCommand", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;updateLastActionTime()V", shift = At.Shift.AFTER), cancellable = true) - private void automobility$openAutomobileInventory(ClientCommandC2SPacket packet, CallbackInfo ci) { - var vehicle = this.player.getVehicle(); - if (packet.getMode() == ClientCommandC2SPacket.Mode.OPEN_INVENTORY && vehicle instanceof AutomobileEntity automobile) { - if (automobile.hasInventory()) { - automobile.openInventory(this.player); - ci.cancel(); - } - } - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/particle/AutomobilityParticles.java b/src/main/java/io/github/foundationgames/automobility/particle/AutomobilityParticles.java deleted file mode 100644 index 35bdf94..0000000 --- a/src/main/java/io/github/foundationgames/automobility/particle/AutomobilityParticles.java +++ /dev/null @@ -1,18 +0,0 @@ -package io.github.foundationgames.automobility.particle; - -import io.github.foundationgames.automobility.Automobility; -import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry; -import net.fabricmc.fabric.api.particle.v1.FabricParticleTypes; -import net.minecraft.particle.DefaultParticleType; -import net.minecraft.util.registry.Registry; - -public class AutomobilityParticles { - public static final DefaultParticleType DRIFT_SMOKE = Registry.register(Registry.PARTICLE_TYPE, Automobility.id("drift_smoke"), FabricParticleTypes.simple(true)); - - public static void init() { - } - - public static void initClient() { - ParticleFactoryRegistry.getInstance().register(DRIFT_SMOKE, DriftSmokeParticle.Factory::new); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/particle/DriftSmokeParticle.java b/src/main/java/io/github/foundationgames/automobility/particle/DriftSmokeParticle.java deleted file mode 100644 index db81bc9..0000000 --- a/src/main/java/io/github/foundationgames/automobility/particle/DriftSmokeParticle.java +++ /dev/null @@ -1,49 +0,0 @@ -package io.github.foundationgames.automobility.particle; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.particle.Particle; -import net.minecraft.client.particle.ParticleFactory; -import net.minecraft.client.particle.ParticleTextureSheet; -import net.minecraft.client.particle.SpriteBillboardParticle; -import net.minecraft.client.particle.SpriteProvider; -import net.minecraft.client.world.ClientWorld; -import net.minecraft.particle.DefaultParticleType; - -public class DriftSmokeParticle extends SpriteBillboardParticle { - private static final float SCALE_FACTOR = 0.83f; - private static final int MAX_AGE = (int)(Math.log(0.1) / Math.log(SCALE_FACTOR)); - - protected DriftSmokeParticle(ClientWorld world, double x, double y, double z) { - super(world, x, y, z); - this.scale = 0.6f - (world.random.nextFloat() * 0.1f); - this.alpha = this.scale; - this.setMaxAge(MAX_AGE); - } - - @Override - public void tick() { - this.scale(SCALE_FACTOR); - this.alpha = this.scale; - } - - @Override - public ParticleTextureSheet getType() { - return ParticleTextureSheet.PARTICLE_SHEET_TRANSLUCENT; - } - - @Environment(EnvType.CLIENT) - public static class Factory implements ParticleFactory { - private final SpriteProvider sprites; - - public Factory(SpriteProvider sprites) { - this.sprites = sprites; - } - - public Particle createParticle(DefaultParticleType type, ClientWorld world, double x, double y, double z, double vx, double vy, double vz) { - var particle = new DriftSmokeParticle(world, x, y, z); - particle.setSprite(this.sprites); - return particle; - } - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/render/AutomobilityModels.java b/src/main/java/io/github/foundationgames/automobility/render/AutomobilityModels.java deleted file mode 100644 index aa2c68d..0000000 --- a/src/main/java/io/github/foundationgames/automobility/render/AutomobilityModels.java +++ /dev/null @@ -1,86 +0,0 @@ -package io.github.foundationgames.automobility.render; - -import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.automobile.render.EmptyModel; -import io.github.foundationgames.automobility.automobile.render.attachment.front.HarvesterFrontAttachmentModel; -import io.github.foundationgames.automobility.automobile.render.attachment.front.MobControllerFrontAttachmentModel; -import io.github.foundationgames.automobility.automobile.render.attachment.rear.BannerPostRearAttachmentModel; -import io.github.foundationgames.automobility.automobile.render.attachment.rear.BlockRearAttachmentModel; -import io.github.foundationgames.automobility.automobile.render.attachment.rear.ChestRearAttachmentModel; -import io.github.foundationgames.automobility.automobile.render.attachment.rear.GrindstoneRearAttachmentModel; -import io.github.foundationgames.automobility.automobile.render.attachment.rear.PassengerSeatRearAttachmentModel; -import io.github.foundationgames.automobility.automobile.render.attachment.rear.PlowRearAttachmentModel; -import io.github.foundationgames.automobility.automobile.render.attachment.rear.StonecutterRearAttachmentModel; -import io.github.foundationgames.automobility.automobile.render.engine.CopperEngineModel; -import io.github.foundationgames.automobility.automobile.render.engine.CreativeEngineModel; -import io.github.foundationgames.automobility.automobile.render.engine.DiamondEngineModel; -import io.github.foundationgames.automobility.automobile.render.engine.GoldEngineModel; -import io.github.foundationgames.automobility.automobile.render.engine.IronEngineModel; -import io.github.foundationgames.automobility.automobile.render.engine.StoneEngineModel; -import io.github.foundationgames.automobility.automobile.render.frame.CARRFrameModel; -import io.github.foundationgames.automobility.automobile.render.frame.DaBabyFrameModel; -import io.github.foundationgames.automobility.automobile.render.frame.MotorcarFrameModel; -import io.github.foundationgames.automobility.automobile.render.frame.PineappleFrameModel; -import io.github.foundationgames.automobility.automobile.render.frame.RickshawFrameModel; -import io.github.foundationgames.automobility.automobile.render.frame.ShoppingCartFrameModel; -import io.github.foundationgames.automobility.automobile.render.frame.StandardFrameModel; -import io.github.foundationgames.automobility.automobile.render.frame.TractorFrameModel; -import io.github.foundationgames.automobility.automobile.render.wheel.CarriageWheelModel; -import io.github.foundationgames.automobility.automobile.render.wheel.ConvertibleWheelModel; -import io.github.foundationgames.automobility.automobile.render.wheel.OffRoadWheelModel; -import io.github.foundationgames.automobility.automobile.render.wheel.StandardWheelModel; -import io.github.foundationgames.automobility.automobile.render.wheel.SteelWheelModel; -import io.github.foundationgames.automobility.automobile.render.wheel.TractorWheelModel; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.model.Model; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.util.Identifier; - -import java.util.HashMap; -import java.util.Map; -import java.util.function.Function; - -@Environment(EnvType.CLIENT) -public enum AutomobilityModels {; - public static final Map> MODELS = new HashMap<>(); - - @Environment(EnvType.CLIENT) - public static void init() { - MODELS.put(Automobility.id("empty"), EmptyModel::new); - - MODELS.put(Automobility.id("frame_standard"), StandardFrameModel::new); - MODELS.put(Automobility.id("frame_tractor"), TractorFrameModel::new); - MODELS.put(Automobility.id("frame_shopping_cart"), ShoppingCartFrameModel::new); - MODELS.put(Automobility.id("frame_c_arr"), CARRFrameModel::new); - MODELS.put(Automobility.id("frame_pineapple"), PineappleFrameModel::new); - MODELS.put(Automobility.id("frame_motorcar"), MotorcarFrameModel::new); - MODELS.put(Automobility.id("frame_rickshaw"), RickshawFrameModel::new); - MODELS.put(Automobility.id("frame_dababy"), DaBabyFrameModel::new); - - MODELS.put(Automobility.id("wheel_standard"), StandardWheelModel::new); - MODELS.put(Automobility.id("wheel_off_road"), OffRoadWheelModel::new); - MODELS.put(Automobility.id("wheel_steel"), SteelWheelModel::new); - MODELS.put(Automobility.id("wheel_tractor"), TractorWheelModel::new); - MODELS.put(Automobility.id("wheel_carriage"), CarriageWheelModel::new); - MODELS.put(Automobility.id("wheel_convertible"), ConvertibleWheelModel::new); - - MODELS.put(Automobility.id("engine_stone"), StoneEngineModel::new); - MODELS.put(Automobility.id("engine_iron"), IronEngineModel::new); - MODELS.put(Automobility.id("engine_copper"), CopperEngineModel::new); - MODELS.put(Automobility.id("engine_gold"), GoldEngineModel::new); - MODELS.put(Automobility.id("engine_diamond"), DiamondEngineModel::new); - MODELS.put(Automobility.id("engine_creative"), CreativeEngineModel::new); - - MODELS.put(Automobility.id("rearatt_passenger_seat"), PassengerSeatRearAttachmentModel::new); - MODELS.put(Automobility.id("rearatt_block"), BlockRearAttachmentModel::new); - MODELS.put(Automobility.id("rearatt_grindstone"), GrindstoneRearAttachmentModel::new); - MODELS.put(Automobility.id("rearatt_stonecutter"), StonecutterRearAttachmentModel::new); - MODELS.put(Automobility.id("rearatt_chest"), ChestRearAttachmentModel::new); - MODELS.put(Automobility.id("rearatt_banner_post"), BannerPostRearAttachmentModel::new); - MODELS.put(Automobility.id("rearatt_plow"), PlowRearAttachmentModel::new); - - MODELS.put(Automobility.id("frontatt_mob_controller"), MobControllerFrontAttachmentModel::new); - MODELS.put(Automobility.id("frontatt_harvester"), HarvesterFrontAttachmentModel::new); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/resource/AutomobilityAssets.java b/src/main/java/io/github/foundationgames/automobility/resource/AutomobilityAssets.java deleted file mode 100644 index b52eae5..0000000 --- a/src/main/java/io/github/foundationgames/automobility/resource/AutomobilityAssets.java +++ /dev/null @@ -1,128 +0,0 @@ -package io.github.foundationgames.automobility.resource; - -import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.util.AUtils; -import net.devtech.arrp.api.RRPCallback; -import net.devtech.arrp.api.RuntimeResourcePack; -import net.devtech.arrp.json.blockstate.JState; -import net.devtech.arrp.json.blockstate.JVariant; -import net.devtech.arrp.json.models.JModel; -import net.minecraft.util.math.Direction; - -import java.util.HashSet; -import java.util.Set; -import java.util.function.Consumer; - -public enum AutomobilityAssets {; - public static final RuntimeResourcePack PACK = RuntimeResourcePack.create("automobility:assets"); - private static final Set> PROCESSORS = new HashSet<>(); - - public static void setup() { - addOffRoad("grass_off_road"); - addOffRoad("dirt_off_road"); - addOffRoad("sand_off_road"); - addOffRoad("snow_off_road"); - - var dashPanel = JState.variant(); - for (Direction dir : AUtils.HORIZONTAL_DIRS) { - dashPanel.put("left=false,right=false,facing="+ dir, JState.model(Automobility.id("block/dash_panel_single")).y((int)dir.asRotation() + 180)); - dashPanel.put("left=true,right=false,facing="+ dir, JState.model(Automobility.id("block/dash_panel_left")).y((int)dir.asRotation() + 180)); - dashPanel.put("left=false,right=true,facing="+ dir, JState.model(Automobility.id("block/dash_panel_right")).y((int)dir.asRotation() + 180)); - dashPanel.put("left=true,right=true,facing="+ dir, JState.model(Automobility.id("block/dash_panel_center")).y((int)dir.asRotation() + 180)); - } - PACK.addBlockState(new JState().add(dashPanel), Automobility.id("dash_panel")); - - var slopedDashPanel = JState.variant(); - for (Direction dir : AUtils.HORIZONTAL_DIRS) { - slopedDashPanel.put("half=bottom,left=false,right=false,facing="+ dir, JState.model(Automobility.id("block/sloped_dash_panel_single_bottom")).y((int)dir.asRotation())); - slopedDashPanel.put("half=bottom,left=true,right=false,facing="+ dir, JState.model(Automobility.id("block/sloped_dash_panel_left_bottom")).y((int)dir.asRotation())); - slopedDashPanel.put("half=bottom,left=false,right=true,facing="+ dir, JState.model(Automobility.id("block/sloped_dash_panel_right_bottom")).y((int)dir.asRotation())); - slopedDashPanel.put("half=bottom,left=true,right=true,facing="+ dir, JState.model(Automobility.id("block/sloped_dash_panel_center_bottom")).y((int)dir.asRotation())); - slopedDashPanel.put("half=top,left=false,right=false,facing="+ dir, JState.model(Automobility.id("block/sloped_dash_panel_single_top")).y((int)dir.asRotation())); - slopedDashPanel.put("half=top,left=true,right=false,facing="+ dir, JState.model(Automobility.id("block/sloped_dash_panel_left_top")).y((int)dir.asRotation())); - slopedDashPanel.put("half=top,left=false,right=true,facing="+ dir, JState.model(Automobility.id("block/sloped_dash_panel_right_top")).y((int)dir.asRotation())); - slopedDashPanel.put("half=top,left=true,right=true,facing="+ dir, JState.model(Automobility.id("block/sloped_dash_panel_center_top")).y((int)dir.asRotation())); - } - PACK.addBlockState(new JState().add(slopedDashPanel), Automobility.id("sloped_dash_panel")); - - var steepDashPanel = JState.variant(); - for (Direction dir : AUtils.HORIZONTAL_DIRS) { - steepDashPanel.put("left=false,right=false,facing="+ dir, JState.model(Automobility.id("block/steep_sloped_dash_panel_single")).y((int)dir.asRotation())); - steepDashPanel.put("left=true,right=false,facing="+ dir, JState.model(Automobility.id("block/steep_sloped_dash_panel_left")).y((int)dir.asRotation())); - steepDashPanel.put("left=false,right=true,facing="+ dir, JState.model(Automobility.id("block/steep_sloped_dash_panel_right")).y((int)dir.asRotation())); - steepDashPanel.put("left=true,right=true,facing="+ dir, JState.model(Automobility.id("block/steep_sloped_dash_panel_center")).y((int)dir.asRotation())); - } - PACK.addBlockState(new JState().add(steepDashPanel), Automobility.id("steep_sloped_dash_panel")); - - PACK.addBlockState(new JState().add(JState.variant().put("", JState.model(Automobility.id("block/launch_gel")))), Automobility.id("launch_gel")); - - for (var p : PROCESSORS) { - p.accept(PACK); - } - - RRPCallback.AFTER_VANILLA.register(a -> a.add(PACK)); - } - - public static void addOffRoad(String name) { - for (int i = 0; i < 3; i++) { - PACK.addModel(new JModel().parent("automobility:block/template_off_road_"+i).textures(JModel.textures().var("off_road", "automobility:block/"+name)), Automobility.id("block/"+name+"_"+i)); - } - PACK.addModel(new JModel().parent("automobility:block/"+name+"_0"), Automobility.id("item/"+name)); - PACK.addBlockState(new JState().add(new JVariant() - .put("layers=1", JState.model("automobility:block/"+name+"_0")) - .put("layers=2", JState.model("automobility:block/"+name+"_1")) - .put("layers=3", JState.model("automobility:block/"+name+"_2")) - ), Automobility.id(name)); - } - - public static void addSlope(String name, String texture) { - { - var path = "block/"+name; - PACK.addModel(new JModel().parent("automobility:block/template_slope_bottom").textures(JModel.textures().var("slope", texture)), Automobility.id(path+"_bottom")); - PACK.addModel(new JModel().parent("automobility:block/template_slope_top").textures(JModel.textures().var("slope", texture)), Automobility.id(path+"_top")); - var variants = JState.variant(); - for (Direction dir : AUtils.HORIZONTAL_DIRS) { - variants.put("half=bottom,facing="+ dir, JState.model(Automobility.id(path)+"_bottom").y((int)dir.asRotation())); - variants.put("half=top,facing="+ dir, JState.model(Automobility.id(path)+"_top").y((int)dir.asRotation())); - } - PACK.addBlockState(new JState().add(variants), Automobility.id(name)); - PACK.addModel(new JModel().parent("automobility:"+path+"_bottom"), Automobility.id("item/"+name)); - } - { - name = "steep_"+name; - var path = "block/"+name; - PACK.addModel(new JModel().parent("automobility:block/template_steep_slope").textures(JModel.textures().var("slope", texture)), Automobility.id(path)); - var variants = JState.variant(); - for (Direction dir : AUtils.HORIZONTAL_DIRS) { - variants.put("facing="+ dir, JState.model(Automobility.id(path)).y((int)dir.asRotation())); - } - PACK.addBlockState(new JState().add(variants), Automobility.id(name)); - PACK.addModel(new JModel().parent("automobility:"+path), Automobility.id("item/"+name)); - } - } - - // Yes I didn't want to do actual smart datagen so behold - // I will more than likely replace this in the future - public static void addMinecraftSlope(String name, String base) { - base = switch (base) { - case "snow_block" -> "snow"; - case "quartz_block" -> "quartz_block_side"; - case "smooth_sandstone" -> "sandstone_top"; - case "smooth_quartz" -> "quartz_block_top"; - case "smooth_red_sandstone" -> "red_sandstone_top"; - case "dried_kelp_block" -> "dried_kelp_side"; - case "ancient_debris" -> "ancient_debris_side"; - case "lodestone" -> "lodestone_top"; - default -> base; - }; - if (base.startsWith("waxed_") && base.contains("copper")) { - base = base.replaceFirst("waxed_", ""); - } - var tex = "minecraft:block/"+base; - addSlope(name, tex); - } - - public static void addProcessor(Consumer processor) { - PROCESSORS.add(processor); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/screen/AutomobileHud.java b/src/main/java/io/github/foundationgames/automobility/screen/AutomobileHud.java deleted file mode 100644 index 1a0881a..0000000 --- a/src/main/java/io/github/foundationgames/automobility/screen/AutomobileHud.java +++ /dev/null @@ -1,83 +0,0 @@ -package io.github.foundationgames.automobility.screen; - -import com.google.common.collect.Lists; -import com.mojang.blaze3d.platform.GlStateManager; -import com.mojang.blaze3d.systems.RenderSystem; -import io.github.foundationgames.automobility.entity.AutomobileEntity; -import io.github.foundationgames.automobility.util.AUtils; -import io.github.foundationgames.automobility.util.midnightcontrols.ControllerUtils; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawableHelper; -import net.minecraft.client.option.GameOptions; -import net.minecraft.client.option.KeyBinding; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.text.Text; - -import java.util.List; -import java.util.function.Function; - -public enum AutomobileHud {; - public static final List CONTROL_HINTS = Lists.newArrayList( - new ControlHint("accelerate", options -> options.forwardKey), - new ControlHint("brake", options -> options.backKey), - new ControlHint("steer_left", options -> options.leftKey), - new ControlHint("steer_right", options -> options.rightKey), - new ControlHint("drift", options -> options.jumpKey) - ); - - public static void render(MatrixStack matrices, PlayerEntity player, AutomobileEntity auto, float tickDelta) { - renderSpeedometer(matrices, auto); - - if (!ControllerUtils.inControllerMode()) { - float alpha = Math.max(0, (auto.getStandStillTime() * 2) - 1); - - // Check on a 0-255 converted version of alpha, because 0 alpha will render things at 100% alpha for some - // 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(matrices, alpha); - } - } - } - - private static void renderSpeedometer(MatrixStack matrices, 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; - DrawableHelper.drawTextWithShadow(matrices, MinecraftClient.getInstance().textRenderer, Text.literal(AUtils.DEC_TWO_PLACES.format(speed) +" m/s"), 20, 20, color); - } - - private static void renderControlHints(MatrixStack matrices, float alpha) { - int x = 20; - int y = 50; - var options = MinecraftClient.getInstance().options; - var font = MinecraftClient.getInstance().textRenderer; - - for (var control : CONTROL_HINTS) { - var keyTxt = control.getKeybindText(options); - int keyTxtWid = font.getWidth(keyTxt); - - DrawableHelper.fill(matrices, x, y, x + keyTxtWid + 6, y + 14, ((int)(alpha * 0xAB) << 24)); - - int textColor = 0x00FFFFFF | ((int)(alpha * 0xFF) << 24); - DrawableHelper.drawTextWithShadow(matrices, font, keyTxt, x + 3, y + 3, textColor); - DrawableHelper.drawTextWithShadow(matrices, font, control.getText(), x + keyTxtWid + 9, y + 3, textColor); - - y += 17; - } - } - - public record ControlHint(String name, Function keybind) { - public Text getText() { - return Text.translatable("automobile_control."+name); - } - - public Text getKeybindText(GameOptions options) { - return keybind.apply(options).getBoundKeyLocalizedText(); - } - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/screen/AutomobileScreenHandlerContext.java b/src/main/java/io/github/foundationgames/automobility/screen/AutomobileScreenHandlerContext.java deleted file mode 100644 index d7800a6..0000000 --- a/src/main/java/io/github/foundationgames/automobility/screen/AutomobileScreenHandlerContext.java +++ /dev/null @@ -1,31 +0,0 @@ -package io.github.foundationgames.automobility.screen; - -import io.github.foundationgames.automobility.automobile.attachment.rear.BlockRearAttachment; -import io.github.foundationgames.automobility.entity.AutomobileEntity; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.screen.ScreenHandlerContext; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; - -import java.util.Optional; -import java.util.function.BiFunction; - -public class AutomobileScreenHandlerContext implements ScreenHandlerContext { - private final World world; - private final AutomobileEntity automobile; - - public AutomobileScreenHandlerContext(AutomobileEntity automobile) { - this.world = automobile.getWorld(); - this.automobile = automobile; - } - - @Override - public Optional get(BiFunction getter) { - return Optional.of(getter.apply(world, automobile.getBlockPos())); - } - - public BlockState getAttachmentBlockState() { - return automobile.getRearAttachment() instanceof BlockRearAttachment att ? att.block : Blocks.AIR.getDefaultState(); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/screen/SingleSlotScreen.java b/src/main/java/io/github/foundationgames/automobility/screen/SingleSlotScreen.java deleted file mode 100644 index fe1fdac..0000000 --- a/src/main/java/io/github/foundationgames/automobility/screen/SingleSlotScreen.java +++ /dev/null @@ -1,39 +0,0 @@ -package io.github.foundationgames.automobility.screen; - -import com.mojang.blaze3d.systems.RenderSystem; -import io.github.foundationgames.automobility.Automobility; -import net.minecraft.client.gui.screen.ingame.HandledScreen; -import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider; -import net.minecraft.client.render.GameRenderer; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; - -public class SingleSlotScreen extends HandledScreen implements ScreenHandlerProvider { - private static final Identifier TEXTURE = Automobility.id("textures/gui/container/single_slot.png"); - - public SingleSlotScreen(SingleSlotScreenHandler handler, PlayerInventory inventory, Text title) { - super(handler, inventory, title); - - this.backgroundHeight = 140; - this.playerInventoryTitleY = 47; - this.titleX = 60; - } - - @Override - public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { - super.render(matrices, mouseX, mouseY, delta); - this.drawMouseoverTooltip(matrices, mouseX, mouseY); - } - - @Override - protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY) { - this.renderBackground(matrices); - - RenderSystem.setShader(GameRenderer::getPositionTexShader); - RenderSystem.setShaderColor(1, 1, 1, 1); - RenderSystem.setShaderTexture(0, TEXTURE); - this.drawTexture(matrices, this.x, this.y, 0, 0, this.backgroundWidth, this.backgroundHeight); - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/screen/SingleSlotScreenHandler.java b/src/main/java/io/github/foundationgames/automobility/screen/SingleSlotScreenHandler.java deleted file mode 100644 index a115eec..0000000 --- a/src/main/java/io/github/foundationgames/automobility/screen/SingleSlotScreenHandler.java +++ /dev/null @@ -1,70 +0,0 @@ -package io.github.foundationgames.automobility.screen; - -import io.github.foundationgames.automobility.Automobility; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.Inventory; -import net.minecraft.inventory.SimpleInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.screen.slot.Slot; - -public class SingleSlotScreenHandler extends ScreenHandler { - private final Inventory inventory; - - public SingleSlotScreenHandler(int syncId, PlayerInventory playerInv) { - this(syncId, playerInv, new SimpleInventory(1)); - } - - public SingleSlotScreenHandler(int syncId, PlayerInventory playerInv, Inventory inv) { - super(Automobility.SINGLE_SLOT_SCREEN, syncId); - - checkSize(inv, 1); - this.inventory = inv; - inv.onOpen(playerInv.player); - - this.addSlot(new Slot(inventory, 0, 80, 23)); - - // Player inventory - int row; - int col; - for(row = 0; row < 3; ++row) { - for(col = 0; col < 9; ++col) { - this.addSlot(new Slot(playerInv, col + row * 9 + 9, 8 + col * 18, 58 + row * 18)); - } - } - for(row = 0; row < 9; ++row) { - this.addSlot(new Slot(playerInv, row, 8 + row * 18, 116)); - } - } - - @Override - public boolean canUse(PlayerEntity player) { - return true; - } - - public ItemStack transferSlot(PlayerEntity player, int fromSlotId) { - var newStack = ItemStack.EMPTY; - var fromSlot = this.slots.get(fromSlotId); - - if (fromSlot.hasStack()) { - var fromStack = fromSlot.getStack(); - newStack = fromStack.copy(); - if (fromSlotId == 0) { - if (!this.insertItem(fromStack, 1, 37, true)) { - return ItemStack.EMPTY; - } - } else if (!this.insertItem(fromStack, 0, 1, false)) { - return ItemStack.EMPTY; - } - - if (fromStack.isEmpty()) { - fromSlot.setStack(ItemStack.EMPTY); - } else { - fromSlot.markDirty(); - } - } - - return newStack; - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/sound/AutomobilitySounds.java b/src/main/java/io/github/foundationgames/automobility/sound/AutomobilitySounds.java deleted file mode 100644 index 5af6122..0000000 --- a/src/main/java/io/github/foundationgames/automobility/sound/AutomobilitySounds.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.github.foundationgames.automobility.sound; - -import io.github.foundationgames.automobility.Automobility; -import net.minecraft.sound.SoundEvent; -import net.minecraft.util.registry.Registry; - -public class AutomobilitySounds { - public static final SoundEvent COLLISION = register("entity.automobile.collision"); - public static final SoundEvent LANDING = register("entity.automobile.landing"); - public static final SoundEvent SKID = register("entity.automobile.skid"); - - public static final SoundEvent STONE_ENGINE = register("entity.automobile.stone_engine"); - public static final SoundEvent COPPER_ENGINE = register("entity.automobile.copper_engine"); - public static final SoundEvent IRON_ENGINE = register("entity.automobile.iron_engine"); - public static final SoundEvent GOLD_ENGINE = register("entity.automobile.gold_engine"); - public static final SoundEvent DIAMOND_ENGINE = register("entity.automobile.diamond_engine"); - public static final SoundEvent CREATIVE_ENGINE = register("entity.automobile.creative_engine"); - - private static SoundEvent register(String path) { - var id = Automobility.id(path); - return Registry.register(Registry.SOUND_EVENT, id, new SoundEvent(id)); - } - - public static void init() { - } -} diff --git a/src/main/java/io/github/foundationgames/automobility/util/network/PayloadPackets.java b/src/main/java/io/github/foundationgames/automobility/util/network/PayloadPackets.java deleted file mode 100644 index 2c27270..0000000 --- a/src/main/java/io/github/foundationgames/automobility/util/network/PayloadPackets.java +++ /dev/null @@ -1,175 +0,0 @@ -package io.github.foundationgames.automobility.util.network; - -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.AutomobileWheel; -import io.github.foundationgames.automobility.automobile.attachment.FrontAttachmentType; -import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType; -import io.github.foundationgames.automobility.automobile.attachment.rear.BannerPostRearAttachment; -import io.github.foundationgames.automobility.automobile.attachment.rear.ExtendableRearAttachment; -import io.github.foundationgames.automobility.entity.AutomobileEntity; -import io.netty.buffer.Unpooled; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; -import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtList; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.util.Identifier; - -public enum PayloadPackets {; - @Environment(EnvType.CLIENT) - public static void sendSyncAutomobileInputPacket(AutomobileEntity entity, boolean fwd, boolean back, boolean left, boolean right, boolean space) { - var buf = new PacketByteBuf(Unpooled.buffer()); - buf.writeBoolean(fwd); - buf.writeBoolean(back); - buf.writeBoolean(left); - buf.writeBoolean(right); - buf.writeBoolean(space); - buf.writeInt(entity.getId()); - ClientPlayNetworking.send(Automobility.id("sync_automobile_inputs"), buf); - } - - @Environment(EnvType.CLIENT) - public static void requestSyncAutomobileComponentsPacket(AutomobileEntity entity) { - var buf = new PacketByteBuf(Unpooled.buffer()); - buf.writeInt(entity.getId()); - ClientPlayNetworking.send(Automobility.id("request_sync_automobile_components"), buf); - } - - public static void sendSyncAutomobileDataPacket(AutomobileEntity entity, ServerPlayerEntity player) { - var buf = new PacketByteBuf(Unpooled.buffer()); - buf.writeInt(entity.getId()); - entity.writeSyncToClientData(buf); - ServerPlayNetworking.send(player, Automobility.id("sync_automobile_data"), buf); - } - - public static void sendSyncAutomobileComponentsPacket(AutomobileEntity entity, ServerPlayerEntity player) { - var buf = new PacketByteBuf(Unpooled.buffer()); - buf.writeInt(entity.getId()); - buf.writeString(entity.getFrame().id().toString()); - buf.writeString(entity.getWheels().id().toString()); - buf.writeString(entity.getEngine().id().toString()); - ServerPlayNetworking.send(player, Automobility.id("sync_automobile_components"), buf); - } - - public static void sendSyncAutomobileAttachmentsPacket(AutomobileEntity entity, ServerPlayerEntity player) { - var buf = new PacketByteBuf(Unpooled.buffer()); - buf.writeInt(entity.getId()); - buf.writeString(entity.getRearAttachmentType().id().toString()); - buf.writeString(entity.getFrontAttachmentType().id().toString()); - ServerPlayNetworking.send(player, Automobility.id("sync_automobile_attachments"), buf); - } - - public static void sendBannerPostAttachmentUpdatePacket(AutomobileEntity entity, NbtCompound banner, ServerPlayerEntity player) { - var buf = new PacketByteBuf(Unpooled.buffer()); - - if (entity.getRearAttachment() instanceof BannerPostRearAttachment) { - buf.writeInt(entity.getId()); - buf.writeNbt(banner); - ServerPlayNetworking.send(player, Automobility.id("update_banner_post"), buf); - } - } - - public static void sendExtendableAttachmentUpdatePacket(AutomobileEntity entity, boolean extended, ServerPlayerEntity player) { - var buf = new PacketByteBuf(Unpooled.buffer()); - - if (entity.getRearAttachment() instanceof ExtendableRearAttachment) { - buf.writeInt(entity.getId()); - buf.writeBoolean(extended); - ServerPlayNetworking.send(player, Automobility.id("update_extendable_attachment"), buf); - } - } - - public static void init() { - ServerPlayNetworking.registerGlobalReceiver(Automobility.id("sync_automobile_inputs"), (server, player, handler, buf, responseSender) -> { - boolean fwd = buf.readBoolean(); - boolean back = buf.readBoolean(); - boolean left = buf.readBoolean(); - boolean right = buf.readBoolean(); - boolean space = buf.readBoolean(); - int entityId = buf.readInt(); - server.execute(() -> { - if (player.world.getEntityById(entityId) instanceof AutomobileEntity automobile) { - automobile.setInputs(fwd, back, left, right, space); - automobile.markDirty(); - } - }); - }); - ServerPlayNetworking.registerGlobalReceiver(Automobility.id("request_sync_automobile_components"), (server, player, handler, buf, responseSender) -> { - int entityId = buf.readInt(); - server.execute(() -> { - if (player.world.getEntityById(entityId) instanceof AutomobileEntity automobile) { - sendSyncAutomobileComponentsPacket(automobile, player); - sendSyncAutomobileAttachmentsPacket(automobile, player); - - var fAtt = automobile.getFrontAttachment(); - if (fAtt != null) fAtt.updatePacketRequested(player); - - var rAtt = automobile.getRearAttachment(); - if (rAtt != null) rAtt.updatePacketRequested(player); - } - }); - }); - } - - @Environment(EnvType.CLIENT) - public static void initClient() { - ClientPlayNetworking.registerGlobalReceiver(Automobility.id("sync_automobile_data"), (client, handler, buf, responseSender) -> { - PacketByteBuf dup = PacketByteBufs.copy(buf); - int entityId = dup.readInt(); - client.execute(() -> { - if (client.player.world.getEntityById(entityId) instanceof AutomobileEntity automobile) { - automobile.readSyncToClientData(dup); - } - }); - }); - ClientPlayNetworking.registerGlobalReceiver(Automobility.id("sync_automobile_components"), (client, handler, buf, responseSender) -> { - int entityId = buf.readInt(); - var frame = AutomobileFrame.REGISTRY.getOrDefault(Identifier.tryParse(buf.readString())); - var wheel = AutomobileWheel.REGISTRY.getOrDefault(Identifier.tryParse(buf.readString())); - var engine = AutomobileEngine.REGISTRY.getOrDefault(Identifier.tryParse(buf.readString())); - client.execute(() -> { - if (client.player.world.getEntityById(entityId) instanceof AutomobileEntity automobile) { - automobile.setComponents(frame, wheel, engine); - } - }); - }); - ClientPlayNetworking.registerGlobalReceiver(Automobility.id("sync_automobile_attachments"), (client, handler, buf, responseSender) -> { - int entityId = buf.readInt(); - var rearAtt = RearAttachmentType.REGISTRY.getOrDefault(Identifier.tryParse(buf.readString())); - var frontAtt = FrontAttachmentType.REGISTRY.getOrDefault(Identifier.tryParse(buf.readString())); - client.execute(() -> { - if (client.player.world.getEntityById(entityId) instanceof AutomobileEntity automobile) { - automobile.setRearAttachment(rearAtt); - automobile.setFrontAttachment(frontAtt); - } - }); - }); - ClientPlayNetworking.registerGlobalReceiver(Automobility.id("update_banner_post"), (client, handler, buf, responseSender) -> { - int entityId = buf.readInt(); - var banner = buf.readNbt(); - client.execute(() -> { - if (client.player.world.getEntityById(entityId) instanceof AutomobileEntity automobile && - automobile.getRearAttachment() instanceof BannerPostRearAttachment bannerPost) { - bannerPost.setFromNbt(banner); - } - }); - }); - ClientPlayNetworking.registerGlobalReceiver(Automobility.id("update_extendable_attachment"), (client, handler, buf, responseSender) -> { - int entityId = buf.readInt(); - boolean extended = buf.readBoolean(); - client.execute(() -> { - if (client.player.world.getEntityById(entityId) instanceof AutomobileEntity automobile && - automobile.getRearAttachment() instanceof ExtendableRearAttachment att) { - att.setExtended(extended); - } - }); - }); - } -} diff --git a/src/main/resources/assets/automobility/particles/drift_smoke.json b/src/main/resources/assets/automobility/particles/drift_smoke.json deleted file mode 100644 index faa6337..0000000 --- a/src/main/resources/assets/automobility/particles/drift_smoke.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "textures": [ - "automobility:drift_smoke" - ] -} \ No newline at end of file diff --git a/src/main/resources/assets/automobility/textures/block/snow_off_road.png b/src/main/resources/assets/automobility/textures/block/snow_off_road.png deleted file mode 100644 index f542ec9..0000000 Binary files a/src/main/resources/assets/automobility/textures/block/snow_off_road.png and /dev/null differ diff --git a/src/main/resources/automobility.mixins.json b/src/main/resources/automobility.mixins.json deleted file mode 100644 index 5a83888..0000000 --- a/src/main/resources/automobility.mixins.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "io.github.foundationgames.automobility.mixin", - "compatibilityLevel": "JAVA_17", - "mixins": [ - "BoxMixin", - "EnderChestInventoryMixin", - "EntityMixin", - "ForgingScreenHandlerMixin", - "ScreenHandlerMixin", - "ServerPlayNetworkHandlerMixin", - "ShovelItemAccess" - ], - "client": [ - "ClientPlayerEntityMixin", - "ClientPlayerInteractionManagerMixin", - "EntityRenderersMixin", - "GameRendererMixin", - "ModelElementDeserializerMixin", - "midnightcontrols.InputHandlersMixin" - ], - "injectors": { - "defaultRequire": 1 - } -} diff --git a/src/main/resources/data/minecraft/tags/blocks/mineable/pickaxe.json b/src/main/resources/data/minecraft/tags/blocks/mineable/pickaxe.json deleted file mode 100644 index 243a0c0..0000000 --- a/src/main/resources/data/minecraft/tags/blocks/mineable/pickaxe.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "replace": false, - "values": [ - "automobility:auto_mechanic_table", - "automobility:automobile_assembler" - ] -} \ No newline at end of file