diff --git a/src/main/java/com/fusionflux/portalcubed/PortalCubed.java b/src/main/java/com/fusionflux/portalcubed/PortalCubed.java index 02af94a2..30abc1c5 100644 --- a/src/main/java/com/fusionflux/portalcubed/PortalCubed.java +++ b/src/main/java/com/fusionflux/portalcubed/PortalCubed.java @@ -23,7 +23,6 @@ import com.fusionflux.portalcubed.gui.FaithPlateScreenHandler; import com.fusionflux.portalcubed.gui.VelocityHelperScreenHandler; import com.fusionflux.portalcubed.items.PortalCubedItems; -import com.fusionflux.portalcubed.optionslist.OptionsListScreenHandler; import com.fusionflux.portalcubed.packet.PortalCubedServerPackets; import com.fusionflux.portalcubed.particle.PortalCubedParticleTypes; import com.fusionflux.portalcubed.sound.PortalCubedSounds; @@ -84,10 +83,10 @@ BuiltInRegistries.MENU, id("faith_plate_screen"), BuiltInRegistries.MENU, id("velocity_helper"), new ExtendedScreenHandlerType<>(VelocityHelperScreenHandler::new) ); - public static final MenuType OPTIONS_LIST_SCREEN_HANDLER = Registry.register( - BuiltInRegistries.MENU, id("options_list"), - new ExtendedScreenHandlerType<>(OptionsListScreenHandler::new) - ); +// public static final MenuType OPTIONS_LIST_SCREEN_HANDLER = Registry.register( +// BuiltInRegistries.MENU, id("options_list"), +// new ExtendedScreenHandlerType<>(OptionsListScreenHandler::new) +// ); public static final double MAX_SPEED = 2225 / 64.0 / 20.0, MAX_SPEED_SQR = MAX_SPEED * MAX_SPEED; @@ -112,7 +111,7 @@ public void onInitialize(ModContainer mod) { } server.execute(() -> { boolean rubberband = false; - if (!(player.level.getEntity(targetEntityId) instanceof Portal portal)) { + if (!(player.level().getEntity(targetEntityId) instanceof Portal portal)) { LOGGER.warn("{} tried to teleport through nonexistent portal", player); handler.teleport(player.getX(), player.getY(), player.getZ(), player.getYRot(), player.getXRot()); CalledValues.setIsTeleporting(player, false); @@ -176,7 +175,7 @@ public void onInitialize(ModContainer mod) { double y = buf.readDouble(); double z = buf.readDouble(); server.execute(() -> { - final BlockEntity entity = player.level.getBlockEntity(target); + final BlockEntity entity = player.level().getBlockEntity(target); if (entity instanceof FaithPlateBlockEntity faithPlateBlockEntity) { faithPlateBlockEntity.setVelX(x); faithPlateBlockEntity.setVelY(y); @@ -211,7 +210,7 @@ public void onInitialize(ModContainer mod) { float rotYaw = buf.readFloat(); UUID cubeuuid = buf.readUUID(); server.execute(() -> { - if (!(player.getLevel().getEntity(cubeuuid) instanceof CorePhysicsEntity cube)) { + if (!(player.serverLevel().getEntity(cubeuuid) instanceof CorePhysicsEntity cube)) { LOGGER.warn("{} tried to drop nonexistent physics object", player); return; } @@ -233,13 +232,13 @@ public void onInitialize(ModContainer mod) { }); ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> { - if (!handler.player.level.getGameRules().getBoolean(PortalCubedGameRules.ALLOW_CROUCH_FLY_GLITCH)) { + if (!handler.player.level().getGameRules().getBoolean(PortalCubedGameRules.ALLOW_CROUCH_FLY_GLITCH)) { // Default is true on the client, so we don't need to send in that case final FriendlyByteBuf buf = PacketByteBufs.create(); buf.writeBoolean(false); handler.send(ServerPlayNetworking.createS2CPacket(PortalCubedClientPackets.ENABLE_CFG, buf)); } - if (handler.player.level.getGameRules().getBoolean(PortalCubedGameRules.USE_PORTAL_HUD)) { + if (handler.player.level().getGameRules().getBoolean(PortalCubedGameRules.USE_PORTAL_HUD)) { // Same as above, but false final FriendlyByteBuf buf = PacketByteBufs.create(); buf.writeBoolean(true); @@ -288,7 +287,7 @@ public void onInitialize(ModContainer mod) { public static void syncFog(ServerPlayer player) { final FriendlyByteBuf buf = PacketByteBufs.create(); - FogSettings.encodeOptional(FogPersistentState.getOrCreate((ServerLevel)player.level).getSettings(), buf); + FogSettings.encodeOptional(FogPersistentState.getOrCreate(player.serverLevel()).getSettings(), buf); ServerPlayNetworking.send(player, PortalCubedClientPackets.SET_CUSTOM_FOG, buf); } @@ -302,11 +301,11 @@ public static void syncFog(ServerLevel world) { } public static void playBounceSound(Entity entity) { - entity.level.playSound( + entity.level().playSound( null, entity.position().x(), entity.position().y(), entity.position().z(), PortalCubedSounds.GEL_BOUNCE_EVENT, SoundSource.BLOCKS, - 1f, 0.95f + entity.level.random.nextFloat() * 0.1f + 1f, 0.95f + entity.level().random.nextFloat() * 0.1f ); } diff --git a/src/main/java/com/fusionflux/portalcubed/PortalTabsLoader.java b/src/main/java/com/fusionflux/portalcubed/PortalTabsLoader.java index e76d0880..71097084 100644 --- a/src/main/java/com/fusionflux/portalcubed/PortalTabsLoader.java +++ b/src/main/java/com/fusionflux/portalcubed/PortalTabsLoader.java @@ -10,6 +10,7 @@ import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.TagParser; +import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.GsonHelper; import net.minecraft.world.flag.FeatureFlagSet; @@ -30,8 +31,6 @@ import java.util.function.Predicate; import java.util.function.Supplier; -import static com.fusionflux.portalcubed.PortalCubed.id; - public class PortalTabsLoader { private static final Map>> CONDITION_TYPES = Map.of( "and", o -> GsonHelper.getAsJsonArray(o, "conditions") @@ -61,19 +60,22 @@ public class PortalTabsLoader { ); public static void load(ModContainer mod) { - final JsonObject jsonObject; + final JsonArray jsonArray; try (Reader reader = Files.newBufferedReader(mod.getPath("portal_tabs.json"))) { - jsonObject = GsonHelper.parse(reader); + jsonArray = GsonHelper.parseArray(reader); } catch (IOException e) { throw new UncheckedIOException(e); } - load(jsonObject); + load(jsonArray); } - private static void load(JsonObject jsonObject) { - for (final var entry : jsonObject.entrySet()) { - final CreativeModeTab.Builder builder = FabricItemGroup.builder(id(entry.getKey())); - final JsonObject entryData = GsonHelper.convertToJsonObject(entry.getValue(), "tab"); + private static void load(JsonArray jsonArray) { + for (final var entry : jsonArray) { + final CreativeModeTab.Builder builder = FabricItemGroup.builder(); + final JsonObject entryData = GsonHelper.convertToJsonObject(entry, "tab"); + if (entryData.has("title")) { + builder.title(Component.Serializer.fromJson(entryData.get("title"))); + } if (entryData.has("icon")) { builder.icon(parseItemStack(entryData.get("icon"), "icon")); } diff --git a/src/main/java/com/fusionflux/portalcubed/blocks/AdhesionGel.java b/src/main/java/com/fusionflux/portalcubed/blocks/AdhesionGel.java index 3a392423..a53cff51 100644 --- a/src/main/java/com/fusionflux/portalcubed/blocks/AdhesionGel.java +++ b/src/main/java/com/fusionflux/portalcubed/blocks/AdhesionGel.java @@ -33,7 +33,7 @@ public void entityInside(BlockState state, Level world, BlockPos pos, Entity ent private void addCollisionEffects(Level world, Entity entity, BlockPos pos, BlockState state) { FriendlyByteBuf info = AdhesionGravityVerifier.packInfo(pos); - if ((entity.isOnGround() && entity.horizontalCollision) || (!entity.isOnGround() && entity.horizontalCollision) || (!entity.isOnGround() && !entity.horizontalCollision)) { + if ((entity.onGround() && entity.horizontalCollision) || (!entity.onGround() && entity.horizontalCollision) || (!entity.onGround() && !entity.horizontalCollision)) { if (((EntityExt) entity).getGelTimer() == 0) { Direction current = GravityChangerAPI.getGravityDirection(entity); diff --git a/src/main/java/com/fusionflux/portalcubed/blocks/AutoPortalBlock.java b/src/main/java/com/fusionflux/portalcubed/blocks/AutoPortalBlock.java index 5a8754ab..a1a997b9 100644 --- a/src/main/java/com/fusionflux/portalcubed/blocks/AutoPortalBlock.java +++ b/src/main/java/com/fusionflux/portalcubed/blocks/AutoPortalBlock.java @@ -30,7 +30,6 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.*; -import net.minecraft.world.level.material.PushReaction; import net.minecraft.world.level.pathfinder.PathComputationType; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec3; @@ -277,13 +276,6 @@ public static int getColor(Level world, BlockPos pos) { ); } - @NotNull - @Override - @SuppressWarnings("deprecation") - public PushReaction getPistonPushReaction(BlockState state) { - return PushReaction.DESTROY; - } - @NotNull @Override @SuppressWarnings("deprecation") diff --git a/src/main/java/com/fusionflux/portalcubed/blocks/BaseGel.java b/src/main/java/com/fusionflux/portalcubed/blocks/BaseGel.java index f4bac92d..e37fb76a 100644 --- a/src/main/java/com/fusionflux/portalcubed/blocks/BaseGel.java +++ b/src/main/java/com/fusionflux/portalcubed/blocks/BaseGel.java @@ -31,7 +31,7 @@ public boolean propagatesSkylightDown(BlockState state, BlockGetter world, Block public static boolean collides(Entity entity, BlockPos pos, BlockState state) { return Shapes.joinIsNotEmpty( - state.getShape(entity.level, pos, CollisionContext.of(entity)).move(pos.getX(), pos.getY(), pos.getZ()), + state.getShape(entity.level(), pos, CollisionContext.of(entity)).move(pos.getX(), pos.getY(), pos.getZ()), Shapes.create(entity.getBoundingBox()), BooleanOp.AND ); diff --git a/src/main/java/com/fusionflux/portalcubed/blocks/MapColorNames.java b/src/main/java/com/fusionflux/portalcubed/blocks/MapColorNames.java new file mode 100644 index 00000000..2cfad968 --- /dev/null +++ b/src/main/java/com/fusionflux/portalcubed/blocks/MapColorNames.java @@ -0,0 +1,76 @@ +package com.fusionflux.portalcubed.blocks; + +import com.google.common.collect.ImmutableMap; +import net.minecraft.world.level.material.MapColor; + +import java.util.Map; + +public class MapColorNames { + public static final Map COLORS = ImmutableMap.builder() + .put("none", MapColor.NONE) + .put("grass", MapColor.GRASS) + .put("sand", MapColor.SAND) + .put("wool", MapColor.WOOL) + .put("fire", MapColor.FIRE) + .put("ice", MapColor.ICE) + .put("metal", MapColor.METAL) + .put("plant", MapColor.PLANT) + .put("snow", MapColor.SNOW) + .put("clay", MapColor.CLAY) + .put("dirt", MapColor.DIRT) + .put("stone", MapColor.STONE) + .put("water", MapColor.WATER) + .put("wood", MapColor.WOOD) + .put("quartz", MapColor.QUARTZ) + .put("color_orange", MapColor.COLOR_ORANGE) + .put("color_magenta", MapColor.COLOR_MAGENTA) + .put("color_light_blue", MapColor.COLOR_LIGHT_BLUE) + .put("color_yellow", MapColor.COLOR_YELLOW) + .put("color_light_green", MapColor.COLOR_LIGHT_GREEN) + .put("color_pink", MapColor.COLOR_PINK) + .put("color_gray", MapColor.COLOR_GRAY) + .put("color_light_gray", MapColor.COLOR_LIGHT_GRAY) + .put("color_cyan", MapColor.COLOR_CYAN) + .put("color_purple", MapColor.COLOR_PURPLE) + .put("color_blue", MapColor.COLOR_BLUE) + .put("color_brown", MapColor.COLOR_BROWN) + .put("color_green", MapColor.COLOR_GREEN) + .put("color_red", MapColor.COLOR_RED) + .put("color_black", MapColor.COLOR_BLACK) + .put("gold", MapColor.GOLD) + .put("diamond", MapColor.DIAMOND) + .put("lapis", MapColor.LAPIS) + .put("emerald", MapColor.EMERALD) + .put("podzol", MapColor.PODZOL) + .put("nether", MapColor.NETHER) + .put("terracotta_white", MapColor.TERRACOTTA_WHITE) + .put("terracotta_orange", MapColor.TERRACOTTA_ORANGE) + .put("terracotta_magenta", MapColor.TERRACOTTA_MAGENTA) + .put("terracotta_light_blue", MapColor.TERRACOTTA_LIGHT_BLUE) + .put("terracotta_yellow", MapColor.TERRACOTTA_YELLOW) + .put("terracotta_light_green", MapColor.TERRACOTTA_LIGHT_GREEN) + .put("terracotta_pink", MapColor.TERRACOTTA_PINK) + .put("terracotta_gray", MapColor.TERRACOTTA_GRAY) + .put("terracotta_light_gray", MapColor.TERRACOTTA_LIGHT_GRAY) + .put("terracotta_cyan", MapColor.TERRACOTTA_CYAN) + .put("terracotta_purple", MapColor.TERRACOTTA_PURPLE) + .put("terracotta_blue", MapColor.TERRACOTTA_BLUE) + .put("terracotta_brown", MapColor.TERRACOTTA_BROWN) + .put("terracotta_green", MapColor.TERRACOTTA_GREEN) + .put("terracotta_red", MapColor.TERRACOTTA_RED) + .put("terracotta_black", MapColor.TERRACOTTA_BLACK) + .put("crimson_nylium", MapColor.CRIMSON_NYLIUM) + .put("crimson_stem", MapColor.CRIMSON_STEM) + .put("crimson_hyphae", MapColor.CRIMSON_HYPHAE) + .put("warped_nylium", MapColor.WARPED_NYLIUM) + .put("warped_stem", MapColor.WARPED_STEM) + .put("warped_hyphae", MapColor.WARPED_HYPHAE) + .put("warped_wart_block", MapColor.WARPED_WART_BLOCK) + .put("deepslate", MapColor.DEEPSLATE) + .put("raw_iron", MapColor.RAW_IRON) + .put("glow_lichen", MapColor.GLOW_LICHEN) + .build(); + + private MapColorNames() { + } +} diff --git a/src/main/java/com/fusionflux/portalcubed/blocks/MaterialColorNames.java b/src/main/java/com/fusionflux/portalcubed/blocks/MaterialColorNames.java deleted file mode 100644 index 76f0c2c8..00000000 --- a/src/main/java/com/fusionflux/portalcubed/blocks/MaterialColorNames.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.fusionflux.portalcubed.blocks; - -import com.google.common.collect.ImmutableMap; -import net.minecraft.world.level.material.MaterialColor; - -import java.util.Map; - -public class MaterialColorNames { - public static final Map COLORS = ImmutableMap.builder() - .put("none", MaterialColor.NONE) - .put("grass", MaterialColor.GRASS) - .put("sand", MaterialColor.SAND) - .put("wool", MaterialColor.WOOL) - .put("fire", MaterialColor.FIRE) - .put("ice", MaterialColor.ICE) - .put("metal", MaterialColor.METAL) - .put("plant", MaterialColor.PLANT) - .put("snow", MaterialColor.SNOW) - .put("clay", MaterialColor.CLAY) - .put("dirt", MaterialColor.DIRT) - .put("stone", MaterialColor.STONE) - .put("water", MaterialColor.WATER) - .put("wood", MaterialColor.WOOD) - .put("quartz", MaterialColor.QUARTZ) - .put("color_orange", MaterialColor.COLOR_ORANGE) - .put("color_magenta", MaterialColor.COLOR_MAGENTA) - .put("color_light_blue", MaterialColor.COLOR_LIGHT_BLUE) - .put("color_yellow", MaterialColor.COLOR_YELLOW) - .put("color_light_green", MaterialColor.COLOR_LIGHT_GREEN) - .put("color_pink", MaterialColor.COLOR_PINK) - .put("color_gray", MaterialColor.COLOR_GRAY) - .put("color_light_gray", MaterialColor.COLOR_LIGHT_GRAY) - .put("color_cyan", MaterialColor.COLOR_CYAN) - .put("color_purple", MaterialColor.COLOR_PURPLE) - .put("color_blue", MaterialColor.COLOR_BLUE) - .put("color_brown", MaterialColor.COLOR_BROWN) - .put("color_green", MaterialColor.COLOR_GREEN) - .put("color_red", MaterialColor.COLOR_RED) - .put("color_black", MaterialColor.COLOR_BLACK) - .put("gold", MaterialColor.GOLD) - .put("diamond", MaterialColor.DIAMOND) - .put("lapis", MaterialColor.LAPIS) - .put("emerald", MaterialColor.EMERALD) - .put("podzol", MaterialColor.PODZOL) - .put("nether", MaterialColor.NETHER) - .put("terracotta_white", MaterialColor.TERRACOTTA_WHITE) - .put("terracotta_orange", MaterialColor.TERRACOTTA_ORANGE) - .put("terracotta_magenta", MaterialColor.TERRACOTTA_MAGENTA) - .put("terracotta_light_blue", MaterialColor.TERRACOTTA_LIGHT_BLUE) - .put("terracotta_yellow", MaterialColor.TERRACOTTA_YELLOW) - .put("terracotta_light_green", MaterialColor.TERRACOTTA_LIGHT_GREEN) - .put("terracotta_pink", MaterialColor.TERRACOTTA_PINK) - .put("terracotta_gray", MaterialColor.TERRACOTTA_GRAY) - .put("terracotta_light_gray", MaterialColor.TERRACOTTA_LIGHT_GRAY) - .put("terracotta_cyan", MaterialColor.TERRACOTTA_CYAN) - .put("terracotta_purple", MaterialColor.TERRACOTTA_PURPLE) - .put("terracotta_blue", MaterialColor.TERRACOTTA_BLUE) - .put("terracotta_brown", MaterialColor.TERRACOTTA_BROWN) - .put("terracotta_green", MaterialColor.TERRACOTTA_GREEN) - .put("terracotta_red", MaterialColor.TERRACOTTA_RED) - .put("terracotta_black", MaterialColor.TERRACOTTA_BLACK) - .put("crimson_nylium", MaterialColor.CRIMSON_NYLIUM) - .put("crimson_stem", MaterialColor.CRIMSON_STEM) - .put("crimson_hyphae", MaterialColor.CRIMSON_HYPHAE) - .put("warped_nylium", MaterialColor.WARPED_NYLIUM) - .put("warped_stem", MaterialColor.WARPED_STEM) - .put("warped_hyphae", MaterialColor.WARPED_HYPHAE) - .put("warped_wart_block", MaterialColor.WARPED_WART_BLOCK) - .put("deepslate", MaterialColor.DEEPSLATE) - .put("raw_iron", MaterialColor.RAW_IRON) - .put("glow_lichen", MaterialColor.GLOW_LICHEN) - .build(); - - private MaterialColorNames() { - } -} diff --git a/src/main/java/com/fusionflux/portalcubed/blocks/PortalBlocksLoader.java b/src/main/java/com/fusionflux/portalcubed/blocks/PortalBlocksLoader.java index bf3e3cf5..0281245f 100644 --- a/src/main/java/com/fusionflux/portalcubed/blocks/PortalBlocksLoader.java +++ b/src/main/java/com/fusionflux/portalcubed/blocks/PortalBlocksLoader.java @@ -16,7 +16,6 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.RotatedPillarBlock; import net.minecraft.world.level.block.SoundType; -import net.minecraft.world.level.material.Material; import org.jetbrains.annotations.Nullable; import org.quiltmc.loader.api.ModContainer; import org.quiltmc.loader.api.minecraft.ClientOnly; @@ -122,7 +121,7 @@ private static BlockData parseBlock(JsonObject json) { ? BuiltInRegistries.BLOCK.getOptional(new ResourceLocation(GsonHelper.getAsString(json, "inherit"))) .map(QuiltBlockSettings::copyOf) .orElseThrow(() -> new IllegalArgumentException("Unknown block " + json.get("inherit"))) - : QuiltBlockSettings.of(Material.STONE) + : PortalCubedBlocks.settings() .strength(3.5f, 3.5f) .requiresTool(); json.remove("inherit"); @@ -137,7 +136,7 @@ private static BlockData parseBlock(JsonObject json) { case "slipperiness" -> settings.friction(GsonHelper.convertToFloat(value, "slipperiness")); case "sounds" -> settings.sound(parseBlockSounds(value)); case "map_color" -> settings.mapColor( - Optional.ofNullable(MaterialColorNames.COLORS.get(GsonHelper.convertToString(value, "map_color"))) + Optional.ofNullable(MapColorNames.COLORS.get(GsonHelper.convertToString(value, "map_color"))) .orElseThrow(() -> new IllegalArgumentException("Unknown map_color " + value)) ); case "render_layer" -> renderLayer = GsonHelper.convertToString(value, "render_layer"); diff --git a/src/main/java/com/fusionflux/portalcubed/blocks/PortalCubedBlocks.java b/src/main/java/com/fusionflux/portalcubed/blocks/PortalCubedBlocks.java index 6f13b7d1..ba75417b 100644 --- a/src/main/java/com/fusionflux/portalcubed/blocks/PortalCubedBlocks.java +++ b/src/main/java/com/fusionflux/portalcubed/blocks/PortalCubedBlocks.java @@ -1,34 +1,14 @@ package com.fusionflux.portalcubed.blocks; -import static com.fusionflux.portalcubed.PortalCubed.id; - -import com.fusionflux.portalcubed.blocks.blockentities.AutoPortalBlockEntity; -import com.fusionflux.portalcubed.blocks.blockentities.BetaFaithPlateBlockEntity; -import com.fusionflux.portalcubed.blocks.blockentities.CatapultBlockEntity; -import com.fusionflux.portalcubed.blocks.blockentities.ExcursionFunnelEmitterBlockEntity; -import com.fusionflux.portalcubed.blocks.blockentities.FaithPlateBlockEntity; -import com.fusionflux.portalcubed.blocks.blockentities.FloorButtonBlockEntity; -import com.fusionflux.portalcubed.blocks.blockentities.LaserEmitterBlockEntity; -import com.fusionflux.portalcubed.blocks.blockentities.LaserNodeBlockEntity; -import com.fusionflux.portalcubed.blocks.blockentities.NeurotoxinBlockEntity; -import com.fusionflux.portalcubed.blocks.blockentities.NeurotoxinEmitterBlockEntity; -import com.fusionflux.portalcubed.blocks.blockentities.OldApFloorButtonBlockEntity; -import com.fusionflux.portalcubed.blocks.blockentities.RocketTurretBlockEntity; -import com.fusionflux.portalcubed.blocks.blockentities.VelocityHelperBlockEntity; +import com.fusionflux.portalcubed.blocks.blockentities.*; import com.fusionflux.portalcubed.blocks.bridge.HardLightBridgeBlock; import com.fusionflux.portalcubed.blocks.bridge.HardLightBridgeEmitterBlock; -import com.fusionflux.portalcubed.blocks.fizzler.DeathFizzlerBlock; -import com.fusionflux.portalcubed.blocks.fizzler.FizzlerBlock; -import com.fusionflux.portalcubed.blocks.fizzler.FizzlerEmitter; -import com.fusionflux.portalcubed.blocks.fizzler.LaserFizzlerBlock; -import com.fusionflux.portalcubed.blocks.fizzler.MatterInquisitionField; -import com.fusionflux.portalcubed.blocks.fizzler.PhysicsRepulsionField; +import com.fusionflux.portalcubed.blocks.fizzler.*; import com.fusionflux.portalcubed.blocks.funnel.ExcursionFunnelEmitterBlock; import com.fusionflux.portalcubed.blocks.funnel.ExcursionFunnelTubeBlock; import com.fusionflux.portalcubed.entity.PortalCubedEntities; import com.fusionflux.portalcubed.items.ExcursionFunnelEmitterBlockItem; import com.fusionflux.portalcubed.items.GelBlobItem; - import net.minecraft.core.Registry; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; @@ -40,65 +20,67 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.material.MaterialColor; - +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.material.MapColor; +import net.minecraft.world.level.material.PushReaction; import org.quiltmc.qsl.block.entity.api.QuiltBlockEntityTypeBuilder; import org.quiltmc.qsl.block.extensions.api.QuiltBlockSettings; import org.quiltmc.qsl.item.setting.api.QuiltItemSettings; +import static com.fusionflux.portalcubed.PortalCubed.id; + public class PortalCubedBlocks { public static final Item BASE_GEL = new Item(new QuiltItemSettings().fireResistant()); - public static final PropulsionGel PROPULSION_GEL = new PropulsionGel(QuiltBlockSettings.of(Material.PLANT).randomTicks().destroyTime(0f).noOcclusion().noCollission().sound(new SoundType(1, -1, SoundEvents.HONEY_BLOCK_BREAK, SoundEvents.HONEY_BLOCK_STEP, SoundEvents.HONEY_BLOCK_PLACE, SoundEvents.HONEY_BLOCK_HIT, SoundEvents.HONEY_BLOCK_FALL)).color(MaterialColor.COLOR_ORANGE)); - public static final RepulsionGel REPULSION_GEL = new RepulsionGel(QuiltBlockSettings.copyOf(PROPULSION_GEL).mapColor(MaterialColor.COLOR_LIGHT_BLUE)); - public static final AdhesionGel ADHESION_GEL = new AdhesionGel(QuiltBlockSettings.copyOf(PROPULSION_GEL).mapColor(MaterialColor.COLOR_PURPLE)); - public static final BaseGel CONVERSION_GEL = new BaseGel(QuiltBlockSettings.copyOf(PROPULSION_GEL).mapColor(MaterialColor.METAL)); - public static final BaseGel REFLECTION_GEL = new ReflectionGel(QuiltBlockSettings.copyOf(PROPULSION_GEL).mapColor(MaterialColor.COLOR_LIGHT_GRAY)); + public static final PropulsionGel PROPULSION_GEL = new PropulsionGel(settings().randomTicks().destroyTime(0f).noOcclusion().noCollission().sound(new SoundType(1, -1, SoundEvents.HONEY_BLOCK_BREAK, SoundEvents.HONEY_BLOCK_STEP, SoundEvents.HONEY_BLOCK_PLACE, SoundEvents.HONEY_BLOCK_HIT, SoundEvents.HONEY_BLOCK_FALL)).mapColor(MapColor.COLOR_ORANGE)); + public static final RepulsionGel REPULSION_GEL = new RepulsionGel(QuiltBlockSettings.copyOf(PROPULSION_GEL).mapColor(MapColor.COLOR_LIGHT_BLUE)); + public static final AdhesionGel ADHESION_GEL = new AdhesionGel(QuiltBlockSettings.copyOf(PROPULSION_GEL).mapColor(MapColor.COLOR_PURPLE)); + public static final BaseGel CONVERSION_GEL = new BaseGel(QuiltBlockSettings.copyOf(PROPULSION_GEL).mapColor(MapColor.METAL)); + public static final BaseGel REFLECTION_GEL = new ReflectionGel(QuiltBlockSettings.copyOf(PROPULSION_GEL).mapColor(MapColor.COLOR_LIGHT_GRAY)); - public static final HardLightBridgeEmitterBlock HLB_EMITTER_BLOCK = new HardLightBridgeEmitterBlock(QuiltBlockSettings.of(Material.STONE).strength(3.5f, 3.5f).requiresCorrectToolForDrops().sound(SoundType.STONE)); - public static final HardLightBridgeBlock HLB_BLOCK = new HardLightBridgeBlock(QuiltBlockSettings.of(Material.STONE).destroyTime(999999f).noOcclusion().explosionResistance(9999999999f).color(MaterialColor.DIAMOND).randomTicks()); + public static final HardLightBridgeEmitterBlock HLB_EMITTER_BLOCK = new HardLightBridgeEmitterBlock(settings().strength(3.5f, 3.5f).requiresCorrectToolForDrops().sound(SoundType.STONE).pushReaction(PushReaction.BLOCK)); + public static final HardLightBridgeBlock HLB_BLOCK = new HardLightBridgeBlock(settings().destroyTime(999999f).noOcclusion().explosionResistance(9999999999f).mapColor(MapColor.DIAMOND).randomTicks().pushReaction(PushReaction.DESTROY)); public static final AutoPortalBlock AUTO_PORTAL_BLOCK = new AutoPortalBlock( - QuiltBlockSettings.of(Material.STONE).strength(3.5f, 3.5f).requiresCorrectToolForDrops().sound(SoundType.STONE) + settings().strength(3.5f, 3.5f).requiresCorrectToolForDrops().sound(SoundType.STONE).pushReaction(PushReaction.DESTROY) ); // TODO: Due to remapping weirdness, QuiltMaterialBuilder couldn't be used properly here. However, the whole material system is redone in 1.20, and neurotoxin is broken anyway, so this is just a temporary patch. - public static final NeurotoxinBlock NEUROTOXIN_BLOCK = new NeurotoxinBlock(QuiltBlockSettings.of(Material.AIR).noOcclusion().noCollission()); - public static final NeurotoxinEmitterBlock NEUROTOXIN_EMITTER = new NeurotoxinEmitterBlock(QuiltBlockSettings.of(Material.STONE).strength(3.5f, 3.5f).requiresCorrectToolForDrops().noOcclusion().noCollission().sound(SoundType.STONE)); - public static final ExcursionFunnelEmitterBlock EXCURSION_FUNNEL_EMITTER = new ExcursionFunnelEmitterBlock(QuiltBlockSettings.of(Material.STONE).strength(3.5f, 3.5f).requiresCorrectToolForDrops().sound(SoundType.STONE)); - public static final ExcursionFunnelTubeBlock EXCURSION_FUNNEL = new ExcursionFunnelTubeBlock(QuiltBlockSettings.of(Material.AIR).noOcclusion().noCollission().randomTicks()); + public static final NeurotoxinBlock NEUROTOXIN_BLOCK = new NeurotoxinBlock(settings().noOcclusion().noCollission()); + public static final NeurotoxinEmitterBlock NEUROTOXIN_EMITTER = new NeurotoxinEmitterBlock(settings().strength(3.5f, 3.5f).requiresCorrectToolForDrops().noOcclusion().noCollission().sound(SoundType.STONE)); + public static final ExcursionFunnelEmitterBlock EXCURSION_FUNNEL_EMITTER = new ExcursionFunnelEmitterBlock(settings().strength(3.5f, 3.5f).requiresCorrectToolForDrops().sound(SoundType.STONE).pushReaction(PushReaction.BLOCK)); + public static final ExcursionFunnelTubeBlock EXCURSION_FUNNEL = new ExcursionFunnelTubeBlock(settings().noOcclusion().noCollission().randomTicks().pushReaction(PushReaction.DESTROY)); - public static final TallButton TALL_BUTTON = new TallButton(QuiltBlockSettings.of(Material.STONE).strength(3.5f, 3.5f).requiresCorrectToolForDrops()); - public static final OldApTallButton OLD_AP_PEDESTAL_BUTTON = new OldApTallButton(QuiltBlockSettings.of(Material.STONE).strength(3.5f, 3.5f).requiresCorrectToolForDrops()); + public static final TallButton TALL_BUTTON = new TallButton(settings().strength(3.5f, 3.5f).requiresCorrectToolForDrops()); + public static final OldApTallButton OLD_AP_PEDESTAL_BUTTON = new OldApTallButton(settings().strength(3.5f, 3.5f).requiresCorrectToolForDrops()); - public static final SlidingDoorBlock PORTAL2DOOR = new SlidingDoorBlock(QuiltBlockSettings.of(Material.STONE).strength(3.5f, 3.5f).requiresCorrectToolForDrops()); - public static final SlidingDoorBlock OCTOPUS_DOOR = new SlidingDoorBlock(QuiltBlockSettings.of(Material.STONE).strength(3.5f, 3.5f).requiresCorrectToolForDrops()); - public static final SlidingDoorBlock OLD_AP_DOOR = new SlidingDoorBlock(QuiltBlockSettings.of(Material.STONE).strength(3.5f, 3.5f).requiresCorrectToolForDrops()); - public static final SlidingDoorBlock PORTAL1DOOR = new SlidingDoorBlock(QuiltBlockSettings.of(Material.STONE).strength(3.5f, 3.5f).requiresCorrectToolForDrops()); + public static final SlidingDoorBlock PORTAL2DOOR = new SlidingDoorBlock(settings().strength(3.5f, 3.5f).requiresCorrectToolForDrops().pushReaction(PushReaction.DESTROY)); + public static final SlidingDoorBlock OCTOPUS_DOOR = new SlidingDoorBlock(settings().strength(3.5f, 3.5f).requiresCorrectToolForDrops().pushReaction(PushReaction.DESTROY)); + public static final SlidingDoorBlock OLD_AP_DOOR = new SlidingDoorBlock(settings().strength(3.5f, 3.5f).requiresCorrectToolForDrops().pushReaction(PushReaction.DESTROY)); + public static final SlidingDoorBlock PORTAL1DOOR = new SlidingDoorBlock(settings().strength(3.5f, 3.5f).requiresCorrectToolForDrops().pushReaction(PushReaction.DESTROY)); public static final BlockEntityType AUTO_PORTAL_BLOCK_ENTITY = QuiltBlockEntityTypeBuilder.create(AutoPortalBlockEntity::new, AUTO_PORTAL_BLOCK).build(); - public static final Block FAITH_PLATE = new FaithPlateBlock(QuiltBlockSettings.of(Material.STONE).destroyTime(999999f).explosionResistance(9999999999f).sound(new SoundType(1, 1, SoundEvents.STONE_BREAK, SoundEvents.STONE_STEP, SoundEvents.STONE_PLACE, SoundEvents.STONE_HIT, SoundEvents.STONE_FALL)), PortalCubedBlocks::getFaithPlateBlockEntity); + public static final Block FAITH_PLATE = new FaithPlateBlock(settings().destroyTime(999999f).explosionResistance(9999999999f).sound(new SoundType(1, 1, SoundEvents.STONE_BREAK, SoundEvents.STONE_STEP, SoundEvents.STONE_PLACE, SoundEvents.STONE_HIT, SoundEvents.STONE_FALL)), PortalCubedBlocks::getFaithPlateBlockEntity); public static final Block BETA_FAITH_PLATE = new FaithPlateBlock(QuiltBlockSettings.copyOf(FAITH_PLATE), PortalCubedBlocks::getBetaFaithPlateBlockEntity); public static final BlockEntityType FAITH_PLATE_BLOCK_ENTITY = QuiltBlockEntityTypeBuilder.create(FaithPlateBlockEntity::new, FAITH_PLATE).build(); public static final BlockEntityType BETA_FAITH_PLATE_BLOCK_ENTITY = QuiltBlockEntityTypeBuilder.create(BetaFaithPlateBlockEntity::new, BETA_FAITH_PLATE).build(); - public static final Block FAITH_PLATE_TARGET = new FaithPlateTargetBlock(QuiltBlockSettings.of(Material.PLANT).destroyTime(0).noOcclusion().noCollission().color(MaterialColor.COLOR_CYAN)); + public static final Block FAITH_PLATE_TARGET = new FaithPlateTargetBlock(settings().destroyTime(0).noOcclusion().noCollission().mapColor(MapColor.COLOR_CYAN)); public static final BlockEntityType NEUROTOXIN_BLOCK_ENTITY = QuiltBlockEntityTypeBuilder.create(NeurotoxinBlockEntity::new, NEUROTOXIN_BLOCK).build(); public static final BlockEntityType NEUROTOXIN_EMITTER_ENTITY = QuiltBlockEntityTypeBuilder.create(NeurotoxinEmitterBlockEntity::new, NEUROTOXIN_EMITTER).build(); public static final BlockEntityType EXCURSION_FUNNEL_EMITTER_ENTITY = QuiltBlockEntityTypeBuilder.create(ExcursionFunnelEmitterBlockEntity::new, EXCURSION_FUNNEL_EMITTER).build(); - public static final PowerBlock POWER_BLOCK = new PowerBlock(QuiltBlockSettings.of(Material.AIR).strength(-1.0F, 3600000.8F).noLootTable().noOcclusion()); + public static final PowerBlock POWER_BLOCK = new PowerBlock(settings().strength(-1.0F, 3600000.8F).noLootTable().noOcclusion()); - public static final Block VELOCITY_HELPER = new VelocityHelperBlock(QuiltBlockSettings.of(Material.AIR).strength(-1.0F, 3600000.8F).noLootTable().noOcclusion()); + public static final Block VELOCITY_HELPER = new VelocityHelperBlock(settings().strength(-1.0F, 3600000.8F).noLootTable().noOcclusion()); public static final BlockEntityType VELOCITY_HELPER_BLOCK_ENTITY = QuiltBlockEntityTypeBuilder.create(VelocityHelperBlockEntity::new, VELOCITY_HELPER).build(); - public static final Block CATAPULT = new CatapultBlock(QuiltBlockSettings.of(Material.AIR).strength(-1.0F, 3600000.8F).noLootTable().noOcclusion()); + public static final Block CATAPULT = new CatapultBlock(settings().strength(-1.0F, 3600000.8F).noLootTable().noOcclusion()); public static final BlockEntityType CATAPULT_BLOCK_ENTITY = QuiltBlockEntityTypeBuilder.create(CatapultBlockEntity::new, CATAPULT).build(); - public static final FizzlerBlock FIZZLER = new FizzlerBlock(QuiltBlockSettings.of(Material.PORTAL).noCollission().strength(-1, 3600000)); - public static final FizzlerEmitter FIZZLER_EMITTER = new FizzlerEmitter(QuiltBlockSettings.of(Material.STONE).strength(3.5f, 3.5f).requiresCorrectToolForDrops().noOcclusion().sound(SoundType.STONE), FIZZLER); + public static final FizzlerBlock FIZZLER = new FizzlerBlock(settings().noCollission().strength(-1, 3600000)); + public static final FizzlerEmitter FIZZLER_EMITTER = new FizzlerEmitter(settings().strength(3.5f, 3.5f).requiresCorrectToolForDrops().noOcclusion().sound(SoundType.STONE), FIZZLER); public static final FizzlerBlock PORTAL_1_FIZZLER = new FizzlerBlock(QuiltBlockSettings.copyOf(FIZZLER)); public static final FizzlerEmitter PORTAL_1_FIZZLER_EMITTER = new FizzlerEmitter(QuiltBlockSettings.copyOf(FIZZLER_EMITTER), PORTAL_1_FIZZLER); public static final FizzlerBlock OLD_APERTURE_FIZZLER = new FizzlerBlock(QuiltBlockSettings.copyOf(FIZZLER)); @@ -114,20 +96,20 @@ public class PortalCubedBlocks { public static final PhysicsRepulsionField PHYSICS_REPULSION_FIELD = new PhysicsRepulsionField(QuiltBlockSettings.copyOf(FIZZLER)); public static final FizzlerEmitter PHYSICS_REPULSION_FIELD_EMITTER = new FizzlerEmitter(QuiltBlockSettings.copyOf(FIZZLER_EMITTER), PHYSICS_REPULSION_FIELD); - public static final LaserEmitterBlock LASER_EMITTER = new LaserEmitterBlock(QuiltBlockSettings.of(Material.STONE).strength(3.5f, 3.5f).requiresCorrectToolForDrops().noOcclusion().sound(SoundType.STONE)); + public static final LaserEmitterBlock LASER_EMITTER = new LaserEmitterBlock(settings().strength(3.5f, 3.5f).requiresCorrectToolForDrops().noOcclusion().sound(SoundType.STONE)); public static final BlockEntityType LASER_EMITTER_BLOCK_ENTITY = QuiltBlockEntityTypeBuilder.create(LaserEmitterBlockEntity::new, LASER_EMITTER).build(); - public static final LaserCatcherBlock LASER_CATCHER = new LaserCatcherBlock(QuiltBlockSettings.of(Material.STONE).strength(3.5f, 3.5f).requiresCorrectToolForDrops().noOcclusion().sound(SoundType.STONE)); - public static final LaserRelayBlock LASER_RELAY = new LaserRelayBlock(QuiltBlockSettings.of(Material.STONE).strength(3.5f, 3.5f).requiresCorrectToolForDrops().noOcclusion().sound(SoundType.STONE)); + public static final LaserCatcherBlock LASER_CATCHER = new LaserCatcherBlock(settings().strength(3.5f, 3.5f).requiresCorrectToolForDrops().noOcclusion().sound(SoundType.STONE)); + public static final LaserRelayBlock LASER_RELAY = new LaserRelayBlock(settings().strength(3.5f, 3.5f).requiresCorrectToolForDrops().noOcclusion().sound(SoundType.STONE)); public static final BlockEntityType LASER_NODE_BLOCK_ENTITY = QuiltBlockEntityTypeBuilder.create(LaserNodeBlockEntity::new, LASER_CATCHER, LASER_RELAY).build(); - public static final FloorButtonBlock FLOOR_BUTTON = new FloorButtonBlock(QuiltBlockSettings.of(Material.STONE).strength(3.5f, 3.5f).requiresCorrectToolForDrops().sound(SoundType.STONE)); + public static final FloorButtonBlock FLOOR_BUTTON = new FloorButtonBlock(settings().strength(3.5f, 3.5f).requiresCorrectToolForDrops().sound(SoundType.STONE)); public static final BlockEntityType FLOOR_BUTTON_BLOCK_ENTITY = QuiltBlockEntityTypeBuilder.create(FloorButtonBlockEntity::new, FLOOR_BUTTON).build(); - public static final OldApFloorButtonBlock OLD_AP_FLOOR_BUTTON = new OldApFloorButtonBlock(QuiltBlockSettings.of(Material.STONE).strength(3.5f, 3.5f).requiresCorrectToolForDrops().sound(SoundType.STONE)); + public static final OldApFloorButtonBlock OLD_AP_FLOOR_BUTTON = new OldApFloorButtonBlock(settings().strength(3.5f, 3.5f).requiresCorrectToolForDrops().sound(SoundType.STONE)); public static final BlockEntityType OLD_AP_FLOOR_BUTTON_BLOCK_ENTITY = QuiltBlockEntityTypeBuilder.create(OldApFloorButtonBlockEntity::new, OLD_AP_FLOOR_BUTTON).build(); - public static final RocketTurretBlock ROCKET_TURRET = new RocketTurretBlock(QuiltBlockSettings.of(Material.STONE).strength(3.5f, 3.5f).requiresCorrectToolForDrops().sound(SoundType.STONE)); + public static final RocketTurretBlock ROCKET_TURRET = new RocketTurretBlock(settings().strength(3.5f, 3.5f).requiresCorrectToolForDrops().sound(SoundType.STONE)); public static final BlockEntityType ROCKET_TURRET_BLOCK_ENTITY = QuiltBlockEntityTypeBuilder.create(RocketTurretBlockEntity::new, ROCKET_TURRET).build(); public static final TagKey BULLET_HOLE_CONCRETE = TagKey.create(Registries.BLOCK, id("bullet_hole_concrete")); @@ -282,4 +264,8 @@ private static BlockEntityType getFaithPlateBlockEntity() private static BlockEntityType getBetaFaithPlateBlockEntity() { return BETA_FAITH_PLATE_BLOCK_ENTITY; } + + public static QuiltBlockSettings settings() { + return QuiltBlockSettings.copyOf(BlockBehaviour.Properties.of()); + } } diff --git a/src/main/java/com/fusionflux/portalcubed/blocks/PropulsionGel.java b/src/main/java/com/fusionflux/portalcubed/blocks/PropulsionGel.java index 63692294..8d285054 100644 --- a/src/main/java/com/fusionflux/portalcubed/blocks/PropulsionGel.java +++ b/src/main/java/com/fusionflux/portalcubed/blocks/PropulsionGel.java @@ -27,7 +27,7 @@ private void addCollisionEffects(Level level, Entity entity) { if (entity.getType().equals(EntityType.BOAT)) { entity.hurt(level.damageSources().magic(), 200); } else { - if (entity.isOnGround()) { + if (entity.onGround()) { if (!entity.isShiftKeyDown()) { if (limiter.check(level, entity)) { if (Math.abs(entity.getDeltaMovement().x) < 2 && Math.abs(entity.getDeltaMovement().z) < 2) { diff --git a/src/main/java/com/fusionflux/portalcubed/blocks/SlidingDoorBlock.java b/src/main/java/com/fusionflux/portalcubed/blocks/SlidingDoorBlock.java index 39955a68..2cd47fec 100644 --- a/src/main/java/com/fusionflux/portalcubed/blocks/SlidingDoorBlock.java +++ b/src/main/java/com/fusionflux/portalcubed/blocks/SlidingDoorBlock.java @@ -19,12 +19,12 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.*; -import net.minecraft.world.level.material.PushReaction; import net.minecraft.world.level.pathfinder.PathComputationType; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.quiltmc.loader.api.minecraft.ClientOnly; @@ -72,6 +72,7 @@ protected SlidingDoorBlock(Properties settings) { this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(OPEN, false).setValue(HINGE, DoorHingeSide.LEFT).setValue(POWERED, false).setValue(HALF, DoubleBlockHalf.LOWER)); } + @NotNull @Override @SuppressWarnings("deprecation") public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) { @@ -86,6 +87,7 @@ public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, Co }; } + @NotNull @Override @SuppressWarnings("deprecation") public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, BlockPos pos, BlockPos posFrom) { @@ -158,6 +160,7 @@ private DoorHingeSide getHinge(BlockPlaceContext ctx) { } } + @NotNull @Override @SuppressWarnings("deprecation") public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { @@ -215,18 +218,14 @@ public static void onBreakInCreative(Level world, BlockPos pos, BlockState state } - @Override - @SuppressWarnings("deprecation") - public PushReaction getPistonPushReaction(BlockState state) { - return PushReaction.DESTROY; - } - + @NotNull @Override @SuppressWarnings("deprecation") public BlockState rotate(BlockState state, Rotation rotation) { return state.setValue(FACING, rotation.rotate(state.getValue(FACING))); } + @NotNull @Override @SuppressWarnings("deprecation") public BlockState mirror(BlockState state, Mirror mirror) { diff --git a/src/main/java/com/fusionflux/portalcubed/blocks/blockentities/CatapultBlockEntity.java b/src/main/java/com/fusionflux/portalcubed/blocks/blockentities/CatapultBlockEntity.java index 545e4700..259c80b2 100644 --- a/src/main/java/com/fusionflux/portalcubed/blocks/blockentities/CatapultBlockEntity.java +++ b/src/main/java/com/fusionflux/portalcubed/blocks/blockentities/CatapultBlockEntity.java @@ -1,9 +1,7 @@ +// TODO: Reimplement GUI without optionslist package com.fusionflux.portalcubed.blocks.blockentities; import com.fusionflux.portalcubed.blocks.PortalCubedBlocks; -import com.fusionflux.portalcubed.optionslist.OptionsListBlockEntity; -import com.fusionflux.portalcubed.optionslist.OptionsListData; -import com.fusionflux.portalcubed.optionslist.OptionsListScreenHandler; import eu.midnightdust.lib.config.MidnightConfig; import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory; import net.minecraft.core.BlockPos; @@ -18,12 +16,14 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; +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.minecraft.world.phys.Vec3; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class CatapultBlockEntity extends OptionsListBlockEntity implements ExtendedScreenHandlerFactory { +public class CatapultBlockEntity extends BlockEntity implements ExtendedScreenHandlerFactory { @MidnightConfig.Entry(min = -30_000_000, max = 30_000_000) private double destX; @@ -49,14 +49,15 @@ public CatapultBlockEntity(BlockPos pos, BlockState state) { @Override public void load(CompoundTag nbt) { - OptionsListData.read(nbt, this); +// OptionsListData.read(nbt, this); } @Override protected void saveAdditional(CompoundTag nbt) { - OptionsListData.write(nbt, this); +// OptionsListData.write(nbt, this); } + @NotNull @Override public CompoundTag getUpdateTag() { return saveWithoutMetadata(); @@ -68,6 +69,7 @@ public Packet getUpdatePacket() { return ClientboundBlockEntityDataPacket.create(this); } + @NotNull @Override public Component getDisplayName() { return Component.translatable(getBlockState().getBlock().getDescriptionId()); @@ -76,7 +78,8 @@ public Component getDisplayName() { @Nullable @Override public AbstractContainerMenu createMenu(int i, Inventory playerInventory, Player playerEntity) { - return new OptionsListScreenHandler(i, worldPosition); + return null; +// return new OptionsListScreenHandler(i, worldPosition); } @Override diff --git a/src/main/java/com/fusionflux/portalcubed/blocks/blockentities/LaserEmitterBlockEntity.java b/src/main/java/com/fusionflux/portalcubed/blocks/blockentities/LaserEmitterBlockEntity.java index bfbe9928..70880ad1 100644 --- a/src/main/java/com/fusionflux/portalcubed/blocks/blockentities/LaserEmitterBlockEntity.java +++ b/src/main/java/com/fusionflux/portalcubed/blocks/blockentities/LaserEmitterBlockEntity.java @@ -184,7 +184,7 @@ public void tick(Level level, BlockPos pos, BlockState state) { if (hitEntity instanceof CorePhysicsEntity) { continue; // TODO: Turrets and chairs burn } - if (!hitEntity.isOnGround()) continue; + if (!hitEntity.onGround()) continue; hitEntity.hurt(pcSources(level).laser(), PortalCubedConfig.laserDamage); hitEntity.setRemainingFireTicks(Math.max(10, hitEntity.getRemainingFireTicks())); final Vec3 velocity = GeneralUtil.calculatePerpendicularVector(ray.start(), ray.end(), hitEntity.position()) diff --git a/src/main/java/com/fusionflux/portalcubed/blocks/blockentities/RocketTurretBlockEntity.java b/src/main/java/com/fusionflux/portalcubed/blocks/blockentities/RocketTurretBlockEntity.java index 38df9aba..c55d9587 100644 --- a/src/main/java/com/fusionflux/portalcubed/blocks/blockentities/RocketTurretBlockEntity.java +++ b/src/main/java/com/fusionflux/portalcubed/blocks/blockentities/RocketTurretBlockEntity.java @@ -247,7 +247,7 @@ public void tick(Level world, BlockPos pos, BlockState state) { //noinspection DataFlowIssue final LivingEntity player = world.getNearestEntity( LivingEntity.class, - TargetingConditions.forCombat().selector(e -> !(e instanceof CorePhysicsEntity) && e.level.clip(new ClipContext( + TargetingConditions.forCombat().selector(e -> !(e instanceof CorePhysicsEntity) && e.level().clip(new ClipContext( eye, e.position().with(Direction.Axis.Y, e.getY(0.5)), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, null )).getType() == HitResult.Type.MISS), null, diff --git a/src/main/java/com/fusionflux/portalcubed/blocks/bridge/HardLightBridgeBlock.java b/src/main/java/com/fusionflux/portalcubed/blocks/bridge/HardLightBridgeBlock.java index ef443d26..325389b3 100644 --- a/src/main/java/com/fusionflux/portalcubed/blocks/bridge/HardLightBridgeBlock.java +++ b/src/main/java/com/fusionflux/portalcubed/blocks/bridge/HardLightBridgeBlock.java @@ -12,7 +12,6 @@ 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.material.PushReaction; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; import org.jetbrains.annotations.NotNull; @@ -99,13 +98,6 @@ public boolean skipRendering(BlockState state, BlockState stateFrom, Direction d return false; } - @SuppressWarnings("deprecation") - @Override - @NotNull - public PushReaction getPistonPushReaction(BlockState state) { - return PushReaction.DESTROY; - } - static VoxelShape makeShape(BlockState state) { Direction facing = state.getValue(FACING); Edge edge = state.getValue(EDGE); diff --git a/src/main/java/com/fusionflux/portalcubed/blocks/bridge/HardLightBridgeEmitterBlock.java b/src/main/java/com/fusionflux/portalcubed/blocks/bridge/HardLightBridgeEmitterBlock.java index fb3138f0..38eaa9cf 100644 --- a/src/main/java/com/fusionflux/portalcubed/blocks/bridge/HardLightBridgeEmitterBlock.java +++ b/src/main/java/com/fusionflux/portalcubed/blocks/bridge/HardLightBridgeEmitterBlock.java @@ -22,7 +22,6 @@ 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.PushReaction; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.Shapes; @@ -149,13 +148,6 @@ public boolean skipRendering(BlockState state, BlockState stateFrom, Direction d return false; } - @SuppressWarnings("deprecation") - @Override - @NotNull - public PushReaction getPistonPushReaction(BlockState state) { - return PushReaction.BLOCK; - } - public static void updateEmission(ServerLevel level, BlockState emitterState, BlockPos emitterPos, boolean powered) { withUpdatesSuppressed(() -> { Direction facing = emitterState.getValue(FACING); diff --git a/src/main/java/com/fusionflux/portalcubed/blocks/fizzler/AbstractFizzlerBlock.java b/src/main/java/com/fusionflux/portalcubed/blocks/fizzler/AbstractFizzlerBlock.java index 11a88c61..f64898eb 100644 --- a/src/main/java/com/fusionflux/portalcubed/blocks/fizzler/AbstractFizzlerBlock.java +++ b/src/main/java/com/fusionflux/portalcubed/blocks/fizzler/AbstractFizzlerBlock.java @@ -100,10 +100,10 @@ protected void createBlockStateDefinition(StateDefinition.Builder { + HudRenderCallback.EVENT.register((graphics, tickDelta) -> { if (!isPortalHudMode()) return; final Minecraft client = Minecraft.getInstance(); assert client.player != null; @@ -384,7 +383,7 @@ Items.LIGHT, new ResourceLocation("level") client.player.getHealth() / client.player.getMaxHealth(), 0.65f, 1f ), 0f, 1f); BufferBuilder bufferBuilder = Tesselator.getInstance().getBuilder(); - final Matrix4f matrix = matrixStack.last().pose(); + final Matrix4f matrix = graphics.pose().last().pose(); final float w = client.getWindow().getGuiScaledWidth(); final float h = client.getWindow().getGuiScaledHeight(); bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); @@ -395,7 +394,7 @@ Items.LIGHT, new ResourceLocation("level") BufferUploader.drawWithShader(bufferBuilder.end()); }); - HudRenderCallback.EVENT.register((matrixStack, tickDelta) -> { + HudRenderCallback.EVENT.register((graphics, tickDelta) -> { if (gelOverlayTimer < 0) return; if (gelOverlayTimer > 100) { gelOverlayTimer = -1; @@ -415,7 +414,7 @@ Items.LIGHT, new ResourceLocation("level") RenderSystem.enableBlend(); RenderSystem.setShaderTexture(0, gelOverlayTexture); BufferBuilder bufferBuilder = Tesselator.getInstance().getBuilder(); - final Matrix4f matrix = matrixStack.last().pose(); + final Matrix4f matrix = graphics.pose().last().pose(); final float w = client.getWindow().getGuiScaledWidth(); final float h = client.getWindow().getGuiScaledHeight(); bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR); @@ -466,17 +465,17 @@ Items.LIGHT, new ResourceLocation("level") WorldRenderEvents.START.register(context -> worldRenderContext = context); - HudRenderCallback.EVENT.register((poseStack, tickDelta) -> { + HudRenderCallback.EVENT.register((graphics, tickDelta) -> { if (!showPos) return; final Minecraft minecraft = Minecraft.getInstance(); if (minecraft.options.renderDebug) return; final LocalPlayer player = minecraft.player; if (player == null) return; - minecraft.font.draw(poseStack, Component.literal("name: ").append(player.getName()), 2, 11, 0xffffffff); + graphics.drawString(minecraft.font, Component.literal("name: ").append(player.getName()), 2, 11, 0xffffffff); - minecraft.font.draw( - poseStack, + graphics.drawString( + minecraft.font, "pos: " + CL_SHOWPOS_FORMAT.format(player.getX()) + ' ' + CL_SHOWPOS_FORMAT.format(player.getY()) + ' ' + CL_SHOWPOS_FORMAT.format(player.getZ()), @@ -489,16 +488,16 @@ Items.LIGHT, new ResourceLocation("level") quat = quat.hamiltonProduct(rotation.get()); } final Vector3d angle = quat.toQuaterniond().getEulerAnglesZXY(new Vector3d()); - minecraft.font.draw( - poseStack, + graphics.drawString( + minecraft.font, "ang: " + CL_SHOWPOS_FORMAT.format(Math.toDegrees(angle.x)) + ' ' + CL_SHOWPOS_FORMAT.format(Mth.wrapDegrees(Math.toDegrees(angle.y) + 180)) + ' ' + CL_SHOWPOS_FORMAT.format(Math.toDegrees(angle.z)), 2, 29, 0xffffffff ); - minecraft.font.draw( - poseStack, + graphics.drawString( + minecraft.font, "vel: " + CL_SHOWPOS_FORMAT.format(player.getDeltaMovement().length()), 2, 38, 0xffffffff ); diff --git a/src/main/java/com/fusionflux/portalcubed/client/gui/FaithPlateScreen.java b/src/main/java/com/fusionflux/portalcubed/client/gui/FaithPlateScreen.java index 45eb5698..50d62c40 100644 --- a/src/main/java/com/fusionflux/portalcubed/client/gui/FaithPlateScreen.java +++ b/src/main/java/com/fusionflux/portalcubed/client/gui/FaithPlateScreen.java @@ -3,7 +3,7 @@ import com.fusionflux.portalcubed.gui.FaithPlateScreenHandler; import com.fusionflux.portalcubed.packet.NetworkingSafetyWrapper; import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.EditBox; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; @@ -65,16 +65,16 @@ private static double getZVar(AbstractContainerMenu handler) { } @Override - protected void renderBg(PoseStack matrices, float delta, int mouseX, int mouseY) { + protected void renderBg(GuiGraphics graphics, float delta, int mouseX, int mouseY) { RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - RenderSystem.setShaderTexture(0, TEXTURE); int x = (width - imageWidth) / 2; int y = (height - imageHeight) / 2; - blit(matrices, x, y, 0, 0, imageWidth, imageHeight); + graphics.blit(TEXTURE, x, y, 0, 0, imageWidth, imageHeight); } + @Override - protected void renderLabels(PoseStack matrices, int mouseX, int mouseY) { + protected void renderLabels(GuiGraphics graphics, int mouseX, int mouseY) { } @Override @@ -156,10 +156,10 @@ protected void init() { } @Override - public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { - renderBackground(matrices); - super.render(matrices, mouseX, mouseY, delta); - renderTooltip(matrices, mouseX, mouseY); + public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { + renderBackground(graphics); + super.render(graphics, mouseX, mouseY, delta); + renderTooltip(graphics, mouseX, mouseY); } diff --git a/src/main/java/com/fusionflux/portalcubed/client/gui/VelocityHelperScreen.java b/src/main/java/com/fusionflux/portalcubed/client/gui/VelocityHelperScreen.java index f24ca7ff..ca6fedbc 100644 --- a/src/main/java/com/fusionflux/portalcubed/client/gui/VelocityHelperScreen.java +++ b/src/main/java/com/fusionflux/portalcubed/client/gui/VelocityHelperScreen.java @@ -5,9 +5,13 @@ import com.fusionflux.portalcubed.blocks.blockentities.VelocityHelperBlockEntity; import com.fusionflux.portalcubed.gui.VelocityHelperScreenHandler; import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.*; +import com.mojang.blaze3d.vertex.BufferBuilder; +import com.mojang.blaze3d.vertex.DefaultVertexFormat; +import com.mojang.blaze3d.vertex.Tesselator; +import com.mojang.blaze3d.vertex.VertexFormat; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.EditBox; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; @@ -47,38 +51,37 @@ public VelocityHelperScreen(VelocityHelperScreenHandler handler, Inventory inven } @Override - protected void renderBg(PoseStack matrices, float delta, int mouseX, int mouseY) { + protected void renderBg(GuiGraphics graphics, float delta, int mouseX, int mouseY) { RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderColor(1, 1, 1, 1); - RenderSystem.setShaderTexture(0, TEXTURE); - blit(matrices, leftPos, topPos, 0, 0, imageWidth, imageHeight); + graphics.blit(TEXTURE, leftPos, topPos, 0, 0, imageWidth, imageHeight); } @Override - protected void renderLabels(PoseStack matrices, int mouseX, int mouseY) { - font.draw(matrices, title, (float)titleLabelX, (float)titleLabelY, 0x404040); + protected void renderLabels(GuiGraphics graphics, int mouseX, int mouseY) { + graphics.drawString(font, title, titleLabelX, titleLabelY, 0x404040); drawTextRightAligned( - matrices, font, + graphics, font, Component.translatable("portalcubed.velocity_helper.flight_duration"), 139, 23, 0x404040 ); drawTextCentered( - matrices, font, + graphics, font, Component.translatable("portalcubed.velocity_helper.condition"), imageWidth / 2, 39, 0x404040 ); drawTextCentered( - matrices, font, + graphics, font, Component.translatable("portalcubed.velocity_helper.interpolation_curve"), imageWidth / 2, 71, 0x404040 ); } @Override - public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { - renderBackground(matrices); - super.render(matrices, mouseX, mouseY, delta); - renderTooltip(matrices, mouseX, mouseY); + public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { + renderBackground(graphics); + super.render(graphics, mouseX, mouseY, delta); + renderTooltip(graphics, mouseX, mouseY); final Expression curve = icWidget.getExpression(); if (curve != null) { @@ -92,7 +95,7 @@ public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { for (int i = 1; i <= pointCount; i++, x += spacing) { curve.setVariable("x", 1.0 / pointCount * i); final float calculation = (float)Mth.clamp(curve.evaluate(), 0, 1) * 44; - drawLine(matrices, x - spacing, this.topPos + 157 - last, x, this.topPos + 157 - calculation, 0xffffffff); + drawLine(graphics, x - spacing, this.topPos + 157 - last, x, this.topPos + 157 - calculation, 0xffffffff); last = calculation; } } catch (RuntimeException e) { @@ -169,9 +172,9 @@ protected void containerTick() { !icWidget.getValue().isEmpty(); } - public static void drawLine(PoseStack matrices, float x0, float y0, float x1, float y1, int color) { - final Matrix4f model = matrices.last().pose(); - final Matrix3f normal = matrices.last().normal(); + public static void drawLine(GuiGraphics graphics, float x0, float y0, float x1, float y1, int color) { + final Matrix4f model = graphics.pose().last().pose(); + final Matrix3f normal = graphics.pose().last().normal(); final float mag = Math.invsqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)); final float normalX = Math.abs(x1 - x0) * mag; final float normalY = Math.abs(y1 - y0) * mag; @@ -186,11 +189,11 @@ public static void drawLine(PoseStack matrices, float x0, float y0, float x1, fl Tesselator.getInstance().end(); } - public static void drawTextRightAligned(PoseStack matrices, Font textRenderer, Component text, int x, int y, int color) { - textRenderer.draw(matrices, text, x - textRenderer.width(text), y, color); + public static void drawTextRightAligned(GuiGraphics graphics, Font font, Component text, int x, int y, int color) { + graphics.drawString(font, text, x - font.width(text), y, color); } - public static void drawTextCentered(PoseStack matrices, Font textRenderer, Component text, int x, int y, int color) { - textRenderer.draw(matrices, text, x - textRenderer.width(text) / 2f, y, color); + public static void drawTextCentered(GuiGraphics graphics, Font font, Component text, int x, int y, int color) { + graphics.drawString(font, text, x - font.width(text) / 2, y, color); } } diff --git a/src/main/java/com/fusionflux/portalcubed/client/render/PortalHud.java b/src/main/java/com/fusionflux/portalcubed/client/render/PortalHud.java index 2dd726c9..df901bd1 100644 --- a/src/main/java/com/fusionflux/portalcubed/client/render/PortalHud.java +++ b/src/main/java/com/fusionflux/portalcubed/client/render/PortalHud.java @@ -7,8 +7,12 @@ import com.fusionflux.portalcubed.util.PortalCubedComponents; import com.mojang.blaze3d.platform.Window; import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.*; +import com.mojang.blaze3d.vertex.BufferBuilder; +import com.mojang.blaze3d.vertex.DefaultVertexFormat; +import com.mojang.blaze3d.vertex.Tesselator; +import com.mojang.blaze3d.vertex.VertexFormat; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.EquipmentSlot; @@ -21,7 +25,7 @@ public class PortalHud { private static final ResourceLocation ROUND_TEXTURE = id("textures/gui/active_portal_indicator.png"); private static final ResourceLocation SQUARE_TEXTURE = id("textures/gui/active_portal_indicator_square.png"); - public static void renderPortals(@SuppressWarnings("unused") PoseStack matrices, @SuppressWarnings("unused") float tickDelta) { + public static void renderPortals(@SuppressWarnings("unused") GuiGraphics graphics, @SuppressWarnings("unused") float tickDelta) { renderPortalSide(false, -9, -9, 16); renderPortalSide(true, 0, -5, 0); } diff --git a/src/main/java/com/fusionflux/portalcubed/client/render/entity/PortalRenderer.java b/src/main/java/com/fusionflux/portalcubed/client/render/entity/PortalRenderer.java index abfe0491..58542286 100644 --- a/src/main/java/com/fusionflux/portalcubed/client/render/entity/PortalRenderer.java +++ b/src/main/java/com/fusionflux/portalcubed/client/render/entity/PortalRenderer.java @@ -102,11 +102,11 @@ public void renderPortal( private void renderOtherEntities(Portal entity, PoseStack poseStack, float tickDelta, MultiBufferSource buffer, int packedLight) { if (renderPhase != PortalRenderPhase.ENTITY || !entity.getActive()) return; final UUID otherUuid = entity.getLinkedPortalUUID().orElse(null); - if (otherUuid == null || !(((LevelExt)entity.level).getEntityByUuid(otherUuid) instanceof Portal otherPortal)) return; + if (otherUuid == null || !(((LevelExt)entity.level()).getEntityByUuid(otherUuid) instanceof Portal otherPortal)) return; final double oplx = Mth.lerp(tickDelta, otherPortal.xOld, otherPortal.getX()); final double oply = Mth.lerp(tickDelta, otherPortal.yOld, otherPortal.getY()); final double oplz = Mth.lerp(tickDelta, otherPortal.zOld, otherPortal.getZ()); - final List otherEntities = otherPortal.level.getEntities(otherPortal, otherPortal.getBoundingBox().deflate(0.01), e -> !e.isInvisible()); + final List otherEntities = otherPortal.level().getEntities(otherPortal, otherPortal.getBoundingBox().deflate(0.01), e -> !e.isInvisible()); final EntityRenderDispatcher dispatcher = Minecraft.getInstance().getEntityRenderDispatcher(); final boolean renderHitboxes = dispatcher.shouldRenderHitBoxes(); dispatcher.setRenderHitBoxes(false); diff --git a/src/main/java/com/fusionflux/portalcubed/commands/FizzleCommand.java b/src/main/java/com/fusionflux/portalcubed/commands/FizzleCommand.java index 25f0c506..0cf0c2b1 100644 --- a/src/main/java/com/fusionflux/portalcubed/commands/FizzleCommand.java +++ b/src/main/java/com/fusionflux/portalcubed/commands/FizzleCommand.java @@ -28,7 +28,7 @@ public static void register(CommandDispatcher dispatcher) { } fizzle(entities); ctx.getSource().sendSuccess( - Component.translatable("portalcubed.command.fizzle.success", entities.size()), + () -> Component.translatable("portalcubed.command.fizzle.success", entities.size()), true ); return entities.size(); diff --git a/src/main/java/com/fusionflux/portalcubed/commands/FogCommand.java b/src/main/java/com/fusionflux/portalcubed/commands/FogCommand.java index 08980ce6..41e0ac08 100644 --- a/src/main/java/com/fusionflux/portalcubed/commands/FogCommand.java +++ b/src/main/java/com/fusionflux/portalcubed/commands/FogCommand.java @@ -68,7 +68,7 @@ private static > ArgumentBuilde public static int getFog(CommandContext ctx, boolean defaultDimension) throws CommandSyntaxException { final ServerLevel dimension = getDimension(ctx, defaultDimension); - ctx.getSource().sendSuccess(Component.translatable( + ctx.getSource().sendSuccess(() -> Component.translatable( "portalcubed.command.fog.success", dimension.dimension().location(), FogPersistentState.getOrCreate(dimension).getSettings() @@ -80,7 +80,7 @@ public static int resetFog(CommandContext ctx, boolean defau final ServerLevel dimension = getDimension(ctx, defaultDimension); FogPersistentState.getOrCreate(dimension).setSettings(null); PortalCubed.syncFog(dimension); - ctx.getSource().sendSuccess(Component.translatable( + ctx.getSource().sendSuccess(() -> Component.translatable( "portalcubed.command.fog.reset.success", dimension.dimension().location() ), true); @@ -103,7 +103,7 @@ public static int setFog(CommandContext ctx, boolean default ); FogPersistentState.getOrCreate(dimension).setSettings(settings); PortalCubed.syncFog(dimension); - ctx.getSource().sendSuccess(Component.translatable( + ctx.getSource().sendSuccess(() -> Component.translatable( "portalcubed.command.fog.set.success", dimension.dimension().location(), settings @@ -116,7 +116,7 @@ public static int presetFog(CommandContext ctx, boolean defa final FogPreset preset = getEnumConstant(ctx, "preset", FogPreset.class); FogPersistentState.getOrCreate(dimension).setSettings(preset.getSettings()); PortalCubed.syncFog(dimension); - ctx.getSource().sendSuccess(Component.translatable( + ctx.getSource().sendSuccess(() -> Component.translatable( "portalcubed.command.fog.preset.success", dimension.dimension().location(), preset diff --git a/src/main/java/com/fusionflux/portalcubed/commands/LaserSongCommand.java b/src/main/java/com/fusionflux/portalcubed/commands/LaserSongCommand.java index e3423e8b..ac4b021f 100644 --- a/src/main/java/com/fusionflux/portalcubed/commands/LaserSongCommand.java +++ b/src/main/java/com/fusionflux/portalcubed/commands/LaserSongCommand.java @@ -38,7 +38,7 @@ public static void register(CommandDispatcher dispatcher) { } entity.setSound(song); ctx.getSource().sendSuccess( - Component.translatable("portalcubed.command.lasersong.success", pos, song), + () -> Component.translatable("portalcubed.command.lasersong.success", pos, song), true ); return 1; diff --git a/src/main/java/com/fusionflux/portalcubed/entity/AdventureCoreEntity.java b/src/main/java/com/fusionflux/portalcubed/entity/AdventureCoreEntity.java index 9463094e..d2bc6bd9 100644 --- a/src/main/java/com/fusionflux/portalcubed/entity/AdventureCoreEntity.java +++ b/src/main/java/com/fusionflux/portalcubed/entity/AdventureCoreEntity.java @@ -15,9 +15,9 @@ public AdventureCoreEntity(EntityType type, Level world @Override public void tick() { - if (!this.level.isClientSide) { + if (!this.level().isClientSide) { if (t == 0) { - level.playSound(null, this, PortalCubedSounds.ADVENTURE_CORE_EVENT, this.getSoundSource(), 1f, 1f); + level().playSound(null, this, PortalCubedSounds.ADVENTURE_CORE_EVENT, this.getSoundSource(), 1f, 1f); t = 3429; } t--; diff --git a/src/main/java/com/fusionflux/portalcubed/entity/AngerCoreEntity.java b/src/main/java/com/fusionflux/portalcubed/entity/AngerCoreEntity.java index 180fc58b..a25a91b7 100644 --- a/src/main/java/com/fusionflux/portalcubed/entity/AngerCoreEntity.java +++ b/src/main/java/com/fusionflux/portalcubed/entity/AngerCoreEntity.java @@ -15,9 +15,9 @@ public AngerCoreEntity(EntityType type, Level world) { @Override public void tick() { - if (!this.level.isClientSide) { + if (!this.level().isClientSide) { if (t == 0) { - level.playSound(null, this, PortalCubedSounds.ANGER_CORE_EVENT, this.getSoundSource(), 1f, 1f); + level().playSound(null, this, PortalCubedSounds.ANGER_CORE_EVENT, this.getSoundSource(), 1f, 1f); t = 401; } t--; diff --git a/src/main/java/com/fusionflux/portalcubed/entity/CakeCoreEntity.java b/src/main/java/com/fusionflux/portalcubed/entity/CakeCoreEntity.java index dca19876..8de421dc 100644 --- a/src/main/java/com/fusionflux/portalcubed/entity/CakeCoreEntity.java +++ b/src/main/java/com/fusionflux/portalcubed/entity/CakeCoreEntity.java @@ -15,9 +15,9 @@ public CakeCoreEntity(EntityType type, Level world) { @Override public void tick() { - if (!this.level.isClientSide) { + if (!this.level().isClientSide) { if (t == 0) { - level.playSound(null, this, PortalCubedSounds.CAKE_CORE_EVENT, this.getSoundSource(), 1f, 1f); + level().playSound(null, this, PortalCubedSounds.CAKE_CORE_EVENT, this.getSoundSource(), 1f, 1f); t = 2407; } t--; diff --git a/src/main/java/com/fusionflux/portalcubed/entity/CompanionCubeEntity.java b/src/main/java/com/fusionflux/portalcubed/entity/CompanionCubeEntity.java index d56d51ec..3d25a3dd 100644 --- a/src/main/java/com/fusionflux/portalcubed/entity/CompanionCubeEntity.java +++ b/src/main/java/com/fusionflux/portalcubed/entity/CompanionCubeEntity.java @@ -17,9 +17,9 @@ public CompanionCubeEntity(EntityType type, Level world @Override public void tick() { super.tick(); - if (!this.level.isClientSide) { + if (!this.level().isClientSide) { if (t == 1500) { - level.playSound(null, this, PortalCubedSounds.COMPANION_CUBE_AMBIANCE_EVENT, this.getSoundSource(), 1f, 1f); + level().playSound(null, this, PortalCubedSounds.COMPANION_CUBE_AMBIANCE_EVENT, this.getSoundSource(), 1f, 1f); } t--; if (t == 0) { diff --git a/src/main/java/com/fusionflux/portalcubed/entity/CorePhysicsEntity.java b/src/main/java/com/fusionflux/portalcubed/entity/CorePhysicsEntity.java index 3d720086..d3ec85e5 100644 --- a/src/main/java/com/fusionflux/portalcubed/entity/CorePhysicsEntity.java +++ b/src/main/java/com/fusionflux/portalcubed/entity/CorePhysicsEntity.java @@ -89,7 +89,7 @@ public boolean isPushable() { @Override public boolean isInvulnerableTo(DamageSource source) { - if (source.isCreativePlayer() || source == damageSources().outOfWorld()) + if (source.isCreativePlayer() || source == damageSources().fellOutOfWorld()) return false; if (!(source.getEntity() instanceof Player player)) return true; @@ -98,7 +98,7 @@ public boolean isInvulnerableTo(DamageSource source) { @Override public boolean hurt(DamageSource source, float amount) { - if (!level.isClientSide && !isInvulnerableTo(source) && !isRemoved()) { + if (!level().isClientSide && !isInvulnerableTo(source) && !isRemoved()) { dropAllDeathLoot(source); discard(); return true; @@ -181,20 +181,20 @@ public void tick() { canUsePortals = getHolderUUID().isEmpty(); Vec3 rotatedOffset = RotationUtil.vecPlayerToWorld(offsetHeight, GravityChangerAPI.getGravityDirection(this)); this.lastPos = this.position(); - this.setDiscardFriction(!this.isOnGround() && !this.level.getBlockState(this.blockPosition()).getBlock().equals(PortalCubedBlocks.EXCURSION_FUNNEL)); + this.setDiscardFriction(!this.onGround() && !this.level().getBlockState(this.blockPosition()).getBlock().equals(PortalCubedBlocks.EXCURSION_FUNNEL)); if (isBeingHeld) { - Player player = (Player) ((LevelExt) level).getEntityByUuid(getHolderUUID().get()); + Player player = (Player) ((LevelExt) level()).getEntityByUuid(getHolderUUID().get()); if (player != null && player.isAlive()) { Vec3 vec3d = player.getEyePosition(0); double d = 1.5; canUsePortals = false; Vec3 vec3d2 = this.getPlayerRotationVector(player.getXRot(), player.getYRot()); Vec3 vec3d3 = vec3d.add((vec3d2.x * d) - rotatedOffset.x, (vec3d2.y * d) - rotatedOffset.y, (vec3d2.z * d) - rotatedOffset.z); - final AdvancedEntityRaycast.Result raycastResult = PortalDirectionUtils.raycast(level, new ClipContext( + final AdvancedEntityRaycast.Result raycastResult = PortalDirectionUtils.raycast(level(), new ClipContext( vec3d, vec3d3, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this )); final Vec3 holdPos = raycastResult.finalHit().getLocation(); - if (!level.isClientSide) { + if (!level().isClientSide) { GravityChangerAPI.addGravity(this, new Gravity(GravityChangerAPI.getGravityDirection(player), 10, 1, "player_interaction")); } this.fallDistance = 0; @@ -241,7 +241,7 @@ public void tick() { this.setDeltaMovement(this.getDeltaMovement().add(0, .81d, 0)); } if (fizzling) { - if (level.isClientSide) { + if (level().isClientSide) { fizzleProgress += Minecraft.getInstance().getFrameTime(); } else { fizzleProgress += 0.05f; @@ -250,11 +250,11 @@ public void tick() { } } } - if (getHolderUUID().isEmpty() && !level.isClientSide) { + if (getHolderUUID().isEmpty() && !level().isClientSide) { //noinspection DataFlowIssue - level.getServer().getPlayerList().broadcast( + level().getServer().getPlayerList().broadcast( null, getX(), getY(), getZ(), 64, - getLevel().dimension(), + level().dimension(), new ClientboundRotateHeadPacket(this, (byte)Mth.floor(getYHeadRot() * 256f / 360f)) ); } @@ -265,7 +265,7 @@ null, getX(), getY(), getZ(), 64, @Override public boolean isControlledByLocalInstance() { - return !level.isClientSide || getHolderUUID().isPresent(); + return !level().isClientSide || getHolderUUID().isPresent(); } @NotNull @@ -299,7 +299,7 @@ public void startFizzlingProgress() { public void fizzle() { if (fizzling) return; fizzling = true; - level.playSound(null, getX(), getY(), getZ(), PortalCubedSounds.MATERIAL_EMANCIPATION_EVENT, SoundSource.NEUTRAL, 0.1f, 1f); + level().playSound(null, getX(), getY(), getZ(), PortalCubedSounds.MATERIAL_EMANCIPATION_EVENT, SoundSource.NEUTRAL, 0.1f, 1f); RayonIntegration.INSTANCE.setNoGravity(this, true); final FriendlyByteBuf buf = PacketByteBufs.create(); buf.writeVarInt(getId()); @@ -343,8 +343,8 @@ public void move(MoverType movementType, Vec3 movement) { if (horizontalCollision) { if (!hasCollided) { hasCollided = true; - if (!level.isClientSide && timeSinceLastSound >= 20) { - level.playSound(null, this, getCollisionSound(), SoundSource.NEUTRAL, 1f, 1f); + if (!level().isClientSide && timeSinceLastSound >= 20) { + level().playSound(null, this, getCollisionSound(), SoundSource.NEUTRAL, 1f, 1f); timeSinceLastSound = 0; } } @@ -359,8 +359,8 @@ protected SoundEvent getCollisionSound() { @Override public void remove(RemovalReason reason) { - if (!level.isClientSide) //noinspection DataFlowIssue - getHolderUUID().ifPresent(value -> PortalCubedComponents.HOLDER_COMPONENT.get(((ServerLevel) level).getEntity(value)).stopHolding()); + if (!level().isClientSide) //noinspection DataFlowIssue + getHolderUUID().ifPresent(value -> PortalCubedComponents.HOLDER_COMPONENT.get(((ServerLevel) level()).getEntity(value)).stopHolding()); super.remove(reason); } @@ -382,9 +382,9 @@ public Fallsounds getFallSounds() { protected void checkFallDamage(double y, boolean onGround, BlockState state, BlockPos pos) { if (onGround) { if (state.isAir() && fallDistance > 0 && getType().is(PortalCubedEntities.P1_ENTITY)) { - final List collisions = level.getEntitiesOfClass(Entity.class, getBoundingBox().expandTowards(0, -0.1, 0), this::canCollideWith); + final List collisions = level().getEntitiesOfClass(Entity.class, getBoundingBox().expandTowards(0, -0.1, 0), this::canCollideWith); for (final Entity collision : collisions) { - collision.hurt(pcSources(level).cube(), fallDistance * 1.5f); + collision.hurt(pcSources(level()).cube(), fallDistance * 1.5f); } } fallDistance = 0; diff --git a/src/main/java/com/fusionflux/portalcubed/entity/CuriosityCoreEntity.java b/src/main/java/com/fusionflux/portalcubed/entity/CuriosityCoreEntity.java index 69df5d2a..10fb6e1b 100644 --- a/src/main/java/com/fusionflux/portalcubed/entity/CuriosityCoreEntity.java +++ b/src/main/java/com/fusionflux/portalcubed/entity/CuriosityCoreEntity.java @@ -15,9 +15,9 @@ public CuriosityCoreEntity(EntityType type, Level world @Override public void tick() { - if (!this.level.isClientSide) { + if (!this.level().isClientSide) { if (t == 0) { - level.playSound(null, this, PortalCubedSounds.CURIOSITY_CORE_EVENT, this.getSoundSource(), 1f, 1f); + level().playSound(null, this, PortalCubedSounds.CURIOSITY_CORE_EVENT, this.getSoundSource(), 1f, 1f); t = 346; } t--; diff --git a/src/main/java/com/fusionflux/portalcubed/entity/EnergyPelletEntity.java b/src/main/java/com/fusionflux/portalcubed/entity/EnergyPelletEntity.java index de30964e..ad43ef48 100644 --- a/src/main/java/com/fusionflux/portalcubed/entity/EnergyPelletEntity.java +++ b/src/main/java/com/fusionflux/portalcubed/entity/EnergyPelletEntity.java @@ -86,10 +86,10 @@ public void resetLife() { @Override public void tick() { super.tick(); - if (level.isClientSide) return; + if (level().isClientSide) return; Vec3 vel = getDeltaMovement(); { - final var catapult = level.getBlockEntity(blockPosition(), PortalCubedBlocks.CATAPULT_BLOCK_ENTITY); + final var catapult = level().getBlockEntity(blockPosition(), PortalCubedBlocks.CATAPULT_BLOCK_ENTITY); if (catapult.isPresent()) { ((EntityExt)this).collidedWithCatapult(catapult.get()); vel = getDeltaMovement(); @@ -104,7 +104,7 @@ public void tick() { kill(null); } // life < 0 means green pellet if (tickCount == 1) { - level.playSound(null, position().x, position().y, position().z, PortalCubedSounds.PELLET_SPAWN_EVENT, SoundSource.HOSTILE, 1f, 1f); + level().playSound(null, position().x, position().y, position().z, PortalCubedSounds.PELLET_SPAWN_EVENT, SoundSource.HOSTILE, 1f, 1f); } Direction bouncedDir = null; if (verticalCollision) { @@ -123,8 +123,8 @@ public void tick() { } setDeltaMovement(vel); if (bouncedDir != null) { - level.playSound(null, this, PortalCubedSounds.PELLET_BOUNCE_EVENT, SoundSource.HOSTILE, 0.4f, 1f); - if (level instanceof ServerLevel serverLevel) { + level().playSound(null, this, PortalCubedSounds.PELLET_BOUNCE_EVENT, SoundSource.HOSTILE, 0.4f, 1f); + if (level() instanceof ServerLevel serverLevel) { final Vec3 spawnPos = serverLevel.clip(new ClipContext( position(), position().add(vel.with(bouncedDir.getAxis(), -vel.get(bouncedDir.getAxis()))), @@ -144,13 +144,13 @@ public void tick() { } } if ((tickCount - 1) % 34 == 0) { - level.playSound(null, this, PortalCubedSounds.PELLET_TRAVEL_EVENT, SoundSource.HOSTILE, 0.4f, 1f); + level().playSound(null, this, PortalCubedSounds.PELLET_TRAVEL_EVENT, SoundSource.HOSTILE, 0.4f, 1f); } - final HitResult hit = ProjectileUtil.getHitResult(this, this::canHit); + final HitResult hit = ProjectileUtil.getHitResultOnMoveVector(this, this::canHit); if (hit.getType() == HitResult.Type.ENTITY) { bounceOrKill((LivingEntity)((EntityHitResult)hit).getEntity()); } else { - final LivingEntity hit2 = level.getNearestEntity( + final LivingEntity hit2 = level().getNearestEntity( LivingEntity.class, TargetingConditions.forNonCombat().selector(this::canHit), null, getX(), getY(), getZ(), @@ -183,22 +183,22 @@ private void bounceOrKill(LivingEntity entity) { )); final double mag = vel.length(); setDeltaMovement(Math.cos(newAngle) * mag, vel.y, Math.sin(newAngle) * mag); - level.playSound(null, this, PortalCubedSounds.PELLET_BOUNCE_EVENT, SoundSource.HOSTILE, 0.4f, 1f); + level().playSound(null, this, PortalCubedSounds.PELLET_BOUNCE_EVENT, SoundSource.HOSTILE, 0.4f, 1f); } else { kill(entity); } } private void kill(@Nullable LivingEntity entity) { - level.playSound(null, position().x, position().y, position().z, PortalCubedSounds.PELLET_EXPLODE_EVENT, SoundSource.HOSTILE, 0.8f, 1f); - if (level instanceof ServerLevel serverLevel) { + level().playSound(null, position().x, position().y, position().z, PortalCubedSounds.PELLET_EXPLODE_EVENT, SoundSource.HOSTILE, 0.8f, 1f); + if (level() instanceof ServerLevel serverLevel) { serverLevel.sendParticles( PortalCubedParticleTypes.ENERGY_SPARK, getX(), getY(), getZ(), 100, 0.1, 0.1, 0.1, 3.5 ); } if (entity != null) { - entity.hurt(pcSources(level).vaporization(), PortalCubedConfig.pelletDamage); + entity.hurt(pcSources(level()).vaporization(), PortalCubedConfig.pelletDamage); } kill(); } diff --git a/src/main/java/com/fusionflux/portalcubed/entity/FactCoreEntity.java b/src/main/java/com/fusionflux/portalcubed/entity/FactCoreEntity.java index 3d4d3030..5c2afba9 100644 --- a/src/main/java/com/fusionflux/portalcubed/entity/FactCoreEntity.java +++ b/src/main/java/com/fusionflux/portalcubed/entity/FactCoreEntity.java @@ -15,9 +15,9 @@ public FactCoreEntity(EntityType type, Level world) { @Override public void tick() { - if (!this.level.isClientSide) { + if (!this.level().isClientSide) { if (t == 0) { - level.playSound(null, this, PortalCubedSounds.FACT_CORE_EVENT, this.getSoundSource(), 1f, 1f); + level().playSound(null, this, PortalCubedSounds.FACT_CORE_EVENT, this.getSoundSource(), 1f, 1f); t = 5500; } t--; diff --git a/src/main/java/com/fusionflux/portalcubed/entity/GelBlobEntity.java b/src/main/java/com/fusionflux/portalcubed/entity/GelBlobEntity.java index f7aa01c0..864d9cbd 100644 --- a/src/main/java/com/fusionflux/portalcubed/entity/GelBlobEntity.java +++ b/src/main/java/com/fusionflux/portalcubed/entity/GelBlobEntity.java @@ -99,7 +99,7 @@ public void tick() { Vec3 vec3d3 = this.position(); Vec3 vec3d2 = vec3d3.add(vec3d); - HitResult hitResult = this.level.clip(new ClipContext(vec3d3, vec3d2, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this)); + HitResult hitResult = this.level().clip(new ClipContext(vec3d3, vec3d2, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this)); if (hitResult.getType() != HitResult.Type.MISS) { vec3d2 = hitResult.getLocation(); } @@ -150,7 +150,7 @@ public void tick() { @Nullable protected EntityHitResult getEntityCollision(Vec3 currentPosition, Vec3 nextPosition) { return ProjectileUtil.getEntityHitResult( - this.level, this, currentPosition, nextPosition, this.getBoundingBox().expandTowards(this.getDeltaMovement()).inflate(1.0), this::canHitEntity + this.level(), this, currentPosition, nextPosition, this.getBoundingBox().expandTowards(this.getDeltaMovement()).inflate(1.0), this::canHitEntity ); } @@ -158,7 +158,7 @@ protected EntityHitResult getEntityCollision(Vec3 currentPosition, Vec3 nextPosi protected void onHit(HitResult hitResult) { if (hitResult.getType() == HitResult.Type.MISS) return; kill(); - if (!level.isClientSide) { + if (!level().isClientSide) { if (hitResult instanceof EntityHitResult ehr && ehr.getEntity() instanceof ServerPlayer serverPlayer) { final FriendlyByteBuf buf = PacketByteBufs.create(); buf.writeResourceLocation(BuiltInRegistries.BLOCK.getKey(getGel())); @@ -176,17 +176,17 @@ protected void onHit(HitResult hitResult) { protected void checkFallDamage(double heightDifference, boolean onGround, BlockState landedState, BlockPos landedPosition) { super.checkFallDamage(heightDifference, onGround, landedState, landedPosition); kill(); - if (!level.isClientSide) { + if (!level().isClientSide) { explode(); } } public void explode() { - level.playSound(null, getX(), getY(), getZ(), PortalCubedSounds.GEL_SPLAT_EVENT, SoundSource.NEUTRAL, 0.5f, 1f); + level().playSound(null, getX(), getY(), getZ(), PortalCubedSounds.GEL_SPLAT_EVENT, SoundSource.NEUTRAL, 0.5f, 1f); final FriendlyByteBuf buf = PacketByteBufs.create(); buf.writeResourceLocation(BuiltInRegistries.BLOCK.getKey(getGel())); final int overlayDiameter = getSize() + 1; - level.getEntities( + level().getEntities( EntityType.PLAYER, AABB.ofSize(position(), overlayDiameter, overlayDiameter, overlayDiameter), p -> p instanceof ServerPlayer @@ -210,7 +210,7 @@ public void explode() { return; } for (final Vec3 angle : ANGLES) { - final BlockHitResult hit = level.clip(new ClipContext( + final BlockHitResult hit = level().clip(new ClipContext( origin, origin.add(angle.scale(radius)), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, @@ -222,15 +222,15 @@ public void explode() { } private void maybeExplodeAt(BlockHitResult hit) { - final BlockState hitState = level.getBlockState(hit.getBlockPos()); - if (!hitState.isFaceSturdy(level, hit.getBlockPos(), hit.getDirection())) return; + final BlockState hitState = level().getBlockState(hit.getBlockPos()); + if (!hitState.isFaceSturdy(level(), hit.getBlockPos(), hit.getDirection())) return; final BlockPos sidePos = hit.getBlockPos().relative(hit.getDirection()); - final BlockState sideState = level.getBlockState(sidePos); + final BlockState sideState = level().getBlockState(sidePos); final BooleanProperty property = MultifaceBlock.getFaceProperty(hit.getDirection().getOpposite()); if (sideState.is(getGel())) { - level.setBlockAndUpdate(sidePos, sideState.setValue(property, true)); - } else if (sideState.getMaterial().isReplaceable() || sideState.getBlock() instanceof BaseGel) { - level.setBlockAndUpdate(sidePos, getGel().defaultBlockState().setValue(property, true)); + level().setBlockAndUpdate(sidePos, sideState.setValue(property, true)); + } else if (sideState.canBeReplaced() || sideState.getBlock() instanceof BaseGel) { + level().setBlockAndUpdate(sidePos, getGel().defaultBlockState().setValue(property, true)); } } diff --git a/src/main/java/com/fusionflux/portalcubed/entity/Portal.java b/src/main/java/com/fusionflux/portalcubed/entity/Portal.java index 87bd0c04..50c770a8 100644 --- a/src/main/java/com/fusionflux/portalcubed/entity/Portal.java +++ b/src/main/java/com/fusionflux/portalcubed/entity/Portal.java @@ -152,7 +152,7 @@ private void setActive(boolean active) { public Direction getFacingDirection() { final Vec3 normal = getNormal(); final double x = normal.x, y = normal.y, z = normal.z; - final Direction result = Direction.fromNormal((int)x, (int)y, (int)z); + final Direction result = Direction.fromDelta((int)x, (int)y, (int)z); return result != null ? result : Direction.getNearest((float)x, (float)y, (float)z); } @@ -215,7 +215,7 @@ public void setDestination(Optional destination) { @Override public void kill() { getOwnerUUID().ifPresent(uuid -> { - Entity player = ((ServerLevel) level).getEntity(uuid); + Entity player = ((ServerLevel) level()).getEntity(uuid); CalledValues.removePortals(player, this.getUUID()); }); super.kill(); @@ -225,8 +225,8 @@ public void kill() { public void tick() { this.makeBoundingBox(); this.calculateCutoutBox(); - if (!this.level.isClientSide) { - final ServerLevel serverLevel = (ServerLevel)level; + if (!this.level().isClientSide) { + final ServerLevel serverLevel = (ServerLevel)level(); serverLevel.getChunkSource().addRegionTicket(TicketType.PORTAL, chunkPosition(), 2, blockPosition()); getOwnerUUID().ifPresent(uuid -> { @@ -246,7 +246,7 @@ public void tick() { if (!validate()) { this.kill(); - level.playSound(null, getX(), getY(), getZ(), PortalCubedSounds.ENTITY_PORTAL_CLOSE, SoundSource.NEUTRAL, .1F, 1F); + level().playSound(null, getX(), getY(), getZ(), PortalCubedSounds.ENTITY_PORTAL_CLOSE, SoundSource.NEUTRAL, .1F, 1F); } } @@ -291,15 +291,15 @@ private boolean validateBehind() { Mth.floor(portalBox.maxY + EPSILON) + 1, Mth.floor(portalBox.maxZ + EPSILON) + 1 ); - Direction forward = Objects.requireNonNull(Direction.fromNormal(BlockPos.containing(getNormal()))); + Direction forward = getFacingDirection(); BooleanProperty coveringWall = MultifaceBlock.getFaceProperty(forward.getOpposite()); - Player owner = getOwnerUUID().map(level::getPlayerByUUID).orElse(null); + Player owner = getOwnerUUID().map(level()::getPlayerByUUID).orElse(null); while (iter.advance()) { final BlockPos pos = new BlockPos(iter.nextX(), iter.nextY(), iter.nextZ()); if (!AABB.of(BoundingBox.fromCorners(pos, pos)).intersects(portalBox)) continue; - BlockState wall = level.getBlockState(pos); - BlockState facade = level.getBlockState(pos.relative(forward)); + BlockState wall = level().getBlockState(pos); + BlockState facade = level().getBlockState(pos.relative(forward)); BlockState portalSurface; if (!facade.is(PortalCubedBlocks.PORTAL_NONSOLID) && // non-solids fallback to the wall facade.getOptionalValue(coveringWall).orElse(Boolean.FALSE)) { // if property is present and true, facade covers the wall @@ -316,7 +316,7 @@ private boolean validateBehind() { return false; } - final VoxelShape shape = wall.getCollisionShape(level, pos, CollisionContext.of(this)); + final VoxelShape shape = wall.getCollisionShape(level(), pos, CollisionContext.of(this)); if ( shape.move(pos.getX(), pos.getY(), pos.getZ()) .toAabbs() @@ -348,12 +348,12 @@ private boolean validateFront() { while (iter.advance()) { final BlockPos pos = new BlockPos(iter.nextX(), iter.nextY(), iter.nextZ()); if (!AABB.of(BoundingBox.fromCorners(pos, pos)).intersects(portalBox)) continue; - final BlockState state = level.getBlockState(pos); + final BlockState state = level().getBlockState(pos); if (state.is(PortalCubedBlocks.PORTAL_NONSOLID)) continue; if (state.is(PortalCubedBlocks.PORTAL_SOLID)) { return false; } - final VoxelShape shape = state.getCollisionShape(level, pos, CollisionContext.of(this)); + final VoxelShape shape = state.getCollisionShape(level(), pos, CollisionContext.of(this)); if ( shape.move(pos.getX(), pos.getY(), pos.getZ()) .toAabbs() diff --git a/src/main/java/com/fusionflux/portalcubed/entity/RadioEntity.java b/src/main/java/com/fusionflux/portalcubed/entity/RadioEntity.java index 8fb66113..489671e2 100644 --- a/src/main/java/com/fusionflux/portalcubed/entity/RadioEntity.java +++ b/src/main/java/com/fusionflux/portalcubed/entity/RadioEntity.java @@ -117,7 +117,7 @@ public void tick() { @NotNull @Override protected InteractionResult mobInteract(Player player, InteractionHand hand) { - if (!level.isClientSide && player.getItemInHand(hand).is(PortalCubedItems.WRENCHES)) { + if (!level().isClientSide && player.getItemInHand(hand).is(PortalCubedItems.WRENCHES)) { setAllowMute(!isAllowMute()); if (isAllowMute()) { player.displayClientMessage(Component.translatable("portalcubed.radio.allow_mute"), true); diff --git a/src/main/java/com/fusionflux/portalcubed/entity/RocketEntity.java b/src/main/java/com/fusionflux/portalcubed/entity/RocketEntity.java index 75219c88..7c2bc54c 100644 --- a/src/main/java/com/fusionflux/portalcubed/entity/RocketEntity.java +++ b/src/main/java/com/fusionflux/portalcubed/entity/RocketEntity.java @@ -55,7 +55,7 @@ protected void addAdditionalSaveData(@NotNull CompoundTag nbt) { public void tick() { super.tick(); if (fizzling) { - if (level.isClientSide) { + if (level().isClientSide) { fizzleProgress += Minecraft.getInstance().getFrameTime(); } else { fizzleProgress += 0.05f; @@ -67,19 +67,19 @@ public void tick() { setDeltaMovement(Vec3.directionFromRotation(getXRot(), getYRot()).scale(SPEED)); } move(MoverType.SELF, getDeltaMovement()); - if (!level.isClientSide && tickCount > 0 && tickCount % 13 == 0) { - level.playSound(null, this, PortalCubedSounds.ROCKET_FLY_EVENT, SoundSource.HOSTILE, 1, 1); + if (!level().isClientSide && tickCount > 0 && tickCount % 13 == 0) { + level().playSound(null, this, PortalCubedSounds.ROCKET_FLY_EVENT, SoundSource.HOSTILE, 1, 1); } if (fizzling) return; - if (level.isClientSide) { - level.addParticle( + if (level().isClientSide) { + level().addParticle( ParticleTypes.SMOKE, getX() + random.nextGaussian() * 0.1, getY() + random.nextGaussian() * 0.1, getZ() + random.nextGaussian() * 0.1, 0, 0, 0 ); - level.addParticle( + level().addParticle( ParticleTypes.SMALL_FLAME, getX() + random.nextGaussian() * 0.1, getY() + random.nextGaussian() * 0.1, @@ -88,11 +88,11 @@ public void tick() { ); return; } - final HitResult hit = ProjectileUtil.getHitResult(this, this::canHit); + final HitResult hit = ProjectileUtil.getHitResultOnMoveVector(this, this::canHit); if (hit.getType() == HitResult.Type.ENTITY) { explode((LivingEntity)((EntityHitResult)hit).getEntity()); } else { - final LivingEntity hit2 = level.getNearestEntity( + final LivingEntity hit2 = level().getNearestEntity( LivingEntity.class, TargetingConditions.forNonCombat().selector(this::canHit), null, getX(), getY(), getZ(), @@ -115,7 +115,7 @@ protected void onInsideBlock(BlockState state) { state.getFluidState().is(PortalCubedFluids.TOXIC_GOO.still) || state.getFluidState().is(PortalCubedFluids.TOXIC_GOO.flowing) ) { - level.playSound(null, getX(), getY(), getZ(), PortalCubedSounds.ROCKET_GOO_EVENT, SoundSource.HOSTILE, 1, 1); + level().playSound(null, getX(), getY(), getZ(), PortalCubedSounds.ROCKET_GOO_EVENT, SoundSource.HOSTILE, 1, 1); kill(); } } @@ -131,9 +131,9 @@ public void explode(@Nullable LivingEntity entity) { PortalCubedConfig.rocketDamage ); } - level.playSound(null, getX(), getY(), getZ(), PortalCubedSounds.ROCKET_EXPLODE_EVENT, SoundSource.HOSTILE, 1, 1); - if (level instanceof ServerLevel serverWorld) { - serverWorld.sendParticles( + level().playSound(null, getX(), getY(), getZ(), PortalCubedSounds.ROCKET_EXPLODE_EVENT, SoundSource.HOSTILE, 1, 1); + if (level() instanceof ServerLevel serverLevel) { + serverLevel.sendParticles( ParticleTypes.EXPLOSION, getX(), getY(), getZ(), 8, diff --git a/src/main/java/com/fusionflux/portalcubed/entity/SchrodingerCubeEntity.java b/src/main/java/com/fusionflux/portalcubed/entity/SchrodingerCubeEntity.java index 494b38ec..a19e6194 100644 --- a/src/main/java/com/fusionflux/portalcubed/entity/SchrodingerCubeEntity.java +++ b/src/main/java/com/fusionflux/portalcubed/entity/SchrodingerCubeEntity.java @@ -16,7 +16,7 @@ public SchrodingerCubeEntity(EntityType type, Level wor @Override public SchrodingerCubeEntity getConnection() { - return Objects.requireNonNullElse(level.getNearestEntity( + return Objects.requireNonNullElse(level().getNearestEntity( SchrodingerCubeEntity.class, TargetingConditions.forNonCombat() .selector(e -> Objects.equals(e.getCustomName(), getCustomName())) diff --git a/src/main/java/com/fusionflux/portalcubed/entity/SpaceCoreEntity.java b/src/main/java/com/fusionflux/portalcubed/entity/SpaceCoreEntity.java index bde9e32e..ed344660 100644 --- a/src/main/java/com/fusionflux/portalcubed/entity/SpaceCoreEntity.java +++ b/src/main/java/com/fusionflux/portalcubed/entity/SpaceCoreEntity.java @@ -15,9 +15,9 @@ public SpaceCoreEntity(EntityType type, Level world) { @Override public void tick() { - if (!this.level.isClientSide) { + if (!this.level().isClientSide) { if (t == 0) { - level.playSound(null, this, PortalCubedSounds.SPACE_CORE_EVENT, this.getSoundSource(), 1f, 1f); + level().playSound(null, this, PortalCubedSounds.SPACE_CORE_EVENT, this.getSoundSource(), 1f, 1f); t = 2765; } t--; diff --git a/src/main/java/com/fusionflux/portalcubed/entity/StorageCubeEntity.java b/src/main/java/com/fusionflux/portalcubed/entity/StorageCubeEntity.java index be8e1357..ee1240ea 100644 --- a/src/main/java/com/fusionflux/portalcubed/entity/StorageCubeEntity.java +++ b/src/main/java/com/fusionflux/portalcubed/entity/StorageCubeEntity.java @@ -27,7 +27,7 @@ public void setButtonTimer(int time) { @Override public void tick() { super.tick(); - if (!level.isClientSide) { + if (!level().isClientSide) { if (buttonTimer <= 0) { setOnButton(false); } else { diff --git a/src/main/java/com/fusionflux/portalcubed/fluids/PortalCubedFluids.java b/src/main/java/com/fusionflux/portalcubed/fluids/PortalCubedFluids.java index 4d818321..e59e23ae 100644 --- a/src/main/java/com/fusionflux/portalcubed/fluids/PortalCubedFluids.java +++ b/src/main/java/com/fusionflux/portalcubed/fluids/PortalCubedFluids.java @@ -9,7 +9,7 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.material.FlowingFluid; -import net.minecraft.world.level.material.MaterialColor; +import net.minecraft.world.level.material.MapColor; import org.quiltmc.qsl.block.extensions.api.QuiltBlockSettings; import org.quiltmc.qsl.item.setting.api.QuiltItemSettings; @@ -22,7 +22,7 @@ public class PortalCubedFluids { public static final FluidRegistryContainer TOXIC_GOO = createFluid( "toxic_goo", new ToxicGooFluid.Flowing(), new ToxicGooFluid.Still(), - still -> new ToxicGooFluid.Block(still, QuiltBlockSettings.copy(Blocks.WATER).color(MaterialColor.TERRACOTTA_GREEN)) + still -> new ToxicGooFluid.Block(still, QuiltBlockSettings.copy(Blocks.WATER).mapColor(MapColor.TERRACOTTA_GREEN)) ); private static FluidRegistryContainer createFluid(String name, FlowingFluid flowing, FlowingFluid still, Function blockSupplier) { diff --git a/src/main/java/com/fusionflux/portalcubed/items/EnergyPelletItem.java b/src/main/java/com/fusionflux/portalcubed/items/EnergyPelletItem.java index 1259a8ec..7fa1b9ba 100644 --- a/src/main/java/com/fusionflux/portalcubed/items/EnergyPelletItem.java +++ b/src/main/java/com/fusionflux/portalcubed/items/EnergyPelletItem.java @@ -15,6 +15,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.DispenserBlock; import net.minecraft.world.phys.Vec3; +import org.jetbrains.annotations.NotNull; public class EnergyPelletItem extends Item { private final boolean isSuper; @@ -24,6 +25,7 @@ public EnergyPelletItem(Properties settings, boolean isSuper) { this.isSuper = isSuper; } + @NotNull @Override public InteractionResultHolder use(Level world, Player user, InteractionHand hand) { final ItemStack item = user.getItemInHand(hand); @@ -35,7 +37,7 @@ public InteractionResultHolder use(Level world, Player user, Interact if (pellet == null) return InteractionResultHolder.pass(item); pellet.setPos(user.getEyePosition(0).add(user.getLookAngle())); Vec3 userVelocity = user.getDeltaMovement(); - if (user.isOnGround()) { + if (user.onGround()) { userVelocity = userVelocity.with(Direction.Axis.Y, 0); } pellet.setDeltaMovement(userVelocity.add(user.getLookAngle().scale(0.25))); @@ -48,6 +50,7 @@ public InteractionResultHolder use(Level world, Player user, Interact public DispenseItemBehavior createDispenserBehavior() { return new DefaultDispenseItemBehavior() { + @NotNull @Override protected ItemStack execute(BlockSource pointer, ItemStack stack) { final EnergyPelletEntity pellet = PortalCubedEntities.ENERGY_PELLET.create(pointer.getLevel()); diff --git a/src/main/java/com/fusionflux/portalcubed/items/PaintGun.java b/src/main/java/com/fusionflux/portalcubed/items/PaintGun.java index 86dfd59f..e3ec768a 100644 --- a/src/main/java/com/fusionflux/portalcubed/items/PaintGun.java +++ b/src/main/java/com/fusionflux/portalcubed/items/PaintGun.java @@ -5,7 +5,6 @@ import com.fusionflux.portalcubed.entity.PortalCubedEntities; import com.fusionflux.portalcubed.packet.NetworkingSafetyWrapper; import com.fusionflux.portalcubed.util.ClickHandlingItem; - import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.InteractionHand; @@ -18,6 +17,7 @@ import net.minecraft.world.item.UseAnim; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.NotNull; import org.quiltmc.qsl.networking.api.PacketByteBufs; public class PaintGun extends Item implements ClickHandlingItem, DyeableLeatherItem { @@ -38,16 +38,17 @@ public int getColor(ItemStack stack) { @Override public InteractionResult onLeftClick(Player user, InteractionHand hand) { - fireGel(user.level, user, FireableGelType.REPULSION); + fireGel(user.level(), user, FireableGelType.REPULSION); return InteractionResult.CONSUME; } @Override public InteractionResult onRightClick(Player user, InteractionHand hand) { - fireGel(user.level, user, FireableGelType.PROPULSION); + fireGel(user.level(), user, FireableGelType.PROPULSION); return InteractionResult.CONSUME; } + @NotNull @Override public UseAnim getUseAnimation(ItemStack stack) { return UseAnim.NONE; diff --git a/src/main/java/com/fusionflux/portalcubed/items/PortalGun.java b/src/main/java/com/fusionflux/portalcubed/items/PortalGun.java index e78ba1a0..9f9cda9e 100644 --- a/src/main/java/com/fusionflux/portalcubed/items/PortalGun.java +++ b/src/main/java/com/fusionflux/portalcubed/items/PortalGun.java @@ -13,7 +13,6 @@ import com.fusionflux.portalcubed.util.PortalCubedComponents; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; - import it.unimi.dsi.fastutil.Pair; import it.unimi.dsi.fastutil.doubles.Double2DoubleFunction; import net.minecraft.client.multiplayer.ClientLevel; @@ -121,13 +120,13 @@ public boolean isSideActive(ClientLevel level, ItemStack stack, boolean rightSid @Override public InteractionResult onLeftClick(Player user, InteractionHand hand) { - shoot(user.level, user, hand, true); + shoot(user.level(), user, hand, true); return InteractionResult.CONSUME; } @Override public InteractionResult onRightClick(Player user, InteractionHand hand) { - shoot(user.level, user, hand, false); + shoot(user.level(), user, hand, false); return InteractionResult.CONSUME; } @@ -222,7 +221,7 @@ protected void shoot(Level world, Player user, InteractionHand hand, boolean lef portalHolder.setColor(this.getSidedColor(stack)); //noinspection DataFlowIssue - final Direction.Axis hAxis = Direction.fromNormal(new BlockPos(right)).getAxis(); + final Direction.Axis hAxis = Direction.fromDelta(right.getX(), right.getY(), right.getZ()).getAxis(); findCorrectOrientation: if (!portalHolder.validate()) { for (final var try_ : FAIL_TRIES.get(Pair.of(up, right))) { @@ -254,7 +253,7 @@ protected void shoot(Level world, Player user, InteractionHand hand, boolean lef if (overlappingPortals.size() == 1) { final Portal overlappingPortal = overlappingPortals.get(0); if (overlappingPortal.getAxisW().equals(portalHolder.getAxisW())) { - final Direction.Axis axis = Objects.requireNonNull(Direction.fromNormal(new BlockPos(right))).getAxis(); + final Direction.Axis axis = Objects.requireNonNull(Direction.fromDelta(right.getX(), right.getY(), right.getZ())).getAxis(); if (overlappingPortal.getOriginPos().get(axis) < portalHolder.getOriginPos().get(axis)) { portalHolder.setOriginPos(portalHolder.getOriginPos().with(axis, overlappingPortal.getOriginPos().get(axis) + 1)); } else { @@ -346,8 +345,8 @@ public static void linkPortals(Portal portal1, Portal portal2, float volume) { portal2.setOtherRotation(Optional.of(portal1.getRotation())); portal2.setLinkedPortalUUID(Optional.of(portal1.getUUID())); - portal1.getLevel().playSound(null, portal1.position().x(), portal1.position().y(), portal1.position().z(), PortalCubedSounds.ENTITY_PORTAL_OPEN, SoundSource.NEUTRAL, volume, 1F); - portal2.getLevel().playSound(null, portal2.position().x(), portal2.position().y(), portal2.position().z(), PortalCubedSounds.ENTITY_PORTAL_OPEN, SoundSource.NEUTRAL, volume, 1F); + portal1.level().playSound(null, portal1.position().x(), portal1.position().y(), portal1.position().z(), PortalCubedSounds.ENTITY_PORTAL_OPEN, SoundSource.NEUTRAL, volume, 1F); + portal2.level().playSound(null, portal2.position().x(), portal2.position().y(), portal2.position().z(), PortalCubedSounds.ENTITY_PORTAL_OPEN, SoundSource.NEUTRAL, volume, 1F); } /** @@ -368,19 +367,19 @@ public HitResult customRaycast(Entity user, double maxDistance, float tickDelta) final Vec3 start = user.getEyePosition(tickDelta); final Vec3 rotation = user.getViewVector(tickDelta); final Vec3 end = start.add(rotation.x * maxDistance, rotation.y * maxDistance, rotation.z * maxDistance); - final Level world = user.level; + final Level level = user.level(); final CollisionContext shapeContext = CollisionContext.of(user); return BlockGetter.traverseBlocks( start, end, null, (context, pos) -> { - final BlockState block = world.getBlockState(pos); + final BlockState block = level.getBlockState(pos); if (block.is(PortalCubedBlocks.PORTAL_NONSOLID)) { return null; } final VoxelShape blockShape = block.is(PortalCubedBlocks.PORTAL_SOLID) - ? block.getShape(world, pos, shapeContext) - : block.getCollisionShape(world, pos, shapeContext); - return world.clipWithInteractionOverride(start, end, pos, blockShape, block); + ? block.getShape(level, pos, shapeContext) + : block.getCollisionShape(level, pos, shapeContext); + return level.clipWithInteractionOverride(start, end, pos, blockShape, block); }, context -> { final Vec3 offset = start.subtract(end); diff --git a/src/main/java/com/fusionflux/portalcubed/mechanics/CrossPortalInteraction.java b/src/main/java/com/fusionflux/portalcubed/mechanics/CrossPortalInteraction.java index e5b785c3..43d33621 100644 --- a/src/main/java/com/fusionflux/portalcubed/mechanics/CrossPortalInteraction.java +++ b/src/main/java/com/fusionflux/portalcubed/mechanics/CrossPortalInteraction.java @@ -25,7 +25,7 @@ public static BlockHitResult blockInteractionRaycast(@NotNull Level world, @NotN } public static double interactionDistance(@NotNull Entity originEntity, @NotNull Vec3 originPos, @NotNull Vec3 endPos, @NotNull Vec3 regularInteractionPos) { - final var rays = PortalDirectionUtils.raycast(originEntity.level, new ClipContext(originPos, endPos, ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, originEntity)).rays(); + final var rays = PortalDirectionUtils.raycast(originEntity.level(), new ClipContext(originPos, endPos, ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, originEntity)).rays(); if (rays.size() > 1) { var distance = 0.0; for (AdvancedEntityRaycast.Result.Ray ray : rays) { diff --git a/src/main/java/com/fusionflux/portalcubed/mixin/EntityMixin.java b/src/main/java/com/fusionflux/portalcubed/mixin/EntityMixin.java index 5a2d8528..925cf4f7 100644 --- a/src/main/java/com/fusionflux/portalcubed/mixin/EntityMixin.java +++ b/src/main/java/com/fusionflux/portalcubed/mixin/EntityMixin.java @@ -71,9 +71,6 @@ @Mixin(Entity.class) public abstract class EntityMixin implements EntityExt, EntityPortalsAccess, ClientTeleportCheck { - @Shadow - public Level level; - @Unique private double maxFallSpeed = 0; @@ -127,7 +124,7 @@ public void setMaxFallSpeed(double maxFallSpeed) { public abstract boolean isNoGravity(); @Shadow - public abstract boolean isOnGround(); + public abstract boolean onGround(); @Shadow private Vec3 position; @@ -161,6 +158,9 @@ public void setMaxFallSpeed(double maxFallSpeed) { @Shadow public abstract boolean isEffectiveAi(); @Shadow public boolean hasImpulse; + + @Shadow public abstract Level level(); + @Unique private static final AABB NULL_BOX = new AABB(0, 0, 0, 0, 0, 0); @@ -192,7 +192,7 @@ public void tick(CallbackInfo ci) { portalCheckBox = portalCheckBox.expandTowards(entityVelocity.add(0, .08, 0)); - List list = ((Entity) (Object) this).level.getEntitiesOfClass(Portal.class, portalCheckBox); + List list = ((Entity) (Object) this).level().getEntitiesOfClass(Portal.class, portalCheckBox); VoxelShape omittedDirections = Shapes.empty(); for (Portal portal : list) { @@ -220,7 +220,7 @@ public void tick(CallbackInfo ci) { this.gelTransferChangeTimer -= 1; } - if (maxFallSpeed == 10 && level.getBlockState(this.blockPosition()).getBlock() == PortalCubedBlocks.PROPULSION_GEL) { + if (maxFallSpeed == 10 && level().getBlockState(this.blockPosition()).getBlock() == PortalCubedBlocks.PROPULSION_GEL) { maxFallSpeed = 10; } else { if (maxFallSpeed > 0) { @@ -235,7 +235,7 @@ public void tick(CallbackInfo ci) { this.maxFallHeight = rotatedPos.y; } - if (!this.isOnGround()) { + if (!this.onGround()) { if (rotatedPos.y > this.maxFallHeight) { this.maxFallHeight = rotatedPos.y; } @@ -245,7 +245,7 @@ public void tick(CallbackInfo ci) { this.lastVel = this.getDeltaMovement(); - if (level.getBlockState(this.blockPosition()).getBlock() != PortalCubedBlocks.REPULSION_GEL && this.isBounced()) { + if (level().getBlockState(this.blockPosition()).getBlock() != PortalCubedBlocks.REPULSION_GEL && this.isBounced()) { this.setBounced(false); } @@ -257,7 +257,7 @@ public void tick(CallbackInfo ci) { public void tickTail(CallbackInfo ci) { Entity thisEntity = ((Entity) (Object) this); - if (!thisEntity.level.isClientSide() && !(thisEntity instanceof Player) && !(thisEntity instanceof Portal)) { + if (!thisEntity.level().isClientSide() && !(thisEntity instanceof Player) && !(thisEntity instanceof Portal)) { Vec3 entityVelocity = this.getDeltaMovement(); @@ -266,63 +266,58 @@ public void tickTail(CallbackInfo ci) { portalCheckBox = portalCheckBox.expandTowards(entityVelocity.add(0, .08, 0)); - List list = ((Entity) (Object) this).level.getEntitiesOfClass(Portal.class, portalCheckBox); + List list = ((Entity) (Object) this).level().getEntitiesOfClass(Portal.class, portalCheckBox); Portal portal; for (Portal portalCheck : list) { portal = portalCheck; if (this.canChangeDimensions() && portal.getActive() && !CalledValues.getHasTeleportationHappened(thisEntity) && !CalledValues.getIsTeleporting(thisEntity)) { assert portal.getOtherNormal().isPresent(); Direction portalFacing = portal.getFacingDirection(); - final Vec3 otherNormal = portal.getOtherNormal().get(); - Direction otherDirec = Direction.fromNormal((int) otherNormal.x(), (int) otherNormal.y(), (int) otherNormal.z()); - if (otherDirec != null) { - - //noinspection ConstantValue - if ((Object)this instanceof LivingEntity) { - entityVelocity = entityVelocity.add(0, .08, 0); - } + //noinspection ConstantValue + if ((Object)this instanceof LivingEntity) { + entityVelocity = entityVelocity.add(0, .08, 0); + } - Vec3 entityEyePos = thisEntity.getEyePosition(); + Vec3 entityEyePos = thisEntity.getEyePosition(); - if (portalFacing.step().x() < 0) { - if (entityEyePos.x() + entityVelocity.x >= portal.position().x() && entityVelocity.x() > 0 && portal.calculateBoundsCheckBox().intersects(thisEntity.getBoundingBox())) { - performTeleport(thisEntity, portal, entityVelocity); - break; - } + if (portalFacing.step().x() < 0) { + if (entityEyePos.x() + entityVelocity.x >= portal.position().x() && entityVelocity.x() > 0 && portal.calculateBoundsCheckBox().intersects(thisEntity.getBoundingBox())) { + performTeleport(thisEntity, portal, entityVelocity); + break; } - if (portalFacing.step().y() < 0) { - if (entityEyePos.y() + entityVelocity.y >= portal.position().y() && entityVelocity.y() > 0 && portal.calculateBoundsCheckBox().intersects(thisEntity.getBoundingBox())) { - performTeleport(thisEntity, portal, entityVelocity); - break; - } + } + if (portalFacing.step().y() < 0) { + if (entityEyePos.y() + entityVelocity.y >= portal.position().y() && entityVelocity.y() > 0 && portal.calculateBoundsCheckBox().intersects(thisEntity.getBoundingBox())) { + performTeleport(thisEntity, portal, entityVelocity); + break; } - if (portalFacing.step().z() < 0) { - if (entityEyePos.z() + entityVelocity.z >= portal.position().z() && entityVelocity.z() > 0 && portal.calculateBoundsCheckBox().intersects(thisEntity.getBoundingBox())) { - performTeleport(thisEntity, portal, entityVelocity); - break; - } + } + if (portalFacing.step().z() < 0) { + if (entityEyePos.z() + entityVelocity.z >= portal.position().z() && entityVelocity.z() > 0 && portal.calculateBoundsCheckBox().intersects(thisEntity.getBoundingBox())) { + performTeleport(thisEntity, portal, entityVelocity); + break; } - if (portalFacing.step().x() > 0) { - if (entityEyePos.x() + entityVelocity.x <= portal.position().x() && entityVelocity.x() < 0 && portal.calculateBoundsCheckBox().intersects(thisEntity.getBoundingBox())) { - performTeleport(thisEntity, portal, entityVelocity); - break; - } + } + if (portalFacing.step().x() > 0) { + if (entityEyePos.x() + entityVelocity.x <= portal.position().x() && entityVelocity.x() < 0 && portal.calculateBoundsCheckBox().intersects(thisEntity.getBoundingBox())) { + performTeleport(thisEntity, portal, entityVelocity); + break; } - if (portalFacing.step().y() > 0) { - if (entityEyePos.y() + entityVelocity.y <= portal.position().y() && entityVelocity.y() < 0 && portal.calculateBoundsCheckBox().intersects(thisEntity.getBoundingBox())) { - performTeleport(thisEntity, portal, entityVelocity); - break; - } + } + if (portalFacing.step().y() > 0) { + if (entityEyePos.y() + entityVelocity.y <= portal.position().y() && entityVelocity.y() < 0 && portal.calculateBoundsCheckBox().intersects(thisEntity.getBoundingBox())) { + performTeleport(thisEntity, portal, entityVelocity); + break; } - if (portalFacing.step().z() > 0) { - if (entityEyePos.z() + entityVelocity.z <= portal.position().z() && entityVelocity.z() < 0 && portal.calculateBoundsCheckBox().intersects(thisEntity.getBoundingBox())) { - performTeleport(thisEntity, portal, entityVelocity); - break; - } + } + if (portalFacing.step().z() > 0) { + if (entityEyePos.z() + entityVelocity.z <= portal.position().z() && entityVelocity.z() < 0 && portal.calculateBoundsCheckBox().intersects(thisEntity.getBoundingBox())) { + performTeleport(thisEntity, portal, entityVelocity); + break; } - } + } } } @@ -359,7 +354,7 @@ private void performTeleport( thisEntity.moveTo(dest.x, dest.y, dest.z, result.yaw(), result.pitch()); thisEntity.setDeltaMovement(result.velocity()); GravityChangerAPI.clearGravity(thisEntity); - if (level instanceof ServerLevel serverWorld) { + if (level() instanceof ServerLevel serverWorld) { final FriendlyByteBuf buf = PacketByteBufs.create(); buf.writeVarInt(getId()); buf.writeDouble(getX()); @@ -492,7 +487,7 @@ private void midBlockCheck(BlockState instance, Level world, BlockPos pos, Entit private void endBlockCheck(CallbackInfo ci) { for (final var entry : leftBlocks.entrySet()) { if (entry.getKey().getBlock() instanceof BlockCollisionTrigger trigger) { - trigger.onEntityLeave(entry.getKey(), level, entry.getValue(), (Entity) (Object) this); + trigger.onEntityLeave(entry.getKey(), level(), entry.getValue(), (Entity) (Object) this); } collidingBlocks.remove(entry.getKey()); } @@ -563,9 +558,9 @@ private void collideWithFizzlersOnMove(Entity self, double x, double y, double z Vec3 newPos = position(); // based on ProjectileUtil ClipContext ctx = new ClipContext(pos, newPos, Block.OUTLINE, Fluid.NONE, (Entity) (Object) this); - BlockHitResult hit = level.clip(ctx); + BlockHitResult hit = level().clip(ctx); if (hit.getType() == Type.BLOCK) { - BlockState state = level.getBlockState(hit.getBlockPos()); + BlockState state = level().getBlockState(hit.getBlockPos()); if (state.getBlock() instanceof AbstractFizzlerBlock fizzler) fizzler.applyEffectsTo((Entity) (Object) this); } @@ -586,7 +581,7 @@ public void collidedWithVelocityHelper(VelocityHelperBlockEntity block) { return; } velocityHelper = block; - velocityHelperStartTime = level.getGameTime(); + velocityHelperStartTime = level().getGameTime(); velocityHelperOffset = Vec3.atCenterOf(block.getBlockPos()).subtract(position()); } @@ -609,7 +604,7 @@ public void collidedWithCatapult(CatapultBlockEntity block) { @Unique private void logVHWarning(String type, RuntimeException e) { //noinspection ConstantValue - if ((Object)this instanceof Player && level.isClientSide) { + if ((Object)this instanceof Player && level().isClientSide) { logVHWarningToChat(type, e); } PortalCubed.LOGGER.info("{} at {}", getVHWarning(type).getString(), velocityHelper.getBlockPos(), e); @@ -638,7 +633,7 @@ private void tickVelocityHelper(CallbackInfo ci) { velocityHelper = null; return; } - double progress = (level.getGameTime() - velocityHelperStartTime) / (double)velocityHelper.getFlightDuration(); + double progress = (level().getGameTime() - velocityHelperStartTime) / (double)velocityHelper.getFlightDuration(); if (progress >= 1.0) { velocityHelper = null; return; diff --git a/src/main/java/com/fusionflux/portalcubed/mixin/InventoryMixin.java b/src/main/java/com/fusionflux/portalcubed/mixin/InventoryMixin.java index 30e607b3..e5319718 100644 --- a/src/main/java/com/fusionflux/portalcubed/mixin/InventoryMixin.java +++ b/src/main/java/com/fusionflux/portalcubed/mixin/InventoryMixin.java @@ -7,6 +7,7 @@ import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -17,11 +18,12 @@ public class InventoryMixin { @Inject(method = "swapPaint", at = @At("HEAD"), cancellable = true) private void zoomInPortalMode(double scrollAmount, CallbackInfo ci) { - if (player.level.isClientSide && performZoom((int)Math.signum(scrollAmount))) { + if (player.level().isClientSide && performZoom((int)Math.signum(scrollAmount))) { ci.cancel(); } } + @Unique @ClientOnly private boolean performZoom(int delta) { if (!PortalCubedClient.isPortalHudMode()) { diff --git a/src/main/java/com/fusionflux/portalcubed/mixin/LivingEntityMixin.java b/src/main/java/com/fusionflux/portalcubed/mixin/LivingEntityMixin.java index 14e28385..e59f2dff 100644 --- a/src/main/java/com/fusionflux/portalcubed/mixin/LivingEntityMixin.java +++ b/src/main/java/com/fusionflux/portalcubed/mixin/LivingEntityMixin.java @@ -91,7 +91,7 @@ private static Vec3 movementInputToVelocityCustom(Vec3 movementInput, float spee private void crowbarSwoosh(InteractionHand hand, CallbackInfo ci) { //noinspection ConstantValue if ((Object)this instanceof Player player && getItemInHand(hand).is(PortalCubedItems.CROWBAR)) { - level.playSound( + level().playSound( player, player.getX(), player.getY(), player.getZ(), PortalCubedSounds.CROWBAR_SWOOSH_EVENT, SoundSource.PLAYERS, @@ -116,7 +116,7 @@ private void noFallDamage(float fallDistance, float multiplier, DamageSource sou (int)Math.ceil(boundingBox.maxY), (int)Math.ceil(boundingBox.maxZ) )) { - final BlockState state = level.getBlockState(pos); + final BlockState state = level().getBlockState(pos); if (state.is(PortalCubedBlocks.REPULSION_GEL) && BaseGel.collides(this, pos, state)) { cir.setReturnValue(false); return; diff --git a/src/main/java/com/fusionflux/portalcubed/mixin/PlayerMixin.java b/src/main/java/com/fusionflux/portalcubed/mixin/PlayerMixin.java index 83d9bbe2..99c42fdf 100644 --- a/src/main/java/com/fusionflux/portalcubed/mixin/PlayerMixin.java +++ b/src/main/java/com/fusionflux/portalcubed/mixin/PlayerMixin.java @@ -83,7 +83,7 @@ protected PlayerMixin(EntityType entityType, Level world @ModifyVariable(method = "travel", at = @At("HEAD"), argsOnly = true) private Vec3 portalCubed$what(Vec3 travelVectorOriginal) { - if (!this.isNoGravity() && !this.isOnGround() && PortalCubedConfig.enableAccurateMovement && !this.isSwimming() && !this.abilities.flying && !this.isFallFlying() && this.getItemBySlot(EquipmentSlot.FEET).getItem().equals(PortalCubedItems.LONG_FALL_BOOTS) && !this.level.getBlockState(this.blockPosition()).getBlock().equals(PortalCubedBlocks.EXCURSION_FUNNEL) && !this.level.getBlockState(new BlockPos(this.blockPosition().getX(), this.blockPosition().getY() + 1, this.blockPosition().getZ())).getBlock().equals(PortalCubedBlocks.EXCURSION_FUNNEL)) { + if (!this.isNoGravity() && !this.onGround() && PortalCubedConfig.enableAccurateMovement && !this.isSwimming() && !this.abilities.flying && !this.isFallFlying() && this.getItemBySlot(EquipmentSlot.FEET).getItem().equals(PortalCubedItems.LONG_FALL_BOOTS) && !this.level().getBlockState(this.blockPosition()).getBlock().equals(PortalCubedBlocks.EXCURSION_FUNNEL) && !this.level().getBlockState(new BlockPos(this.blockPosition().getX(), this.blockPosition().getY() + 1, this.blockPosition().getZ())).getBlock().equals(PortalCubedBlocks.EXCURSION_FUNNEL)) { double mathVal = 1; double horizontalVelocity = Math.abs(this.getDeltaMovement().x) + Math.abs(this.getDeltaMovement().z); if (horizontalVelocity / 0.01783440120041885 > 1) { @@ -100,19 +100,21 @@ protected PlayerMixin(EntityType entityType, Level world @Inject(method = "getFlyingSpeed", at = @At("HEAD"), cancellable = true) private void replaceFlyingSpeed(CallbackInfoReturnable cir) { - if (!this.isNoGravity() && !this.isOnGround() && PortalCubedConfig.enableAccurateMovement && !this.isSwimming() && !this.abilities.flying && !this.isFallFlying() && this.getItemBySlot(EquipmentSlot.FEET).getItem().equals(PortalCubedItems.LONG_FALL_BOOTS) && !this.level.getBlockState(this.blockPosition()).getBlock().equals(PortalCubedBlocks.EXCURSION_FUNNEL) && !this.level.getBlockState(new BlockPos(this.blockPosition().getX(), this.blockPosition().getY() + 1, this.blockPosition().getZ())).getBlock().equals(PortalCubedBlocks.EXCURSION_FUNNEL)) { + if (!this.isNoGravity() && !this.onGround() && PortalCubedConfig.enableAccurateMovement && !this.isSwimming() && !this.abilities.flying && !this.isFallFlying() && this.getItemBySlot(EquipmentSlot.FEET).getItem().equals(PortalCubedItems.LONG_FALL_BOOTS) && !this.level().getBlockState(this.blockPosition()).getBlock().equals(PortalCubedBlocks.EXCURSION_FUNNEL) && !this.level().getBlockState(new BlockPos(this.blockPosition().getX(), this.blockPosition().getY() + 1, this.blockPosition().getZ())).getBlock().equals(PortalCubedBlocks.EXCURSION_FUNNEL)) { cir.setReturnValue(0.04f); } } + @Unique private boolean enableNoDrag2; + @Unique private static final AABB NULL_BOX = new AABB(0, 0, 0, 0, 0, 0); @Inject(method = "tick", at = @At("HEAD")) public void tickHead(CallbackInfo ci) { Player thisEntity = ((Player) (Object) this); - if (level.isClientSide && CalledValues.getHasTeleportationHappened(thisEntity)) { + if (level().isClientSide && CalledValues.getHasTeleportationHappened(thisEntity)) { var byteBuf = PacketByteBufs.create(); NetworkingSafetyWrapper.sendFromClient("client_teleport_update", byteBuf); CalledValues.setHasTeleportationHappened(thisEntity, false); @@ -124,12 +126,12 @@ public void tickHead(CallbackInfo ci) { Vec3 entityVelocity = this.getDeltaMovement(); AABB portalCheckBox = getBoundingBox(); - if (!this.level.isClientSide) { + if (!this.level().isClientSide) { portalCheckBox = portalCheckBox.inflate(10); } else { portalCheckBox = portalCheckBox.expandTowards(entityVelocity); } - List list = level.getEntitiesOfClass(Portal.class, portalCheckBox); + List list = level().getEntitiesOfClass(Portal.class, portalCheckBox); VoxelShape omittedDirections = Shapes.empty(); for (Portal portal : list) { @@ -142,7 +144,7 @@ public void tickHead(CallbackInfo ci) { ItemStack itemFeet = this.getItemBySlot(EquipmentSlot.FEET); - if ((!this.isOnGround() && PortalCubedConfig.enableAccurateMovement && !this.isSwimming() && !this.abilities.flying && !this.isFallFlying() && itemFeet.getItem().equals(PortalCubedItems.LONG_FALL_BOOTS) && !this.level.getBlockState(this.blockPosition()).getBlock().equals(PortalCubedBlocks.EXCURSION_FUNNEL) && !this.level.getBlockState(new BlockPos(this.blockPosition().getX(), this.blockPosition().getY() + 1, this.blockPosition().getZ())).getBlock().equals(PortalCubedBlocks.EXCURSION_FUNNEL))) { + if ((!this.onGround() && PortalCubedConfig.enableAccurateMovement && !this.isSwimming() && !this.abilities.flying && !this.isFallFlying() && itemFeet.getItem().equals(PortalCubedItems.LONG_FALL_BOOTS) && !this.level().getBlockState(this.blockPosition()).getBlock().equals(PortalCubedBlocks.EXCURSION_FUNNEL) && !this.level().getBlockState(new BlockPos(this.blockPosition().getX(), this.blockPosition().getY() + 1, this.blockPosition().getZ())).getBlock().equals(PortalCubedBlocks.EXCURSION_FUNNEL))) { if (!enableNoDrag2) { enableNoDrag2 = true; } @@ -158,14 +160,14 @@ public void tickHead(CallbackInfo ci) { } } - if (!level.isClientSide || !MixinPCClientAccessor.allowCfg() || !isShiftKeyDown()) { + if (!level().isClientSide || !MixinPCClientAccessor.allowCfg() || !isShiftKeyDown()) { cfg = false; } } @Inject(method = "tick", at = @At("TAIL")) public void tickTail(CallbackInfo ci) { - if (this.level.isClientSide) { + if (this.level().isClientSide) { Player thisEntity = ((Player) (Object) this); Vec3 entityVelocity = thisEntity.getDeltaMovement(); @@ -175,7 +177,7 @@ public void tickTail(CallbackInfo ci) { portalCheckBox = portalCheckBox.expandTowards(entityVelocity).expandTowards(entityVelocity.scale(-1)); - List list = level.getEntitiesOfClass(Portal.class, portalCheckBox); + List list = level().getEntitiesOfClass(Portal.class, portalCheckBox); Set> possiblePortals = new HashSet<>(); @@ -184,51 +186,47 @@ public void tickTail(CallbackInfo ci) { if (this.canChangeDimensions() && portalCheck.getActive() && !CalledValues.getHasTeleportationHappened(thisEntity) && !CalledValues.getIsTeleporting(thisEntity)) { assert portalCheck.getOtherNormal().isPresent(); Direction portalFacing = portalCheck.getFacingDirection(); - final Vec3 otherNormal = portalCheck.getOtherNormal().get(); - Direction otherDirec = Direction.fromNormal((int) otherNormal.x(), (int) otherNormal.y(), (int) otherNormal.z()); - if (otherDirec != null) { - entityVelocity = thisEntity.getDeltaMovement(); - - if (thisEntity.shouldDiscardFriction()) { - entityVelocity = entityVelocity.add(0, .08, 0); - } else { - entityVelocity = entityVelocity.add(0, .08 * .98, 0); - } + entityVelocity = thisEntity.getDeltaMovement(); + + if (thisEntity.shouldDiscardFriction()) { + entityVelocity = entityVelocity.add(0, .08, 0); + } else { + entityVelocity = entityVelocity.add(0, .08 * .98, 0); + } // Vec3 entityPos = portalCheck.getNormal().y > 0 ? thisEntity.position() : thisEntity.getEyePosition(); - Vec3 entityPos = thisEntity.position().add(0, portalCheck.getOtherNormal().get().y < 0 || portalCheck.getNormal().y < 0 ? 0.02 - entityVelocity.y : thisEntity.getEyeHeight(), 0); - final boolean isColliding = portalCheck.getBoundingBox().distanceToSqr(entityPos) <= entityVelocity.lengthSqr(); - if (portalFacing.step().x() < 0) { - if (entityPos.x() + entityVelocity.x >= portalCheck.position().x() && entityVelocity.x() > 0 && isColliding) { - possiblePortals.add(Pair.of(portalCheck, entityPos)); - } + Vec3 entityPos = thisEntity.position().add(0, portalCheck.getOtherNormal().get().y < 0 || portalCheck.getNormal().y < 0 ? 0.02 - entityVelocity.y : thisEntity.getEyeHeight(), 0); + final boolean isColliding = portalCheck.getBoundingBox().distanceToSqr(entityPos) <= entityVelocity.lengthSqr(); + if (portalFacing.step().x() < 0) { + if (entityPos.x() + entityVelocity.x >= portalCheck.position().x() && entityVelocity.x() > 0 && isColliding) { + possiblePortals.add(Pair.of(portalCheck, entityPos)); } - if (portalFacing.step().y() < 0) { - if (entityPos.y() + entityVelocity.y >= portalCheck.position().y() && entityVelocity.y() > 0 && isColliding) { - possiblePortals.add(Pair.of(portalCheck, entityPos)); - } + } + if (portalFacing.step().y() < 0) { + if (entityPos.y() + entityVelocity.y >= portalCheck.position().y() && entityVelocity.y() > 0 && isColliding) { + possiblePortals.add(Pair.of(portalCheck, entityPos)); } - if (portalFacing.step().z() < 0) { - if (entityPos.z() + entityVelocity.z >= portalCheck.position().z() && entityVelocity.z() > 0 && isColliding) { - possiblePortals.add(Pair.of(portalCheck, entityPos)); - } + } + if (portalFacing.step().z() < 0) { + if (entityPos.z() + entityVelocity.z >= portalCheck.position().z() && entityVelocity.z() > 0 && isColliding) { + possiblePortals.add(Pair.of(portalCheck, entityPos)); } - if (portalFacing.step().x() > 0) { - if (entityPos.x() + entityVelocity.x <= portalCheck.position().x() && entityVelocity.x() < 0 && isColliding) { - possiblePortals.add(Pair.of(portalCheck, entityPos)); - } + } + if (portalFacing.step().x() > 0) { + if (entityPos.x() + entityVelocity.x <= portalCheck.position().x() && entityVelocity.x() < 0 && isColliding) { + possiblePortals.add(Pair.of(portalCheck, entityPos)); } - if (portalFacing.step().y() > 0) { - if (entityPos.y() + entityVelocity.y <= portalCheck.position().y() && entityVelocity.y() < 0 && isColliding) { - possiblePortals.add(Pair.of(portalCheck, entityPos)); - } + } + if (portalFacing.step().y() > 0) { + if (entityPos.y() + entityVelocity.y <= portalCheck.position().y() && entityVelocity.y() < 0 && isColliding) { + possiblePortals.add(Pair.of(portalCheck, entityPos)); } - if (portalFacing.step().z() > 0) { - if (entityPos.z() + entityVelocity.z <= portalCheck.position().z() && entityVelocity.z() < 0 && isColliding) { - possiblePortals.add(Pair.of(portalCheck, entityPos)); - } + } + if (portalFacing.step().z() > 0) { + if (entityPos.z() + entityVelocity.z <= portalCheck.position().z() && entityVelocity.z() < 0 && isColliding) { + possiblePortals.add(Pair.of(portalCheck, entityPos)); } - } + } } Pair portal = null; @@ -249,6 +247,7 @@ public void tickTail(CallbackInfo ci) { } } + @Unique private void performTeleport( Player thisEntity, Portal portal, @@ -258,7 +257,7 @@ private void performTeleport( assert portal.getDestination().isPresent(); assert portal.getOtherNormal().isPresent(); - if (this.level.isClientSide && thisEntity.isLocalPlayer()) { + if (this.level().isClientSide && thisEntity.isLocalPlayer()) { Vec3 invert = (portal.getNormal().multiply(portal.getNormal())).scale(-1); if (invert.x != 0) { invert = invert.add(0, 1, 1); @@ -321,11 +320,13 @@ private void performTeleport( } } + @Unique @ClientOnly private static Optional interpCamera() { return PortalCubedClient.interpCamera(); } + @Unique @ClientOnly private static void interpCamera(IPQuaternion interp) { PortalCubedClient.cameraInterpStart = interp; @@ -340,18 +341,18 @@ private static void interpCamera(IPQuaternion interp) { ) ) public void portalCubed$dropItem(ItemStack stack, boolean throwRandomly, boolean retainOwnership, CallbackInfoReturnable<@Nullable ItemEntity> cir) { - if (!this.level.isClientSide && stack.getItem().equals(PortalCubedItems.PORTAL_GUN)) { + if (!this.level().isClientSide && stack.getItem().equals(PortalCubedItems.PORTAL_GUN)) { CompoundTag tag = stack.getOrCreateTag(); - CompoundTag portalsTag = tag.getCompound(level.dimension().location().toString()); + CompoundTag portalsTag = tag.getCompound(level().dimension().location().toString()); Portal portalHolder; if (portalsTag.contains(("Left") + "Portal")) { - portalHolder = (Portal) ((ServerLevel) level).getEntity(portalsTag.getUUID(("Left") + "Portal")); + portalHolder = (Portal) ((ServerLevel) level()).getEntity(portalsTag.getUUID(("Left") + "Portal")); if (portalHolder != null) { portalHolder.kill(); } } if (portalsTag.contains(("Right") + "Portal")) { - portalHolder = (Portal) ((ServerLevel) level).getEntity(portalsTag.getUUID(("Right") + "Portal")); + portalHolder = (Portal) ((ServerLevel) level()).getEntity(portalsTag.getUUID(("Right") + "Portal")); if (portalHolder != null) { portalHolder.kill(); } @@ -378,6 +379,6 @@ public void setCFG() { ) ) private Pose playerCrouching(Operation original) { - return PortalCubed.portalHudModeServerOrClient(level) ? Pose.SWIMMING : original.call(); + return PortalCubed.portalHudModeServerOrClient(level()) ? Pose.SWIMMING : original.call(); } } diff --git a/src/main/java/com/fusionflux/portalcubed/optionslist/ButtonEntry.java b/src/main/java/com/fusionflux/portalcubed/optionslist/ButtonEntry.java deleted file mode 100644 index 4fdd5a79..00000000 --- a/src/main/java/com/fusionflux/portalcubed/optionslist/ButtonEntry.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.fusionflux.portalcubed.optionslist; - -import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Font; -import net.minecraft.client.gui.GuiComponent; -import net.minecraft.client.gui.components.AbstractWidget; -import net.minecraft.client.gui.components.ContainerObjectSelectionList; -import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.gui.narration.NarratableEntry; -import net.minecraft.network.chat.Component; -import org.jetbrains.annotations.NotNull; -import org.quiltmc.loader.api.minecraft.ClientOnly; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@ClientOnly -public class ButtonEntry extends ContainerObjectSelectionList.Entry { - private static final Font TEXT_RENDERER = Minecraft.getInstance().font; - public final List buttons; - private final Component text; - public final EntryInfo info; - private final List children = new ArrayList<>(); - public static final Map BUTTONS_WITH_TEXT = new HashMap<>(); - - ButtonEntry(List buttons, Component text, EntryInfo info) { - if (!buttons.isEmpty()) BUTTONS_WITH_TEXT.put(buttons.get(0), text); - this.buttons = buttons; - this.text = text; - this.info = info; - children.addAll(buttons); - } - - @Override - public void render(PoseStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { - buttons.forEach(b -> { - b.setY(y); - b.render(matrices, mouseX, mouseY, tickDelta); - }); - if (text != null && (!text.getString().contains("spacer") || !buttons.isEmpty())) { - if (info.centered) - TEXT_RENDERER.drawShadow(matrices, text, Minecraft.getInstance().getWindow().getGuiScaledWidth() / 2f - (TEXT_RENDERER.width(text) / 2f), y + 5, 0xFFFFFF); - else GuiComponent.drawString(matrices, TEXT_RENDERER, text, 12, y + 5, 0xFFFFFF); - } - } - - @NotNull - @Override - public List children() { - return children; - } - - @NotNull - @Override - public List narratables() { - return children; - } -} diff --git a/src/main/java/com/fusionflux/portalcubed/optionslist/EntryInfo.java b/src/main/java/com/fusionflux/portalcubed/optionslist/EntryInfo.java deleted file mode 100644 index 28e38168..00000000 --- a/src/main/java/com/fusionflux/portalcubed/optionslist/EntryInfo.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.fusionflux.portalcubed.optionslist; - -import net.minecraft.client.gui.components.AbstractWidget; -import net.minecraft.client.gui.components.EditBox; -import net.minecraft.network.chat.Component; - -import java.lang.reflect.Field; -import java.util.Map; - -class EntryInfo { - Field field; - Object widget; - int width; - int max; - boolean centered; - Map.Entry error; - Object value; - String tempValue; - boolean inLimits = true; - Class owner; - Component name; - int index; - AbstractWidget colorButton; -} diff --git a/src/main/java/com/fusionflux/portalcubed/optionslist/OptionsListBlockEntity.java b/src/main/java/com/fusionflux/portalcubed/optionslist/OptionsListBlockEntity.java deleted file mode 100644 index 7d0911d2..00000000 --- a/src/main/java/com/fusionflux/portalcubed/optionslist/OptionsListBlockEntity.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.fusionflux.portalcubed.optionslist; - -import net.minecraft.core.BlockPos; -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; - -public abstract class OptionsListBlockEntity extends BlockEntity { - public OptionsListBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { - super(type, pos, state); - } - - public void updateListeners() { - setChanged(); - assert level != null; - level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), Block.UPDATE_ALL); - } -} diff --git a/src/main/java/com/fusionflux/portalcubed/optionslist/OptionsListData.java b/src/main/java/com/fusionflux/portalcubed/optionslist/OptionsListData.java deleted file mode 100644 index 40c3b1e3..00000000 --- a/src/main/java/com/fusionflux/portalcubed/optionslist/OptionsListData.java +++ /dev/null @@ -1,188 +0,0 @@ -package com.fusionflux.portalcubed.optionslist; - -import com.fusionflux.portalcubed.PortalCubed; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import eu.midnightdust.lib.config.MidnightConfig; -import net.fabricmc.api.EnvType; -import net.minecraft.ChatFormatting; -import net.minecraft.client.gui.components.Button; -import net.minecraft.client.gui.components.EditBox; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.Style; -import org.quiltmc.loader.api.minecraft.ClientOnly; -import org.quiltmc.loader.api.minecraft.MinecraftQuiltLoader; - -import java.awt.*; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.List; -import java.util.*; -import java.util.function.BiFunction; -import java.util.function.Function; -import java.util.function.Predicate; -import java.util.regex.Pattern; - -// Based on https://github.com/TeamMidnightDust/MidnightLib/blob/architectury/common/src/main/java/eu/midnightdust/lib/config/MidnightConfig.java -public class OptionsListData { - private static final Pattern INTEGER_ONLY = Pattern.compile("(-?[0-9]*)"); - private static final Pattern DECIMAL_ONLY = Pattern.compile("-?(\\d+\\.?\\d*|\\d*\\.?\\d+|\\.)"); - private static final Pattern HEXADECIMAL_ONLY = Pattern.compile("(-?[#0-9a-fA-F]*)"); - - private static final Map, List> ENTRIES = new IdentityHashMap<>(); - - private static final Gson GSON = new GsonBuilder() - .excludeFieldsWithModifiers(Modifier.TRANSIENT | Modifier.STATIC) - .setExclusionStrategies(new MidnightConfig.HiddenAnnotationExclusionStrategy()) - .create(); - - static List getEntries(OptionsListBlockEntity target) { - List entries; - synchronized (ENTRIES) { - entries = ENTRIES.get(target.getClass()); - if (entries == null) { - entries = new ArrayList<>(); - ENTRIES.put(target.getClass(), entries); - for (Class c = target.getClass(); c != null; c = c.getSuperclass()) { - for (Field field : c.getDeclaredFields()) { - if (!field.isAnnotationPresent(MidnightConfig.Entry.class)) continue; - field.setAccessible(true); - EntryInfo info = new EntryInfo(); - info.owner = target.getClass(); - info.field = field; - if (( - field.isAnnotationPresent(MidnightConfig.Entry.class) || - field.isAnnotationPresent(MidnightConfig.Comment.class) - ) && - !field.isAnnotationPresent(MidnightConfig.Server.class) && - !field.isAnnotationPresent(MidnightConfig.Hidden.class) && MinecraftQuiltLoader.getEnvironmentType() == EnvType.CLIENT - ) { - initClient(field, info); - } - if (field.isAnnotationPresent(MidnightConfig.Comment.class)) { - info.centered = field.getAnnotation(MidnightConfig.Comment.class).centered(); - } - entries.add(info); - } - } - } - } - return entries; - } - - public static void read(CompoundTag nbt, OptionsListBlockEntity target) { - read(nbt.getString("OptionsListData"), target); - } - - public static void read(String json, OptionsListBlockEntity target) { - final List entries = getEntries(target); - - if (json.isEmpty()) return; - - OptionsListBlockEntity newInstance; - try { - newInstance = GSON.fromJson(json, target.getClass()); - } catch (Exception e) { - PortalCubed.LOGGER.error("Failed to read OptionsListData for {}", target, e); - return; - } - - for (EntryInfo info : entries) { - if (info.field.isAnnotationPresent(MidnightConfig.Entry.class)) { - try { - info.value = info.field.get(newInstance); - info.field.set(target, info.value); - info.tempValue = info.value.toString(); - } catch (IllegalAccessException ignored) { - } - } - } - } - - public static void write(CompoundTag nbt, OptionsListBlockEntity target) { - nbt.putString("OptionsListData", write(target)); - } - - public static String write(OptionsListBlockEntity target) { - return GSON.toJson(target); - } - - @ClientOnly - private static void initClient(Field field, EntryInfo info) { - Class type = field.getType(); - MidnightConfig.Entry e = field.getAnnotation(MidnightConfig.Entry.class); - info.width = e != null ? e.width() : 0; - - if (e != null) { - if (!e.name().equals("")) info.name = Component.translatable(e.name()); - if (type == int.class) textField(info, Integer::parseInt, INTEGER_ONLY, (int) e.min(), (int) e.max(), true); - else if (type == float.class) textField(info, Float::parseFloat, DECIMAL_ONLY, (float) e.min(), (float) e.max(), false); - else if (type == double.class) textField(info, Double::parseDouble, DECIMAL_ONLY, e.min(), e.max(), false); - else if (type == String.class || type == List.class) { - info.max = e.max() == Double.MAX_VALUE ? Integer.MAX_VALUE : (int) e.max(); - textField(info, String::length, null, Math.min(e.min(), 0), Math.max(e.max(), 1), true); - } else if (type == boolean.class) { - Function func = value -> Component.translatable((Boolean) value ? "gui.yes" : "gui.no").withStyle((Boolean) value ? ChatFormatting.GREEN : ChatFormatting.RED); - info.widget = new AbstractMap.SimpleEntry>(button -> { - info.value = !(Boolean) info.value; - button.setMessage(func.apply(info.value)); - }, func); - } else if (type.isEnum()) { - List values = Arrays.asList(field.getType().getEnumConstants()); - Function func = value -> Component.translatable("optionslist.enum." + type.getSimpleName() + "." + info.value.toString()); - info.widget = new AbstractMap.SimpleEntry>(button -> { - int index = values.indexOf(info.value) + 1; - info.value = values.get(index >= values.size() ? 0 : index); - button.setMessage(func.apply(info.value)); - }, func); - } - } - } - - @SuppressWarnings("unchecked") - private static void textField(EntryInfo info, Function f, Pattern pattern, double min, double max, boolean cast) { - boolean isNumber = pattern != null; - info.widget = (BiFunction>) (t, b) -> s -> { - s = s.trim(); - if (!(s.isEmpty() || !isNumber || pattern.matcher(s).matches())) return false; - - Number value = 0; - boolean inLimits = false; - info.error = null; - if (!(isNumber && s.isEmpty()) && !s.equals("-") && !s.equals(".")) { - try { - value = f.apply(s); - } catch (NumberFormatException e) { - return false; - } - inLimits = value.doubleValue() >= min && value.doubleValue() <= max; - info.error = inLimits ? null : new AbstractMap.SimpleEntry<>(t, Component.literal(value.doubleValue() < min ? - "§cMinimum " + (isNumber ? "value" : "length") + (cast ? " is " + (int)min : " is " + min) : - "§cMaximum " + (isNumber ? "value" : "length") + (cast ? " is " + (int)max : " is " + max))); - } - - info.tempValue = s; - t.setTextColor(inLimits ? 0xFFFFFFFF : 0xFFFF7777); - info.inLimits = inLimits; - b.active = ENTRIES.get(info.owner).stream().allMatch(e -> e.inLimits); - - if (inLimits && info.field.getType() != List.class) - info.value = isNumber ? value : s; - else if (inLimits) { - if (((List) info.value).size() == info.index) ((List) info.value).add(""); - ((List) info.value).set(info.index, Arrays.stream(info.tempValue.replace("[", "").replace("]", "").split(", ")).toList().get(0)); - } - - if (info.field.getAnnotation(MidnightConfig.Entry.class).isColor()) { - if (!s.contains("#")) s = '#' + s; - if (!HEXADECIMAL_ONLY.matcher(s).matches()) return false; - try { - info.colorButton.setMessage(Component.literal("⬛").setStyle(Style.EMPTY.withColor(Color.decode(info.tempValue).getRGB()))); - } catch (Exception ignored) { - } - } - return true; - }; - } -} diff --git a/src/main/java/com/fusionflux/portalcubed/optionslist/OptionsListListWidget.java b/src/main/java/com/fusionflux/portalcubed/optionslist/OptionsListListWidget.java deleted file mode 100644 index 3617b6ad..00000000 --- a/src/main/java/com/fusionflux/portalcubed/optionslist/OptionsListListWidget.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.fusionflux.portalcubed.optionslist; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Font; -import net.minecraft.client.gui.components.AbstractWidget; -import net.minecraft.client.gui.components.ContainerObjectSelectionList; -import net.minecraft.network.chat.Component; -import org.quiltmc.loader.api.minecraft.ClientOnly; - -import java.util.List; -import java.util.Optional; - -@ClientOnly -class OptionsListListWidget extends ContainerObjectSelectionList { - Font textRenderer; - - OptionsListListWidget(Minecraft minecraftClient, int i, int j, int k, int l, int m) { - super(minecraftClient, i, j, k, l, m); - this.centerListVertically = false; - textRenderer = minecraftClient.font; - } - - @Override - public int getScrollbarPosition() { - return this.width - 7; - } - - public void addButton(List buttons, Component text, EntryInfo info) { - this.addEntry(new ButtonEntry(buttons, text, info)); - } - - @Override - public int getRowWidth() { - return 10000; - } - - public Optional getHoveredButton(double mouseX, double mouseY) { - for (ButtonEntry buttonEntry : this.children()) { - if (!buttonEntry.buttons.isEmpty() && buttonEntry.buttons.get(0).isMouseOver(mouseX, mouseY)) { - return Optional.of(buttonEntry.buttons.get(0)); - } - } - return Optional.empty(); - } -} diff --git a/src/main/java/com/fusionflux/portalcubed/optionslist/OptionsListScreen.java b/src/main/java/com/fusionflux/portalcubed/optionslist/OptionsListScreen.java deleted file mode 100644 index 657aaf2f..00000000 --- a/src/main/java/com/fusionflux/portalcubed/optionslist/OptionsListScreen.java +++ /dev/null @@ -1,181 +0,0 @@ -package com.fusionflux.portalcubed.optionslist; - -import com.fusionflux.portalcubed.packet.PortalCubedServerPackets; -import com.mojang.blaze3d.vertex.PoseStack; -import eu.midnightdust.lib.config.MidnightConfig; -import net.minecraft.ChatFormatting; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.components.AbstractWidget; -import net.minecraft.client.gui.components.Button; -import net.minecraft.client.gui.components.EditBox; -import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; -import net.minecraft.client.resources.language.I18n; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.chat.CommonComponents; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.Style; -import net.minecraft.world.entity.player.Inventory; -import org.quiltmc.loader.api.minecraft.ClientOnly; -import org.quiltmc.qsl.networking.api.PacketByteBufs; -import org.quiltmc.qsl.networking.api.client.ClientPlayNetworking; - -import java.awt.*; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.function.BiFunction; -import java.util.function.Function; -import java.util.function.Predicate; - -@ClientOnly -public class OptionsListScreen extends AbstractContainerScreen { - public final String translationPrefix; - public final OptionsListBlockEntity target; - public OptionsListListWidget list; - public boolean reload = false; - - public OptionsListScreen(OptionsListScreenHandler handler, Inventory inventory, Component title) { - super(handler, inventory, title); - assert Minecraft.getInstance().level != null; - final var entity = Minecraft.getInstance().level.getBlockEntity(handler.getAt()); - if (!(entity instanceof OptionsListBlockEntity ola)) { - onClose(); - target = null; - translationPrefix = null; - return; - } - target = ola; - //noinspection DataFlowIssue - this.translationPrefix = "optionslist." + BuiltInRegistries.BLOCK_ENTITY_TYPE.getKey(ola.getType()).toString().replace(':', '.') + "."; - for (final EntryInfo entry : OptionsListData.getEntries(target)) { - try { - entry.value = entry.field.get(target); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - } - } - - @SuppressWarnings("unchecked") - @Override - public void init() { - imageWidth = width; - imageHeight = height; - super.init(); - - Button done = this.addRenderableWidget(Button.builder(CommonComponents.GUI_DONE, (button) -> { - for (EntryInfo info : OptionsListData.getEntries(target)) { - try { - info.field.set(target, info.value); - } catch (IllegalAccessException ignored) { - } - } - onClose(); - }).width(150).pos(this.width / 2 - 75, this.height - 28).build()); - - this.list = new OptionsListListWidget(this.minecraft, this.width, this.height, 32, this.height - 32, 25); - if (this.minecraft != null && this.minecraft.level != null) this.list.setRenderBackground(false); - this.addWidget(this.list); - for (EntryInfo info : OptionsListData.getEntries(target)) { - Component name = Objects.requireNonNullElseGet(info.name, () -> Component.translatable(translationPrefix + info.field.getName())); - - if (info.widget instanceof Map.Entry) { - Map.Entry> widget = (Map.Entry>)info.widget; - if (info.field.getType().isEnum()) - widget.setValue(value -> Component.translatable(translationPrefix + "enum." + info.field.getType().getSimpleName() + "." + info.value.toString())); - this.list.addButton(List.of(Button.builder(widget.getValue().apply(info.value), widget.getKey()).width(150).pos(width - 160, 0).build()), name, info); - } else if (info.field.getType() == List.class) { - if (!reload) info.index = 0; - EditBox widget = new EditBox(font, width - 160, 0, 150, 20, Component.empty()); - widget.setMaxLength(info.width); - if (info.index < ((List)info.value).size()) - widget.setValue((String.valueOf(((List)info.value).get(info.index)))); - Predicate processor = ((BiFunction>)info.widget).apply(widget, done); - widget.setFilter(processor); - Button cycleButton = Button.builder(Component.literal(String.valueOf(info.index)).withStyle(ChatFormatting.GOLD), (button -> { - ((List)info.value).remove(""); - double scrollAmount = list.getScrollAmount(); - this.reload = true; - info.index = info.index + 1; - if (info.index > ((List)info.value).size()) info.index = 0; - Objects.requireNonNull(minecraft).setScreen(this); - list.setScrollAmount(scrollAmount); - })).width(20).size(width - 185, 0).build(); - this.list.addButton(List.of(widget, cycleButton), name, info); - } else if (info.widget != null) { - AbstractWidget widget; - MidnightConfig.Entry e = info.field.getAnnotation(MidnightConfig.Entry.class); - if (e.isSlider()) - widget = new OptionsListSliderWidget(width - 160, 0, 150, 20, Component.nullToEmpty(info.tempValue), (Double.parseDouble(info.tempValue) - e.min()) / (e.max() - e.min()), info); - else widget = new EditBox(font, width - 160, 0, 150, 20, null, Component.nullToEmpty(info.tempValue)); - if (widget instanceof EditBox textField) { - textField.setMaxLength(info.width); - textField.setValue(info.tempValue); - Predicate processor = ((BiFunction>)info.widget).apply(textField, done); - textField.setFilter(processor); - } - if (e.isColor()) { - Button colorButton = Button.builder(Component.literal("⬛"), (button -> { - })).width(20).pos(width - 185, 0).build(); - try { - colorButton.setMessage(Component.literal("⬛").setStyle(Style.EMPTY.withColor(Color.decode(info.tempValue).getRGB()))); - } catch (Exception ignored) { - } - info.colorButton = colorButton; - colorButton.active = false; - this.list.addButton(List.of(widget, colorButton), name, info); - } else { - this.list.addButton(List.of(widget), name, info); - } - } else { - this.list.addButton(List.of(), name, info); - } - } - - } - - @Override - public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { - this.renderBackground(matrices); - this.list.render(matrices, mouseX, mouseY, delta); - drawCenteredString(matrices, font, title, width / 2, 15, 0xFFFFFF); - - for (EntryInfo info : OptionsListData.getEntries(target)) { - if (list.getHoveredButton(mouseX, mouseY).isPresent()) { - AbstractWidget buttonWidget = list.getHoveredButton(mouseX, mouseY).get(); - Component text = ButtonEntry.BUTTONS_WITH_TEXT.get(buttonWidget); - Component name = Component.translatable(this.translationPrefix + info.field.getName()); - String key = translationPrefix + info.field.getName() + ".tooltip"; - - if (info.error != null && text.equals(name)) - renderTooltip(matrices, info.error.getValue(), mouseX, mouseY); - else if (I18n.exists(key) && text.equals(name)) { - List list = new ArrayList<>(); - for (String str : I18n.get(key).split("\n")) - list.add(Component.literal(str)); - renderComponentTooltip(matrices, list, mouseX, mouseY); - } - } - } - super.render(matrices, mouseX, mouseY, delta); - } - - @Override - public void onClose() { - final FriendlyByteBuf buf = PacketByteBufs.create(); - buf.writeBlockPos(menu.getAt()); - buf.writeUtf(OptionsListData.write(target)); - ClientPlayNetworking.send(PortalCubedServerPackets.OPTIONS_LIST_CONFIGURE, buf); - super.onClose(); - } - - @Override - protected void renderLabels(PoseStack matrices, int mouseX, int mouseY) { - } - - @Override - protected void renderBg(PoseStack matrices, float delta, int mouseX, int mouseY) { - } -} diff --git a/src/main/java/com/fusionflux/portalcubed/optionslist/OptionsListScreenHandler.java b/src/main/java/com/fusionflux/portalcubed/optionslist/OptionsListScreenHandler.java deleted file mode 100644 index 37f74cae..00000000 --- a/src/main/java/com/fusionflux/portalcubed/optionslist/OptionsListScreenHandler.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.fusionflux.portalcubed.optionslist; - -import com.fusionflux.portalcubed.PortalCubed; -import net.minecraft.core.BlockPos; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.world.entity.player.Inventory; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.item.ItemStack; - -public class OptionsListScreenHandler extends AbstractContainerMenu { - private final BlockPos at; - - public OptionsListScreenHandler(int syncId, @SuppressWarnings("unused") Inventory playerInventory, FriendlyByteBuf buf) { - this(syncId, buf.readBlockPos()); - } - - public OptionsListScreenHandler(int syncId, BlockPos at) { - super(PortalCubed.OPTIONS_LIST_SCREEN_HANDLER, syncId); - this.at = at; - } - - @Override - public ItemStack quickMoveStack(Player player, int fromIndex) { - return ItemStack.EMPTY; - } - - @Override - public boolean stillValid(Player player) { - return player.isCreative(); - } - - public BlockPos getAt() { - return at; - } -} diff --git a/src/main/java/com/fusionflux/portalcubed/optionslist/OptionsListSliderWidget.java b/src/main/java/com/fusionflux/portalcubed/optionslist/OptionsListSliderWidget.java deleted file mode 100644 index 8d628b8a..00000000 --- a/src/main/java/com/fusionflux/portalcubed/optionslist/OptionsListSliderWidget.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.fusionflux.portalcubed.optionslist; - -import eu.midnightdust.lib.config.MidnightConfig; -import net.minecraft.client.gui.components.AbstractSliderButton; -import net.minecraft.network.chat.Component; -import org.quiltmc.loader.api.minecraft.ClientOnly; - -@ClientOnly -class OptionsListSliderWidget extends AbstractSliderButton { - private final EntryInfo info; - private final MidnightConfig.Entry e; - - OptionsListSliderWidget(int x, int y, int width, int height, Component text, double value, EntryInfo info) { - super(x, y, width, height, text, value); - this.e = info.field.getAnnotation(MidnightConfig.Entry.class); - this.info = info; - } - - @Override - protected void updateMessage() { - this.setMessage(Component.nullToEmpty(info.tempValue)); - } - - @Override - protected void applyValue() { - if (info.field.getType() == int.class) - info.value = ((Number)(e.min() + value * (e.max() - e.min()))).intValue(); - else if (info.field.getType() == double.class) - info.value = Math.round((e.min() + value * (e.max() - e.min())) * (double)e.precision()) / (double)e.precision(); - else if (info.field.getType() == float.class) - info.value = Math.round((e.min() + value * (e.max() - e.min())) * (float)e.precision()) / (float)e.precision(); - info.tempValue = String.valueOf(info.value); - } -} diff --git a/src/main/java/com/fusionflux/portalcubed/packet/PortalCubedServerPackets.java b/src/main/java/com/fusionflux/portalcubed/packet/PortalCubedServerPackets.java index 154cf279..85525606 100644 --- a/src/main/java/com/fusionflux/portalcubed/packet/PortalCubedServerPackets.java +++ b/src/main/java/com/fusionflux/portalcubed/packet/PortalCubedServerPackets.java @@ -10,8 +10,6 @@ import com.fusionflux.portalcubed.entity.CorePhysicsEntity; import com.fusionflux.portalcubed.entity.TurretEntity; import com.fusionflux.portalcubed.items.PortalCubedItems; -import com.fusionflux.portalcubed.optionslist.OptionsListBlockEntity; -import com.fusionflux.portalcubed.optionslist.OptionsListData; import com.fusionflux.portalcubed.sound.PortalCubedSounds; import com.fusionflux.portalcubed.util.AdvancedEntityRaycast; import com.fusionflux.portalcubed.util.ClickHandlingItem; @@ -21,7 +19,6 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerGamePacketListenerImpl; import net.minecraft.sounds.SoundSource; @@ -65,7 +62,7 @@ public static void onGrabKeyPressed(MinecraftServer server, ServerPlayer player, Vec3 vec3d3 = vec3d.add(vec3d2.x * d, vec3d2.y * d, vec3d2.z * d); server.execute(() -> { - final AdvancedEntityRaycast.Result advancedCast = PortalDirectionUtils.raycast(player.level, new ClipContext( + final AdvancedEntityRaycast.Result advancedCast = PortalDirectionUtils.raycast(player.level(), new ClipContext( vec3d, vec3d3, ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player )); EntityHitResult entityHitResult = advancedCast.entityRaycast(player, (entity) -> !entity.isSpectator() && entity.isPickable()); @@ -76,12 +73,12 @@ public static void onGrabKeyPressed(MinecraftServer server, ServerPlayer player, } else if (!PortalCubedComponents.HOLDER_COMPONENT.get(player).stopHolding()) { if (advancedCast.finalHit().getType() == HitResult.Type.BLOCK) { final BlockHitResult hit = (BlockHitResult)advancedCast.finalHit(); - final BlockState state = player.level.getBlockState(hit.getBlockPos()); + final BlockState state = player.level().getBlockState(hit.getBlockPos()); if ( state.getBlock() instanceof TallButtonVariant button && - player.gameMode.useItemOn(player, player.level, ItemStack.EMPTY, InteractionHand.OFF_HAND, hit) != InteractionResult.PASS + player.gameMode.useItemOn(player, player.level(), ItemStack.EMPTY, InteractionHand.OFF_HAND, hit) != InteractionResult.PASS ) { - player.level.playSound(null, hit.getBlockPos(), button.getClickSound(true), SoundSource.BLOCKS, 0.8f, 1f); + player.level().playSound(null, hit.getBlockPos(), button.getClickSound(true), SoundSource.BLOCKS, 0.8f, 1f); return; } } @@ -95,7 +92,7 @@ public static void onRemovePortalKeyPressed(MinecraftServer server, ServerPlayer server.execute(() -> { boolean foundPortal = false; for (final UUID portal : List.copyOf(CalledValues.getPortals(player))) { - final Entity checkPortal = ((ServerLevel)player.level).getEntity(portal); + final Entity checkPortal = player.serverLevel().getEntity(portal); if (checkPortal != null) { foundPortal = true; checkPortal.kill(); @@ -122,7 +119,7 @@ public static void onVelocityHelperConfigure(MinecraftServer server, ServerPlaye } }; if (arg == null) return; - server.execute(() -> player.getLevel().getBlockEntity(origin, PortalCubedBlocks.VELOCITY_HELPER_BLOCK_ENTITY).ifPresentOrElse( + server.execute(() -> player.level().getBlockEntity(origin, PortalCubedBlocks.VELOCITY_HELPER_BLOCK_ENTITY).ifPresentOrElse( entity -> { switch (mode) { case VelocityHelperBlock.CONFIG_DEST -> { @@ -146,15 +143,15 @@ public static void onVelocityHelperConfigure(MinecraftServer server, ServerPlaye } public static void onOptionsListConfigure(MinecraftServer server, ServerPlayer player, @SuppressWarnings("unused") ServerGamePacketListenerImpl handler, @SuppressWarnings("unused") FriendlyByteBuf buf, @SuppressWarnings("unused") PacketSender sender) { - final BlockPos origin = buf.readBlockPos(); - final String json = buf.readUtf(); - server.execute(() -> { - if (!(player.getLevel().getBlockEntity(origin) instanceof OptionsListBlockEntity optionsListBlockEntity) || !player.isCreative()) { - return; - } - OptionsListData.read(json, optionsListBlockEntity); - optionsListBlockEntity.updateListeners(); - }); +// final BlockPos origin = buf.readBlockPos(); +// final String json = buf.readUtf(); +// server.execute(() -> { +// if (!(player.level().getBlockEntity(origin) instanceof OptionsListBlockEntity optionsListBlockEntity) || !player.isCreative()) { +// return; +// } +// OptionsListData.read(json, optionsListBlockEntity); +// optionsListBlockEntity.updateListeners(); +// }); } public static void registerPackets() { @@ -174,13 +171,13 @@ public static void registerPackets() { ); } server.execute(() -> { - player.level.playSound( + player.level().playSound( player, player.getX(), player.getY(), player.getZ(), PortalCubedSounds.CROWBAR_SWOOSH_EVENT, SoundSource.PLAYERS, 1f, 1f ); - TurretEntity.makeBulletHole((ServerLevel)player.level, hit, SoundSource.PLAYERS); + TurretEntity.makeBulletHole(player.serverLevel(), hit, SoundSource.PLAYERS); }); }); ServerPlayNetworking.registerGlobalReceiver(LEFT_CLICK, (server, player, handler, buf, responseSender) -> server.execute(() -> { diff --git a/src/main/java/com/fusionflux/portalcubed/util/HolderComponent.java b/src/main/java/com/fusionflux/portalcubed/util/HolderComponent.java index 05cf9c19..028510e2 100644 --- a/src/main/java/com/fusionflux/portalcubed/util/HolderComponent.java +++ b/src/main/java/com/fusionflux/portalcubed/util/HolderComponent.java @@ -51,7 +51,7 @@ public boolean hold(CorePhysicsEntity entityToHold) { RayonIntegration.INSTANCE.setNoGravity(heldEntity, true); this.heldEntityUUID = Optional.of(entityToHold.getUUID()); PortalCubedComponents.HOLDER_COMPONENT.sync(owner); - if (owner.level.isClientSide) { + if (owner.level().isClientSide) { grabbedWithGun = owner.isHolding(i -> i.getItem() instanceof PortalGun); playClientSound(false); } @@ -71,7 +71,7 @@ private void playClientSound(boolean stop) { } public @Nullable CorePhysicsEntity entityBeingHeld() { - if (heldEntity == null && heldEntityUUID.isPresent()) this.heldEntity = (CorePhysicsEntity) ((LevelExt) this.owner.level).getEntityByUuid(heldEntityUUID.get()); + if (heldEntity == null && heldEntityUUID.isPresent()) this.heldEntity = (CorePhysicsEntity) ((LevelExt) this.owner.level()).getEntityByUuid(heldEntityUUID.get()); return this.heldEntity; } @@ -81,7 +81,7 @@ public boolean stopHolding() { if (!heldEntity.fizzling()) { RayonIntegration.INSTANCE.setNoGravity(heldEntity, false); } - if (owner.level.isClientSide && !heldEntity.isRemoved()) { + if (owner.level().isClientSide && !heldEntity.isRemoved()) { var buf = PacketByteBufs.create(); buf.writeDouble(heldEntity.position().x); buf.writeDouble(heldEntity.position().y); @@ -97,7 +97,7 @@ public boolean stopHolding() { this.heldEntityUUID = Optional.empty(); this.heldEntity = null; PortalCubedComponents.HOLDER_COMPONENT.sync(owner); - if (owner.level.isClientSide) { + if (owner.level().isClientSide) { playClientSound(true); } return true; @@ -125,7 +125,7 @@ public boolean shouldSyncWith(ServerPlayer player) { public void applySyncPacket(FriendlyByteBuf buf) { final var syncedHeldEntityUUID = EntityDataSerializers.OPTIONAL_UUID.read(buf); if (heldEntity == null && syncedHeldEntityUUID.isPresent()) { - hold((CorePhysicsEntity) ((LevelExt) this.owner.level).getEntityByUuid(syncedHeldEntityUUID.get())); + hold((CorePhysicsEntity) ((LevelExt) this.owner.level()).getEntityByUuid(syncedHeldEntityUUID.get())); } else if (syncedHeldEntityUUID.isEmpty() && heldEntity != null) { stopHolding(); } diff --git a/src/main/java/com/fusionflux/portalcubed/util/PortalDirectionUtils.java b/src/main/java/com/fusionflux/portalcubed/util/PortalDirectionUtils.java index 506e3144..44e22e37 100644 --- a/src/main/java/com/fusionflux/portalcubed/util/PortalDirectionUtils.java +++ b/src/main/java/com/fusionflux/portalcubed/util/PortalDirectionUtils.java @@ -42,7 +42,7 @@ public static Vec3 rotateVector(Portal portal, Vec3 vector) { blockHit.getLocation(), AdvancedEntityRaycast.withStartEnd(context, newStart, newStart.add(newOffset)), portal.getLinkedPortalUUID() - .flatMap(id -> Optional.ofNullable(((LevelExt)portal.getLevel()).getEntityByUuid(id))) + .flatMap(id -> Optional.ofNullable(((LevelExt)portal.level()).getEntityByUuid(id))) .map(Set::of) .orElse(Set.of()) ); diff --git a/src/main/resources/portal_tabs.json b/src/main/resources/portal_tabs.json index a6af45b2..047f5971 100644 --- a/src/main/resources/portal_tabs.json +++ b/src/main/resources/portal_tabs.json @@ -1,5 +1,8 @@ -{ - "main_testing_elements": { +[ + { + "title": { + "translate": "itemGroup.portalcubed.main_testing_elements" + }, "icon": "portalcubed:portal_gun", "items": [ "portalcubed:hammer", @@ -51,7 +54,10 @@ "portalcubed:excursion_funnel_emitter" ] }, - "other_testing_elements": { + { + "title": { + "translate": "itemGroup.portalcubed.other_testing_elements" + }, "icon": "portalcubed:paint_gun", "items": [ "portalcubed:paint_gun", @@ -85,7 +91,10 @@ ] }, - "portal_blocks": { + { + "title": { + "translate": "itemGroup.portalcubed.portal_blocks" + }, "icon": "portalcubed:block_item_icon", "items": [ "portalcubed:portal_1_white_checkered_panel", @@ -275,4 +284,4 @@ ] } -} \ No newline at end of file +] \ No newline at end of file