From 34012fd6a6427dedeadaec3b2d9c22e5d5f67d1c Mon Sep 17 00:00:00 2001 From: Ayutac Date: Sun, 20 Nov 2022 17:28:46 +0100 Subject: [PATCH] 1.19 launchpad and elevator, textures by Spearkiller (#3060) * crude launchpad functionality * added launchpad config * gave launchpad ingame config, now speed's changeable * made launchpad orientable * added block drop * added recipe + recipe advancement * launchpad texture by Spearkiller * added configurable launch interval * added sound * cleanup * small cleanup * minor refactoring: static to non static * added elevator block (with launchpad functionality) * added elevator functionality w/o mixin * added blank elevator GUI * added elevator textures by Spearkiller * implemented down travelling * implemented up travelling * fixed energy usage * minor refactoring: changed from static to non-static * improved teleport command * improved getting world limits * minor refactoring, code improvement, documentation * improved sound * made going through blocks optional * corrected prev commit, whoopsie * Mixin KeyBinding * minor formatting * removed generated block loot Co-authored-by: ayutac Co-authored-by: modmuss50 --- .../reborncore/client/ClientJumpEvent.java | 38 +++ .../client/mixin/MixinKeyBinding.java | 45 ++++ .../resources/reborncore.client.mixins.json | 3 +- .../main/resources/reborncore.accesswidener | 3 +- .../java/techreborn/TechRebornClient.java | 4 + .../java/techreborn/client/ClientGuiType.java | 4 +- .../client/events/ClientJumpHandler.java | 50 ++++ .../techreborn/client/gui/GuiElevator.java | 50 ++++ .../techreborn/client/gui/GuiLaunchpad.java | 79 ++++++ .../java/techreborn/blockentity/GuiType.java | 3 + .../machine/tier1/ElevatorBlockEntity.java | 247 ++++++++++++++++++ .../machine/tier2/LaunchpadBlockEntity.java | 202 ++++++++++++++ .../techreborn/config/TechRebornConfig.java | 48 ++++ .../java/techreborn/init/TRBlockEntities.java | 3 + src/main/java/techreborn/init/TRContent.java | 3 + .../packets/ServerboundPackets.java | 40 +++ .../techreborn/blockstates/elevator.json | 5 + .../techreborn/blockstates/launchpad.json | 5 + .../assets/techreborn/lang/en_us.json | 14 +- .../machines/tier1_machines/elevator.json | 9 + .../machines/tier2_machines/launchpad.json | 9 + .../techreborn/models/item/elevator.json | 3 + .../techreborn/models/item/launchpad.json | 3 + .../machines/tier1_machines/elevator_end.png | Bin 0 -> 448 bytes .../machines/tier1_machines/elevator_side.png | Bin 0 -> 549 bytes .../tier2_machines/launchpad_side.png | Bin 0 -> 690 bytes .../machines/tier2_machines/launchpad_top.png | Bin 0 -> 445 bytes .../crafting_table/machine/elevator.json | 43 +++ .../crafting_table/machine/launchpad.json | 43 +++ .../crafting_table/machine/elevator.json | 25 ++ .../crafting_table/machine/launchpad.json | 28 ++ src/main/resources/techreborn.accesswidener | 1 + 32 files changed, 1004 insertions(+), 6 deletions(-) create mode 100644 RebornCore/src/client/java/reborncore/client/ClientJumpEvent.java create mode 100644 RebornCore/src/client/java/reborncore/client/mixin/MixinKeyBinding.java create mode 100644 src/client/java/techreborn/client/events/ClientJumpHandler.java create mode 100644 src/client/java/techreborn/client/gui/GuiElevator.java create mode 100644 src/client/java/techreborn/client/gui/GuiLaunchpad.java create mode 100644 src/main/java/techreborn/blockentity/machine/tier1/ElevatorBlockEntity.java create mode 100644 src/main/java/techreborn/blockentity/machine/tier2/LaunchpadBlockEntity.java create mode 100644 src/main/resources/assets/techreborn/blockstates/elevator.json create mode 100644 src/main/resources/assets/techreborn/blockstates/launchpad.json create mode 100644 src/main/resources/assets/techreborn/models/block/machines/tier1_machines/elevator.json create mode 100644 src/main/resources/assets/techreborn/models/block/machines/tier2_machines/launchpad.json create mode 100644 src/main/resources/assets/techreborn/models/item/elevator.json create mode 100644 src/main/resources/assets/techreborn/models/item/launchpad.json create mode 100644 src/main/resources/assets/techreborn/textures/block/machines/tier1_machines/elevator_end.png create mode 100644 src/main/resources/assets/techreborn/textures/block/machines/tier1_machines/elevator_side.png create mode 100644 src/main/resources/assets/techreborn/textures/block/machines/tier2_machines/launchpad_side.png create mode 100644 src/main/resources/assets/techreborn/textures/block/machines/tier2_machines/launchpad_top.png create mode 100644 src/main/resources/data/techreborn/advancements/recipes/crafting_table/machine/elevator.json create mode 100644 src/main/resources/data/techreborn/advancements/recipes/crafting_table/machine/launchpad.json create mode 100644 src/main/resources/data/techreborn/recipes/crafting_table/machine/elevator.json create mode 100644 src/main/resources/data/techreborn/recipes/crafting_table/machine/launchpad.json diff --git a/RebornCore/src/client/java/reborncore/client/ClientJumpEvent.java b/RebornCore/src/client/java/reborncore/client/ClientJumpEvent.java new file mode 100644 index 000000000..94ad7e6ad --- /dev/null +++ b/RebornCore/src/client/java/reborncore/client/ClientJumpEvent.java @@ -0,0 +1,38 @@ +/* + * This file is part of RebornCore, licensed under the MIT License (MIT). + * + * Copyright (c) 2021 TeamReborn + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package reborncore.client; + +import net.fabricmc.fabric.api.event.Event; +import net.fabricmc.fabric.api.event.EventFactory; + +public interface ClientJumpEvent { + Event EVENT = EventFactory.createArrayBacked(ClientJumpEvent.class, (listeners) -> () -> { + for (ClientJumpEvent callback : listeners) { + callback.jump(); + } + }); + + void jump(); +} diff --git a/RebornCore/src/client/java/reborncore/client/mixin/MixinKeyBinding.java b/RebornCore/src/client/java/reborncore/client/mixin/MixinKeyBinding.java new file mode 100644 index 000000000..0b8439e18 --- /dev/null +++ b/RebornCore/src/client/java/reborncore/client/mixin/MixinKeyBinding.java @@ -0,0 +1,45 @@ +/* + * This file is part of RebornCore, licensed under the MIT License (MIT). + * + * Copyright (c) 2021 TeamReborn + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package reborncore.client.mixin; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.option.KeyBinding; +import net.minecraft.client.util.InputUtil; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; +import reborncore.client.ClientJumpEvent; + +@Mixin(KeyBinding.class) +public abstract class MixinKeyBinding { + @Inject(method = "onKeyPressed", at = @At(value = "FIELD", target = "Lnet/minecraft/client/option/KeyBinding;timesPressed:I"), locals = LocalCapture.CAPTURE_FAILHARD) + private static void onKeyPressed(InputUtil.Key key, CallbackInfo ci, KeyBinding keyBinding) { + if (keyBinding == MinecraftClient.getInstance().options.jumpKey) { + ClientJumpEvent.EVENT.invoker().jump(); + } + } +} diff --git a/RebornCore/src/client/resources/reborncore.client.mixins.json b/RebornCore/src/client/resources/reborncore.client.mixins.json index d31d2cc9f..e47a98e7c 100644 --- a/RebornCore/src/client/resources/reborncore.client.mixins.json +++ b/RebornCore/src/client/resources/reborncore.client.mixins.json @@ -4,7 +4,8 @@ "compatibilityLevel": "JAVA_17", "client": [ "MixinDebugRenderer", - "MixinGameRenderer" + "MixinGameRenderer", + "MixinKeyBinding" ], "injectors": { "defaultRequire": 1 diff --git a/RebornCore/src/main/resources/reborncore.accesswidener b/RebornCore/src/main/resources/reborncore.accesswidener index 178cae04f..b72e1c3a9 100644 --- a/RebornCore/src/main/resources/reborncore.accesswidener +++ b/RebornCore/src/main/resources/reborncore.accesswidener @@ -21,4 +21,5 @@ accessible field net/minecraft/client/gui/screen/Screen selectables accessible field net/minecraft/block/FluidBlock fluid Lnet/minecraft/fluid/FlowableFluid; accessible method net/minecraft/world/gen/foliage/FoliagePlacerType register (Ljava/lang/String;Lcom/mojang/serialization/Codec;)Lnet/minecraft/world/gen/foliage/FoliagePlacerType; accessible method net/minecraft/recipe/RecipeManager getAllOfType (Lnet/minecraft/recipe/RecipeType;)Ljava/util/Map; -accessible field net/minecraft/screen/ScreenHandler listeners Ljava/util/List; \ No newline at end of file +accessible field net/minecraft/screen/ScreenHandler listeners Ljava/util/List; +accessible field net/minecraft/entity/LivingEntity jumping Z \ No newline at end of file diff --git a/src/client/java/techreborn/TechRebornClient.java b/src/client/java/techreborn/TechRebornClient.java index 114a84bcf..9b34c8282 100644 --- a/src/client/java/techreborn/TechRebornClient.java +++ b/src/client/java/techreborn/TechRebornClient.java @@ -50,6 +50,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; import org.jetbrains.annotations.Nullable; +import reborncore.client.ClientJumpEvent; import reborncore.client.gui.builder.GuiBase; import reborncore.client.multiblock.MultiblockRenderer; import reborncore.common.powerSystem.RcEnergyItem; @@ -57,6 +58,7 @@ import reborncore.common.util.ItemUtils; import team.reborn.energy.api.base.SimpleBatteryItem; import techreborn.client.ClientGuiType; import techreborn.client.ClientboundPacketHandlers; +import techreborn.client.events.ClientJumpHandler; import techreborn.client.events.StackToolTipHandler; import techreborn.client.render.DynamicBucketBakedModel; import techreborn.client.render.DynamicCellBakedModel; @@ -245,6 +247,8 @@ public class TechRebornClient implements ClientModInitializer { ); ClientGuiType.validate(); + + ClientJumpEvent.EVENT.register(new ClientJumpHandler()); } private static void registerPredicateProvider(Class itemClass, Identifier identifier, ItemModelPredicateProvider modelPredicateProvider) { diff --git a/src/client/java/techreborn/client/ClientGuiType.java b/src/client/java/techreborn/client/ClientGuiType.java index 5dc19ab4c..e29bcb67e 100644 --- a/src/client/java/techreborn/client/ClientGuiType.java +++ b/src/client/java/techreborn/client/ClientGuiType.java @@ -26,7 +26,6 @@ package techreborn.client; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.fabricmc.fabric.api.client.screenhandler.v1.ScreenRegistry; import net.minecraft.block.entity.BlockEntity; import net.minecraft.client.gui.screen.ingame.HandledScreens; import net.minecraft.util.Identifier; @@ -45,6 +44,7 @@ import techreborn.blockentity.machine.multiblock.*; import techreborn.blockentity.machine.tier0.block.BlockBreakerBlockEntity; import techreborn.blockentity.machine.tier0.block.BlockPlacerBlockEntity; import techreborn.blockentity.machine.tier1.*; +import techreborn.blockentity.machine.tier2.LaunchpadBlockEntity; import techreborn.blockentity.machine.tier3.ChunkLoaderBlockEntity; import techreborn.blockentity.machine.tier3.IndustrialCentrifugeBlockEntity; import techreborn.blockentity.machine.tier3.MatterFabricatorBlockEntity; @@ -113,6 +113,8 @@ public class ClientGuiType { public static final ClientGuiType PLAYER_DETECTOR = register(GuiType.PLAYER_DETECTOR, GuiPlayerDetector::new); public static final ClientGuiType BLOCK_BREAKER = register(GuiType.BLOCK_BREAKER, GuiBlockBreaker::new); public static final ClientGuiType BLOCK_PLACER = register(GuiType.BLOCK_PLACER, GuiBlockPlacer::new); + public static final ClientGuiType LAUNCHPAD = register(GuiType.LAUNCHPAD, GuiLaunchpad::new); + public static final ClientGuiType ELEVATOR = register(GuiType.ELEVATOR, GuiElevator::new); private static ClientGuiType register(GuiType type, GuiFactory factory) { return new ClientGuiType<>(type, factory); diff --git a/src/client/java/techreborn/client/events/ClientJumpHandler.java b/src/client/java/techreborn/client/events/ClientJumpHandler.java new file mode 100644 index 000000000..bf3e0d2ec --- /dev/null +++ b/src/client/java/techreborn/client/events/ClientJumpHandler.java @@ -0,0 +1,50 @@ +/* + * This file is part of TechReborn, licensed under the MIT License (MIT). + * + * Copyright (c) 2020 TechReborn + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package techreborn.client.events; + +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.ClientPlayerEntity; +import reborncore.client.ClientJumpEvent; +import reborncore.client.ClientNetworkManager; +import techreborn.blockentity.machine.tier1.ElevatorBlockEntity; +import techreborn.packets.ServerboundPackets; + +public class ClientJumpHandler implements ClientJumpEvent { + @Override + public void jump() { + ClientPlayerEntity player = MinecraftClient.getInstance().player; + + if (player == null) { + return; + } + + BlockEntity blockEntity = player.getWorld().getBlockEntity(player.getBlockPos().down()); + + if (blockEntity instanceof ElevatorBlockEntity) { + ClientNetworkManager.sendToServer(ServerboundPackets.createPacketJump(player.getBlockPos())); + } + } +} diff --git a/src/client/java/techreborn/client/gui/GuiElevator.java b/src/client/java/techreborn/client/gui/GuiElevator.java new file mode 100644 index 000000000..dd4c6e355 --- /dev/null +++ b/src/client/java/techreborn/client/gui/GuiElevator.java @@ -0,0 +1,50 @@ +/* + * This file is part of TechReborn, licensed under the MIT License (MIT). + * + * Copyright (c) 2020 TechReborn + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package techreborn.client.gui; + +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.entity.player.PlayerEntity; +import reborncore.client.gui.builder.GuiBase; +import reborncore.common.screen.BuiltScreenHandler; +import techreborn.blockentity.machine.tier1.ElevatorBlockEntity; + +public class GuiElevator extends GuiBase { + + ElevatorBlockEntity blockEntity; + + public GuiElevator(int syncID, final PlayerEntity player, final ElevatorBlockEntity blockEntity) { + super(player, blockEntity, blockEntity.createScreenHandler(syncID, player)); + this.blockEntity = blockEntity; + } + + @Override + protected void drawForeground(MatrixStack matrixStack, final int mouseX, final int mouseY) { + super.drawForeground(matrixStack, mouseX, mouseY); + final Layer layer = Layer.FOREGROUND; + + builder.drawMultiEnergyBar(matrixStack, this, 9, 19, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxStoredPower(), mouseX, mouseY, 0, layer); + } + +} diff --git a/src/client/java/techreborn/client/gui/GuiLaunchpad.java b/src/client/java/techreborn/client/gui/GuiLaunchpad.java new file mode 100644 index 000000000..276433801 --- /dev/null +++ b/src/client/java/techreborn/client/gui/GuiLaunchpad.java @@ -0,0 +1,79 @@ +/* + * This file is part of TechReborn, licensed under the MIT License (MIT). + * + * Copyright (c) 2020 TechReborn + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package techreborn.client.gui; + +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.text.Text; +import reborncore.client.ClientNetworkManager; +import reborncore.client.gui.builder.GuiBase; +import reborncore.client.gui.builder.widget.GuiButtonUpDown; +import reborncore.common.screen.BuiltScreenHandler; +import techreborn.blockentity.machine.tier2.LaunchpadBlockEntity; +import techreborn.packets.ServerboundPackets; + +public class GuiLaunchpad extends GuiBase { + + LaunchpadBlockEntity blockEntity; + + public GuiLaunchpad(int syncID, final PlayerEntity player, final LaunchpadBlockEntity blockEntity) { + super(player, blockEntity, blockEntity.createScreenHandler(syncID, player)); + this.blockEntity = blockEntity; + } + + private void onClick(int amount) { + ClientNetworkManager.sendToServer(ServerboundPackets.createPacketLaunchpad(amount, blockEntity)); + } + + @Override + public void init() { + super.init(); + + addDrawableChild(new GuiButtonUpDown(x + 64, y + 40, this, b -> onClick(LaunchpadBlockEntity.MAX_SELECTION), GuiButtonUpDown.UpDownButtonType.FASTFORWARD)); + addDrawableChild(new GuiButtonUpDown(x + 64 + 12, y + 40, this, b -> onClick(1), GuiButtonUpDown.UpDownButtonType.FORWARD)); + addDrawableChild(new GuiButtonUpDown(x + 64 + 24, y + 40, this, b -> onClick(-1), GuiButtonUpDown.UpDownButtonType.REWIND)); + addDrawableChild(new GuiButtonUpDown(x + 64 + 36, y + 40, this, b -> onClick(-LaunchpadBlockEntity.MAX_SELECTION), GuiButtonUpDown.UpDownButtonType.FASTREWIND)); + } + + @Override + protected void drawBackground(MatrixStack matrixStack, float partialTicks, int mouseX, int mouseY) { + super.drawBackground(matrixStack, partialTicks, mouseX, mouseY); + final Layer layer = Layer.BACKGROUND; + + if (hideGuiElements()) return; + + Text text = Text.literal("Launch Speed: ").append(Text.translatable(blockEntity.selectedTranslationKey())); + drawCentredText(matrixStack, text, 25, 4210752, layer); + } + + @Override + protected void drawForeground(MatrixStack matrixStack, final int mouseX, final int mouseY) { + super.drawForeground(matrixStack, mouseX, mouseY); + final Layer layer = Layer.FOREGROUND; + + builder.drawMultiEnergyBar(matrixStack, this, 9, 19, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxStoredPower(), mouseX, mouseY, 0, layer); + } + +} diff --git a/src/main/java/techreborn/blockentity/GuiType.java b/src/main/java/techreborn/blockentity/GuiType.java index b3d7d78fb..3b2da2c14 100644 --- a/src/main/java/techreborn/blockentity/GuiType.java +++ b/src/main/java/techreborn/blockentity/GuiType.java @@ -56,6 +56,7 @@ import techreborn.blockentity.machine.multiblock.*; import techreborn.blockentity.machine.tier0.block.BlockBreakerBlockEntity; import techreborn.blockentity.machine.tier0.block.BlockPlacerBlockEntity; import techreborn.blockentity.machine.tier1.*; +import techreborn.blockentity.machine.tier2.LaunchpadBlockEntity; import techreborn.blockentity.machine.tier3.ChunkLoaderBlockEntity; import techreborn.blockentity.machine.tier3.IndustrialCentrifugeBlockEntity; import techreborn.blockentity.machine.tier3.MatterFabricatorBlockEntity; @@ -121,6 +122,8 @@ public final class GuiType implements IMachineGuiHandler public static final GuiType PLAYER_DETECTOR = register("player_detector"); public static final GuiType BLOCK_BREAKER = register("block_breaker"); public static final GuiType BLOCK_PLACER = register("block_placer"); + public static final GuiType LAUNCHPAD = register("launchpad"); + public static final GuiType ELEVATOR = register("elevator"); private static GuiType register(String id) { return register(new Identifier("techreborn", id)); diff --git a/src/main/java/techreborn/blockentity/machine/tier1/ElevatorBlockEntity.java b/src/main/java/techreborn/blockentity/machine/tier1/ElevatorBlockEntity.java new file mode 100644 index 000000000..ec086ced2 --- /dev/null +++ b/src/main/java/techreborn/blockentity/machine/tier1/ElevatorBlockEntity.java @@ -0,0 +1,247 @@ +/* + * This file is part of TechReborn, licensed under the MIT License (MIT). + * + * Copyright (c) 2020 TechReborn + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package techreborn.blockentity.machine.tier1; + +import net.fabricmc.fabric.api.dimension.v1.FabricDimensions; +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvents; +import net.minecraft.util.math.*; +import net.minecraft.world.TeleportTarget; +import net.minecraft.world.World; +import org.jetbrains.annotations.Nullable; +import reborncore.api.IToolDrop; +import reborncore.common.blockentity.MachineBaseBlockEntity; +import reborncore.common.blockentity.RedstoneConfiguration; +import reborncore.common.powerSystem.PowerAcceptorBlockEntity; +import reborncore.common.screen.BuiltScreenHandler; +import reborncore.common.screen.BuiltScreenHandlerProvider; +import reborncore.common.screen.builder.ScreenHandlerBuilder; +import techreborn.config.TechRebornConfig; +import techreborn.init.TRBlockEntities; +import techreborn.init.TRContent; + +import java.util.List; +import java.util.Optional; + +public class ElevatorBlockEntity extends PowerAcceptorBlockEntity implements IToolDrop, BuiltScreenHandlerProvider { + + public ElevatorBlockEntity(BlockPos pos, BlockState state) { + super(TRBlockEntities.ELEVATOR, pos, state); + } + + /** + * @param targetPos the position of another elevator + */ + public boolean isRunning(final BlockPos targetPos) { + // null-safe because of the following instanceof + final BlockEntity entity = getWorld().getBlockEntity(targetPos); + if (!(entity instanceof ElevatorBlockEntity)) { + return false; + } + return ((ElevatorBlockEntity)entity).getStored() > 0; + } + + /** + * @param targetPos the position will be checked to be an elevator or air + */ + public boolean isAirOrElevator(final BlockPos targetPos) { + return getWorld().isAir(targetPos) || getWorld().getBlockEntity(targetPos) instanceof ElevatorBlockEntity; + } + + /** + * @param targetPos the position of another elevator + */ + public boolean isFree(final BlockPos targetPos) { + return getWorld().getBlockState(targetPos.up()).isAir() && getWorld().getBlockState(targetPos.up().up()).isAir(); + } + + /** + * @param targetPos the position of another elevator + */ + public boolean isValidTarget(final BlockPos targetPos) { + return isRunning(targetPos) && isFree(targetPos); + } + + public Optional nextUpElevator() { + BlockPos upPos = getPos().up().up(); + if (!TechRebornConfig.allowElevatingThroughBlocks && (!isAirOrElevator(getPos().up()) || !isAirOrElevator(getPos().up().up()))) { + return Optional.empty(); + } + do { + upPos = upPos.up(); + if (!TechRebornConfig.allowElevatingThroughBlocks && !isAirOrElevator(upPos)) { + return Optional.empty(); + } + } while (upPos.getY() <= getWorld().getTopY() && !isValidTarget(upPos)); + if (upPos.getY() < getWorld().getTopY() || isValidTarget(upPos)) { + return Optional.of(upPos); + } + return Optional.empty(); + } + + public Optional nextDownElevator() { + BlockPos downPos = getPos().down().down(); + if (!TechRebornConfig.allowElevatingThroughBlocks && (!isAirOrElevator(getPos().down()) || !isAirOrElevator(getPos().down().down()))) { + return Optional.empty(); + } + do { + downPos = downPos.down(); + if (!TechRebornConfig.allowElevatingThroughBlocks && !isAirOrElevator(downPos)) { + return Optional.empty(); + } + } while (downPos.getY() >= getWorld().getBottomY() && !isValidTarget(downPos)); + if (downPos.getY() > getWorld().getBottomY() || isValidTarget(downPos)) { + return Optional.of(downPos); + } + return Optional.empty(); + } + + /** + * @param targetPos the position of another elevator + */ + public int energyCost(final BlockPos targetPos) { + return Math.max(Math.abs(targetPos.getY()-getPos().getY())*TechRebornConfig.elevatorEnergyPerBlock,0); + } + + /** + * @param targetPos the position over another elevator + */ + protected boolean teleport(final PlayerEntity player, final BlockPos targetPos) { + if (!(getWorld() instanceof ServerWorld)) { + return false; + } + final int energy = energyCost(targetPos); + if (getStored() < energy) { + return false; + } + playTeleportSoundAt(getPos()); + FabricDimensions.teleport(player, (ServerWorld)getWorld(), + new TeleportTarget(Vec3d.ofBottomCenter(new Vec3i(targetPos.getX(), targetPos.getY(), targetPos.getZ())), Vec3d.ZERO, player.getYaw(), player.getPitch())); + useEnergy(energy); + playTeleportSoundAt(targetPos); + return true; + } + + protected void playTeleportSoundAt(final BlockPos targetPos) { + getWorld().playSound(null, targetPos, SoundEvents.ENTITY_ENDERMAN_TELEPORT, SoundCategory.BLOCKS, 1f, 1f); + } + + public void teleportUp(final PlayerEntity player) { + if (!this.pos.isWithinDistance(player.getPos(), 5) && player.world == this.world) { + // Ensure the player is close to the elevator and in the same world. + return; + } + + Optional upTarget = nextUpElevator(); + if (upTarget.isEmpty()) { + return; + } + if (teleport(player, upTarget.get().up())) { + player.setJumping(false); + } + } + + // PowerAcceptorBlockEntity + @Override + public void tick(World world, BlockPos pos, BlockState state, MachineBaseBlockEntity blockEntity) { + super.tick(world, pos, state, blockEntity); + if (!(world instanceof ServerWorld) || getStored() <= 0 || !isActive(RedstoneConfiguration.POWER_IO)) { + return; + } + + // teleporting up must be done via mixin for now + Optional downTarget = null; + + List players = world.getNonSpectatingEntities(PlayerEntity.class, new Box(0d,1d,0d,1d,2d,1d).offset(pos)); + if (players.size() == 0) { + return; + } + for (PlayerEntity player : players) { + if (player.isSneaking()) { + if (downTarget == null) { + downTarget = nextDownElevator(); + } + if (downTarget.isEmpty()) { + continue; + } + if (teleport(player, downTarget.get().up())) { + player.setSneaking(false); + } + } + } + } + @Override + public long getBaseMaxPower() { + return TechRebornConfig.elevatorMaxEnergy; + } + + @Override + public boolean canProvideEnergy(@Nullable Direction side) { + return false; + } + + @Override + public long getBaseMaxOutput() { + return 0; + } + + @Override + public long getBaseMaxInput() { + return TechRebornConfig.elevatorMaxInput; + } + + // MachineBaseBlockEntity + @Override + public boolean hasSlotConfig() { + return false; + } + + @Override + public boolean canBeUpgraded() { + return false; + } + + // IToolDrop + @Override + public ItemStack getToolDrop(PlayerEntity p0) { + return TRContent.Machine.ELEVATOR.getStack(); + } + + // BuiltScreenHandlerProvider + @Override + public BuiltScreenHandler createScreenHandler(int syncID, PlayerEntity player) { + return new ScreenHandlerBuilder("elevator") + .player(player.getInventory()) + .inventory().hotbar().addInventory() + .blockEntity(this) + .syncEnergyValue() + .addInventory().create(this, syncID); + } +} diff --git a/src/main/java/techreborn/blockentity/machine/tier2/LaunchpadBlockEntity.java b/src/main/java/techreborn/blockentity/machine/tier2/LaunchpadBlockEntity.java new file mode 100644 index 000000000..142d47866 --- /dev/null +++ b/src/main/java/techreborn/blockentity/machine/tier2/LaunchpadBlockEntity.java @@ -0,0 +1,202 @@ +/* + * This file is part of TechReborn, licensed under the MIT License (MIT). + * + * Copyright (c) 2020 TechReborn + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package techreborn.blockentity.machine.tier2; + +import net.minecraft.block.BlockState; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvents; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Box; +import net.minecraft.util.math.Direction; +import net.minecraft.world.World; +import org.jetbrains.annotations.Nullable; +import reborncore.api.IToolDrop; +import reborncore.common.blockentity.MachineBaseBlockEntity; +import reborncore.common.blockentity.RedstoneConfiguration; +import reborncore.common.powerSystem.PowerAcceptorBlockEntity; +import reborncore.common.screen.BuiltScreenHandler; +import reborncore.common.screen.BuiltScreenHandlerProvider; +import reborncore.common.screen.builder.ScreenHandlerBuilder; +import techreborn.config.TechRebornConfig; +import techreborn.init.TRBlockEntities; +import techreborn.init.TRContent; + +import java.util.List; + +public class LaunchpadBlockEntity extends PowerAcceptorBlockEntity implements IToolDrop, BuiltScreenHandlerProvider { + + public static final int MAX_SELECTION = 3; + private int selection = TechRebornConfig.launchpadDefaultSelection; + + public LaunchpadBlockEntity(BlockPos pos, BlockState state) { + super(TRBlockEntities.LAUNCHPAD, pos, state); + } + + public void handleGuiInputFromClient(int amount) { + selection += amount; + ensureSelectionInRange(); + } + + public void ensureSelectionInRange() { + if (selection > MAX_SELECTION) { + selection = MAX_SELECTION; + } + if (selection <= 0) { + selection = 0; + } + } + + public double selectedSpeed() { + return switch(selection) { + case 0 -> TechRebornConfig.launchpadSpeedLow; + case 1 -> TechRebornConfig.launchpadSpeedMedium; + case 2 -> TechRebornConfig.launchpadSpeedHigh; + case MAX_SELECTION -> TechRebornConfig.launchpadSpeedExtreme; + default -> throw new IllegalArgumentException("Impossible launchpad selection value!"); + }; + } + + public int selectedEnergyCost() { + return switch(selection) { + case 0 -> TechRebornConfig.launchpadEnergyLow; + case 1 -> TechRebornConfig.launchpadEnergyMedium; + case 2 -> TechRebornConfig.launchpadEnergyHigh; + case MAX_SELECTION -> TechRebornConfig.launchpadEnergyExtreme; + default -> throw new IllegalArgumentException("Impossible launchpad selection value!"); + }; + } + + public String selectedTranslationKey() { + return switch(selection) { + case 0 -> "techreborn.message.info.block.techreborn.launchpad.low"; + case 1 -> "techreborn.message.info.block.techreborn.launchpad.medium"; + case 2 -> "techreborn.message.info.block.techreborn.launchpad.high"; + case MAX_SELECTION -> "techreborn.message.info.block.techreborn.launchpad.extreme"; + default -> throw new IllegalArgumentException("Impossible launchpad selection value!"); + }; + } + + // PowerAcceptorBlockEntity + @Override + public void tick(World world, BlockPos pos, BlockState state, MachineBaseBlockEntity blockEntity) { + super.tick(world, pos, state, blockEntity); + if (world == null || getStored() <= 0 || !isActive(RedstoneConfiguration.POWER_IO)) { + return; + } + + if (world.getTime() % TechRebornConfig.launchpadInterval != 0) { + return; + } + + ensureSelectionInRange(); + final double speed = selectedSpeed(); + final int energyCost = selectedEnergyCost(); + + if (getStored() > energyCost) { + List entities = world.getNonSpectatingEntities(Entity.class, new Box(0d,1d,0d,1d,2d,1d).offset(pos)); + if (entities.size() == 0) { + return; + } + world.playSound(null, pos, SoundEvents.BLOCK_PISTON_EXTEND, SoundCategory.BLOCKS, 1f, 1f); + for (Entity entity : entities) { + entity.addVelocity(0d, speed, 0d); + } + useEnergy(energyCost); + } + } + + @Override + public long getBaseMaxPower() { + return TechRebornConfig.launchpadMaxEnergy; + } + + @Override + public boolean canProvideEnergy(@Nullable Direction side) { + return false; + } + + @Override + public long getBaseMaxOutput() { + return 0; + } + + @Override + public long getBaseMaxInput() { + return TechRebornConfig.launchpadMaxInput; + } + + @Override + public void readNbt(NbtCompound tag) { + super.readNbt(tag); + selection = tag.getInt("selection"); + } + + @Override + public void writeNbt(NbtCompound tag) { + super.writeNbt(tag); + tag.putInt("selection", selection); + } + + // MachineBaseBlockEntity + @Override + public boolean hasSlotConfig() { + return false; + } + + @Override + public boolean canBeUpgraded() { + return false; + } + + // IToolDrop + @Override + public ItemStack getToolDrop(PlayerEntity p0) { + return TRContent.Machine.LAUNCHPAD.getStack(); + } + + // BuiltScreenHandlerProvider + @Override + public BuiltScreenHandler createScreenHandler(int syncID, PlayerEntity player) { + return new ScreenHandlerBuilder("launchpad") + .player(player.getInventory()) + .inventory().hotbar().addInventory() + .blockEntity(this) + .syncEnergyValue() + .sync(this::getSelection, this::setSelection) + .addInventory().create(this, syncID); + } + + public int getSelection() { + return selection; + } + + public void setSelection(int selection) { + this.selection = selection; + } +} diff --git a/src/main/java/techreborn/config/TechRebornConfig.java b/src/main/java/techreborn/config/TechRebornConfig.java index f1292580a..a0a4b469d 100644 --- a/src/main/java/techreborn/config/TechRebornConfig.java +++ b/src/main/java/techreborn/config/TechRebornConfig.java @@ -585,6 +585,54 @@ public class TechRebornConfig { @Config(config = "machines", category = "block_placer", key = "BlockPlacerBaseBreakTime", comment = "How many ticks a block of hardness 1 requires to be placed") public static int blockPlacerBaseBreakTime = 100; + @Config(config = "machines", category = "launchpad", key = "LaunchpadMaxInput", comment = "Launchpad Max Input (Energy per tick)") + public static int launchpadMaxInput = 128; + + @Config(config = "machines", category = "launchpad", key = "LaunchpadMaxEnergy", comment = "Launchpad Max Energy") + public static int launchpadMaxEnergy = 40_000; + + @Config(config = "machines", category = "launchpad", key = "LaunchpadSpeedLow", comment = "Launchpad Low Speed") + public static double launchpadSpeedLow = 1d; + + @Config(config = "machines", category = "launchpad", key = "LaunchpadSpeedMedium", comment = "Launchpad Medium Speed") + public static double launchpadSpeedMedium = 3d; + + @Config(config = "machines", category = "launchpad", key = "LaunchpadSpeedHigh", comment = "Launchpad High Speed") + public static double launchpadSpeedHigh = 5d; + + @Config(config = "machines", category = "launchpad", key = "LaunchpadSpeedExtreme", comment = "Launchpad Extreme Speed") + public static double launchpadSpeedExtreme = 10d; + + @Config(config = "machines", category = "launchpad", key = "LaunchpadEnergyLow", comment = "Launchpad Low Energy") + public static int launchpadEnergyLow = 1_000; + + @Config(config = "machines", category = "launchpad", key = "LaunchpadEnergyMedium", comment = "Launchpad Medium Energy") + public static int launchpadEnergyMedium = 6_000; + + @Config(config = "machines", category = "launchpad", key = "LaunchpadEnergyHigh", comment = "Launchpad High Energy") + public static int launchpadEnergyHigh = 10_000; + + @Config(config = "machines", category = "launchpad", key = "LaunchpadEnergyExtreme", comment = "Launchpad Extreme Energy") + public static int launchpadEnergyExtreme = 20_000; + + @Config(config = "machines", category = "launchpad", key = "LaunchpadDefaultSelection", comment = "Launchpad Default Selection (0-3 for Low-Extreme)") + public static int launchpadDefaultSelection = 0; + + @Config(config = "machines", category = "launchpad", key = "LaunchpadInterval", comment = "Launchpad Launch Interval in Ticks > 0") + public static int launchpadInterval = 100; // 5 seconds + + @Config(config = "machines", category = "elevator", key = "ElevatorMaxInput", comment = "Elevator Max Input (Energy per tick)") + public static int elevatorMaxInput = 32; + + @Config(config = "machines", category = "elevator", key = "ElevatorMaxEnergy", comment = "Elevator Max Energy") + public static int elevatorMaxEnergy = 1_000; + + @Config(config = "machines", category = "elevator", key = "ElevatorEnergyPerBlock", comment = "Elevator Energy used per vertical block of transportation") + public static int elevatorEnergyPerBlock = 2; + + @Config(config = "machines", category = "elevator", key = "AllowElevatingThroughBlocks", comment = "Allow elevating through blocks (i.e. non air)") + public static boolean allowElevatingThroughBlocks = true; + // Misc @Config(config = "misc", category = "general", key = "IC2TransformersStyle", comment = "Input from dots side, output from other sides, like in IC2.") public static boolean IC2TransformersStyle = true; diff --git a/src/main/java/techreborn/init/TRBlockEntities.java b/src/main/java/techreborn/init/TRBlockEntities.java index afd6edb01..107f127fd 100644 --- a/src/main/java/techreborn/init/TRBlockEntities.java +++ b/src/main/java/techreborn/init/TRBlockEntities.java @@ -54,6 +54,7 @@ import techreborn.blockentity.machine.multiblock.casing.MachineCasingBlockEntity import techreborn.blockentity.machine.tier0.block.BlockBreakerBlockEntity; import techreborn.blockentity.machine.tier0.block.BlockPlacerBlockEntity; import techreborn.blockentity.machine.tier1.*; +import techreborn.blockentity.machine.tier2.LaunchpadBlockEntity; import techreborn.blockentity.machine.tier3.ChunkLoaderBlockEntity; import techreborn.blockentity.machine.tier3.IndustrialCentrifugeBlockEntity; import techreborn.blockentity.machine.tier3.MatterFabricatorBlockEntity; @@ -143,6 +144,8 @@ public class TRBlockEntities { public static final BlockEntityType GREENHOUSE_CONTROLLER = register(GreenhouseControllerBlockEntity::new, "greenhouse_controller", TRContent.Machine.GREENHOUSE_CONTROLLER); public static final BlockEntityType BLOCK_BREAKER = register(BlockBreakerBlockEntity::new, "block_breaker", TRContent.Machine.BLOCK_BREAKER); public static final BlockEntityType BLOCK_PLACER = register(BlockPlacerBlockEntity::new, "block_placer", TRContent.Machine.BLOCK_PLACER); + public static final BlockEntityType LAUNCHPAD = register(LaunchpadBlockEntity::new, "launchpad", TRContent.Machine.LAUNCHPAD); + public static final BlockEntityType ELEVATOR = register(ElevatorBlockEntity::new, "elevator", TRContent.Machine.ELEVATOR); public static BlockEntityType register(BiFunction supplier, String name, ItemConvertible... items) { return register(supplier, name, Arrays.stream(items).map(itemConvertible -> Block.getBlockFromItem(itemConvertible.asItem())).toArray(Block[]::new)); diff --git a/src/main/java/techreborn/init/TRContent.java b/src/main/java/techreborn/init/TRContent.java index 1e79f19e2..81a8b7496 100644 --- a/src/main/java/techreborn/init/TRContent.java +++ b/src/main/java/techreborn/init/TRContent.java @@ -61,6 +61,7 @@ import techreborn.blockentity.machine.multiblock.*; import techreborn.blockentity.machine.tier0.block.BlockBreakerBlockEntity; import techreborn.blockentity.machine.tier0.block.BlockPlacerBlockEntity; import techreborn.blockentity.machine.tier1.*; +import techreborn.blockentity.machine.tier2.LaunchpadBlockEntity; import techreborn.blockentity.machine.tier3.ChunkLoaderBlockEntity; import techreborn.blockentity.machine.tier3.IndustrialCentrifugeBlockEntity; import techreborn.blockentity.machine.tier3.MatterFabricatorBlockEntity; @@ -764,6 +765,8 @@ public class TRContent { GREENHOUSE_CONTROLLER(new GenericMachineBlock(GuiType.GREENHOUSE_CONTROLLER, GreenhouseControllerBlockEntity::new)), BLOCK_BREAKER(new GenericMachineBlock(GuiType.BLOCK_BREAKER, BlockBreakerBlockEntity::new)), BLOCK_PLACER(new GenericMachineBlock(GuiType.BLOCK_PLACER, BlockPlacerBlockEntity::new)), + LAUNCHPAD(new GenericMachineBlock(GuiType.LAUNCHPAD, LaunchpadBlockEntity::new)), + ELEVATOR(new GenericMachineBlock(GuiType.ELEVATOR, ElevatorBlockEntity::new)), DIESEL_GENERATOR(new GenericGeneratorBlock(GuiType.DIESEL_GENERATOR, DieselGeneratorBlockEntity::new)), DRAGON_EGG_SYPHON(new GenericGeneratorBlock(null, DragonEggSyphonBlockEntity::new)), diff --git a/src/main/java/techreborn/packets/ServerboundPackets.java b/src/main/java/techreborn/packets/ServerboundPackets.java index ade32c335..61b2a02ac 100644 --- a/src/main/java/techreborn/packets/ServerboundPackets.java +++ b/src/main/java/techreborn/packets/ServerboundPackets.java @@ -35,8 +35,10 @@ import techreborn.TechReborn; import techreborn.blockentity.machine.iron.IronFurnaceBlockEntity; import techreborn.blockentity.machine.multiblock.FusionControlComputerBlockEntity; import techreborn.blockentity.machine.tier1.AutoCraftingTableBlockEntity; +import techreborn.blockentity.machine.tier1.ElevatorBlockEntity; import techreborn.blockentity.machine.tier1.PlayerDetectorBlockEntity; import techreborn.blockentity.machine.tier1.RollingMachineBlockEntity; +import techreborn.blockentity.machine.tier2.LaunchpadBlockEntity; import techreborn.blockentity.machine.tier3.ChunkLoaderBlockEntity; import techreborn.blockentity.storage.energy.AdjustableSUBlockEntity; import techreborn.blockentity.storage.item.StorageUnitBaseBlockEntity; @@ -54,6 +56,8 @@ public class ServerboundPackets { public static final Identifier CHUNKLOADER = new Identifier(TechReborn.MOD_ID, "chunkloader"); public static final Identifier EXPERIENCE = new Identifier(TechReborn.MOD_ID, "experience"); public static final Identifier DETECTOR_RADIUS = new Identifier(TechReborn.MOD_ID, "detector_radius"); + public static final Identifier LAUNCH_SPEED = new Identifier(TechReborn.MOD_ID, "launch_speed"); + public static final Identifier JUMP = new Identifier(TechReborn.MOD_ID, "jump"); public static void init() { NetworkManager.registerServerBoundHandler(AESU, (server, player, handler, buf, responseSender) -> { @@ -171,6 +175,29 @@ public class ServerboundPackets { } }); })); + + NetworkManager.registerServerBoundHandler(LAUNCH_SPEED, ((server, player, handler, buf, responseSender) -> { + BlockPos pos = buf.readBlockPos(); + int buttonAmount = buf.readInt(); + + server.execute(() -> { + BlockEntity blockEntity = player.world.getBlockEntity(pos); + if (blockEntity instanceof LaunchpadBlockEntity) { + ((LaunchpadBlockEntity) blockEntity).handleGuiInputFromClient(buttonAmount); + } + }); + })); + + NetworkManager.registerServerBoundHandler(JUMP, (server, player, handler, buf, responseSender) -> { + BlockPos pos = buf.readBlockPos(); + + server.execute(() -> { + BlockEntity blockEntity = player.getWorld().getBlockEntity(pos.down()); + if (blockEntity instanceof ElevatorBlockEntity elevator) { + elevator.teleportUp(player); + } + }); + }); } public static IdentifiedPacket createPacketAesu(int buttonID, boolean shift, boolean ctrl, AdjustableSUBlockEntity blockEntity) { @@ -235,4 +262,17 @@ public class ServerboundPackets { buf.writeInt(buttonAmount); }); } + + public static IdentifiedPacket createPacketLaunchpad(int buttonAmount, LaunchpadBlockEntity blockEntity) { + return NetworkManager.createServerBoundPacket(LAUNCH_SPEED, buf -> { + buf.writeBlockPos(blockEntity.getPos()); + buf.writeInt(buttonAmount); + }); + } + + public static IdentifiedPacket createPacketJump(BlockPos pos) { + return NetworkManager.createServerBoundPacket(JUMP, packetBuffer -> { + packetBuffer.writeBlockPos(pos); + }); + } } diff --git a/src/main/resources/assets/techreborn/blockstates/elevator.json b/src/main/resources/assets/techreborn/blockstates/elevator.json new file mode 100644 index 000000000..7d680a8ef --- /dev/null +++ b/src/main/resources/assets/techreborn/blockstates/elevator.json @@ -0,0 +1,5 @@ +{ + "variants": { + "": { "model": "techreborn:block/machines/tier1_machines/elevator" } + } +} diff --git a/src/main/resources/assets/techreborn/blockstates/launchpad.json b/src/main/resources/assets/techreborn/blockstates/launchpad.json new file mode 100644 index 000000000..129c3ea5c --- /dev/null +++ b/src/main/resources/assets/techreborn/blockstates/launchpad.json @@ -0,0 +1,5 @@ +{ + "variants": { + "": { "model": "techreborn:block/machines/tier2_machines/launchpad" } + } +} diff --git a/src/main/resources/assets/techreborn/lang/en_us.json b/src/main/resources/assets/techreborn/lang/en_us.json index ea35d26c7..f58326502 100644 --- a/src/main/resources/assets/techreborn/lang/en_us.json +++ b/src/main/resources/assets/techreborn/lang/en_us.json @@ -32,6 +32,8 @@ "block.techreborn.matter_fabricator": "Matter Fabricator", "block.techreborn.implosion_compressor": "Implosion Compressor", "block.techreborn.industrial_grinder": "Industrial Grinder", + "block.techreborn.launchpad": "Launchpad", + "block.techreborn.elevator": "Elevator", "block.techreborn.chunk_loader": "Industrial Chunkloader", "block.techreborn.diesel_generator": "Diesel Generator", "block.techreborn.drain": "Drain", @@ -706,7 +708,7 @@ "item.techreborn.transformer_upgrade": "Transformer Upgrade", "item.techreborn.energy_storage_upgrade": "Energy Storage Upgrade", "item.techreborn.superconductor_upgrade": "Superconductor Upgrade", - "item.techreborn.muffler_upgrade": "Muffler Upgrade", + "item.techreborn.muffler_upgrade": "Muffler Upgrade", "item.techreborn.bronze_sword": "Bronze Sword", "item.techreborn.bronze_pickaxe": "Bronze Pickaxe", @@ -776,7 +778,7 @@ "techreborn.message.info.item.techreborn.transformer_upgrade": "Increase energy tier", "techreborn.message.info.item.techreborn.energy_storage_upgrade": "Increase energy store", "techreborn.message.info.item.techreborn.superconductor_upgrade": "Increases energy flow rate", - "techreborn.message.info.item.techreborn.muffler_upgrade": "Muffles the machine", + "techreborn.message.info.item.techreborn.muffler_upgrade": "Muffles the machine", "techreborn.message.info.unplaceable_fluid": "Cannot be placed", @@ -842,7 +844,13 @@ "techreborn.message.info.block.techreborn.drain": "Pulls any fluid directly above it, pairs nicely with a tank unit underneath", "techreborn.message.info.block.techreborn.block_breaker": "Breaks any block directly in front of it", "techreborn.message.info.block.techreborn.block_placer": "Places blocks from its inventory directly in front of it", - + "techreborn.message.info.block.techreborn.launchpad": "Launches entities into the air", + "techreborn.message.info.block.techreborn.launchpad.low": "Low", + "techreborn.message.info.block.techreborn.launchpad.medium": "Medium", + "techreborn.message.info.block.techreborn.launchpad.high": "High", + "techreborn.message.info.block.techreborn.launchpad.extreme": "Extreme", + "techreborn.message.info.block.techreborn.elevator": "Teleports player up or down to the next free elevator block", + "keys.techreborn.category": "TechReborn Category", "keys.techreborn.config": "Config", diff --git a/src/main/resources/assets/techreborn/models/block/machines/tier1_machines/elevator.json b/src/main/resources/assets/techreborn/models/block/machines/tier1_machines/elevator.json new file mode 100644 index 000000000..baf797ad4 --- /dev/null +++ b/src/main/resources/assets/techreborn/models/block/machines/tier1_machines/elevator.json @@ -0,0 +1,9 @@ +{ + "parent": "minecraft:block/orientable", + "textures": { + "up": "techreborn:block/machines/tier1_machines/elevator_end", + "down": "techreborn:block/machines/tier1_machines/elevator_end", + "side": "techreborn:block/machines/tier1_machines/elevator_side", + "front": "techreborn:block/machines/tier1_machines/elevator_side" + } +} diff --git a/src/main/resources/assets/techreborn/models/block/machines/tier2_machines/launchpad.json b/src/main/resources/assets/techreborn/models/block/machines/tier2_machines/launchpad.json new file mode 100644 index 000000000..d8f4b5586 --- /dev/null +++ b/src/main/resources/assets/techreborn/models/block/machines/tier2_machines/launchpad.json @@ -0,0 +1,9 @@ +{ + "parent": "minecraft:block/orientable", + "textures": { + "up": "techreborn:block/machines/tier2_machines/launchpad_top", + "down": "techreborn:block/machines/tier2_machines/machine_bottom", + "side": "techreborn:block/machines/tier2_machines/launchpad_side", + "front": "techreborn:block/machines/tier2_machines/launchpad_side" + } +} diff --git a/src/main/resources/assets/techreborn/models/item/elevator.json b/src/main/resources/assets/techreborn/models/item/elevator.json new file mode 100644 index 000000000..e0aa479f9 --- /dev/null +++ b/src/main/resources/assets/techreborn/models/item/elevator.json @@ -0,0 +1,3 @@ +{ + "parent": "techreborn:block/machines/tier1_machines/elevator" +} \ No newline at end of file diff --git a/src/main/resources/assets/techreborn/models/item/launchpad.json b/src/main/resources/assets/techreborn/models/item/launchpad.json new file mode 100644 index 000000000..5da514971 --- /dev/null +++ b/src/main/resources/assets/techreborn/models/item/launchpad.json @@ -0,0 +1,3 @@ +{ + "parent": "techreborn:block/machines/tier2_machines/launchpad" +} \ No newline at end of file diff --git a/src/main/resources/assets/techreborn/textures/block/machines/tier1_machines/elevator_end.png b/src/main/resources/assets/techreborn/textures/block/machines/tier1_machines/elevator_end.png new file mode 100644 index 0000000000000000000000000000000000000000..76b4086cb03fa94d57173ed2885f5deb3387d62a GIT binary patch literal 448 zcmV;x0YCnUP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D0aZyvK~y+TZIeMu z!$1&)H$h{yhEO6^qz4cFeb0Il@zg_qga;8?EG5KLjY8aSnpby2-=Vw7%$s@hI!W&C zAG`7R%n76HsK3SdYJc}J?x1P5E_ryKcLa(&clqgw%d%sa2L(ax6G7Ylxcc+k?p0k| zAuDh@yK=9qcPpa6A*c~KI+LgQqMJ=GtTGC8hDxMhU42A3G)*nRzo1%3Ho~SdGSY#_ z`Ldiu>p3)57_Rbiz4`x`SZAOvr~vW+ qNFmQ^wEvt#GeM|=*dbL-vvq%;atZ~;fzki~0000Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D0lG;Xu>XhivZUN)Q0AC@Ii z6v_E~R%_d~>~=f#2!({_4|FXc>yP9u~GkRj=10 zhDCN$4X-kFbBJT%kc__&!2SPSaGcDKJuqM&!tn5A7c>E{mWzJ;eVc{hn>T`_9|X&# nRv5SNeGii56Z@^5^?D;8i-AY3t+@6m00000NkvXXu0mjfY(4Qk literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/techreborn/textures/block/machines/tier2_machines/launchpad_side.png b/src/main/resources/assets/techreborn/textures/block/machines/tier2_machines/launchpad_side.png new file mode 100644 index 0000000000000000000000000000000000000000..63a36ab7883db7af57f3dcbbddd7fd678f6f9721 GIT binary patch literal 690 zcmV;j0!{siP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D0!K+iK~y+TbyB}? z(_j#N_GiaVnkH@}Qq)2lBz_Da5ETOhVq|6MfLLH-U}ItBFNBh`m4FBVZBPR!apF4u zZF6^yr6AFhtatvt^SgKNtUZ4CsMy-Pj4GVAv&;Z@<}S1U$ItN@v}aHEi+i{4B8)=V zmMzF6POH5vE5n`7gs`e%{CLza32t4#iSh4W*u2ygyr?r1S2c{EhM!9UzSzC8BSjUv zZQJF07|Iz3pL6hg)#x7&R_9-hixi0mZ(qMCC=dhzbX^1Id0r4^^ll)cZn~z?S%x@C zpiv%%k)WXzv^TGw7u{}`ij@=zGD(_3Bf>n(iKP6%vMeM-!c9`T|1umxFY;XGJsXeV zpZhrY@E*SBp+?1V6iXq;oVIXyIDqR;aXK1_4@{(IStjyZ%_feHkEQsaKfvhp1UgA% z0?(UcObtRJ9Det9%T;@#ZgM`cr!a#CjK@#&>M(YG7)2Xc2s+rIuVht8PHXKK~J=nW1l4aLq zVn#$Pn}4nz&CdV!Z literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/techreborn/textures/block/machines/tier2_machines/launchpad_top.png b/src/main/resources/assets/techreborn/textures/block/machines/tier2_machines/launchpad_top.png new file mode 100644 index 0000000000000000000000000000000000000000..cada01f39c867c78eaf37e82a0cabb650fe8d148 GIT binary patch literal 445 zcmV;u0Yd(XP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D0a8gsK~y+TZIiK1 z0#Oh}A2e_M$*6zLs&;b)D+( zI^ybc9zr2-d47>5A8#RIVjFBkjc4caVZ0h09ECCtJaZ>HKsc|VX_o|lpq7)tY+eN! z>p(KK0KpI-p}J&9x`5rI`GsUeOLDAFe2IqxJ{ zC%OYM0`MvWI>#96A8*Ea-2=5EuJYN*>BjZ^zgR)%{3<`aJpX-6TxVbxT*Py;1E52m nZPb3w&M9&i