diff --git a/README.md b/README.md index e65d098..3213c92 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ If anyone would like to add the remaining features to the game, feel free to che ### **🙎‍♂️ Additional Credits** - Foundation games (Former Author) -- Qboi (Author) +- ~~Qboi~~ XyperCode (Author) - MincraftEinstein (Contributor) - Jab125 (Contributor) - Chumasay (Artist) diff --git a/build.gradle b/build.gradle index b78cb79..77981b0 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ //file:noinspection GroovyAssignabilityCheck plugins { - id 'fabric-loom' version '1.0-SNAPSHOT' - id 'org.jetbrains.kotlin.jvm' version "1.7.10" + id 'fabric-loom' version '1.5-SNAPSHOT' + id 'org.jetbrains.kotlin.jvm' version "1.9.22" id 'maven-publish' } @@ -29,8 +29,8 @@ repositories { maven { url terraformersUrl() } 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://storage.googleapis.com/devan-maven/" } maven { url "https://dl.cloudsmith.io/public/geckolib3/geckolib/maven/" } maven { @@ -40,15 +40,6 @@ repositories { } } -// maven { -// name = "GitHubPackages" -// url = uri("https://maven.pkg.github.com/Ultreon/myron-updated") -// credentials { -// username = rootProject.hasProperty("gpr.user") ? rootProject.property("gpr.user") : System.getenv("GITHUB_ACTOR") -// password = rootProject.hasProperty("gpr.key") ? rootProject.property("gpr.key") : System.getenv("GITHUB_TOKEN") -// } -// } - flatDir { dir "$projectDir/libs" } @@ -64,7 +55,7 @@ dependencies { modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" // Geckolib - modImplementation "software.bernie.geckolib:geckolib-fabric-1.19.3:4.0.3" + modImplementation "software.bernie.geckolib:geckolib-fabric-1.20.1:4.4.2" // Controller Support include modImplementation("dev.lambdaurora:spruceui:${project.spruceui_version}") @@ -82,9 +73,9 @@ dependencies { // modImplementation "maven.modrinth:jsonem:${project.jsonem_version}" // include "maven.modrinth:jsonem:${project.jsonem_version}" - modImplementation("net.fabricmc:fabric-language-kotlin:1.8.6+kotlin.1.7.21") + modImplementation("net.fabricmc:fabric-language-kotlin:1.10.17+kotlin.1.9.22") - modImplementation "com.terraformersmc:modmenu:5.0.2", { + modImplementation "com.terraformersmc:modmenu:7.2.2", { exclude module: "fabric-api" } @@ -107,8 +98,8 @@ tasks.withType(JavaCompile).configureEach { // If Javadoc is generated, this must be specified in that task too. it.options.encoding = "UTF-8" - // Minecraft 1.17 (21w19a) upwards uses Java 16. - it.options.release = 16 + // Minecraft 1.18 upwards uses Java 17. + it.options.release = 17 } java { diff --git a/gradle.properties b/gradle.properties index 22ac8c4..514860f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,19 +1,18 @@ org.gradle.jvmargs=-Xmx1G org.gradle.daemon=false - -minecraft_version=1.19.3 -yarn_mappings=1.19.3+build.4 -loader_version=0.14.12 +minecraft_version=1.20.1 +yarn_mappings=1.20.1+build.10 +loader_version=0.15.6 #Fabric api -fabric_version=0.69.1+1.19.3 +fabric_version=0.91.0+1.20.1 # Other Dependencies -midnightcontrols_version=1.7.2-1.19.3 -midnightlib_version=1.1.0-fabric -spruceui_version=4.1.0+1.19.3 -arrp_version=4180873 +midnightcontrols_version=1.9.3+1.20 +midnightlib_version=1.4.1-fabric +spruceui_version=5.0.0+1.20 +arrp_version=5018841 -mod_version = 1.0.0-1.19.3 -maven_group = motobox -archives_base_name = motobox +mod_version=1.1.0-1.20.1 +maven_group=motobox +archives_base_name=motobox diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ffed3a2..db9a6b8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/motobox/Motobox.java b/src/main/java/motobox/Motobox.java index 4d177d7..32c8b1e 100644 --- a/src/main/java/motobox/Motobox.java +++ b/src/main/java/motobox/Motobox.java @@ -22,15 +22,17 @@ import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; import net.minecraft.registry.tag.TagKey; +import net.minecraft.resource.featuretoggle.FeatureSet; import net.minecraft.screen.ScreenHandlerType; import net.minecraft.server.MinecraftServer; +import net.minecraft.text.Text; import net.minecraft.util.Identifier; // TODO fix player not rotating when vehicle rotating public class Motobox implements ModInitializer { public static final String MOD_ID = "motobox"; - public static final ItemGroup GROUP = FabricItemGroup.builder(id("motobox")).icon(AUtils::createGroupIcon).entries((enabledFeatures, entries, operatorEnabled) -> { + public static final ItemGroup GROUP = FabricItemGroup.builder().icon(AUtils::createGroupIcon).entries((enabledFeatures, entries) -> { for (Item item : Registries.ITEM) { if (item instanceof GenericMotoboxItem) { entries.add(item); @@ -42,8 +44,8 @@ public class Motobox implements ModInitializer { vehicleComponentItem.appendStacks(entries); } } - }).build(); - public static final ItemGroup COURSE_ELEMENTS = FabricItemGroup.builder(id("motobox_course_elements")).icon(AUtils::createCourseElementsIcon).entries((enabledFeatures, entries, operatorEnabled) -> { + }).displayName(Text.translatable("itemGroup.motobox.motobox")).build(); + public static final ItemGroup COURSE_ELEMENTS = FabricItemGroup.builder().icon(AUtils::createCourseElementsIcon).entries((enabledFeatures, entries) -> { for (Item item : Registries.ITEM) { if (item instanceof CourseElementItem) { entries.add(item); @@ -54,12 +56,12 @@ public class Motobox implements ModInitializer { } } } - }).build(); - public static final ItemGroup PREFABS = FabricItemGroup.builder(id("motobox_prefabs")).icon(AUtils::createPrefabsIcon).entries((enabledFeatures, entries, operatorEnabled) -> { + }).displayName(Text.translatable("itemGroup.motobox.motobox_course_elements")).build(); + public static final ItemGroup PREFABS = FabricItemGroup.builder().icon(AUtils::createPrefabsIcon).entries((enabledFeatures, entries) -> { for (var prefab : VehicleItem.PREFABS) { entries.add(prefab.toStack()); } - }).build(); + }).displayName(Text.translatable("itemGroup.motobox.motobox_prefabs")).build(); public static final TagKey SLOPES = TagKey.of(Registries.BLOCK.getKey(), id("slopes")); public static final TagKey STEEP_SLOPES = TagKey.of(Registries.BLOCK.getKey(), id("steep_slopes")); @@ -67,9 +69,9 @@ public class Motobox implements ModInitializer { public static final TagKey STICKY_SLOPES = TagKey.of(Registries.BLOCK.getKey(), id("sticky_slopes")); public static final ScreenHandlerType MECHANIC_SCREEN = - Registry.register(Registries.SCREEN_HANDLER, Motobox.id("mechanic_table"), new ScreenHandlerType<>(MechanicTableScreenHandler::new)); + Registry.register(Registries.SCREEN_HANDLER, Motobox.id("mechanic_table"), new ScreenHandlerType<>(MechanicTableScreenHandler::new, FeatureSet.empty())); public static final ScreenHandlerType SINGLE_SLOT_SCREEN = - Registry.register(Registries.SCREEN_HANDLER, Motobox.id("single_slot"), new ScreenHandlerType<>(SingleSlotScreenHandler::new)); + Registry.register(Registries.SCREEN_HANDLER, Motobox.id("single_slot"), new ScreenHandlerType<>(SingleSlotScreenHandler::new, FeatureSet.empty())); private static MinecraftServer server; public static MinecraftServer server() { @@ -89,6 +91,11 @@ public void onInitialize() { MotoboxData.setup(); ControllerUtils.initMidnightControlsHandler(); + // Register Item Group + Registry.register(Registries.ITEM_GROUP, Motobox.id("motobox"), GROUP); + Registry.register(Registries.ITEM_GROUP, Motobox.id("course_elements"), COURSE_ELEMENTS); + Registry.register(Registries.ITEM_GROUP, Motobox.id("prefabs"), PREFABS); + ServerLifecycleEvents.SERVER_STARTING.register(server -> Motobox.server = server); ServerLifecycleEvents.SERVER_STOPPED.register(server -> Motobox.server = null); diff --git a/src/main/java/motobox/block/DashPanelBlock.java b/src/main/java/motobox/block/DashPanelBlock.java index 52a5411..7c4e5b8 100644 --- a/src/main/java/motobox/block/DashPanelBlock.java +++ b/src/main/java/motobox/block/DashPanelBlock.java @@ -44,7 +44,7 @@ protected void appendProperties(StateManager.Builder builder) @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)); + return super.getPlacementState(ctx).with(FACING, ctx.getPlayerLookDirection()).with(WATERLOGGED, ctx.getWorld().getBlockState(ctx.getBlockPos()).isOf(Blocks.WATER)); } @Override diff --git a/src/main/java/motobox/block/MechanicTableBlock.java b/src/main/java/motobox/block/MechanicTableBlock.java index 3b9a83e..e30bcb8 100644 --- a/src/main/java/motobox/block/MechanicTableBlock.java +++ b/src/main/java/motobox/block/MechanicTableBlock.java @@ -102,7 +102,7 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt @Nullable @Override public BlockState getPlacementState(ItemPlacementContext ctx) { - return super.getPlacementState(ctx).with(FACING, ctx.getPlayerFacing().getOpposite()); + return super.getPlacementState(ctx).with(FACING, ctx.getPlayerLookDirection().getOpposite()); } diff --git a/src/main/java/motobox/block/MotoboxBlocks.java b/src/main/java/motobox/block/MotoboxBlocks.java index a907155..f528d54 100644 --- a/src/main/java/motobox/block/MotoboxBlocks.java +++ b/src/main/java/motobox/block/MotoboxBlocks.java @@ -48,7 +48,7 @@ public enum MotoboxBlocks { public static final Block SAND_OFF_ROAD = register("sand_off_road", new OffRoadBlock(FabricBlockSettings.copyOf(Blocks.SAND).noCollision(), new Color(0xC2B185)), MotoboxBlocks::simpleItem); public static final Block SNOW_OFF_ROAD = register("snow_off_road", new OffRoadBlock(FabricBlockSettings.copyOf(Blocks.SNOW_BLOCK).noCollision(), new Color(0xD0E7ED)), MotoboxBlocks::simpleItem); - public static final Block ASPHALT = register("asphalt", new AsphaltBlock(FabricBlockSettings.of(Material.STONE, MapColor.BLACK).requiresTool().strength(1.5f, 6.0f)), MotoboxBlocks::simpleItem); + public static final Block ASPHALT = register("asphalt", new AsphaltBlock(FabricBlockSettings.create().mapColor(MapColor.BLACK).requiresTool().strength(1.5f, 6.0f)), MotoboxBlocks::simpleItem); public static final Block TRAFFIC_CONE = register("traffic_cone", new TrafficConeBlock(FabricBlockSettings.copyOf(Blocks.STONE).strength(0.5f, 2.0f)), MotoboxBlocks::simpleItem); public static final Block ROADBLOCK = register("roadblock", new RoadblockBlock(FabricBlockSettings.copyOf(Blocks.GRAY_CONCRETE).requiresTool().strength(2.0f, 6.0f)), MotoboxBlocks::simpleItem); diff --git a/src/main/java/motobox/block/OffRoadBlock.java b/src/main/java/motobox/block/OffRoadBlock.java index c5d3717..d40ef0c 100644 --- a/src/main/java/motobox/block/OffRoadBlock.java +++ b/src/main/java/motobox/block/OffRoadBlock.java @@ -28,7 +28,7 @@ public class OffRoadBlock extends Block implements CourseElementItem { public final Color color; public OffRoadBlock(Settings settings, Color color) { - super(settings); + super(settings.pistonBehavior(PistonBehavior.DESTROY)); setDefaultState(getDefaultState().with(LAYERS, 1)); this.color = color; } @@ -56,11 +56,6 @@ public void neighborUpdate(BlockState state, World world, BlockPos pos, Block bl } } - @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); diff --git a/src/main/java/motobox/block/SlopeBlock.java b/src/main/java/motobox/block/SlopeBlock.java index 17ceaf7..30fa5e1 100644 --- a/src/main/java/motobox/block/SlopeBlock.java +++ b/src/main/java/motobox/block/SlopeBlock.java @@ -49,7 +49,7 @@ public BlockState getPlacementState(ItemPlacementContext ctx) { .with(HALF, slopeCtx.getSlopeHalf()) : super.getPlacementState(ctx) - .with(FACING, ctx.getPlayerFacing().getOpposite()) + .with(FACING, ctx.getPlayerLookDirection().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); } diff --git a/src/main/java/motobox/block/SteepSlopeBlock.java b/src/main/java/motobox/block/SteepSlopeBlock.java index ff22e31..f5e1b38 100644 --- a/src/main/java/motobox/block/SteepSlopeBlock.java +++ b/src/main/java/motobox/block/SteepSlopeBlock.java @@ -41,7 +41,7 @@ public BlockState getPlacementState(ItemPlacementContext ctx) { .with(WATERLOGGED, ctx.getWorld().getBlockState(ctx.getBlockPos()).isOf(Blocks.WATER)) : super.getPlacementState(ctx) - .with(FACING, ctx.getPlayerFacing().getOpposite()) + .with(FACING, ctx.getPlayerLookDirection().getOpposite()) .with(WATERLOGGED, ctx.getWorld().getBlockState(ctx.getBlockPos()).isOf(Blocks.WATER)); } diff --git a/src/main/java/motobox/block/VehicleAssemblerBlock.java b/src/main/java/motobox/block/VehicleAssemblerBlock.java index f27a344..aa316ce 100644 --- a/src/main/java/motobox/block/VehicleAssemblerBlock.java +++ b/src/main/java/motobox/block/VehicleAssemblerBlock.java @@ -92,7 +92,7 @@ public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos po @Nullable @Override public BlockState getPlacementState(ItemPlacementContext ctx) { - return super.getPlacementState(ctx).with(FACING, ctx.getPlayerFacing().getOpposite()); + return super.getPlacementState(ctx).with(FACING, ctx.getPlayerLookDirection().getOpposite()); } @Override diff --git a/src/main/java/motobox/block/entity/VehicleAssemblerBlockEntity.java b/src/main/java/motobox/block/entity/VehicleAssemblerBlockEntity.java index ef34b54..0fdffdd 100644 --- a/src/main/java/motobox/block/entity/VehicleAssemblerBlockEntity.java +++ b/src/main/java/motobox/block/entity/VehicleAssemblerBlockEntity.java @@ -26,8 +26,8 @@ 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.Packet; import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket; import net.minecraft.network.packet.s2c.play.ParticleS2CPacket; import net.minecraft.particle.ParticleTypes; diff --git a/src/main/java/motobox/block/entity/render/VehicleAssemblerBlockEntityRenderer.java b/src/main/java/motobox/block/entity/render/VehicleAssemblerBlockEntityRenderer.java index 8382496..5c98dc0 100644 --- a/src/main/java/motobox/block/entity/render/VehicleAssemblerBlockEntityRenderer.java +++ b/src/main/java/motobox/block/entity/render/VehicleAssemblerBlockEntityRenderer.java @@ -43,7 +43,7 @@ public void render(VehicleAssemblerBlockEntity entity, float tickDelta, MatrixSt for (var text : entity.label) { matrices.push(); matrices.translate(-0.5 * textRenderer.getWidth(text), 0, 0); - textRenderer.drawWithShadow(matrices, text, 0, 0, 0xFFFFFF); + textRenderer.draw(text, 0, 0, 0xFFFFFF, true, matrices.peek().getPositionMatrix(), vertexConsumers, TextRenderer.TextLayerType.SEE_THROUGH, light, overlay); matrices.pop(); matrices.translate(0, 12, 0); } diff --git a/src/main/java/motobox/entity/MotoboxEntities.java b/src/main/java/motobox/entity/MotoboxEntities.java index 713b44e..3d55348 100644 --- a/src/main/java/motobox/entity/MotoboxEntities.java +++ b/src/main/java/motobox/entity/MotoboxEntities.java @@ -24,8 +24,12 @@ import net.minecraft.entity.EntityType; import net.minecraft.entity.SpawnGroup; import net.minecraft.entity.damage.DamageSource; +import net.minecraft.entity.damage.DamageType; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.registry.tag.TagKey; public enum MotoboxEntities { @@ -46,9 +50,10 @@ public enum MotoboxEntities { public static final TagKey> DASH_PANEL_BOOSTABLES = TagKey.of(Registries.ENTITY_TYPE.getKey(), Motobox.id("dash_panel_boostables")); - public static final DamageSource VEHICLE_DAMAGE_SOURCE = new VehicleDamageSource("vehicle"); + public static final RegistryKey VEHICLE_DAMAGE_TYPE = RegistryKey.of(RegistryKeys.DAMAGE_TYPE, Motobox.id("vehicle")); public static void init() { + } @Environment(EnvType.CLIENT) diff --git a/src/main/java/motobox/entity/VehicleDamageSource.java b/src/main/java/motobox/entity/VehicleDamageSource.java deleted file mode 100644 index 3e11e26..0000000 --- a/src/main/java/motobox/entity/VehicleDamageSource.java +++ /dev/null @@ -1,9 +0,0 @@ -package motobox.entity; - -import net.minecraft.entity.damage.DamageSource; - -public class VehicleDamageSource extends DamageSource { - protected VehicleDamageSource(String name) { - super(name); - } -} diff --git a/src/main/java/motobox/entity/VehicleEntity.java b/src/main/java/motobox/entity/VehicleEntity.java index ab96f4e..f217906 100644 --- a/src/main/java/motobox/entity/VehicleEntity.java +++ b/src/main/java/motobox/entity/VehicleEntity.java @@ -32,16 +32,14 @@ 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.listener.ClientPlayPacketListener; +import net.minecraft.network.packet.Packet; 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; @@ -319,7 +317,7 @@ public VehicleEntity(World world) { @Override public void onSpawnPacket(EntitySpawnS2CPacket packet) { super.onSpawnPacket(packet); - if (world.isClient()) { + if (getWorld().isClient()) { PayloadPackets.requestSyncVehicleComponentsPacket(this); } } @@ -397,7 +395,7 @@ public int getBoostTimer() { } public double getEffectiveSpeed() { - if (this.getPrimaryPassenger() instanceof PlayerEntity player && player.isMainPlayer()) { + if (this.getControllingPassenger() instanceof PlayerEntity player && player.isMainPlayer()) { return Math.max(this.addedVelocity.length(), Math.abs(this.hSpeed)); } @@ -424,7 +422,7 @@ public boolean burningOut() { } private void setDrifting(boolean drifting) { - if (this.world.isClient() && !this.drifting && drifting) { + if (this.getWorld().isClient() && !this.drifting && drifting) { playSkiddingSound(); } @@ -432,7 +430,7 @@ private void setDrifting(boolean drifting) { } private void setBurningOut(boolean burningOut) { - if (this.world.isClient() && !this.drifting && !this.burningOut && burningOut) { + if (this.getWorld().isClient() && !this.drifting && !this.burningOut && burningOut) { playSkiddingSound(); } @@ -455,7 +453,7 @@ public void setRearAttachment(RearAttachmentType r this.rearAttachment = rearAttachment.constructor().apply(rearAttachment, this); this.rearAttachment.setYaw(this.getYaw()); - if (!world.isClient() && !this.rearAttachment.isRideable() && this.getPassengerList().size() > 1) { + if (!getWorld().isClient() && !this.rearAttachment.isRideable() && this.getPassengerList().size() > 1) { this.getPassengerList().get(1).stopRiding(); } @@ -484,14 +482,14 @@ public void setComponents(VehicleFrame frame, VehicleWheel wheel, VehicleEngine this.wheels = wheel; this.engine = engine; this.updateModels = true; - this.stepHeight = wheels.size(); + this.setStepHeight(wheels.size()); this.stats.from(frame, wheel, engine); this.displacement.applyWheelbase(frame.model().wheelBase().get()); - if (!world.isClient()) syncComponents(); + if (!getWorld().isClient()) syncComponents(); } public void forNearbyPlayers(int radius, boolean ignoreDriver, Consumer action) { - for (PlayerEntity p : world.getPlayers()) { + for (PlayerEntity p : getWorld().getPlayers()) { if (ignoreDriver && p == getFirstPassenger()) { continue; } @@ -547,7 +545,6 @@ private void playSkiddingSound() { @Override public boolean damage(DamageSource source, float amount) { - boolean bl; if (this.isInvulnerableTo(source)) { return false; } @@ -565,9 +562,9 @@ protected void dropItems(DamageSource source) { @Override public void tick() { - this.ticksUnderwater = this.location == Location.UNDER_WATER || this.location == Location.UNDER_FLOWING_WATER ? (this.ticksUnderwater += 1.0f) : 0.0f; + this.ticksUnderwater = this.location == Location.UNDER_WATER || this.location == Location.UNDER_FLOWING_WATER ? this.ticksUnderwater + 1.0f : 0.0f; - if (!this.world.isClient && this.ticksUnderwater >= 60.0f) { + if (!this.getWorld().isClient && this.ticksUnderwater >= 60.0f) { this.removeAllPassengers(); } @@ -576,7 +573,7 @@ public void tick() { if (lastWheelAngle != wheelAngle) markDirty(); lastWheelAngle = wheelAngle; - if (!this.wasEngineRunning && this.engineRunning() && this.world.isClient()) { + if (!this.wasEngineRunning && this.engineRunning() && this.getWorld().isClient()) { playEngineSound(); } this.wasEngineRunning = this.engineRunning(); @@ -611,7 +608,7 @@ public void tick() { } postMovementTick(); - if (!world.isClient()) { + if (!getWorld().isClient()) { var prevTailPos = this.prevTailPos != null ? this.prevTailPos : this.getTailPos(); var tailPos = this.getTailPos(); @@ -623,7 +620,7 @@ 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.getWorld().getOtherEntities(this, this.getBoundingBox().expand(0.2, 0, 0.2), EntityPredicates.canBePushedBy(this)); // for (Entity entity : touchingEntities) { // if (!entity.hasPassenger(this)) { // if (!entity.hasVehicle() && entity.getWidth() <= this.getWidth() && entity instanceof MobEntity && !(entity instanceof WaterCreatureEntity)) { @@ -653,7 +650,7 @@ 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 PlayerEntity) { this.standStillTime = AUtils.shift(this.standStillTime, 0.05f, 1f); } else { this.standStillTime = AUtils.shift(this.standStillTime, 0.15f, -1.3f); @@ -751,7 +748,7 @@ public void provideMobDriverInputs(MobEntity driver) { // 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); if (pos.length() < 20 * mul && Math.abs(offset) > 180 - (170 * mul)) { - long time = world.getTime(); + long time = getWorld().getTime(); // this is so that the vehicle alternates between reverse and forward, // like a driver would do in order to angle their vehicle toward a target location reverse = (time % 80 <= 30); @@ -791,11 +788,11 @@ public void movementTick() { } // Get block below's friction - var blockBelow = new BlockPos(getX(), getY() - 0.05, getZ()); - float grip = 1 - ((MathHelper.clamp((world.getBlockState(blockBelow).getBlock().getSlipperiness() - 0.6f) / 0.4f, 0, 1) * (1 - stats.getGrip() * 0.8f))); + var blockBelow = new BlockPos(getBlockX(), (int) (getY() - 0.05), getBlockZ()); + float grip = 1 - ((MathHelper.clamp((getWorld().getBlockState(blockBelow).getBlock().getSlipperiness() - 0.6f) / 0.4f, 0, 1) * (1 - stats.getGrip() * 0.8f))); // Bounce on gel - if (this.vehicleOnGround && this.jumpCooldown <= 0 && world.getBlockState(this.getBlockPos()).getBlock() instanceof LaunchGelBlock) { + if (this.vehicleOnGround && this.jumpCooldown <= 0 && getWorld().getBlockState(this.getBlockPos()).getBlock() instanceof LaunchGelBlock) { this.setSpeed(Math.max(this.getHSpeed(), 0.1f), Math.max(this.getVSpeed(), 0.9f)); this.jumpCooldown = 5; this.vehicleOnGround = false; @@ -821,14 +818,14 @@ public void movementTick() { this.engineSpeed += // The following conditions check whether the vehicle should NOT receive normal acceleration // It will not receive this acceleration if the vehicle is steering or tight-drifting - ( - (this.drifting && AUtils.haveSameSign(this.steering, this.driftDir)) || - (!this.drifting && this.steering != 0 && hSpeed > 0.5) - ) ? (this.hSpeed < stats.getComfortableSpeed() ? 0.001 : 0) // This will supply a small amount of acceleration if the vehicle is moving slowly only - - // Otherwise, it will receive acceleration as normal - // It will receive this acceleration if the vehicle is moving straight or wide-drifting (the latter slightly reduces acceleration) - : calculateAcceleration(speed, stats) * (drifting ? 0.86 : 1) * (engineSpeed > stats.getComfortableSpeed() ? 0.25f : 1) * grip; + (float) (( + (this.drifting && AUtils.haveSameSign(this.steering, this.driftDir)) || + (!this.drifting && this.steering != 0 && hSpeed > 0.5) + ) ? (this.hSpeed < stats.getComfortableSpeed() ? 0.001 : 0) // This will supply a small amount of acceleration if the vehicle is moving slowly only + + // Otherwise, it will receive acceleration as normal + // It will receive this acceleration if the vehicle is moving straight or wide-drifting (the latter slightly reduces acceleration) + : calculateAcceleration(speed, stats) * (drifting ? 0.86 : 1) * (engineSpeed > stats.getComfortableSpeed() ? 0.25f : 1) * grip); } // Handle braking/reverse @@ -846,22 +843,22 @@ public void movementTick() { } if (this.burningOut()) { - engineSpeed -= (engineSpeed) * 0.5; + engineSpeed -= (float) ((engineSpeed) * 0.5); } // Allows for the sticky slope effect to continue for a tick after not being on a slope // This prevents the vehicle 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); + var below = new BlockPos(MathHelper.floor(getX()), MathHelper.floor(getY() - 0.51), MathHelper.floor(getZ())); + var state = getWorld().getBlockState(below); if (state.isIn(Motobox.STICKY_SLOPES)) { slopeStickingTimer = 1; } else { - slopeStickingTimer = Math.max(0, slopeStickingTimer--); + slopeStickingTimer = Math.max(0, slopeStickingTimer - 1); } // Handle being in off-road - if (boostSpeed < 0.4f && world.getBlockState(getBlockPos()).getBlock() instanceof OffRoadBlock offRoadBlock) { - int layers = world.getBlockState(getBlockPos()).get(OffRoadBlock.LAYERS); + if (boostSpeed < 0.4f && getWorld().getBlockState(getBlockPos()).getBlock() instanceof OffRoadBlock offRoadBlock) { + int layers = getWorld().getBlockState(getBlockPos()).get(OffRoadBlock.LAYERS); float cap = stats.getComfortableSpeed() * (1 - ((float) layers / 3.5f)); engineSpeed = Math.min(cap, engineSpeed); this.debrisColor = offRoadBlock.color; @@ -915,10 +912,10 @@ 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())) { + for (var entity : getWorld().getEntitiesByType(TypeFilter.instanceOf(Entity.class), frontBox, entity -> entity != this && entity != getFirstPassenger())) { if (!entity.isInvulnerable()) { if (entity instanceof LivingEntity living && entity.getVehicle() != this) { - living.damage(MotoboxEntities.VEHICLE_DAMAGE_SOURCE, hSpeed * 10); + living.damage(getWorld().getDamageSources().create(MotoboxEntities.VEHICLE_DAMAGE_TYPE), hSpeed * 10); entity.addVelocity(velAdd.x, velAdd.y, velAdd.z); } @@ -939,11 +936,11 @@ public void postMovementTick() { float angle = (float) Math.toRadians(-speedDirection); if (touchingWall && hSpeed > 0.1 && addedVelocity.length() <= 0) { - engineSpeed /= 3.6; + engineSpeed /= 3.6F; 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(), MotoboxSounds.COLLISION, SoundCategory.AMBIENT, 0.76f, 0.65f + (0.06f * (this.world.random.nextFloat() - 0.5f)), true); + getWorld().playSound(this.getX(), this.getY(), this.getZ(), MotoboxSounds.COLLISION, SoundCategory.AMBIENT, 0.76f, 0.65f + (0.06f * (this.getWorld().random.nextFloat() - 0.5f)), true); } double yDisp = getPos().subtract(this.lastPosForDisplacement).getY(); @@ -1006,7 +1003,7 @@ public void postMovementTick() { float prevYaw = getYaw(); this.setYaw(getYaw() + yawInc); // Commented out to stop player model from jittering around when driving -// if (world.isClient) { +// if (getWorld().isClient) { // var passenger = getFirstPassenger(); // if (passenger instanceof PlayerEntity player) { // if (inLockedViewMode()) { @@ -1025,7 +1022,7 @@ public void postMovementTick() { // } // } // } - if (world.isClient()) { + if (getWorld().isClient()) { this.prevYaw = prevYaw; } } @@ -1033,7 +1030,7 @@ public void postMovementTick() { @Override public void move(MovementType movementType, Vec3d movement) { - if (!this.world.isClient() && movementType == MovementType.PLAYER) { + if (!this.getWorld().isClient() && movementType == MovementType.PLAYER) { AUtils.IGNORE_ENTITY_GROUND_CHECK_STEPPING = true; } super.move(movementType, movement); @@ -1045,14 +1042,14 @@ public boolean handleFallDamage(float fallDistance, float damageMultiplier, Dama } public void displacementTick(boolean tick) { - if (this.world.isClient()) { + if (this.getWorld().isClient()) { this.displacement.preTick(); if (tick) { - this.displacement.tick(this.world, this, this.getPos(), this.getYaw(), this.stepHeight); + this.displacement.tick(this.getWorld(), this, this.getPos(), this.getYaw(), this.getStepHeight()); } - if (world.getBlockState(this.getBlockPos()).getBlock() instanceof VehicleAssemblerBlock) { + if (getWorld().getBlockState(this.getBlockPos()).getBlock() instanceof VehicleAssemblerBlock) { this.displacement.lastVertical = this.displacement.verticalTarget = (-this.wheels.model().radius() / 16); } } @@ -1072,23 +1069,24 @@ public void collisionStateTick() { 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 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 start = new BlockPos( + (int) (b.minX - 0.1), (int) (b.minY - 0.2), (int) (b.minZ - 0.1)); + var end = new BlockPos((int) (b.maxX + 0.1), (int) (b.maxY + 0.2 + this.getStepHeight()), (int) (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 stepWallCuboid = wallCuboid.offset(0, this.getStepHeight() - 0.05, 0); boolean wallHit = false; boolean stepWallHit = false; var shapeCtx = ShapeContext.of(this); - if (this.world.isRegionLoaded(start, end)) { + if (this.getWorld().isRegionLoaded(start, end)) { var pos = new BlockPos.Mutable(); 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()); + var state = this.getWorld().getBlockState(pos); + var blockShape = state.getCollisionShape(this.getWorld(), pos, shapeCtx).offset(pos.getX(), pos.getY(), pos.getZ()); this.vehicleOnGround = this.vehicleOnGround || VoxelShapes.matchesAnywhere(blockShape, groundCuboid, BooleanBiFunction.AND); this.isFloorDirectlyBelow = this.isFloorDirectlyBelow || VoxelShapes.matchesAnywhere(blockShape, floorCuboid, BooleanBiFunction.AND); wallHit = wallHit || VoxelShapes.matchesAnywhere(blockShape, wallCuboid, BooleanBiFunction.AND); @@ -1180,7 +1178,7 @@ private void driftingTick() { driftDir = steering > 0 ? 1 : -1; // 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; + engineSpeed -= (float) (0.028 * engineSpeed); } } // Handles drifting effects, ending a drift, and the drift timer (for drift turbos) @@ -1235,7 +1233,7 @@ public void createDriftParticles() { .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(MotoboxParticles.DRIFT_SMOKE, origin.x + pos.x, origin.y + pos.y, origin.z + pos.z, 0, 0, 0); + getWorld().addParticle(MotoboxParticles.DRIFT_SMOKE, origin.x + pos.x, origin.y + pos.y, origin.z + pos.z, 0, 0, 0); } } } @@ -1296,11 +1294,9 @@ public float getVehicleYaw(float tickDelta) { public float getRearAttachmentYaw(float tickDelta) { return this.rearAttachment.yaw(tickDelta); } - - @Nullable - @Override - public Entity getPrimaryPassenger() { - return getFirstPassenger(); + + public LivingEntity getControllingPassenger() { + return getFirstPassenger() instanceof LivingEntity entity ? entity : null; } @Override @@ -1329,23 +1325,23 @@ public float getStandStillTime() { } public void playHitSound() { - world.emitGameEvent(this, GameEvent.ENTITY_DAMAGE, getPos()); - world.playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.BLOCK_COPPER_BREAK, SoundCategory.AMBIENT, 1, 0.9f + (this.world.random.nextFloat() * 0.2f)); + getWorld().emitGameEvent(this, GameEvent.ENTITY_DAMAGE, getPos()); + getWorld().playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.BLOCK_COPPER_BREAK, SoundCategory.AMBIENT, 1, 0.9f + (this.getWorld().random.nextFloat() * 0.2f)); } private void dropParts(Vec3d pos) { - world.spawnEntity(new ItemEntity(world, pos.x, pos.y, pos.z, MotoboxItems.VEHICLE_FRAME.createStack(this.getFrame()))); - world.spawnEntity(new ItemEntity(world, pos.x, pos.y, pos.z, MotoboxItems.VEHICLE_ENGINE.createStack(this.getEngine()))); + getWorld().spawnEntity(new ItemEntity(getWorld(), pos.x, pos.y, pos.z, MotoboxItems.VEHICLE_FRAME.createStack(this.getFrame()))); + getWorld().spawnEntity(new ItemEntity(getWorld(), pos.x, pos.y, pos.z, MotoboxItems.VEHICLE_ENGINE.createStack(this.getEngine()))); var wheelStack = MotoboxItems.VEHICLE_WHEEL.createStack(this.getWheels()); wheelStack.setCount(this.getFrame().model().wheelBase().get().wheelCount); - world.spawnEntity(new ItemEntity(world, pos.x, pos.y, pos.z, wheelStack)); + getWorld().spawnEntity(new ItemEntity(getWorld(), 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, + getWorld().spawnEntity(new ItemEntity(getWorld(), dropPos.x, dropPos.y, dropPos.z, MotoboxItems.REAR_ATTACHMENT.createStack(this.getRearAttachmentType()))); } this.setRearAttachment(RearAttachmentType.EMPTY); @@ -1354,7 +1350,7 @@ 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, + getWorld().spawnEntity(new ItemEntity(getWorld(), dropPos.x, dropPos.y, dropPos.z, MotoboxItems.FRONT_ATTACHMENT.createStack(this.getFrontAttachmentType()))); } this.setFrontAttachment(FrontAttachmentType.EMPTY); @@ -1377,7 +1373,7 @@ public void destroyVehicle(boolean drop, RemovalReason reason) { public ActionResult interact(PlayerEntity player, Hand hand) { if (player.isSneaking()) { if (this.hasInventory()) { - if (!world.isClient()) { + if (!getWorld().isClient()) { openInventory(player); return ActionResult.PASS; } else { @@ -1395,17 +1391,17 @@ public ActionResult interact(PlayerEntity player, Hand hand) { this.destroyFrontAttachment(!player.isCreative()); this.playHitSound(); - return ActionResult.success(world.isClient); + return ActionResult.success(getWorld().isClient); } else if (!this.rearAttachment.type.isEmpty()) { this.destroyRearAttachment(!player.isCreative()); this.playHitSound(); - return ActionResult.success(world.isClient); + return ActionResult.success(getWorld().isClient); } else { this.destroyVehicle(!player.isCreative(), RemovalReason.KILLED); this.playHitSound(); - return ActionResult.success(world.isClient); + return ActionResult.success(getWorld().isClient); } } @@ -1417,17 +1413,17 @@ public ActionResult interact(PlayerEntity player, Hand hand) { if (!this.hasSpaceForPassengers()) { final Entity firstPassenger = this.getFirstPassenger(); if (!(firstPassenger instanceof PlayerEntity)) { - if (!world.isClient() && firstPassenger != null) { + if (!getWorld().isClient() && firstPassenger != null) { firstPassenger.stopRiding(); } - return ActionResult.success(world.isClient); + return ActionResult.success(getWorld().isClient); } return ActionResult.PASS; } - if (!world.isClient()) { + if (!getWorld().isClient()) { player.startRiding(this); } - return ActionResult.success(world.isClient()); + return ActionResult.success(getWorld().isClient()); } return ActionResult.PASS; @@ -1445,9 +1441,9 @@ public double getMountedHeightOffset() { private float velocityDecay; private float yawVelocity; - + @Override - public void updatePassengerPosition(Entity passenger) { + public void updatePassengerPosition(Entity passenger, PositionUpdater updater) { if (!this.hasPassenger(passenger)) { return; } @@ -1573,20 +1569,20 @@ public Vec3d updatePassengerForDismount(LivingEntity passenger) { double e; Vec3d vec3d = BoatEntity.getPassengerDismountOffset(this.getWidth() * MathHelper.SQUARE_ROOT_OF_TWO, passenger.getWidth(), passenger.getYaw()); double d = this.getX() + vec3d.x; - BlockPos blockPos = new BlockPos(d, this.getBoundingBox().maxY, e = this.getZ() + vec3d.z); + BlockPos blockPos = new BlockPos((int) d, (int) this.getBoundingBox().maxY, (int) (e = this.getZ() + vec3d.z)); BlockPos blockPos2 = blockPos.down(); double g; ArrayList list = Lists.newArrayList(); - double f = this.world.getDismountHeight(blockPos); + double f = this.getWorld().getDismountHeight(blockPos); if (Dismounting.canDismountInBlock(f)) { list.add(new Vec3d(d, (double)blockPos.getY() + f, e)); } - if (Dismounting.canDismountInBlock(g = this.world.getDismountHeight(blockPos2))) { + if (Dismounting.canDismountInBlock(g = this.getWorld().getDismountHeight(blockPos2))) { list.add(new Vec3d(d, (double)blockPos2.getY() + g, e)); } for (EntityPose entityPose : passenger.getPoses()) { for (Vec3d vec3d2 : list) { - if (!Dismounting.canPlaceEntityAt(this.world, vec3d2, passenger, entityPose)) continue; + if (!Dismounting.canPlaceEntityAt(this.getWorld(), vec3d2, passenger, entityPose)) continue; passenger.setPose(entityPose); return vec3d2; } @@ -1665,7 +1661,7 @@ public float getTrackedFrontAttachmentAnimation() { public void bounce() { suspensionBounceTimer = 3; - world.playSound(this.getX(), this.getY(), this.getZ(), MotoboxSounds.LANDING, SoundCategory.AMBIENT, 1, 1.5f + (0.15f * (this.world.random.nextFloat() - 0.5f)), true); + getWorld().playSound(this.getX(), this.getY(), this.getZ(), MotoboxSounds.LANDING, SoundCategory.AMBIENT, 1, 1.5f + (0.15f * (this.getWorld().random.nextFloat() - 0.5f)), true); } @SuppressWarnings("ConstantValue") @@ -1711,12 +1707,12 @@ public void tick(World world, VehicleEntity entity, Vec3d centerPos, double yaw, int heightOffset = (int) Math.ceil(scanDist); var iter = new CuboidBlockIterator( - (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)), - (int) Math.max(Math.floor(centerPos.x), Math.floor(pointPos.x)), - (int) Math.floor(centerPos.y) + heightOffset, - (int) Math.max(Math.floor(centerPos.z), Math.floor(pointPos.z)) + Math.min(MathHelper.floor(centerPos.x), MathHelper.floor(pointPos.x)), + MathHelper.floor(centerPos.y) - heightOffset, + Math.min(MathHelper.floor(centerPos.z), MathHelper.floor(pointPos.z)), + Math.max(MathHelper.floor(centerPos.x), MathHelper.floor(pointPos.x)), + MathHelper.floor(centerPos.y) + heightOffset, + Math.max(MathHelper.floor(centerPos.z), MathHelper.floor(pointPos.z)) ); var mpos = new BlockPos.Mutable(); diff --git a/src/main/java/motobox/entity/ufo/AbstractUfoEntity.java b/src/main/java/motobox/entity/ufo/AbstractUfoEntity.java index 2db9d8c..261a770 100644 --- a/src/main/java/motobox/entity/ufo/AbstractUfoEntity.java +++ b/src/main/java/motobox/entity/ufo/AbstractUfoEntity.java @@ -55,7 +55,7 @@ public void tick() { if (this.isLogicalSideForUpdatingMovement()) { this.updateInterpolatedPose(); this.decayVelocity(); - if (this.world.isClient) { + if (this.getWorld().isClient) { this.applyInput(); } this.move(MovementType.SELF, this.getVelocity()); @@ -63,7 +63,7 @@ public void tick() { this.setVelocity(Vec3d.ZERO); // TODO radius - List collisions = this.world.getEntitiesByClass(PlayerEntity.class, this.getBoundingBox().withMinY(this.getBoundingBox().maxY - 0.1), entity -> true); + List collisions = this.getWorld().getEntitiesByClass(PlayerEntity.class, this.getBoundingBox().withMinY(this.getBoundingBox().maxY - 0.1), entity -> true); for (PlayerEntity player : collisions) { player.setPosition(player.getPos().getX(), this.getBoundingBox().getMax(Axis.Y), player.getPos().getZ()); player.setVelocity(player.getVelocity().getX(), 0, player.getVelocity().getZ()); @@ -105,19 +105,19 @@ private void decayVelocity() { private void applyInput() { if (!this.hasPassengers()) return; - this.setYaw(-this.getPrimaryPassenger().getHeadYaw()); + this.setYaw(-this.getControllingPassenger().getHeadYaw()); float fockwardVelocity = 0.0f; // FOrward and baCKward = fockward - if (UfoInput.pressingForward()) fockwardVelocity += 0.05; - if (UfoInput.pressingBackward()) fockwardVelocity -= 0.05; + if (UfoInput.pressingForward()) fockwardVelocity += 0.05F; + if (UfoInput.pressingBackward()) fockwardVelocity -= 0.05F; float sidewaysVelocity = 0.0f; - if (UfoInput.pressingRight()) sidewaysVelocity += 0.05; - if (UfoInput.pressingLeft()) sidewaysVelocity -= 0.05; + if (UfoInput.pressingRight()) sidewaysVelocity += 0.05F; + if (UfoInput.pressingLeft()) sidewaysVelocity -= 0.05F; float verticalVelocity = 0.0f; - if (UfoInput.pressingUp()) verticalVelocity += 0.05; - if (UfoInput.pressingDown()) verticalVelocity -= 0.05; + if (UfoInput.pressingUp()) verticalVelocity += 0.05F; + if (UfoInput.pressingDown()) verticalVelocity -= 0.05F; this.setVelocity( this.getVelocity().add( @@ -154,7 +154,7 @@ public ActionResult interact(PlayerEntity player, Hand hand) { if (player.shouldCancelInteraction()) { return ActionResult.PASS; } - if (!this.world.isClient) { + if (!this.getWorld().isClient) { return player.startRiding(this) ? ActionResult.CONSUME : ActionResult.PASS; } return ActionResult.SUCCESS; @@ -176,8 +176,8 @@ public double getMountedHeightOffset() { } @Override - public Entity getPrimaryPassenger() { - return this.getFirstPassenger(); + public LivingEntity getControllingPassenger() { + return this.getFirstPassenger() instanceof LivingEntity living ? living : null; } @Override diff --git a/src/main/java/motobox/item/FrontAttachmentItem.java b/src/main/java/motobox/item/FrontAttachmentItem.java index 934f37d..c5f86f7 100644 --- a/src/main/java/motobox/item/FrontAttachmentItem.java +++ b/src/main/java/motobox/item/FrontAttachmentItem.java @@ -15,7 +15,7 @@ public FrontAttachmentItem(Settings settings) { @Override public ActionResult interactVehicle(ItemStack stack, PlayerEntity player, Hand hand, VehicleEntity vehicle) { if (vehicle.getFrontAttachment().type.isEmpty()) { - if (player.world.isClient()) { + if (player.getWorld().isClient()) { return ActionResult.SUCCESS; } diff --git a/src/main/java/motobox/item/RearAttachmentItem.java b/src/main/java/motobox/item/RearAttachmentItem.java index ab9b708..b6a1b23 100644 --- a/src/main/java/motobox/item/RearAttachmentItem.java +++ b/src/main/java/motobox/item/RearAttachmentItem.java @@ -15,7 +15,7 @@ public RearAttachmentItem(Settings settings) { @Override public ActionResult interactVehicle(ItemStack stack, PlayerEntity player, Hand hand, VehicleEntity vehicle) { if (vehicle.getRearAttachment().type.isEmpty()) { - if (player.world.isClient()) { + if (player.getWorld().isClient()) { return ActionResult.SUCCESS; } diff --git a/src/main/java/motobox/item/SlopeBlockItem.java b/src/main/java/motobox/item/SlopeBlockItem.java index 0f12837..74ac8ea 100644 --- a/src/main/java/motobox/item/SlopeBlockItem.java +++ b/src/main/java/motobox/item/SlopeBlockItem.java @@ -13,6 +13,7 @@ import net.minecraft.util.Formatting; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; +import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; @@ -30,12 +31,12 @@ public SlopeBlockItem(Block base, Block block, Settings settings) { @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 pos = new BlockPos(MathHelper.floor(hitPos.x), MathHelper.floor(hitPos.y), MathHelper.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 playerFacing = context.getPlayerLookDirection(); 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); diff --git a/src/main/java/motobox/item/SteepSlopeBlockItem.java b/src/main/java/motobox/item/SteepSlopeBlockItem.java index 65d7457..beef956 100644 --- a/src/main/java/motobox/item/SteepSlopeBlockItem.java +++ b/src/main/java/motobox/item/SteepSlopeBlockItem.java @@ -12,6 +12,7 @@ import net.minecraft.util.Formatting; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; +import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; @@ -29,11 +30,11 @@ public SteepSlopeBlockItem(Block base, Block block, Settings settings) { @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 pos = new BlockPos(MathHelper.floor(hitPos.x), MathHelper.floor(hitPos.y), MathHelper.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 playerFacing = context.getPlayerLookDirection(); var vOffset = playerFacing == facing ? Direction.DOWN : playerFacing == facing.getOpposite() ? Direction.UP : null; var place = pos.offset(playerFacing); if (vOffset != null) place = place.offset(vOffset); diff --git a/src/main/java/motobox/item/VehicleItem.java b/src/main/java/motobox/item/VehicleItem.java index 4db271e..9e8ab4b 100644 --- a/src/main/java/motobox/item/VehicleItem.java +++ b/src/main/java/motobox/item/VehicleItem.java @@ -36,7 +36,7 @@ public ActionResult useOnBlock(ItemUsageContext context) { data.read(stack.getOrCreateSubNbt("Vehicle")); var e = new VehicleEntity(MotoboxEntities.VEHICLE_ENTITY, context.getWorld()); var pos = context.getHitPos(); - e.refreshPositionAndAngles(pos.x, pos.y, pos.z, context.getPlayerFacing().asRotation(), 0); + e.refreshPositionAndAngles(pos.x, pos.y, pos.z, context.getSide().getOpposite().asRotation(), 0); e.setComponents(data.getFrame(), data.getWheel(), data.getEngine()); context.getWorld().spawnEntity(e); stack.decrement(1); diff --git a/src/main/java/motobox/recipe/MechanicTableRecipe.java b/src/main/java/motobox/recipe/MechanicTableRecipe.java index 21d83e5..830a5d8 100644 --- a/src/main/java/motobox/recipe/MechanicTableRecipe.java +++ b/src/main/java/motobox/recipe/MechanicTableRecipe.java @@ -8,15 +8,14 @@ import net.minecraft.recipe.Recipe; import net.minecraft.recipe.RecipeSerializer; import net.minecraft.recipe.RecipeType; +import net.minecraft.registry.DynamicRegistryManager; import net.minecraft.util.Identifier; import net.minecraft.world.World; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Map; -import java.util.Set; import java.util.function.BiConsumer; -import java.util.function.Consumer; public class MechanicTableRecipe implements Recipe, Comparable { public static final Identifier ID = Motobox.id("mechanic_table"); @@ -50,7 +49,7 @@ public boolean matches(SimpleInventory inventory, World world) { } @Override - public ItemStack craft(SimpleInventory inv) { + public ItemStack craft(SimpleInventory inv, DynamicRegistryManager registryManager) { for (var ing : this.ingredients.keySet()) { int count = ingredients.get(ing); for (int i = 0; i < inv.size(); i++) { @@ -71,7 +70,7 @@ public boolean fits(int width, int height) { } @Override - public ItemStack getOutput() { + public ItemStack getOutput(DynamicRegistryManager registryManager) { return this.result; } diff --git a/src/main/java/motobox/resource/MotoboxAssets.java b/src/main/java/motobox/resource/MotoboxAssets.java index 445c536..a099170 100644 --- a/src/main/java/motobox/resource/MotoboxAssets.java +++ b/src/main/java/motobox/resource/MotoboxAssets.java @@ -102,7 +102,7 @@ public static void addSlope(String name, String texture) { } } - // Yes I didn't want to do actual smart datagen so behold + // 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) { diff --git a/src/main/java/motobox/screen/MechanicTableScreen.java b/src/main/java/motobox/screen/MechanicTableScreen.java index 50461cb..7ef3648 100644 --- a/src/main/java/motobox/screen/MechanicTableScreen.java +++ b/src/main/java/motobox/screen/MechanicTableScreen.java @@ -3,12 +3,11 @@ import com.mojang.blaze3d.systems.RenderSystem; import motobox.Motobox; import motobox.recipe.MechanicTableRecipe; -import net.minecraft.client.gui.DrawableHelper; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.ingame.HandledScreen; 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.item.ItemStack; import net.minecraft.recipe.Ingredient; @@ -103,37 +102,37 @@ protected void handledScreenTick() { } @Override - public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { - super.render(matrices, mouseX, mouseY, delta); - this.drawMouseoverTooltip(matrices, mouseX, mouseY); + public void render(DrawContext context, int mouseX, int mouseY, float delta) { + super.render(context, mouseX, mouseY, delta); + this.drawMouseoverTooltip(context, mouseX, mouseY); } private void preDraw() { RenderSystem.setShader(GameRenderer::getPositionTexProgram); RenderSystem.setShaderColor(1, 1, 1, 1); - RenderSystem.setShaderTexture(0, TEXTURE); } @Override - protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY) { - this.renderBackground(matrices); + protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) { + this.renderBackground(context); this.preDraw(); - this.drawTexture(matrices, this.x, this.y, 0, 0, this.backgroundWidth, this.backgroundHeight); - this.drawCategoryBar(matrices, mouseX, mouseY); - this.drawRecipes(matrices, mouseX, mouseY); + context.drawTexture(TEXTURE, this.x, this.y, 0, 0, this.backgroundWidth, this.backgroundHeight); + this.drawCategoryBar(context, mouseX, mouseY); + this.drawRecipes(context, mouseX, mouseY); - this.drawMissingIngredients(matrices); + this.drawMissingIngredients(context); } @Override - protected void drawForeground(MatrixStack matrices, int mouseX, int mouseY) { - this.textRenderer.draw(matrices, this.title, (float)this.titleX, (float)this.titleY, 0xffffffff); - this.textRenderer.draw(matrices, this.playerInventoryTitle, (float)this.playerInventoryTitleX, (float)this.playerInventoryTitleY, 4210752); + protected void drawForeground(DrawContext context, int mouseX, int mouseY) { + context.drawText(this.textRenderer, this.title, this.titleX, this.titleY, 0xffffffff, false); + context.drawText(this.textRenderer, this.playerInventoryTitle, this.playerInventoryTitleX, this.playerInventoryTitleY, 0x404040, false); int hoveredRecipe = this.getHoveredRecipe(mouseX, mouseY); if (hoveredRecipe >= 0) { - this.renderTooltip(matrices, this.handler.recipes.get(hoveredRecipe).getOutput(), mouseX - this.x, mouseY - this.y); + assert this.client != null; + context.drawItemTooltip(this.textRenderer, this.handler.recipes.get(hoveredRecipe).getOutput(this.client.world.getRegistryManager()), mouseX - this.x, mouseY - this.y); } } @@ -202,21 +201,20 @@ 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(DrawContext context, Ingredient ing, int x, int y) { + context.fill(x, y, x + 16, y + 16, 0x45FF0000); var stacks = ing.getMatchingStacks(); ItemStack stack = stacks[MathHelper.floor((float)this.time / 30) % stacks.length]; stack.setCount(handler.missingIngredients.get(ing)); - itemRenderer.renderInGuiWithOverrides(stack, x, y); - itemRenderer.renderGuiItemOverlay(client.textRenderer, stack, x, y); + context.drawItemInSlot(this.textRenderer, stack, x, y); RenderSystem.depthFunc(516); - DrawableHelper.fill(matrices, x, y, x + 16, y + 16, 0x30FFFFFF); + context.fill(x, y, x + 16, y + 16, 0x30FFFFFF); RenderSystem.depthFunc(515); } - protected void drawMissingIngredients(MatrixStack matrices) { + protected void drawMissingIngredients(DrawContext context) { var inputInv = this.handler.inputInv; var missingIngs = new ArrayDeque<>(this.handler.missingIngredients.keySet()); @@ -225,7 +223,7 @@ protected void drawMissingIngredients(MatrixStack matrices) { int y = this.y + 88; if (inputInv.getStack(i).isEmpty()) { - this.drawMissingIngredient(matrices, missingIngs.removeFirst(), x, y); + this.drawMissingIngredient(context, missingIngs.removeFirst(), x, y); } } } @@ -279,21 +277,21 @@ protected int getHoveredRecipe(int mouseX, int mouseY) { return -2; } - protected void drawCategoryBar(MatrixStack matrices, int mouseX, int mouseY) { + protected void drawCategoryBar(DrawContext context, int mouseX, int mouseY) { int hoveredCatButton = this.getHoveredCategoryButton(mouseX, mouseY); this.preDraw(); - this.drawTexture(matrices, this.categoryButtonsX, this.categoryButtonsY, + context.drawTexture(TEXTURE, 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, + context.drawTexture(TEXTURE, this.categoryButtonsX + (CATEGORY_BUTTON_AREA_WIDTH - CATEGORY_BUTTON_WIDTH), this.categoryButtonsY, 188, 17 + (hoveredCatButton > 0 ? CATEGORY_BUTTON_HEIGHT : 0), CATEGORY_BUTTON_WIDTH, CATEGORY_BUTTON_HEIGHT); if (this.categoryTitle != null) { - DrawableHelper.drawCenteredTextWithShadow(matrices, this.textRenderer, this.categoryTitle, this.x + 120, this.y + 8, 0xFFFFFF); + context.drawCenteredTextWithShadow(this.textRenderer, this.categoryTitle, this.x + 120, this.y + 8, 0xFFFFFF); } } - protected void drawRecipes(MatrixStack matrices, int mouseX, int mouseY) { + protected void drawRecipes(DrawContext context, int mouseX, int mouseY) { if (this.orderedCategories.size() > 0) { var recipes = this.recipes.get(this.orderedCategories.get(this.currentCategory)); @@ -315,7 +313,7 @@ protected void drawRecipes(MatrixStack matrices, int mouseX, int mouseY) { state = RecipeButtonState.HOVERED; } - this.drawRecipeEntry(entry, matrices, x, y, state); + this.drawRecipeEntry(entry, context, x, y, state); } else { break; } @@ -332,15 +330,16 @@ protected void drawRecipes(MatrixStack matrices, int mouseX, int mouseY) { 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); + context.drawTexture(TEXTURE, 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, DrawContext context, 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); + context.drawTexture(TEXTURE, 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); + assert this.client != null; + var stack = entry.recipe.getOutput(this.client.world.getRegistryManager()); + context.drawItemInSlot(this.textRenderer, stack, x, y); } public record RecipeEntry(int id, MechanicTableRecipe recipe) {} diff --git a/src/main/java/motobox/screen/MechanicTableScreenHandler.java b/src/main/java/motobox/screen/MechanicTableScreenHandler.java index 345af0c..02f39de 100644 --- a/src/main/java/motobox/screen/MechanicTableScreenHandler.java +++ b/src/main/java/motobox/screen/MechanicTableScreenHandler.java @@ -67,7 +67,7 @@ public MechanicTableScreenHandler(int syncId, PlayerInventory playerInv, ScreenH public Optional getSelectedRecipe() { int id = this.selectedRecipe.get(); - return (id >= 0 && this.recipes.size() > 0 && id < this.recipes.size()) ? Optional.of(this.recipes.get(id)) : Optional.empty(); + return (id >= 0 && !this.recipes.isEmpty() && id < this.recipes.size()) ? Optional.of(this.recipes.get(id)) : Optional.empty(); } public int getSelectedRecipeId() { @@ -85,7 +85,7 @@ private void updateRecipeState() { this.getSelectedRecipe().ifPresent(recipe -> { if (recipe.matches(this.inputInv, this.world)) { - this.outputSlot.setStack(recipe.getOutput().copy()); + this.outputSlot.setStack(recipe.getOutput(this.world.getRegistryManager()).copy()); } else { this.outputSlot.setStack(ItemStack.EMPTY); } @@ -112,8 +112,8 @@ private void selectRecipe(int id) { } @Override - public void close(PlayerEntity player) { - super.close(player); + public void onClosed(PlayerEntity player) { + super.onClosed(player); this.outputSlot.setStack(ItemStack.EMPTY); this.context.run((world, pos) -> this.dropInventory(player, this.inputInv)); @@ -141,7 +141,7 @@ public ItemStack quickMove(PlayerEntity player, int fromSlotId) { // Items transferred out of output slot if (fromSlotId == this.outputSlot.id) { - fromItem.onCraft(fromStack, player.world, player); + fromItem.onCraft(fromStack, player.getWorld(), player); if (!this.insertItem(fromStack, this.playerInvSlot, this.playerInvSlot + 36, true)) { return ItemStack.EMPTY; } @@ -205,7 +205,7 @@ public void onTakeItem(PlayerEntity player, ItemStack stack) { MechanicTableScreenHandler.this.getSelectedRecipe() .ifPresent(recipe -> { - recipe.craft(MechanicTableScreenHandler.this.inputInv); + recipe.craft(MechanicTableScreenHandler.this.inputInv, MechanicTableScreenHandler.this.world.getRegistryManager()); stack.getItem().onCraft(stack, player.getWorld(), player); MechanicTableScreenHandler.this.updateRecipeState(); }); diff --git a/src/main/java/motobox/screen/SingleSlotScreen.java b/src/main/java/motobox/screen/SingleSlotScreen.java index c6850d3..99d6187 100644 --- a/src/main/java/motobox/screen/SingleSlotScreen.java +++ b/src/main/java/motobox/screen/SingleSlotScreen.java @@ -2,10 +2,10 @@ import com.mojang.blaze3d.systems.RenderSystem; import motobox.Motobox; +import net.minecraft.client.gui.DrawContext; 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; @@ -22,18 +22,17 @@ public SingleSlotScreen(SingleSlotScreenHandler handler, PlayerInventory invento } @Override - public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { - super.render(matrices, mouseX, mouseY, delta); - this.drawMouseoverTooltip(matrices, mouseX, mouseY); + public void render(DrawContext context, int mouseX, int mouseY, float delta) { + super.render(context, mouseX, mouseY, delta); + this.drawMouseoverTooltip(context, mouseX, mouseY); } @Override - protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY) { - this.renderBackground(matrices); + protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) { + this.renderBackground(context); RenderSystem.setShader(GameRenderer::getPositionTexProgram); RenderSystem.setShaderColor(1, 1, 1, 1); - RenderSystem.setShaderTexture(0, TEXTURE); - this.drawTexture(matrices, this.x, this.y, 0, 0, this.backgroundWidth, this.backgroundHeight); + context.drawTexture(TEXTURE, this.x, this.y, 0, 0, this.backgroundWidth, this.backgroundHeight); } } diff --git a/src/main/java/motobox/screen/VehicleHud.java b/src/main/java/motobox/screen/VehicleHud.java index a806a85..1aaaf27 100644 --- a/src/main/java/motobox/screen/VehicleHud.java +++ b/src/main/java/motobox/screen/VehicleHud.java @@ -5,10 +5,9 @@ import motobox.util.AUtils; import motobox.util.midnightcontrols.ControllerUtils; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawableHelper; +import net.minecraft.client.gui.DrawContext; 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; @@ -25,8 +24,8 @@ public enum VehicleHud { new ControlHint("drift", options -> options.jumpKey) ); - public static void render(MatrixStack matrices, PlayerEntity player, VehicleEntity vehicle, float tickDelta) { - renderSpeedometer(matrices, vehicle); + public static void render(DrawContext context, PlayerEntity player, VehicleEntity vehicle, float tickDelta) { + renderSpeedometer(context, vehicle); if (!ControllerUtils.inControllerMode()) { float alpha = Math.max(0, (vehicle.getStandStillTime() * 2) - 1); @@ -35,26 +34,26 @@ public static void render(MatrixStack matrices, PlayerEntity player, VehicleEnti // 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); + renderControlHints(context, alpha); } } } - private static void renderSpeedometer(MatrixStack matrices, VehicleEntity vehicle) { + private static void renderSpeedometer(DrawContext context, VehicleEntity vehicle) { float speed = (float) vehicle.getEffectiveSpeed() * 20; int color = 0xFFFFFF; if (vehicle.getBoostTimer() > 0) color = 0xFF6F00; if (vehicle.getTurboCharge() > VehicleEntity.SMALL_TURBO_TIME) color = 0xFFEA4A; if (vehicle.getTurboCharge() > VehicleEntity.MEDIUM_TURBO_TIME) color = 0x7DE9FF; if (vehicle.getTurboCharge() > VehicleEntity.LARGE_TURBO_TIME) color = 0x906EFF; - DrawableHelper.drawTextWithShadow(matrices, MinecraftClient.getInstance().textRenderer, Text.literal(AUtils.DEC_TWO_PLACES.format(convert(speed)) + " km/h"), 20, 20, color); + context.drawText(MinecraftClient.getInstance().textRenderer, Text.literal(AUtils.DEC_TWO_PLACES.format(convert(speed)) + " km/h"), 20, 20, color, true); } private static float convert(float blockPerSecond) { return (float) (blockPerSecond * 3.6); } - private static void renderControlHints(MatrixStack matrices, float alpha) { + private static void renderControlHints(DrawContext context, float alpha) { int x = 20; int y = 50; var options = MinecraftClient.getInstance().options; @@ -64,11 +63,11 @@ private static void renderControlHints(MatrixStack matrices, float alpha) { var keyTxt = control.getKeybindText(options); int keyTxtWid = font.getWidth(keyTxt); - DrawableHelper.fill(matrices, x, y, x + keyTxtWid + 6, y + 14, ((int)(alpha * 0xAB) << 24)); + context.fill(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); + context.drawText(font, keyTxt, x + 3, y + 3, textColor, true); + context.drawText(font, control.getText(), x + keyTxtWid + 9, y + 3, textColor, true); y += 17; } diff --git a/src/main/java/motobox/util/AUtils.java b/src/main/java/motobox/util/AUtils.java index a4e3b2e..abeb7ac 100644 --- a/src/main/java/motobox/util/AUtils.java +++ b/src/main/java/motobox/util/AUtils.java @@ -169,7 +169,7 @@ public static Color colorFromInt(int color) { } public static boolean canMerge(ItemStack a, ItemStack b) { - return (a.isItemEqual(b)) && (a.getCount() + b.getCount() <= a.getMaxCount()); + return (ItemStack.canCombine(a, b)) && (a.getCount() + b.getCount() <= a.getMaxCount()); } /** diff --git a/src/main/java/motobox/util/SimpleMapContentRegistry.java b/src/main/java/motobox/util/SimpleMapContentRegistry.java index d66711c..376e70b 100644 --- a/src/main/java/motobox/util/SimpleMapContentRegistry.java +++ b/src/main/java/motobox/util/SimpleMapContentRegistry.java @@ -42,7 +42,7 @@ private FeatureSet getEnabledFeaturesClient() { } public V getOrDefault(Identifier name) { - if (orderedKeys.size() == 0) throw new IllegalStateException("Tried to get from empty registry!"); + if (orderedKeys.isEmpty()) throw new IllegalStateException("Tried to get from empty registry!"); return entries.getOrDefault(name, entries.get(orderedKeys.get(0))); } diff --git a/src/main/java/motobox/util/network/PayloadPackets.java b/src/main/java/motobox/util/network/PayloadPackets.java index 082fd6d..130ce5f 100644 --- a/src/main/java/motobox/util/network/PayloadPackets.java +++ b/src/main/java/motobox/util/network/PayloadPackets.java @@ -84,7 +84,7 @@ public static void init() { boolean space = buf.readBoolean(); int entityId = buf.readInt(); server.execute(() -> { - if (player.world.getEntityById(entityId) instanceof VehicleEntity vehicle) { + if (player.getWorld().getEntityById(entityId) instanceof VehicleEntity vehicle) { vehicle.setInputs(fwd, back, left, right, space); vehicle.markDirty(); } @@ -93,7 +93,7 @@ public static void init() { ServerPlayNetworking.registerGlobalReceiver(Motobox.id("request_sync_vehicle_components"), (server, player, handler, buf, responseSender) -> { int entityId = buf.readInt(); server.execute(() -> { - if (player.world.getEntityById(entityId) instanceof VehicleEntity vehicle) { + if (player.getWorld().getEntityById(entityId) instanceof VehicleEntity vehicle) { sendSyncVehicleComponentsPacket(vehicle, player); sendSyncVehicleAttachmentsPacket(vehicle, player); @@ -113,7 +113,7 @@ public static void initClient() { PacketByteBuf dup = PacketByteBufs.copy(buf); int entityId = dup.readInt(); client.execute(() -> { - if (client.player.world.getEntityById(entityId) instanceof VehicleEntity vehicle) { + if (client.player.getWorld().getEntityById(entityId) instanceof VehicleEntity vehicle) { vehicle.readSyncToClientData(dup); } }); @@ -124,7 +124,7 @@ public static void initClient() { var wheel = VehicleWheel.REGISTRY.getOrDefault(Identifier.tryParse(buf.readString())); var engine = VehicleEngine.REGISTRY.getOrDefault(Identifier.tryParse(buf.readString())); client.execute(() -> { - if (client.player.world.getEntityById(entityId) instanceof VehicleEntity vehicle) { + if (client.player.getWorld().getEntityById(entityId) instanceof VehicleEntity vehicle) { vehicle.setComponents(frame, wheel, engine); } }); @@ -134,7 +134,7 @@ public static void initClient() { 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 VehicleEntity vehicle) { + if (client.player.getWorld().getEntityById(entityId) instanceof VehicleEntity vehicle) { vehicle.setRearAttachment(rearAtt); vehicle.setFrontAttachment(frontAtt); } @@ -144,7 +144,7 @@ public static void initClient() { int entityId = buf.readInt(); var banner = buf.readNbt(); client.execute(() -> { - if (client.player.world.getEntityById(entityId) instanceof VehicleEntity vehicle && + if (client.player.getWorld().getEntityById(entityId) instanceof VehicleEntity vehicle && vehicle.getRearAttachment() instanceof BannerPostRearAttachment bannerPost) { bannerPost.setFromNbt(banner); } diff --git a/src/main/java/motobox/vehicle/attachment/BaseAttachment.java b/src/main/java/motobox/vehicle/attachment/BaseAttachment.java index e2e4425..0c9d672 100644 --- a/src/main/java/motobox/vehicle/attachment/BaseAttachment.java +++ b/src/main/java/motobox/vehicle/attachment/BaseAttachment.java @@ -25,7 +25,7 @@ public final VehicleEntity vehicle() { } protected final World world() { - return this.vehicle.world; + return this.vehicle.getWorld(); } public abstract Vec3d pos(); diff --git a/src/main/resources/data/motobox/damage_type/vehicle.json b/src/main/resources/data/motobox/damage_type/vehicle.json new file mode 100644 index 0000000..649336e --- /dev/null +++ b/src/main/resources/data/motobox/damage_type/vehicle.json @@ -0,0 +1,5 @@ +{ + "exhaustion": 0.0, + "message_id": "flyIntoWall", + "scaling": "when_caused_by_living_non_player" +} \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 7d6848b..8ac312b 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -37,7 +37,7 @@ "depends": { "fabricloader": ">=0.11.3", "fabric": "*", - "minecraft": "1.19.x", + "minecraft": ">=1.20 <=1.20.1", "java": ">=17", "fabric-language-kotlin": ">=1.8.6+kotlin.1.7.21", "geckolib": ">=4.0.3"