From 077b09c37de1483411abdaad3c3c464af82c1760 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 2 Dec 2021 14:44:26 +0100 Subject: [PATCH] PipeNetwork is error-free! --- build.gradle | 2 +- .../java/de/ellpeck/prettypipes/Registry.java | 105 +++++----- .../java/de/ellpeck/prettypipes/Utility.java | 18 +- .../prettypipes/entities/PipeFrameEntity.java | 90 +++++---- .../de/ellpeck/prettypipes/items/IModule.java | 38 ++-- .../ellpeck/prettypipes/items/ModuleItem.java | 28 +-- .../ellpeck/prettypipes/items/WrenchItem.java | 4 +- .../ellpeck/prettypipes/misc/FilterSlot.java | 33 ++-- .../ellpeck/prettypipes/misc/ItemFilter.java | 8 +- .../prettypipes/network/NetworkLocation.java | 25 ++- .../ellpeck/prettypipes/network/PipeItem.java | 16 +- .../prettypipes/network/PipeNetwork.java | 184 +++++++++--------- .../prettypipes/packets/PacketButton.java | 49 +++-- .../prettypipes/packets/PacketGhostSlot.java | 5 +- .../prettypipes/packets/PacketHandler.java | 13 +- .../packets/PacketItemEnterPipe.java | 20 +- .../packets/PacketNetworkItems.java | 28 ++- .../prettypipes/packets/PacketRequest.java | 18 +- .../prettypipes/pipe/IPipeConnectable.java | 4 +- .../ellpeck/prettypipes/pipe/IPipeItem.java | 15 +- .../ellpeck/prettypipes/pipe/PipeBlock.java | 152 +++++++-------- ...peTileEntity.java => PipeBlockEntity.java} | 41 ++-- .../prettypipes/pipe/PipeRenderer.java | 57 +++--- .../containers/AbstractPipeContainer.java | 52 ++--- .../pipe/containers/AbstractPipeGui.java | 73 ++++--- .../pipe/containers/MainPipeContainer.java | 9 +- .../pipe/containers/MainPipeGui.java | 5 +- .../pipe/modules/HighPriorityModuleItem.java | 8 +- .../pipe/modules/LowPriorityModuleItem.java | 8 +- .../pipe/modules/RedstoneModuleItem.java | 8 +- .../pipe/modules/SortingModuleItem.java | 8 +- .../pipe/modules/SpeedModuleItem.java | 8 +- .../modules/craft/CraftingModuleItem.java | 30 +-- .../extraction/ExtractionModuleItem.java | 16 +- .../filter/FilterIncreaseModuleItem.java | 10 +- .../modules/insertion/FilterModuleItem.java | 12 +- .../modifier/FilterModifierModuleItem.java | 8 +- .../retrieval/RetrievalModuleItem.java | 16 +- .../stacksize/StackSizeModuleItem.java | 10 +- .../pressurizer/PressurizerBlockEntity.java | 4 +- .../terminal/CraftingTerminalBlock.java | 2 +- ....java => CraftingTerminalBlockEntity.java} | 19 +- .../terminal/ItemTerminalBlock.java | 6 +- ...tity.java => ItemTerminalBlockEntity.java} | 98 +++++----- .../containers/CraftingTerminalContainer.java | 6 +- .../containers/CraftingTerminalGui.java | 9 +- .../containers/ItemTerminalContainer.java | 35 ++-- .../terminal/containers/ItemTerminalGui.java | 52 ++--- 48 files changed, 738 insertions(+), 727 deletions(-) rename src/main/java/de/ellpeck/prettypipes/pipe/{PipeTileEntity.java => PipeBlockEntity.java} (92%) rename src/main/java/de/ellpeck/prettypipes/terminal/{CraftingTerminalTileEntity.java => CraftingTerminalBlockEntity.java} (91%) rename src/main/java/de/ellpeck/prettypipes/terminal/{ItemTerminalTileEntity.java => ItemTerminalBlockEntity.java} (79%) diff --git a/build.gradle b/build.gradle index 26e98f3..8929d33 100644 --- a/build.gradle +++ b/build.gradle @@ -95,7 +95,7 @@ repositories { configurations { embed - compile.extendsFrom(embed) + implementation.extendsFrom(embed) } dependencies { diff --git a/src/main/java/de/ellpeck/prettypipes/Registry.java b/src/main/java/de/ellpeck/prettypipes/Registry.java index 54240dc..afc6924 100644 --- a/src/main/java/de/ellpeck/prettypipes/Registry.java +++ b/src/main/java/de/ellpeck/prettypipes/Registry.java @@ -9,7 +9,7 @@ import de.ellpeck.prettypipes.packets.PacketHandler; import de.ellpeck.prettypipes.pipe.IPipeConnectable; import de.ellpeck.prettypipes.pipe.PipeBlock; import de.ellpeck.prettypipes.pipe.PipeRenderer; -import de.ellpeck.prettypipes.pipe.PipeTileEntity; +import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer; import de.ellpeck.prettypipes.pipe.containers.MainPipeContainer; import de.ellpeck.prettypipes.pipe.containers.MainPipeGui; @@ -40,31 +40,39 @@ import de.ellpeck.prettypipes.pressurizer.PressurizerContainer; import de.ellpeck.prettypipes.pressurizer.PressurizerGui; import de.ellpeck.prettypipes.pressurizer.PressurizerBlockEntity; import de.ellpeck.prettypipes.terminal.CraftingTerminalBlock; -import de.ellpeck.prettypipes.terminal.CraftingTerminalTileEntity; +import de.ellpeck.prettypipes.terminal.CraftingTerminalBlockEntity; import de.ellpeck.prettypipes.terminal.ItemTerminalBlock; -import de.ellpeck.prettypipes.terminal.ItemTerminalTileEntity; +import de.ellpeck.prettypipes.terminal.ItemTerminalBlockEntity; import de.ellpeck.prettypipes.terminal.containers.CraftingTerminalContainer; import de.ellpeck.prettypipes.terminal.containers.CraftingTerminalGui; import de.ellpeck.prettypipes.terminal.containers.ItemTerminalContainer; import de.ellpeck.prettypipes.terminal.containers.ItemTerminalGui; import net.minecraft.block.Block; import net.minecraft.client.gui.ScreenManager; +import net.minecraft.client.gui.screens.MenuScreens; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderTypeLookup; import net.minecraft.entity.EntityClassification; import net.minecraft.entity.EntityType; -import net.minecraft.inventory.container.ContainerType; +import net.minecraft.inventory.container.MenuType; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.nbt.INBT; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.CapabilityInject; import net.minecraftforge.common.capabilities.CapabilityManager; -import net.minecraftforge.common.extensions.IForgeContainerType; +import net.minecraftforge.common.capabilities.CapabilityToken; +import net.minecraftforge.common.extensions.IForgeMenuType; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.client.registry.ClientRegistry; @@ -86,46 +94,46 @@ import java.util.function.BiFunction; @Mod.EventBusSubscriber(bus = Bus.MOD) public final class Registry { - public static final ItemGroup GROUP = new ItemGroup(PrettyPipes.ID) { + public static final CreativeModeTab GROUP = new CreativeModeTab(PrettyPipes.ID) { @Override - public ItemStack createIcon() { + public ItemStack makeIcon() { return new ItemStack(wrenchItem); } }; - @CapabilityInject(PipeNetwork.class) - public static Capability pipeNetworkCapability; - @CapabilityInject(IPipeConnectable.class) - public static Capability pipeConnectableCapability; + public static Capability pipeNetworkCapability = CapabilityManager.get(new CapabilityToken<>() { + }); + public static Capability pipeConnectableCapability = CapabilityManager.get(new CapabilityToken<>() { + }); public static Item wrenchItem; public static Item pipeFrameItem; public static Block pipeBlock; - public static TileEntityType pipeTileEntity; - public static ContainerType pipeContainer; + public static BlockEntityType pipeTileEntity; + public static MenuType pipeContainer; public static Block itemTerminalBlock; - public static TileEntityType itemTerminalTileEntity; - public static ContainerType itemTerminalContainer; + public static BlockEntityType itemTerminalTileEntity; + public static MenuType itemTerminalContainer; public static Block craftingTerminalBlock; - public static TileEntityType craftingTerminalTileEntity; - public static ContainerType craftingTerminalContainer; + public static BlockEntityType craftingTerminalTileEntity; + public static MenuType craftingTerminalContainer; public static EntityType pipeFrameEntity; public static Block pressurizerBlock; - public static TileEntityType pressurizerTileEntity; - public static ContainerType pressurizerContainer; + public static BlockEntityType pressurizerTileEntity; + public static MenuType pressurizerContainer; - public static ContainerType extractionModuleContainer; - public static ContainerType filterModuleContainer; - public static ContainerType retrievalModuleContainer; - public static ContainerType stackSizeModuleContainer; - public static ContainerType filterIncreaseModuleContainer; - public static ContainerType craftingModuleContainer; - public static ContainerType filterModifierModuleContainer; + public static MenuType extractionModuleContainer; + public static MenuType filterModuleContainer; + public static MenuType retrievalModuleContainer; + public static MenuType stackSizeModuleContainer; + public static MenuType filterIncreaseModuleContainer; + public static MenuType craftingModuleContainer; + public static MenuType filterModifierModuleContainer; @SubscribeEvent public static void registerBlocks(RegistryEvent.Register event) { @@ -166,9 +174,9 @@ public final class Registry { @SubscribeEvent public static void registerTiles(RegistryEvent.Register> event) { event.getRegistry().registerAll( - pipeTileEntity = (TileEntityType) TileEntityType.Builder.create(PipeTileEntity::new, pipeBlock).build(null).setRegistryName("pipe"), - itemTerminalTileEntity = (TileEntityType) TileEntityType.Builder.create(ItemTerminalTileEntity::new, itemTerminalBlock).build(null).setRegistryName("item_terminal"), - craftingTerminalTileEntity = (TileEntityType) TileEntityType.Builder.create(CraftingTerminalTileEntity::new, craftingTerminalBlock).build(null).setRegistryName("crafting_terminal"), + pipeTileEntity = (TileEntityType) TileEntityType.Builder.create(PipeBlockEntity::new, pipeBlock).build(null).setRegistryName("pipe"), + itemTerminalTileEntity = (TileEntityType) TileEntityType.Builder.create(ItemTerminalBlockEntity::new, itemTerminalBlock).build(null).setRegistryName("item_terminal"), + craftingTerminalTileEntity = (TileEntityType) TileEntityType.Builder.create(CraftingTerminalBlockEntity::new, craftingTerminalBlock).build(null).setRegistryName("crafting_terminal"), pressurizerTileEntity = (TileEntityType) TileEntityType.Builder.create(PressurizerBlockEntity::new, pressurizerBlock).build(null).setRegistryName("pressurizer") ); } @@ -181,12 +189,12 @@ public final class Registry { } @SubscribeEvent - public static void registerContainers(RegistryEvent.Register> event) { + public static void registerContainers(RegistryEvent.Register> event) { event.getRegistry().registerAll( - pipeContainer = (ContainerType) IForgeContainerType.create((windowId, inv, data) -> new MainPipeContainer(pipeContainer, windowId, inv.player, data.readBlockPos())).setRegistryName("pipe"), - itemTerminalContainer = (ContainerType) IForgeContainerType.create((windowId, inv, data) -> new ItemTerminalContainer(itemTerminalContainer, windowId, inv.player, data.readBlockPos())).setRegistryName("item_terminal"), - craftingTerminalContainer = (ContainerType) IForgeContainerType.create((windowId, inv, data) -> new CraftingTerminalContainer(craftingTerminalContainer, windowId, inv.player, data.readBlockPos())).setRegistryName("crafting_terminal"), - pressurizerContainer = (ContainerType) IForgeContainerType.create((windowId, inv, data) -> new PressurizerContainer(pressurizerContainer, windowId, inv.player, data.readBlockPos())).setRegistryName("pressurizer"), + pipeContainer = (MenuType) IForgeMenuType.create((windowId, inv, data) -> new MainPipeContainer(pipeContainer, windowId, inv.player, data.readBlockPos())).setRegistryName("pipe"), + itemTerminalContainer = (MenuType) IForgeMenuType.create((windowId, inv, data) -> new ItemTerminalContainer(itemTerminalContainer, windowId, inv.player, data.readBlockPos())).setRegistryName("item_terminal"), + craftingTerminalContainer = (MenuType) IForgeMenuType.create((windowId, inv, data) -> new CraftingTerminalContainer(craftingTerminalContainer, windowId, inv.player, data.readBlockPos())).setRegistryName("crafting_terminal"), + pressurizerContainer = (MenuType) IForgeMenuType.create((windowId, inv, data) -> new PressurizerContainer(pressurizerContainer, windowId, inv.player, data.readBlockPos())).setRegistryName("pressurizer"), extractionModuleContainer = createPipeContainer("extraction_module"), filterModuleContainer = createPipeContainer("filter_module"), retrievalModuleContainer = createPipeContainer("retrieval_module"), @@ -197,9 +205,9 @@ public final class Registry { ); } - private static > ContainerType createPipeContainer(String name) { - return (ContainerType) IForgeContainerType.create((windowId, inv, data) -> { - PipeTileEntity tile = Utility.getBlockEntity(PipeTileEntity.class, inv.player.world, data.readBlockPos()); + private static > MenuType createPipeContainer(String name) { + return (MenuType) IForgeMenuType.create((windowId, inv, data) -> { + PipeBlockEntity tile = Utility.getBlockEntity(PipeBlockEntity.class, inv.player.world, data.readBlockPos()); int moduleIndex = data.readInt(); ItemStack moduleStack = tile.modules.getStackInSlot(moduleIndex); return ((IModule) moduleStack.getItem()).getContainer(moduleStack, tile, windowId, inv, inv.player, moduleIndex); @@ -220,22 +228,23 @@ public final class Registry { } public static final class Client { + public static void setup(FMLClientSetupEvent event) { RenderTypeLookup.setRenderLayer(pipeBlock, RenderType.getCutout()); ClientRegistry.bindTileEntityRenderer(pipeTileEntity, PipeRenderer::new); RenderingRegistry.registerEntityRenderingHandler(pipeFrameEntity, PipeFrameRenderer::new); - ScreenManager.registerFactory(pipeContainer, MainPipeGui::new); - ScreenManager.registerFactory(itemTerminalContainer, ItemTerminalGui::new); - ScreenManager.registerFactory(pressurizerContainer, PressurizerGui::new); - ScreenManager.registerFactory(craftingTerminalContainer, CraftingTerminalGui::new); - ScreenManager.registerFactory(extractionModuleContainer, ExtractionModuleGui::new); - ScreenManager.registerFactory(filterModuleContainer, FilterModuleGui::new); - ScreenManager.registerFactory(retrievalModuleContainer, RetrievalModuleGui::new); - ScreenManager.registerFactory(stackSizeModuleContainer, StackSizeModuleGui::new); - ScreenManager.registerFactory(filterIncreaseModuleContainer, FilterIncreaseModuleGui::new); - ScreenManager.registerFactory(craftingModuleContainer, CraftingModuleGui::new); - ScreenManager.registerFactory(filterModifierModuleContainer, FilterModifierModuleGui::new); + MenuScreens.register(pipeContainer, MainPipeGui::new); + MenuScreens.register(itemTerminalContainer, ItemTerminalGui::new); + MenuScreens.register(pressurizerContainer, PressurizerGui::new); + MenuScreens.register(craftingTerminalContainer, CraftingTerminalGui::new); + MenuScreens.register(extractionModuleContainer, ExtractionModuleGui::new); + MenuScreens.register(filterModuleContainer, FilterModuleGui::new); + MenuScreens.register(retrievalModuleContainer, RetrievalModuleGui::new); + MenuScreens.register(stackSizeModuleContainer, StackSizeModuleGui::new); + MenuScreens.register(filterIncreaseModuleContainer, FilterIncreaseModuleGui::new); + MenuScreens.register(craftingModuleContainer, CraftingModuleGui::new); + MenuScreens.register(filterModifierModuleContainer, FilterModifierModuleGui::new); } } diff --git a/src/main/java/de/ellpeck/prettypipes/Utility.java b/src/main/java/de/ellpeck/prettypipes/Utility.java index 69fcfb4..974da7e 100644 --- a/src/main/java/de/ellpeck/prettypipes/Utility.java +++ b/src/main/java/de/ellpeck/prettypipes/Utility.java @@ -5,25 +5,23 @@ import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.resources.language.I18n; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.network.chat.*; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.Style; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.Containers; -import net.minecraft.world.WorldlyContainer; import net.minecraft.world.WorldlyContainerHolder; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; +import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.Level; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.common.util.INBTSerializable; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.wrapper.SidedInvWrapper; @@ -36,7 +34,7 @@ import java.util.function.Function; public final class Utility { - public static T getBlockEntity(Class type, LevelAccessor world, BlockPos pos) { + public static T getBlockEntity(Class type, BlockGetter world, BlockPos pos) { var tile = world.getBlockEntity(pos); return type.isInstance(tile) ? (T) tile : null; } diff --git a/src/main/java/de/ellpeck/prettypipes/entities/PipeFrameEntity.java b/src/main/java/de/ellpeck/prettypipes/entities/PipeFrameEntity.java index 5433cd1..a49050c 100644 --- a/src/main/java/de/ellpeck/prettypipes/entities/PipeFrameEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/entities/PipeFrameEntity.java @@ -4,36 +4,34 @@ import de.ellpeck.prettypipes.Registry; import de.ellpeck.prettypipes.network.NetworkLocation; import de.ellpeck.prettypipes.network.PipeNetwork; import de.ellpeck.prettypipes.pipe.PipeBlock; -import net.minecraft.block.BlockState; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.item.ItemFrameEntity; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.FilledMapItem; +import net.minecraft.network.IPacket; +import net.minecraft.network.PacketBuffer; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.decoration.ItemFrame; -import net.minecraft.world.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.network.IPacket; -import net.minecraft.network.PacketBuffer; -import net.minecraft.network.datasync.DataParameter; -import net.minecraft.network.datasync.DataSerializers; -import net.minecraft.network.datasync.EntityDataManager; -import net.minecraft.util.math.BlockPos; +import net.minecraft.sounds.SoundEvents; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.GameRules; -import net.minecraft.world.World; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.decoration.ItemFrame; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.GameRules; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.storage.MapData; +import net.minecraft.world.phys.HitResult; import net.minecraftforge.entity.IEntityAdditionalSpawnData; -import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData; import net.minecraftforge.fml.network.NetworkHooks; +import net.minecraftforge.network.ICustomPacket; +import net.minecraftforge.network.NetworkHooks; import javax.annotation.Nullable; import java.util.List; @@ -83,8 +81,8 @@ public class PipeFrameEntity extends ItemFrame implements IEntityAdditionalSpawn } @Override - public boolean onValidSurface() { - return super.onValidSurface() && canPlace(this.world, this.hangingPosition, this.facingDirection); + public boolean survives() { + return super.survives() && canPlace(this.level, this.pos, this.direction); } private static BlockPos getAttachedPipe(Level world, BlockPos pos, Direction direction) { @@ -97,77 +95,77 @@ public class PipeFrameEntity extends ItemFrame implements IEntityAdditionalSpawn return null; } - public static boolean canPlace(World world, BlockPos pos, Direction direction) { + public static boolean canPlace(Level world, BlockPos pos, Direction direction) { return getAttachedPipe(world, pos, direction) != null; } public int getAmount() { - return this.dataManager.get(AMOUNT); + return this.entityData.get(AMOUNT); } @Override - public boolean attackEntityFrom(DamageSource source, float amount) { + public boolean hurt(DamageSource source, float amount) { if (this.isInvulnerableTo(source)) { return false; - } else if (!source.isExplosion() && !this.getDisplayedItem().isEmpty()) { - if (!this.world.isRemote) { - this.dropItemOrSelf(source.getTrueSource(), false); - this.playSound(SoundEvents.ENTITY_ITEM_FRAME_REMOVE_ITEM, 1.0F, 1.0F); + } else if (!source.isExplosion() && !this.getItem().isEmpty()) { + if (!this.level.isClientSide) { + this.dropItemOrSelf(source.getDirectEntity(), false); + this.playSound(SoundEvents.ITEM_FRAME_REMOVE_ITEM, 1.0F, 1.0F); } return true; } else { - return super.attackEntityFrom(source, amount); + return super.hurt(source, amount); } } @Override - public void onBroken(@Nullable Entity brokenEntity) { - this.playSound(SoundEvents.ENTITY_ITEM_FRAME_BREAK, 1.0F, 1.0F); + public void dropItem(@Nullable Entity brokenEntity) { + this.playSound(SoundEvents.ITEM_FRAME_BREAK, 1.0F, 1.0F); this.dropItemOrSelf(brokenEntity, true); } private void dropItemOrSelf(@Nullable Entity entityIn, boolean b) { - if (!this.world.getGameRules().getBoolean(GameRules.DO_ENTITY_DROPS)) { + if (!this.level.getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) { if (entityIn == null) - this.getDisplayedItem().setAttachedEntity(null); + this.getItem().setEntityRepresentation(null); } else { - ItemStack itemstack = this.getDisplayedItem(); - this.setDisplayedItem(ItemStack.EMPTY); - if (entityIn instanceof PlayerEntity) { - PlayerEntity playerentity = (PlayerEntity) entityIn; - if (playerentity.abilities.isCreativeMode) { - itemstack.setAttachedEntity(null); + ItemStack itemstack = this.getItem(); + this.setItem(ItemStack.EMPTY); + if (entityIn instanceof Player playerentity) { + if (playerentity.isCreative()) { + itemstack.setEntityRepresentation(null); return; } } if (b) - this.entityDropItem(Registry.pipeFrameItem); + this.spawnAtLocation(Registry.pipeFrameItem); if (!itemstack.isEmpty()) { itemstack = itemstack.copy(); - itemstack.setAttachedEntity(null); - this.entityDropItem(itemstack); + itemstack.setEntityRepresentation(null); + this.spawnAtLocation(itemstack); } } } @Override - public ActionResultType processInitialInteract(PlayerEntity player, Hand hand) { - if (this.getDisplayedItem().isEmpty()) - return super.processInitialInteract(player, hand); - return ActionResultType.FAIL; + public InteractionResult interact(Player player, InteractionHand hand) { + if (this.getItem().isEmpty()) + return super.interact(player, hand); + return InteractionResult.FAIL; } + @Override - public ItemStack getPickedResult(RayTraceResult target) { + public ItemStack getPickedResult(HitResult target) { return new ItemStack(Registry.pipeFrameItem); } @Override - public IPacket createSpawnPacket() { + public ICustomPacket createSpawnPacket() { return NetworkHooks.getEntitySpawningPacket(this); } diff --git a/src/main/java/de/ellpeck/prettypipes/items/IModule.java b/src/main/java/de/ellpeck/prettypipes/items/IModule.java index e8ecf38..21a4ecf 100644 --- a/src/main/java/de/ellpeck/prettypipes/items/IModule.java +++ b/src/main/java/de/ellpeck/prettypipes/items/IModule.java @@ -1,12 +1,12 @@ package de.ellpeck.prettypipes.items; import de.ellpeck.prettypipes.misc.ItemFilter; -import de.ellpeck.prettypipes.pipe.PipeTileEntity; +import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; -import net.minecraft.util.math.BlockPos; import net.minecraftforge.items.IItemHandler; import java.util.List; @@ -15,33 +15,33 @@ import java.util.function.Consumer; public interface IModule { - void tick(ItemStack module, PipeTileEntity tile); + void tick(ItemStack module, PipeBlockEntity tile); - boolean canNetworkSee(ItemStack module, PipeTileEntity tile); + boolean canNetworkSee(ItemStack module, PipeBlockEntity tile); - boolean canAcceptItem(ItemStack module, PipeTileEntity tile, ItemStack stack); + boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack); - int getMaxInsertionAmount(ItemStack module, PipeTileEntity tile, ItemStack stack, IItemHandler destination); + int getMaxInsertionAmount(ItemStack module, PipeBlockEntity tile, ItemStack stack, IItemHandler destination); - int getPriority(ItemStack module, PipeTileEntity tile); + int getPriority(ItemStack module, PipeBlockEntity tile); - boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other); + boolean isCompatible(ItemStack module, PipeBlockEntity tile, IModule other); - boolean hasContainer(ItemStack module, PipeTileEntity tile); + boolean hasContainer(ItemStack module, PipeBlockEntity tile); - AbstractPipeContainer getContainer(ItemStack module, PipeTileEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex); + AbstractPipeContainer getContainer(ItemStack module, PipeBlockEntity tile, int windowId, Inventory inv, Player player, int moduleIndex); - float getItemSpeedIncrease(ItemStack module, PipeTileEntity tile); + float getItemSpeedIncrease(ItemStack module, PipeBlockEntity tile); - boolean canPipeWork(ItemStack module, PipeTileEntity tile); + boolean canPipeWork(ItemStack module, PipeBlockEntity tile); - List getAllCraftables(ItemStack module, PipeTileEntity tile); + List getAllCraftables(ItemStack module, PipeBlockEntity tile); - int getCraftableAmount(ItemStack module, PipeTileEntity tile, Consumer unavailableConsumer, ItemStack stack, Stack dependencyChain); + int getCraftableAmount(ItemStack module, PipeBlockEntity tile, Consumer unavailableConsumer, ItemStack stack, Stack dependencyChain); - ItemStack craft(ItemStack module, PipeTileEntity tile, BlockPos destPipe, Consumer unavailableConsumer, ItemStack stack, Stack dependencyChain); + ItemStack craft(ItemStack module, PipeBlockEntity tile, BlockPos destPipe, Consumer unavailableConsumer, ItemStack stack, Stack dependencyChain); - Integer getCustomNextNode(ItemStack module, PipeTileEntity tile, List nodes, int index); + Integer getCustomNextNode(ItemStack module, PipeBlockEntity tile, List nodes, int index); - ItemFilter getItemFilter(ItemStack module, PipeTileEntity tile); + ItemFilter getItemFilter(ItemStack module, PipeBlockEntity tile); } diff --git a/src/main/java/de/ellpeck/prettypipes/items/ModuleItem.java b/src/main/java/de/ellpeck/prettypipes/items/ModuleItem.java index ab36d10..1e4872e 100644 --- a/src/main/java/de/ellpeck/prettypipes/items/ModuleItem.java +++ b/src/main/java/de/ellpeck/prettypipes/items/ModuleItem.java @@ -3,7 +3,7 @@ package de.ellpeck.prettypipes.items; import de.ellpeck.prettypipes.Registry; import de.ellpeck.prettypipes.Utility; import de.ellpeck.prettypipes.misc.ItemFilter; -import de.ellpeck.prettypipes.pipe.PipeTileEntity; +import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.player.PlayerEntity; @@ -40,67 +40,67 @@ public abstract class ModuleItem extends Item implements IModule { } @Override - public void tick(ItemStack module, PipeTileEntity tile) { + public void tick(ItemStack module, PipeBlockEntity tile) { } @Override - public boolean canNetworkSee(ItemStack module, PipeTileEntity tile) { + public boolean canNetworkSee(ItemStack module, PipeBlockEntity tile) { return true; } @Override - public boolean canAcceptItem(ItemStack module, PipeTileEntity tile, ItemStack stack) { + public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack) { return true; } @Override - public int getMaxInsertionAmount(ItemStack module, PipeTileEntity tile, ItemStack stack, IItemHandler destination) { + public int getMaxInsertionAmount(ItemStack module, PipeBlockEntity tile, ItemStack stack, IItemHandler destination) { return Integer.MAX_VALUE; } @Override - public int getPriority(ItemStack module, PipeTileEntity tile) { + public int getPriority(ItemStack module, PipeBlockEntity tile) { return 0; } @Override - public AbstractPipeContainer getContainer(ItemStack module, PipeTileEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) { + public AbstractPipeContainer getContainer(ItemStack module, PipeBlockEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) { return null; } @Override - public float getItemSpeedIncrease(ItemStack module, PipeTileEntity tile) { + public float getItemSpeedIncrease(ItemStack module, PipeBlockEntity tile) { return 0; } @Override - public boolean canPipeWork(ItemStack module, PipeTileEntity tile) { + public boolean canPipeWork(ItemStack module, PipeBlockEntity tile) { return true; } @Override - public List getAllCraftables(ItemStack module, PipeTileEntity tile) { + public List getAllCraftables(ItemStack module, PipeBlockEntity tile) { return Collections.emptyList(); } @Override - public int getCraftableAmount(ItemStack module, PipeTileEntity tile, Consumer unavailableConsumer, ItemStack stack, Stack dependencyChain) { + public int getCraftableAmount(ItemStack module, PipeBlockEntity tile, Consumer unavailableConsumer, ItemStack stack, Stack dependencyChain) { return 0; } @Override - public ItemStack craft(ItemStack module, PipeTileEntity tile, BlockPos destPipe, Consumer unavailableConsumer, ItemStack stack, Stack dependencyChain) { + public ItemStack craft(ItemStack module, PipeBlockEntity tile, BlockPos destPipe, Consumer unavailableConsumer, ItemStack stack, Stack dependencyChain) { return stack; } @Override - public Integer getCustomNextNode(ItemStack module, PipeTileEntity tile, List nodes, int index) { + public Integer getCustomNextNode(ItemStack module, PipeBlockEntity tile, List nodes, int index) { return null; } @Override - public ItemFilter getItemFilter(ItemStack module, PipeTileEntity tile) { + public ItemFilter getItemFilter(ItemStack module, PipeBlockEntity tile) { return null; } } diff --git a/src/main/java/de/ellpeck/prettypipes/items/WrenchItem.java b/src/main/java/de/ellpeck/prettypipes/items/WrenchItem.java index 238ebf9..9ce2809 100644 --- a/src/main/java/de/ellpeck/prettypipes/items/WrenchItem.java +++ b/src/main/java/de/ellpeck/prettypipes/items/WrenchItem.java @@ -4,7 +4,7 @@ import de.ellpeck.prettypipes.Registry; import de.ellpeck.prettypipes.Utility; import de.ellpeck.prettypipes.pipe.ConnectionType; import de.ellpeck.prettypipes.pipe.PipeBlock; -import de.ellpeck.prettypipes.pipe.PipeTileEntity; +import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.client.util.ITooltipFlag; @@ -40,7 +40,7 @@ public class WrenchItem extends Item { BlockState state = world.getBlockState(pos); if (!(state.getBlock() instanceof PipeBlock)) return ActionResultType.PASS; - PipeTileEntity tile = Utility.getBlockEntity(PipeTileEntity.class, world, pos); + PipeBlockEntity tile = Utility.getBlockEntity(PipeBlockEntity.class, world, pos); if (tile == null) return ActionResultType.FAIL; diff --git a/src/main/java/de/ellpeck/prettypipes/misc/FilterSlot.java b/src/main/java/de/ellpeck/prettypipes/misc/FilterSlot.java index 8c75f78..586a80b 100644 --- a/src/main/java/de/ellpeck/prettypipes/misc/FilterSlot.java +++ b/src/main/java/de/ellpeck/prettypipes/misc/FilterSlot.java @@ -1,11 +1,11 @@ package de.ellpeck.prettypipes.misc; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.Slot; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.SlotItemHandler; +import org.jetbrains.annotations.NotNull; public class FilterSlot extends SlotItemHandler { @@ -16,9 +16,9 @@ public class FilterSlot extends SlotItemHandler { this.onlyOneItem = onlyOneItem; } - public static boolean checkFilter(Container container, int slotId, PlayerEntity player) { - if (slotId >= 0 && slotId < container.inventorySlots.size()) { - Slot slot = container.getSlot(slotId); + public static boolean checkFilter(AbstractContainerMenu container, int slotId, Player player) { + if (slotId >= 0 && slotId < container.slots.size()) { + var slot = container.getSlot(slotId); if (slot instanceof FilterSlot) { ((FilterSlot) slot).slotClick(player); return true; @@ -27,32 +27,33 @@ public class FilterSlot extends SlotItemHandler { return false; } - private void slotClick(PlayerEntity player) { - ItemStack heldStack = player.inventory.getItemStack(); - ItemStack stackInSlot = this.getStack(); + private void slotClick(Player player) { + var heldStack = player.inventoryMenu.getCarried(); + var stackInSlot = this.getItem(); if (!stackInSlot.isEmpty() && heldStack.isEmpty()) { - this.putStack(ItemStack.EMPTY); + this.safeInsert(ItemStack.EMPTY); } else if (!heldStack.isEmpty()) { - ItemStack s = heldStack.copy(); + var s = heldStack.copy(); if (this.onlyOneItem) s.setCount(1); - this.putStack(s); + this.safeInsert(s); } } @Override - public boolean isItemValid(ItemStack stack) { + public boolean mayPlace(@NotNull ItemStack stack) { return false; } @Override - public void putStack(ItemStack stack) { - super.putStack(stack.copy()); + public ItemStack safeInsert(ItemStack stack) { + return super.safeInsert(stack.copy()); } @Override - public boolean canTakeStack(PlayerEntity playerIn) { + public boolean mayPickup(Player playerIn) { return false; } + } diff --git a/src/main/java/de/ellpeck/prettypipes/misc/ItemFilter.java b/src/main/java/de/ellpeck/prettypipes/misc/ItemFilter.java index 12b0851..4825595 100644 --- a/src/main/java/de/ellpeck/prettypipes/misc/ItemFilter.java +++ b/src/main/java/de/ellpeck/prettypipes/misc/ItemFilter.java @@ -3,7 +3,7 @@ package de.ellpeck.prettypipes.misc; import com.mojang.blaze3d.vertex.PoseStack; import de.ellpeck.prettypipes.PrettyPipes; import de.ellpeck.prettypipes.packets.PacketButton; -import de.ellpeck.prettypipes.pipe.PipeTileEntity; +import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import de.ellpeck.prettypipes.pipe.modules.modifier.FilterModifierModuleItem; import net.minecraft.ChatFormatting; import net.minecraft.client.gui.components.Button; @@ -25,14 +25,14 @@ import java.util.function.Supplier; public class ItemFilter extends ItemStackHandler { private final ItemStack stack; - private final PipeTileEntity pipe; + private final PipeBlockEntity pipe; public boolean isWhitelist; public boolean canPopulateFromInventories; public boolean canModifyWhitelist = true; private boolean modified; - public ItemFilter(int size, ItemStack stack, PipeTileEntity pipe) { + public ItemFilter(int size, ItemStack stack, PipeBlockEntity pipe) { super(size); this.stack = stack; this.pipe = pipe; @@ -144,7 +144,7 @@ public class ItemFilter extends ItemStackHandler { this.modified = true; } - public static ItemEquality[] getEqualityTypes(PipeTileEntity pipe) { + public static ItemEquality[] getEqualityTypes(PipeBlockEntity pipe) { return pipe.streamModules() .filter(m -> m.getRight() instanceof FilterModifierModuleItem) .map(m -> ((FilterModifierModuleItem) m.getRight()).getEqualityType(m.getLeft())) diff --git a/src/main/java/de/ellpeck/prettypipes/network/NetworkLocation.java b/src/main/java/de/ellpeck/prettypipes/network/NetworkLocation.java index c09a93c..ca920fe 100644 --- a/src/main/java/de/ellpeck/prettypipes/network/NetworkLocation.java +++ b/src/main/java/de/ellpeck/prettypipes/network/NetworkLocation.java @@ -1,13 +1,12 @@ package de.ellpeck.prettypipes.network; import de.ellpeck.prettypipes.misc.ItemEquality; -import de.ellpeck.prettypipes.pipe.PipeTileEntity; +import de.ellpeck.prettypipes.pipe.PipeBlockEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.world.item.ItemStack; import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.NBTUtil; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.level.Level; import net.minecraftforge.common.util.INBTSerializable; import net.minecraftforge.items.IItemHandler; @@ -33,7 +32,7 @@ public class NetworkLocation implements INBTSerializable { this.deserializeNBT(nbt); } - public List getStackSlots(World world, ItemStack stack, ItemEquality... equalityTypes) { + public List getStackSlots(Level world, ItemStack stack, ItemEquality... equalityTypes) { if (this.isEmpty(world)) return Collections.emptyList(); return this.getItems(world).entrySet().stream() @@ -41,7 +40,7 @@ public class NetworkLocation implements INBTSerializable { .map(Map.Entry::getKey).collect(Collectors.toList()); } - public int getItemAmount(World world, ItemStack stack, ItemEquality... equalityTypes) { + public int getItemAmount(Level world, ItemStack stack, ItemEquality... equalityTypes) { if (this.isEmpty(world)) return 0; return this.getItems(world).entrySet().stream() @@ -49,7 +48,7 @@ public class NetworkLocation implements INBTSerializable { .mapToInt(kv -> kv.getValue().getCount()).sum(); } - public Map getItems(World world) { + public Map getItems(Level world) { if (this.itemCache == null) { IItemHandler handler = this.getItemHandler(world); if (handler != null) { @@ -68,27 +67,27 @@ public class NetworkLocation implements INBTSerializable { return this.itemCache; } - public boolean canExtract(World world, int slot) { + public boolean canExtract(Level world, int slot) { IItemHandler handler = this.getItemHandler(world); return handler != null && !handler.extractItem(slot, 1, true).isEmpty(); } - public IItemHandler getItemHandler(World world) { + public IItemHandler getItemHandler(Level world) { if (this.handlerCache == null) { PipeNetwork network = PipeNetwork.get(world); - PipeTileEntity pipe = network.getPipe(this.pipePos); + PipeBlockEntity pipe = network.getPipe(this.pipePos); this.handlerCache = pipe.getItemHandler(this.direction); } return this.handlerCache; } - public boolean isEmpty(World world) { + public boolean isEmpty(Level world) { Map items = this.getItems(world); return items == null || items.isEmpty(); } public BlockPos getPos() { - return this.pipePos.offset(this.direction); + return this.pipePos.relative(this.direction); } @Override diff --git a/src/main/java/de/ellpeck/prettypipes/network/PipeItem.java b/src/main/java/de/ellpeck/prettypipes/network/PipeItem.java index 2eb1962..22b11ad 100644 --- a/src/main/java/de/ellpeck/prettypipes/network/PipeItem.java +++ b/src/main/java/de/ellpeck/prettypipes/network/PipeItem.java @@ -5,7 +5,7 @@ import de.ellpeck.prettypipes.PrettyPipes; import de.ellpeck.prettypipes.Utility; import de.ellpeck.prettypipes.pipe.IPipeConnectable; import de.ellpeck.prettypipes.pipe.IPipeItem; -import de.ellpeck.prettypipes.pipe.PipeTileEntity; +import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.model.ItemCameraTransforms; @@ -95,7 +95,7 @@ public class PipeItem implements IPipeItem { } @Override - public void updateInPipe(PipeTileEntity currPipe) { + public void updateInPipe(PipeBlockEntity currPipe) { // this prevents pipes being updated after one another // causing an item that just switched to tick twice long worldTick = currPipe.getWorld().getGameTime(); @@ -112,7 +112,7 @@ public class PipeItem implements IPipeItem { if (!myPos.equals(currPipe.getPos()) && (currPipe.getPos().equals(this.getDestPipe()) || !myPos.equals(this.startInventory))) { // we're done with the current pipe, so switch to the next one currPipe.getItems().remove(this); - PipeTileEntity next = this.getNextTile(currPipe, true); + PipeBlockEntity next = this.getNextTile(currPipe, true); if (next == null) { if (!currPipe.getWorld().isRemote) { if (currPipe.getPos().equals(this.getDestPipe())) { @@ -134,7 +134,7 @@ public class PipeItem implements IPipeItem { if (dist < currSpeed * currSpeed) { // we're past the start of the pipe, so move to the center of the next pipe BlockPos nextPos; - PipeTileEntity next = this.getNextTile(currPipe, false); + PipeBlockEntity next = this.getNextTile(currPipe, false); if (next == null || next == currPipe) { if (currPipe.getPos().equals(this.getDestPipe())) { nextPos = this.destInventory; @@ -177,7 +177,7 @@ public class PipeItem implements IPipeItem { } } - protected void onPathObstructed(PipeTileEntity currPipe, boolean tryReturn) { + protected void onPathObstructed(PipeBlockEntity currPipe, boolean tryReturn) { if (currPipe.getWorld().isRemote) return; PipeNetwork network = PipeNetwork.get(currPipe.getWorld()); @@ -203,7 +203,7 @@ public class PipeItem implements IPipeItem { item.world.addEntity(item); } - protected ItemStack store(PipeTileEntity currPipe) { + protected ItemStack store(PipeBlockEntity currPipe) { Direction dir = Utility.getDirectionFromOffset(this.destInventory, this.getDestPipe()); IPipeConnectable connectable = currPipe.getPipeConnectable(dir); if (connectable != null) @@ -214,7 +214,7 @@ public class PipeItem implements IPipeItem { return this.stack; } - protected PipeTileEntity getNextTile(PipeTileEntity currPipe, boolean progress) { + protected PipeBlockEntity getNextTile(PipeBlockEntity currPipe, boolean progress) { if (this.path.size() <= this.currentTile + 1) return null; BlockPos pos = this.path.get(this.currentTile + 1); @@ -289,7 +289,7 @@ public class PipeItem implements IPipeItem { @Override @OnlyIn(Dist.CLIENT) - public void render(PipeTileEntity tile, MatrixStack matrixStack, Random random, float partialTicks, int light, int overlay, IRenderTypeBuffer buffer) { + public void render(PipeBlockEntity tile, MatrixStack matrixStack, Random random, float partialTicks, int light, int overlay, IRenderTypeBuffer buffer) { matrixStack.translate( MathHelper.lerp(partialTicks, this.lastX, this.x), MathHelper.lerp(partialTicks, this.lastY, this.y), diff --git a/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java b/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java index d2e1790..a98d10e 100644 --- a/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java +++ b/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java @@ -11,29 +11,21 @@ import de.ellpeck.prettypipes.packets.PacketHandler; import de.ellpeck.prettypipes.packets.PacketItemEnterPipe; import de.ellpeck.prettypipes.pipe.IPipeItem; import de.ellpeck.prettypipes.pipe.PipeBlock; -import de.ellpeck.prettypipes.pipe.PipeTileEntity; -import net.minecraft.block.BlockState; +import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.nbt.*; -import net.minecraft.world.item.ItemStack; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.NBTUtil; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.nbt.NbtUtils; +import net.minecraft.nbt.Tag; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ICapabilitySerializable; -import net.minecraftforge.common.util.Constants.NBT; import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.items.IItemHandler; import org.apache.commons.lang3.tuple.Pair; -import org.jgrapht.GraphPath; import org.jgrapht.ListenableGraph; -import org.jgrapht.alg.interfaces.ShortestPathAlgorithm; import org.jgrapht.alg.shortestpath.DijkstraShortestPath; import org.jgrapht.event.GraphEdgeChangeEvent; import org.jgrapht.event.GraphListener; @@ -56,7 +48,7 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL public final ListenableGraph graph; private final DijkstraShortestPath dijkstra; private final Map> nodeToConnectedNodes = new HashMap<>(); - private final Map tileCache = new HashMap<>(); + private final Map tileCache = new HashMap<>(); private final ListMultimap pipeItems = ArrayListMultimap.create(); private final ListMultimap networkLocks = ArrayListMultimap.create(); private final Level world; @@ -77,13 +69,13 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL @Override public CompoundTag serializeNBT() { - CompoundTag nbt = new CompoundTag(); - ListTag nodes = new ListTag(); - for (BlockPos node : this.graph.vertexSet()) + var nbt = new CompoundTag(); + var nodes = new ListTag(); + for (var node : this.graph.vertexSet()) nodes.add(NbtUtils.writeBlockPos(node)); nbt.put("nodes", nodes); - ListTag edges = new ListTag(); - for (NetworkEdge edge : this.graph.edgeSet()) + var edges = new ListTag(); + for (var edge : this.graph.edgeSet()) edges.add(edge.serializeNBT()); nbt.put("edges", edges); nbt.put("items", Utility.serializeAll(this.pipeItems.values())); @@ -97,15 +89,15 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL this.pipeItems.clear(); this.networkLocks.clear(); - ListTag nodes = nbt.getList("nodes", Tag.TAG_COMPOUND); - for (int i = 0; i < nodes.size(); i++) - this.graph.addVertex(NBTUtil.readBlockPos(nodes.getCompound(i))); - ListTag edges = nbt.getList("edges", Tag.TAG_COMPOUND); - for (int i = 0; i < edges.size(); i++) + var nodes = nbt.getList("nodes", Tag.TAG_COMPOUND); + for (var i = 0; i < nodes.size(); i++) + this.graph.addVertex(NbtUtils.readBlockPos(nodes.getCompound(i))); + var edges = nbt.getList("edges", Tag.TAG_COMPOUND); + for (var i = 0; i < edges.size(); i++) this.addEdge(new NetworkEdge(edges.getCompound(i))); - for (IPipeItem item : Utility.deserializeAll(nbt.getList("items", NBT.TAG_COMPOUND), IPipeItem::load)) + for (var item : Utility.deserializeAll(nbt.getList("items", Tag.TAG_COMPOUND), IPipeItem::load)) this.pipeItems.put(item.getCurrentPipe(), item); - for (NetworkLock lock : Utility.deserializeAll(nbt.getList("locks", NBT.TAG_COMPOUND), NetworkLock::new)) + for (var lock : Utility.deserializeAll(nbt.getList("locks", Tag.TAG_COMPOUND), NetworkLock::new)) this.createNetworkLock(lock); } @@ -126,12 +118,12 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL } public void onPipeChanged(BlockPos pos, BlockState state) { - List neighbors = this.createAllEdges(pos, state, true); + var neighbors = this.createAllEdges(pos, state, true); // if we only have one neighbor, then there can't be any new connections if (neighbors.size() <= 1 && !this.isNode(pos)) return; - for (NetworkEdge edge : neighbors) { - BlockPos end = edge.getEndPipe(); + for (var edge : neighbors) { + var end = edge.getEndPipe(); this.refreshNode(end, this.world.getBlockState(end)); } } @@ -143,24 +135,24 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL public ItemStack routeItem(BlockPos startPipePos, BlockPos startInventory, ItemStack stack, BiFunction itemSupplier, boolean preventOversending) { if (!this.isNode(startPipePos)) return stack; - if (!this.world.isBlockLoaded(startPipePos)) + if (!this.world.isLoaded(startPipePos)) return stack; - PipeTileEntity startPipe = this.getPipe(startPipePos); + var startPipe = this.getPipe(startPipePos); if (startPipe == null) return stack; this.startProfile("find_destination"); - List nodes = this.getOrderedNetworkNodes(startPipePos); - for (int i = 0; i < nodes.size(); i++) { - BlockPos pipePos = nodes.get(startPipe.getNextNode(nodes, i)); - if (!this.world.isBlockLoaded(pipePos)) + var nodes = this.getOrderedNetworkNodes(startPipePos); + for (var i = 0; i < nodes.size(); i++) { + var pipePos = nodes.get(startPipe.getNextNode(nodes, i)); + if (!this.world.isLoaded(pipePos)) continue; - PipeTileEntity pipe = this.getPipe(pipePos); - Pair dest = pipe.getAvailableDestination(stack, false, preventOversending); + var pipe = this.getPipe(pipePos); + var dest = pipe.getAvailableDestination(stack, false, preventOversending); if (dest == null || dest.getLeft().equals(startInventory)) continue; - Function sup = speed -> itemSupplier.apply(dest.getRight(), speed); - if (this.routeItemToLocation(startPipePos, startInventory, pipe.getPos(), dest.getLeft(), dest.getRight(), sup)) { - ItemStack remain = stack.copy(); + var sup = (Function) speed -> itemSupplier.apply(dest.getRight(), speed); + if (this.routeItemToLocation(startPipePos, startInventory, pipe.getBlockPos(), dest.getLeft(), dest.getRight(), sup)) { + var remain = stack.copy(); remain.shrink(dest.getRight().getCount()); this.endProfile(); return remain; @@ -173,17 +165,17 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL public boolean routeItemToLocation(BlockPos startPipePos, BlockPos startInventory, BlockPos destPipePos, BlockPos destInventory, ItemStack stack, Function itemSupplier) { if (!this.isNode(startPipePos) || !this.isNode(destPipePos)) return false; - if (!this.world.isBlockLoaded(startPipePos) || !this.world.isBlockLoaded(destPipePos)) + if (!this.world.isLoaded(startPipePos) || !this.world.isLoaded(destPipePos)) return false; - PipeTileEntity startPipe = this.getPipe(startPipePos); + var startPipe = this.getPipe(startPipePos); if (startPipe == null) return false; this.startProfile("get_path"); - GraphPath path = this.dijkstra.getPath(startPipePos, destPipePos); + var path = this.dijkstra.getPath(startPipePos, destPipePos); this.endProfile(); if (path == null) return false; - IPipeItem item = itemSupplier.apply(startPipe.getItemSpeed(stack)); + var item = itemSupplier.apply(startPipe.getItemSpeed(stack)); item.setDestination(startInventory, destInventory, path); startPipe.addNewItem(item); PacketHandler.sendToAllLoaded(this.world, startPipePos, new PacketItemEnterPipe(startPipePos, item)); @@ -191,9 +183,9 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL } public ItemStack requestItem(BlockPos destPipe, BlockPos destInventory, ItemStack stack, ItemEquality... equalityTypes) { - ItemStack remain = stack.copy(); + var remain = stack.copy(); // check existing items - for (NetworkLocation location : this.getOrderedNetworkItems(destPipe)) { + for (var location : this.getOrderedNetworkItems(destPipe)) { remain = this.requestExistingItem(location, destPipe, destInventory, null, remain, equalityTypes); if (remain.isEmpty()) return remain; @@ -203,10 +195,10 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL } public ItemStack requestCraftedItem(BlockPos destPipe, Consumer unavailableConsumer, ItemStack stack, Stack dependencyChain, ItemEquality... equalityTypes) { - for (Pair craftable : this.getAllCraftables(destPipe)) { + for (var craftable : this.getAllCraftables(destPipe)) { if (!ItemEquality.compareItems(stack, craftable.getRight(), equalityTypes)) continue; - PipeTileEntity pipe = this.getPipe(craftable.getLeft()); + var pipe = this.getPipe(craftable.getLeft()); if (pipe == null) continue; stack = pipe.craft(destPipe, unavailableConsumer, stack, dependencyChain); @@ -224,21 +216,21 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL if (location.getPos().equals(destInventory)) return stack; // make sure we don't pull any locked items - int amount = location.getItemAmount(this.world, stack, equalityTypes); + var amount = location.getItemAmount(this.world, stack, equalityTypes); if (amount <= 0) return stack; amount -= this.getLockedAmount(location.getPos(), stack, ignoredLock, equalityTypes); if (amount <= 0) return stack; - ItemStack remain = stack.copy(); + var remain = stack.copy(); // make sure we only extract less than or equal to the requested amount if (remain.getCount() < amount) amount = remain.getCount(); remain.shrink(amount); for (int slot : location.getStackSlots(this.world, stack, equalityTypes)) { // try to extract from that location's inventory and send the item - IItemHandler handler = location.getItemHandler(this.world); - ItemStack extracted = handler.extractItem(slot, amount, true); + var handler = location.getItemHandler(this.world); + var extracted = handler.extractItem(slot, amount, true); if (this.routeItemToLocation(location.pipePos, location.getPos(), destPipe, destInventory, extracted, speed -> itemSupplier.apply(extracted, speed))) { handler.extractItem(slot, extracted.getCount(), false); amount -= extracted.getCount(); @@ -249,10 +241,10 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL return remain; } - public PipeTileEntity getPipe(BlockPos pos) { - PipeTileEntity tile = this.tileCache.get(pos); + public PipeBlockEntity getPipe(BlockPos pos) { + var tile = this.tileCache.get(pos); if (tile == null || tile.isRemoved()) { - tile = Utility.getBlockEntity(PipeTileEntity.class, this.world, pos); + tile = Utility.getBlockEntity(PipeBlockEntity.class, this.world, pos); this.tileCache.put(pos, tile); } return tile; @@ -265,14 +257,14 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL public List> getCurrentlyCrafting(BlockPos node, ItemEquality... equalityTypes) { this.startProfile("get_currently_crafting"); List> items = new ArrayList<>(); - Iterator craftingPipes = this.getAllCraftables(node).stream().map(c -> this.getPipe(c.getLeft())).distinct().iterator(); + var craftingPipes = this.getAllCraftables(node).stream().map(c -> this.getPipe(c.getLeft())).distinct().iterator(); while (craftingPipes.hasNext()) { - PipeTileEntity pipe = craftingPipes.next(); - for (Pair request : pipe.craftResultRequests) { - BlockPos dest = request.getLeft(); - ItemStack stack = request.getRight(); + var pipe = craftingPipes.next(); + for (var request : pipe.craftResultRequests) { + var dest = request.getLeft(); + var stack = request.getRight(); // add up all the items that should go to the same location - Optional> existing = items.stream() + var existing = items.stream() .filter(s -> s.getLeft().equals(dest) && ItemEquality.compareItems(s.getRight(), stack, equalityTypes)) .findFirst(); if (existing.isPresent()) { @@ -297,25 +289,25 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL return Collections.emptyList(); this.startProfile("get_all_craftables"); List> craftables = new ArrayList<>(); - for (BlockPos dest : this.getOrderedNetworkNodes(node)) { - if (!this.world.isBlockLoaded(dest)) + for (var dest : this.getOrderedNetworkNodes(node)) { + if (!this.world.isLoaded(dest)) continue; - PipeTileEntity pipe = this.getPipe(dest); - for (ItemStack stack : pipe.getAllCraftables()) - craftables.add(Pair.of(pipe.getPos(), stack)); + var pipe = this.getPipe(dest); + for (var stack : pipe.getAllCraftables()) + craftables.add(Pair.of(pipe.getBlockPos(), stack)); } this.endProfile(); return craftables; } public int getCraftableAmount(BlockPos node, Consumer unavailableConsumer, ItemStack stack, Stack dependencyChain, ItemEquality... equalityTypes) { - int total = 0; - for (Pair pair : this.getAllCraftables(node)) { + var total = 0; + for (var pair : this.getAllCraftables(node)) { if (!ItemEquality.compareItems(pair.getRight(), stack, equalityTypes)) continue; - if (!this.world.isBlockLoaded(pair.getLeft())) + if (!this.world.isLoaded(pair.getLeft())) continue; - PipeTileEntity pipe = this.getPipe(pair.getLeft()); + var pipe = this.getPipe(pair.getLeft()); if (pipe != null) total += pipe.getCraftableAmount(unavailableConsumer, stack, dependencyChain); } @@ -327,20 +319,20 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL return Collections.emptyList(); this.startProfile("get_network_items"); List info = new ArrayList<>(); - for (BlockPos dest : this.getOrderedNetworkNodes(node)) { - if (!this.world.isBlockLoaded(dest)) + for (var dest : this.getOrderedNetworkNodes(node)) { + if (!this.world.isLoaded(dest)) continue; - PipeTileEntity pipe = this.getPipe(dest); + var pipe = this.getPipe(dest); if (!pipe.canNetworkSee()) continue; - for (Direction dir : Direction.values()) { - IItemHandler handler = pipe.getItemHandler(dir); + for (var dir : Direction.values()) { + var handler = pipe.getItemHandler(dir); if (handler == null) continue; // check if this handler already exists (double-connected pipes, double chests etc.) if (info.stream().anyMatch(l -> handler.equals(l.getItemHandler(this.world)))) continue; - NetworkLocation location = new NetworkLocation(dest, dir); + var location = new NetworkLocation(dest, dir); if (!location.isEmpty(this.world)) info.add(location); } @@ -370,7 +362,7 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL private void refreshNode(BlockPos pos, BlockState state) { this.startProfile("refresh_node"); this.graph.removeAllEdges(new ArrayList<>(this.graph.edgesOf(pos))); - for (NetworkEdge edge : this.createAllEdges(pos, state, false)) + for (var edge : this.createAllEdges(pos, state, false)) this.addEdge(edge); this.endProfile(); } @@ -384,11 +376,11 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL public BlockPos getNodeFromPipe(BlockPos pos) { if (this.isNode(pos)) return pos; - BlockState state = this.world.getBlockState(pos); + var state = this.world.getBlockState(pos); if (!(state.getBlock() instanceof PipeBlock)) return null; - for (Direction dir : Direction.values()) { - NetworkEdge edge = this.createEdge(pos, state, dir, false); + for (var dir : Direction.values()) { + var edge = this.createEdge(pos, state, dir, false); if (edge != null) return edge.getEndPipe(); } @@ -398,8 +390,8 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL private List createAllEdges(BlockPos pos, BlockState state, boolean ignoreCurrBlocked) { this.startProfile("create_all_edges"); List edges = new ArrayList<>(); - for (Direction dir : Direction.values()) { - NetworkEdge edge = this.createEdge(pos, state, dir, ignoreCurrBlocked); + for (var dir : Direction.values()) { + var edge = this.createEdge(pos, state, dir, ignoreCurrBlocked); if (edge != null) edges.add(edge); } @@ -408,14 +400,14 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL } private NetworkEdge createEdge(BlockPos pos, BlockState state, Direction dir, boolean ignoreCurrBlocked) { - if (!ignoreCurrBlocked && !state.get(PipeBlock.DIRECTIONS.get(dir)).isConnected()) + if (!ignoreCurrBlocked && !state.getValue(PipeBlock.DIRECTIONS.get(dir)).isConnected()) return null; - BlockPos currPos = pos.offset(dir); - BlockState currState = this.world.getBlockState(currPos); + var currPos = pos.relative(dir); + var currState = this.world.getBlockState(currPos); if (!(currState.getBlock() instanceof PipeBlock)) return null; this.startProfile("create_edge"); - NetworkEdge edge = new NetworkEdge(); + var edge = new NetworkEdge(); edge.pipes.add(pos); edge.pipes.add(currPos); @@ -427,12 +419,12 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL return edge; } - boolean found = false; - for (Direction nextDir : Direction.values()) { - if (!currState.get(PipeBlock.DIRECTIONS.get(nextDir)).isConnected()) + var found = false; + for (var nextDir : Direction.values()) { + if (!currState.getValue(PipeBlock.DIRECTIONS.get(nextDir)).isConnected()) continue; - BlockPos offset = currPos.offset(nextDir); - BlockState offState = this.world.getBlockState(offset); + var offset = currPos.relative(nextDir); + var offState = this.world.getBlockState(offset); if (!(offState.getBlock() instanceof PipeBlock)) continue; if (edge.pipes.contains(offset)) @@ -453,10 +445,10 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL public List getOrderedNetworkNodes(BlockPos node) { if (!this.isNode(node)) return Collections.emptyList(); - List ret = this.nodeToConnectedNodes.get(node); + var ret = this.nodeToConnectedNodes.get(node); if (ret == null) { this.startProfile("compile_connected_nodes"); - ShortestPathAlgorithm.SingleSourcePaths paths = this.dijkstra.getPaths(node); + var paths = this.dijkstra.getPaths(node); // sort destinations first by their priority (eg trash pipes should be last) // and then by their distance from the specified node ret = Streams.stream(new BreadthFirstIterator<>(this.graph, node)) @@ -472,7 +464,7 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL public void clearDestinationCache(BlockPos... nodes) { this.startProfile("clear_node_cache"); // remove caches for the nodes - for (BlockPos node : nodes) + for (var node : nodes) this.nodeToConnectedNodes.keySet().remove(node); // remove caches that contain the nodes as a destination this.nodeToConnectedNodes.values().removeIf(cached -> Arrays.stream(nodes).anyMatch(cached::contains)); @@ -485,7 +477,7 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL public Stream getPipeItemsOnTheWay(BlockPos goalInv) { this.startProfile("get_pipe_items_on_the_way"); - Stream ret = this.pipeItems.values().stream().filter(i -> i.getDestInventory().equals(goalInv)); + var ret = this.pipeItems.values().stream().filter(i -> i.getDestInventory().equals(goalInv)); this.endProfile(); return ret; } @@ -515,11 +507,11 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL } public void startProfile(String name) { - this.world.getProfiler().startSection(() -> PrettyPipes.ID + ":pipe_network_" + name); + this.world.getProfiler().push(() -> PrettyPipes.ID + ":pipe_network_" + name); } public void endProfile() { - this.world.getProfiler().endSection(); + this.world.getProfiler().pop(); } public static PipeNetwork get(Level world) { diff --git a/src/main/java/de/ellpeck/prettypipes/packets/PacketButton.java b/src/main/java/de/ellpeck/prettypipes/packets/PacketButton.java index d5f82b9..6fc9f54 100644 --- a/src/main/java/de/ellpeck/prettypipes/packets/PacketButton.java +++ b/src/main/java/de/ellpeck/prettypipes/packets/PacketButton.java @@ -4,25 +4,35 @@ import de.ellpeck.prettypipes.Utility; import de.ellpeck.prettypipes.items.IModule; import de.ellpeck.prettypipes.misc.ItemFilter; import de.ellpeck.prettypipes.misc.ItemFilter.IFilteredContainer; -import de.ellpeck.prettypipes.pipe.PipeTileEntity; +import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer; import de.ellpeck.prettypipes.pipe.modules.modifier.FilterModifierModuleContainer; import de.ellpeck.prettypipes.pipe.modules.modifier.FilterModifierModuleItem; import de.ellpeck.prettypipes.pipe.modules.stacksize.StackSizeModuleItem; -import de.ellpeck.prettypipes.terminal.CraftingTerminalTileEntity; -import de.ellpeck.prettypipes.terminal.ItemTerminalTileEntity; +import de.ellpeck.prettypipes.terminal.CraftingTerminalBlockEntity; +import de.ellpeck.prettypipes.terminal.ItemTerminalBlockEntity; import net.minecraft.client.Minecraft; +import net.minecraft.core.BlockPos; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.INamedContainerProvider; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; import net.minecraft.network.PacketBuffer; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.ITextComponent; import net.minecraftforge.fml.network.NetworkEvent; import net.minecraftforge.fml.network.NetworkHooks; +import net.minecraftforge.network.NetworkEvent; +import net.minecraftforge.network.NetworkHooks; import org.apache.logging.log4j.util.TriConsumer; import javax.annotation.Nullable; @@ -44,7 +54,7 @@ public class PacketButton { } - public static PacketButton fromBytes(PacketBuffer buf) { + public static PacketButton fromBytes(FriendlyByteBuf buf) { PacketButton packet = new PacketButton(); packet.pos = buf.readBlockPos(); packet.result = ButtonResult.values()[buf.readByte()]; @@ -52,7 +62,7 @@ public class PacketButton { return packet; } - public static void toBytes(PacketButton packet, PacketBuffer buf) { + public static void toBytes(PacketButton packet, FriendlyByteBuf buf) { buf.writeBlockPos(packet.pos); buf.writeByte(packet.result.ordinal()); buf.writeVarIntArray(packet.data); @@ -63,7 +73,7 @@ public class PacketButton { ctx.get().enqueueWork(new Runnable() { @Override public void run() { - PlayerEntity player = ctx.get().getSender(); + Player player = ctx.get().getSender(); message.result.action.accept(message.pos, message.data, player); } }); @@ -77,22 +87,23 @@ public class PacketButton { public enum ButtonResult { PIPE_TAB((pos, data, player) -> { - PipeTileEntity tile = Utility.getBlockEntity(PipeTileEntity.class, player.world, pos); + PipeBlockEntity tile = Utility.getBlockEntity(PipeBlockEntity.class, player.level, pos); if (data[0] < 0) { - NetworkHooks.openGui((ServerPlayerEntity) player, tile, pos); + NetworkHooks.openGui((ServerPlayer) player, tile, pos); } else { ItemStack stack = tile.modules.getStackInSlot(data[0]); - NetworkHooks.openGui((ServerPlayerEntity) player, new INamedContainerProvider() { + NetworkHooks.openGui((ServerPlayer) player, new MenuProvider() { @Override - public ITextComponent getDisplayName() { + public Component getDisplayName() { return stack.getDisplayName(); } @Nullable @Override - public Container createMenu(int windowId, PlayerInventory inv, PlayerEntity player) { + public AbstractContainerMenu createMenu(int windowId, Inventory inv, Player player) { return ((IModule) stack.getItem()).getContainer(stack, tile, windowId, inv, player, data[0]); } + }, buf -> { buf.writeBlockPos(pos); buf.writeInt(data[0]); @@ -100,34 +111,34 @@ public class PacketButton { } }), FILTER_CHANGE((pos, data, player) -> { - IFilteredContainer container = (IFilteredContainer) player.openContainer; + IFilteredContainer container = (IFilteredContainer) player.containerMenu; ItemFilter filter = container.getFilter(); filter.onButtonPacket(data[0]); }), STACK_SIZE_MODULE_BUTTON((pos, data, player) -> { - AbstractPipeContainer container = (AbstractPipeContainer) player.openContainer; + AbstractPipeContainer container = (AbstractPipeContainer) player.containerMenu; StackSizeModuleItem.setLimitToMaxStackSize(container.moduleStack, !StackSizeModuleItem.getLimitToMaxStackSize(container.moduleStack)); }), STACK_SIZE_AMOUNT((pos, data, player) -> { - AbstractPipeContainer container = (AbstractPipeContainer) player.openContainer; + AbstractPipeContainer container = (AbstractPipeContainer) player.containerMenu; StackSizeModuleItem.setMaxStackSize(container.moduleStack, data[0]); }), CRAFT_TERMINAL_REQUEST((pos, data, player) -> { - CraftingTerminalTileEntity tile = Utility.getBlockEntity(CraftingTerminalTileEntity.class, player.world, pos); + CraftingTerminalBlockEntity tile = Utility.getBlockEntity(CraftingTerminalBlockEntity.class, player.level, pos); tile.requestCraftingItems(player, data[0]); }), CANCEL_CRAFTING((pos, data, player) -> { - ItemTerminalTileEntity tile = Utility.getBlockEntity(ItemTerminalTileEntity.class, player.world, pos); + ItemTerminalBlockEntity tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, player.level, pos); tile.cancelCrafting(); }), TAG_FILTER((pos, data, player) -> { - FilterModifierModuleContainer container = (FilterModifierModuleContainer) player.openContainer; + FilterModifierModuleContainer container = (FilterModifierModuleContainer) player.containerMenu; FilterModifierModuleItem.setFilterTag(container.moduleStack, container.getTags().get(data[0])); }); - public final TriConsumer action; + public final TriConsumer action; - ButtonResult(TriConsumer action) { + ButtonResult(TriConsumer action) { this.action = action; } } diff --git a/src/main/java/de/ellpeck/prettypipes/packets/PacketGhostSlot.java b/src/main/java/de/ellpeck/prettypipes/packets/PacketGhostSlot.java index 13dbb6e..bd4ea1d 100644 --- a/src/main/java/de/ellpeck/prettypipes/packets/PacketGhostSlot.java +++ b/src/main/java/de/ellpeck/prettypipes/packets/PacketGhostSlot.java @@ -3,8 +3,9 @@ package de.ellpeck.prettypipes.packets; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ListMultimap; import de.ellpeck.prettypipes.Utility; -import de.ellpeck.prettypipes.terminal.CraftingTerminalTileEntity; +import de.ellpeck.prettypipes.terminal.CraftingTerminalBlockEntity; import net.minecraft.client.Minecraft; +import net.minecraft.core.BlockPos; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.world.item.ItemStack; import net.minecraft.network.PacketBuffer; @@ -50,7 +51,7 @@ public class PacketGhostSlot { @SuppressWarnings("Convert2Lambda") public static void onMessage(PacketGhostSlot message, Supplier ctx) { Consumer doIt = p -> { - CraftingTerminalTileEntity tile = Utility.getBlockEntity(CraftingTerminalTileEntity.class, p.world, message.pos); + CraftingTerminalBlockEntity tile = Utility.getBlockEntity(CraftingTerminalBlockEntity.class, p.world, message.pos); if (tile != null) tile.setGhostItems(message.stacks); }; diff --git a/src/main/java/de/ellpeck/prettypipes/packets/PacketHandler.java b/src/main/java/de/ellpeck/prettypipes/packets/PacketHandler.java index 55ab804..3f45a18 100644 --- a/src/main/java/de/ellpeck/prettypipes/packets/PacketHandler.java +++ b/src/main/java/de/ellpeck/prettypipes/packets/PacketHandler.java @@ -1,15 +1,22 @@ package de.ellpeck.prettypipes.packets; import de.ellpeck.prettypipes.PrettyPipes; +import net.minecraft.core.BlockPos; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IWorld; import net.minecraft.world.World; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; import net.minecraftforge.fml.network.NetworkRegistry; import net.minecraftforge.fml.network.PacketDistributor; import net.minecraftforge.fml.network.simple.SimpleChannel; +import net.minecraftforge.network.NetworkRegistry; +import net.minecraftforge.network.PacketDistributor; +import net.minecraftforge.network.simple.SimpleChannel; public final class PacketHandler { @@ -26,12 +33,12 @@ public final class PacketHandler { network.registerMessage(5, PacketCraftingModuleTransfer.class, PacketCraftingModuleTransfer::toBytes, PacketCraftingModuleTransfer::fromBytes, PacketCraftingModuleTransfer::onMessage); } - public static void sendToAllLoaded(World world, BlockPos pos, Object message) { + public static void sendToAllLoaded(Level world, BlockPos pos, Object message) { network.send(PacketDistributor.TRACKING_CHUNK.with(() -> world.getChunkAt(pos)), message); } - public static void sendTo(PlayerEntity player, Object message) { - network.send(PacketDistributor.PLAYER.with(() -> (ServerPlayerEntity) player), message); + public static void sendTo(Player player, Object message) { + network.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), message); } public static void sendToServer(Object message) { diff --git a/src/main/java/de/ellpeck/prettypipes/packets/PacketItemEnterPipe.java b/src/main/java/de/ellpeck/prettypipes/packets/PacketItemEnterPipe.java index 43d38d9..0244dcf 100644 --- a/src/main/java/de/ellpeck/prettypipes/packets/PacketItemEnterPipe.java +++ b/src/main/java/de/ellpeck/prettypipes/packets/PacketItemEnterPipe.java @@ -2,12 +2,12 @@ package de.ellpeck.prettypipes.packets; import de.ellpeck.prettypipes.Utility; import de.ellpeck.prettypipes.pipe.IPipeItem; -import de.ellpeck.prettypipes.pipe.PipeTileEntity; +import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import net.minecraft.client.Minecraft; +import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.math.BlockPos; -import net.minecraftforge.fml.network.NetworkEvent; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; @@ -25,16 +25,16 @@ public class PacketItemEnterPipe { } - public static PacketItemEnterPipe fromBytes(PacketBuffer buf) { + public static PacketItemEnterPipe fromBytes(FriendlyByteBuf buf) { PacketItemEnterPipe client = new PacketItemEnterPipe(); client.tilePos = buf.readBlockPos(); - client.item = buf.readCompoundTag(); + client.item = buf.readNbt(); return client; } - public static void toBytes(PacketItemEnterPipe packet, PacketBuffer buf) { + public static void toBytes(PacketItemEnterPipe packet, FriendlyByteBuf buf) { buf.writeBlockPos(packet.tilePos); - buf.writeCompoundTag(packet.item); + buf.writeNbt(packet.item); } @SuppressWarnings("Convert2Lambda") @@ -43,10 +43,10 @@ public class PacketItemEnterPipe { @Override public void run() { Minecraft mc = Minecraft.getInstance(); - if (mc.world == null) + if (mc.level == null) return; IPipeItem item = IPipeItem.load(message.item); - PipeTileEntity pipe = Utility.getBlockEntity(PipeTileEntity.class, mc.world, message.tilePos); + PipeBlockEntity pipe = Utility.getBlockEntity(PipeBlockEntity.class, mc.level, message.tilePos); if (pipe != null) pipe.getItems().add(item); } diff --git a/src/main/java/de/ellpeck/prettypipes/packets/PacketNetworkItems.java b/src/main/java/de/ellpeck/prettypipes/packets/PacketNetworkItems.java index 000b94a..80cb92b 100644 --- a/src/main/java/de/ellpeck/prettypipes/packets/PacketNetworkItems.java +++ b/src/main/java/de/ellpeck/prettypipes/packets/PacketNetworkItems.java @@ -2,13 +2,9 @@ package de.ellpeck.prettypipes.packets; import de.ellpeck.prettypipes.terminal.containers.ItemTerminalGui; import net.minecraft.client.Minecraft; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.inventory.container.Container; +import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.item.ItemStack; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.math.BlockPos; -import net.minecraftforge.fml.network.NetworkEvent; +import net.minecraftforge.network.NetworkEvent; import java.util.ArrayList; import java.util.List; @@ -30,37 +26,37 @@ public class PacketNetworkItems { } - public static PacketNetworkItems fromBytes(PacketBuffer buf) { + public static PacketNetworkItems fromBytes(FriendlyByteBuf buf) { PacketNetworkItems client = new PacketNetworkItems(); client.items = new ArrayList<>(); for (int i = buf.readVarInt(); i > 0; i--) { - ItemStack stack = buf.readItemStack(); + ItemStack stack = buf.readItem(); stack.setCount(buf.readVarInt()); client.items.add(stack); } client.craftables = new ArrayList<>(); for (int i = buf.readVarInt(); i > 0; i--) - client.craftables.add(buf.readItemStack()); + client.craftables.add(buf.readItem()); client.currentlyCrafting = new ArrayList<>(); for (int i = buf.readVarInt(); i > 0; i--) - client.currentlyCrafting.add(buf.readItemStack()); + client.currentlyCrafting.add(buf.readItem()); return client; } - public static void toBytes(PacketNetworkItems packet, PacketBuffer buf) { + public static void toBytes(PacketNetworkItems packet, FriendlyByteBuf buf) { buf.writeVarInt(packet.items.size()); for (ItemStack stack : packet.items) { ItemStack copy = stack.copy(); copy.setCount(1); - buf.writeItemStack(copy); + buf.writeItem(copy); buf.writeVarInt(stack.getCount()); } buf.writeVarInt(packet.craftables.size()); for (ItemStack stack : packet.craftables) - buf.writeItemStack(stack); + buf.writeItem(stack); buf.writeVarInt(packet.currentlyCrafting.size()); for (ItemStack stack : packet.currentlyCrafting) - buf.writeItemStack(stack); + buf.writeItem(stack); } @SuppressWarnings("Convert2Lambda") @@ -69,8 +65,8 @@ public class PacketNetworkItems { @Override public void run() { Minecraft mc = Minecraft.getInstance(); - if (mc.currentScreen instanceof ItemTerminalGui) - ((ItemTerminalGui) mc.currentScreen).updateItemList(message.items, message.craftables, message.currentlyCrafting); + if (mc.screen instanceof ItemTerminalGui terminal) + terminal.updateItemList(message.items, message.craftables, message.currentlyCrafting); } }); ctx.get().setPacketHandled(true); diff --git a/src/main/java/de/ellpeck/prettypipes/packets/PacketRequest.java b/src/main/java/de/ellpeck/prettypipes/packets/PacketRequest.java index 0067dd9..b105e8b 100644 --- a/src/main/java/de/ellpeck/prettypipes/packets/PacketRequest.java +++ b/src/main/java/de/ellpeck/prettypipes/packets/PacketRequest.java @@ -1,12 +1,16 @@ package de.ellpeck.prettypipes.packets; import de.ellpeck.prettypipes.Utility; -import de.ellpeck.prettypipes.terminal.ItemTerminalTileEntity; +import de.ellpeck.prettypipes.terminal.ItemTerminalBlockEntity; +import net.minecraft.core.BlockPos; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.network.PacketBuffer; import net.minecraft.util.math.BlockPos; import net.minecraftforge.fml.network.NetworkEvent; +import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; @@ -26,17 +30,17 @@ public class PacketRequest { } - public static PacketRequest fromBytes(PacketBuffer buf) { + public static PacketRequest fromBytes(FriendlyByteBuf buf) { PacketRequest packet = new PacketRequest(); packet.pos = buf.readBlockPos(); - packet.stack = buf.readItemStack(); + packet.stack = buf.readItem(); packet.amount = buf.readVarInt(); return packet; } - public static void toBytes(PacketRequest packet, PacketBuffer buf) { + public static void toBytes(PacketRequest packet, FriendlyByteBuf buf) { buf.writeBlockPos(packet.pos); - buf.writeItemStack(packet.stack); + buf.writeItem(packet.stack); buf.writeVarInt(packet.amount); } @@ -45,8 +49,8 @@ public class PacketRequest { ctx.get().enqueueWork(new Runnable() { @Override public void run() { - PlayerEntity player = ctx.get().getSender(); - ItemTerminalTileEntity tile = Utility.getBlockEntity(ItemTerminalTileEntity.class, player.world, message.pos); + Player player = ctx.get().getSender(); + ItemTerminalBlockEntity tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, player.level, message.pos); message.stack.setCount(message.amount); tile.requestItem(player, message.stack); } diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/IPipeConnectable.java b/src/main/java/de/ellpeck/prettypipes/pipe/IPipeConnectable.java index 6d9d366..6c9c2b1 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/IPipeConnectable.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/IPipeConnectable.java @@ -1,8 +1,8 @@ package de.ellpeck.prettypipes.pipe; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.world.item.ItemStack; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; public interface IPipeConnectable { diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/IPipeItem.java b/src/main/java/de/ellpeck/prettypipes/pipe/IPipeItem.java index 0352ce9..5348a72 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/IPipeItem.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/IPipeItem.java @@ -1,16 +1,13 @@ package de.ellpeck.prettypipes.pipe; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; -import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.vertex.PoseStack; import de.ellpeck.prettypipes.network.NetworkEdge; import de.ellpeck.prettypipes.network.PipeItem; -import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.core.BlockPos; import net.minecraft.world.item.ItemStack; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.level.Level; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.common.util.INBTSerializable; @@ -31,9 +28,9 @@ public interface IPipeItem extends INBTSerializable { void setDestination(BlockPos startInventory, BlockPos destInventory, GraphPath path); - void updateInPipe(PipeTileEntity currPipe); + void updateInPipe(PipeBlockEntity currPipe); - void drop(World world, ItemStack stack); + void drop(Level world, ItemStack stack); BlockPos getDestPipe(); @@ -44,7 +41,7 @@ public interface IPipeItem extends INBTSerializable { int getItemsOnTheWay(BlockPos goalInv); @OnlyIn(Dist.CLIENT) - void render(PipeTileEntity tile, MatrixStack matrixStack, Random random, float partialTicks, int light, int overlay, IRenderTypeBuffer buffer); + void render(PipeBlockEntity tile, PoseStack matrixStack, Random random, float partialTicks, int light, int overlay); static IPipeItem load(CompoundTag nbt) { // TODO legacy compat, remove eventually diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java b/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java index 06fdea6..2a87f62 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java @@ -5,49 +5,33 @@ import de.ellpeck.prettypipes.Registry; import de.ellpeck.prettypipes.Utility; import de.ellpeck.prettypipes.items.IModule; import de.ellpeck.prettypipes.network.PipeNetwork; -import net.minecraft.block.*; -import net.minecraft.block.material.Material; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.fluid.FluidState; -import net.minecraft.fluid.Fluids; -import net.minecraft.item.BlockItemUseContext; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.tags.FluidTags; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; -import net.minecraft.state.EnumProperty; -import net.minecraft.state.StateContainer; -import net.minecraft.state.properties.BlockStateProperties; -import net.minecraft.tags.FluidTags; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.Direction; -import net.minecraft.util.Hand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.util.math.shapes.IBooleanFunction; -import net.minecraft.util.math.shapes.ISelectionContext; -import net.minecraft.util.math.shapes.VoxelShape; -import net.minecraft.util.math.shapes.VoxelShapes; -import net.minecraft.world.IBlockReader; -import net.minecraft.world.IWorld; -import net.minecraft.world.World; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.BaseEntityBlock; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.*; +import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.EnumProperty; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; import net.minecraft.world.level.material.Material; import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.shapes.BooleanOp; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; -import net.minecraftforge.fml.network.NetworkHooks; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemHandlerHelper; @@ -91,7 +75,7 @@ public class PipeBlock extends BaseEntityBlock { @Override public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult result) { - PipeTileEntity tile = Utility.getBlockEntity(PipeTileEntity.class, worldIn, pos); + PipeBlockEntity tile = Utility.getBlockEntity(PipeBlockEntity.class, worldIn, pos); if (tile == null) return InteractionResult.PASS; if (!tile.canHaveModules()) @@ -114,62 +98,62 @@ public class PipeBlock extends BaseEntityBlock { } @Override - protected void fillStateContainer(StateContainer.Builder builder) { + protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(DIRECTIONS.values().toArray(new EnumProperty[0])); builder.add(BlockStateProperties.WATERLOGGED); } @Override public FluidState getFluidState(BlockState state) { - return state.get(BlockStateProperties.WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : super.getFluidState(state); + return state.getValue(BlockStateProperties.WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); } @Override - public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) { + public void neighborChanged(BlockState state, Level worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) { BlockState newState = this.createState(worldIn, pos, state); if (newState != state) { - worldIn.setBlockState(pos, newState); + worldIn.setBlockAndUpdate(pos, newState); onStateChanged(worldIn, pos, newState); } } @Nullable @Override - public BlockState getStateForPlacement(BlockItemUseContext context) { - return this.createState(context.getWorld(), context.getPos(), this.getDefaultState()); + public BlockState getStateForPlacement(BlockPlaceContext context) { + return this.createState(context.getLevel(), context.getClickedPos(), this.defaultBlockState()); } @Override - public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) { - if (stateIn.get(BlockStateProperties.WATERLOGGED)) - worldIn.getPendingFluidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn)); - return super.updatePostPlacement(stateIn, facing, facingState, worldIn, currentPos, facingPos); + public BlockState updateShape(BlockState stateIn, Direction facing, BlockState facingState, LevelAccessor worldIn, BlockPos currentPos, BlockPos facingPos) { + if (stateIn.getValue(BlockStateProperties.WATERLOGGED)) + worldIn.scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickDelay(worldIn)); + return super.updateShape(stateIn, facing, facingState, worldIn, currentPos, facingPos); } @Override - public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) { + public void setPlacedBy(Level worldIn, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) { onStateChanged(worldIn, pos, state); } @Override - public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { + public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) { return this.cacheAndGetShape(state, worldIn, pos, s -> s.getShape(worldIn, pos, context), SHAPE_CACHE, null); } @Override - public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { + public VoxelShape getCollisionShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) { return this.cacheAndGetShape(state, worldIn, pos, s -> s.getCollisionShape(worldIn, pos, context), COLL_SHAPE_CACHE, s -> { // make the shape a bit higher so we can jump up onto a higher block - MutableObject newShape = new MutableObject<>(VoxelShapes.empty()); - s.forEachBox((x1, y1, z1, x2, y2, z2) -> newShape.setValue(VoxelShapes.combine(VoxelShapes.create(x1, y1, z1, x2, y2 + 3 / 16F, z2), newShape.getValue(), IBooleanFunction.OR))); - return newShape.getValue().simplify(); + MutableObject newShape = new MutableObject<>(Shapes.empty()); + s.forAllBoxes((x1, y1, z1, x2, y2, z2) -> newShape.setValue(Shapes.join(Shapes.create(x1, y1, z1, x2, y2 + 3 / 16F, z2), newShape.getValue(), BooleanOp.OR))); + return newShape.getValue().optimize(); }); } - private VoxelShape cacheAndGetShape(BlockState state, IBlockReader worldIn, BlockPos pos, Function coverShapeSelector, Map, VoxelShape> cache, Function shapeModifier) { + private VoxelShape cacheAndGetShape(BlockState state, BlockGetter worldIn, BlockPos pos, Function coverShapeSelector, Map, VoxelShape> cache, Function shapeModifier) { VoxelShape coverShape = null; BlockState cover = null; - PipeTileEntity tile = Utility.getBlockEntity(PipeTileEntity.class, worldIn, pos); + PipeBlockEntity tile = Utility.getBlockEntity(PipeBlockEntity.class, worldIn, pos); if (tile != null && tile.cover != null) { cover = tile.cover; // try catch since the block might expect to find itself at the position @@ -183,41 +167,41 @@ public class PipeBlock extends BaseEntityBlock { if (shape == null) { shape = CENTER_SHAPE; for (Map.Entry> entry : DIRECTIONS.entrySet()) { - if (state.get(entry.getValue()).isConnected()) - shape = VoxelShapes.or(shape, DIR_SHAPES.get(entry.getKey())); + if (state.getValue(entry.getValue()).isConnected()) + shape = Shapes.or(shape, DIR_SHAPES.get(entry.getKey())); } if (shapeModifier != null) shape = shapeModifier.apply(shape); if (coverShape != null) - shape = VoxelShapes.or(shape, coverShape); + shape = Shapes.or(shape, coverShape); cache.put(key, shape); } return shape; } - private BlockState createState(World world, BlockPos pos, BlockState curr) { - BlockState state = this.getDefaultState(); + private BlockState createState(Level world, BlockPos pos, BlockState curr) { + BlockState state = this.defaultBlockState(); FluidState fluid = world.getFluidState(pos); - if (fluid.isTagged(FluidTags.WATER) && fluid.getLevel() == 8) - state = state.with(BlockStateProperties.WATERLOGGED, true); + if (fluid.is(FluidTags.WATER) && fluid.getAmount() == 8) + state = state.setValue(BlockStateProperties.WATERLOGGED, true); for (Direction dir : Direction.values()) { EnumProperty prop = DIRECTIONS.get(dir); ConnectionType type = this.getConnectionType(world, pos, dir, state); // don't reconnect on blocked faces - if (type.isConnected() && curr.get(prop) == ConnectionType.BLOCKED) + if (type.isConnected() && curr.getValue(prop) == ConnectionType.BLOCKED) type = ConnectionType.BLOCKED; - state = state.with(prop, type); + state = state.setValue(prop, type); } return state; } - protected ConnectionType getConnectionType(World world, BlockPos pos, Direction direction, BlockState state) { - BlockPos offset = pos.offset(direction); - if (!world.isBlockLoaded(offset)) + protected ConnectionType getConnectionType(Level world, BlockPos pos, Direction direction, BlockState state) { + BlockPos offset = pos.relative(direction); + if (!world.isLoaded(offset)) return ConnectionType.DISCONNECTED; Direction opposite = direction.getOpposite(); - TileEntity tile = world.getTileEntity(offset); + BlockEntity tile = world.getBlockEntity(offset); if (tile != null) { IPipeConnectable connectable = tile.getCapability(Registry.pipeConnectableCapability, opposite).orElse(null); if (connectable != null) @@ -231,23 +215,23 @@ public class PipeBlock extends BaseEntityBlock { return ConnectionType.CONNECTED; BlockState offState = world.getBlockState(offset); if (hasLegsTo(world, offState, offset, direction)) { - if (DIRECTIONS.values().stream().noneMatch(d -> state.get(d) == ConnectionType.LEGS)) + if (DIRECTIONS.values().stream().noneMatch(d -> state.getValue(d) == ConnectionType.LEGS)) return ConnectionType.LEGS; } return ConnectionType.DISCONNECTED; } - protected static boolean hasLegsTo(World world, BlockState state, BlockPos pos, Direction direction) { + protected static boolean hasLegsTo(Level world, BlockState state, BlockPos pos, Direction direction) { if (state.getBlock() instanceof WallBlock || state.getBlock() instanceof FenceBlock) return direction == Direction.DOWN; - if (state.getMaterial() == Material.ROCK || state.getMaterial() == Material.IRON) - return hasEnoughSolidSide(world, pos, direction.getOpposite()); + if (state.getMaterial() == Material.STONE || state.getMaterial() == Material.METAL) + return canSupportCenter(world, pos, direction.getOpposite()); return false; } - public static void onStateChanged(World world, BlockPos pos, BlockState newState) { + public static void onStateChanged(Level world, BlockPos pos, BlockState newState) { // wait a few ticks before checking if we have to drop our modules, so that things like iron -> gold chest work - PipeTileEntity tile = Utility.getBlockEntity(PipeTileEntity.class, world, pos); + PipeBlockEntity tile = Utility.getBlockEntity(PipeBlockEntity.class, world, pos); if (tile != null) tile.moduleDropCheck = 5; @@ -255,11 +239,11 @@ public class PipeBlock extends BaseEntityBlock { int connections = 0; boolean force = false; for (Direction dir : Direction.values()) { - ConnectionType value = newState.get(DIRECTIONS.get(dir)); + ConnectionType value = newState.getValue(DIRECTIONS.get(dir)); if (!value.isConnected()) continue; connections++; - BlockState otherState = world.getBlockState(pos.offset(dir)); + BlockState otherState = world.getBlockState(pos.relative(dir)); // force a node if we're connecting to a different block (inventory etc.) if (otherState.getBlock() != newState.getBlock()) { force = true; @@ -275,53 +259,53 @@ public class PipeBlock extends BaseEntityBlock { } @Override - public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) { + public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState newState, boolean isMoving) { if (state.getBlock() != newState.getBlock()) { PipeNetwork network = PipeNetwork.get(worldIn); network.removeNode(pos); network.onPipeChanged(pos, state); - super.onReplaced(state, worldIn, pos, newState, isMoving); + super.onRemove(state, worldIn, pos, newState, isMoving); } } @Override - public void onBlockHarvested(World worldIn, BlockPos pos, BlockState state, PlayerEntity player) { + public void playerWillDestroy(Level worldIn, BlockPos pos, BlockState state, Player player) { dropItems(worldIn, pos, player); - super.onBlockHarvested(worldIn, pos, state, player); + super.playerWillDestroy(worldIn, pos, state, player); } @Override - public boolean hasComparatorInputOverride(BlockState state) { + public boolean hasAnalogOutputSignal(BlockState state) { return true; } @Override - public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos) { - PipeTileEntity pipe = Utility.getBlockEntity(PipeTileEntity.class, worldIn, pos); + public int getAnalogOutputSignal(BlockState state, Level world, BlockPos pos) { + PipeBlockEntity pipe = Utility.getBlockEntity(PipeBlockEntity.class, world, pos); if (pipe == null) return 0; return Math.min(15, pipe.getItems().size()); } - @Nullable + @org.jetbrains.annotations.Nullable @Override - public TileEntity createNewTileEntity(IBlockReader worldIn) { - return new PipeTileEntity(); + public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { + return new PipeBlockEntity(); } @Override - public BlockRenderType getRenderType(BlockState state) { - return BlockRenderType.MODEL; + public RenderShape getRenderShape(BlockState state) { + return RenderShape.MODEL; } - public static void dropItems(World worldIn, BlockPos pos, PlayerEntity player) { - PipeTileEntity tile = Utility.getBlockEntity(PipeTileEntity.class, worldIn, pos); + public static void dropItems(Level worldIn, BlockPos pos, Player player) { + PipeBlockEntity tile = Utility.getBlockEntity(PipeBlockEntity.class, worldIn, pos); if (tile != null) { Utility.dropInventory(tile, tile.modules); for (IPipeItem item : tile.getItems()) item.drop(worldIn, item.getContent()); if (tile.cover != null) - tile.removeCover(player, Hand.MAIN_HAND); + tile.removeCover(player, InteractionHand.MAIN_HAND); } } } diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java b/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlockEntity.java similarity index 92% rename from src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java rename to src/main/java/de/ellpeck/prettypipes/pipe/PipeBlockEntity.java index e2f929b..c043fa8 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlockEntity.java @@ -13,6 +13,7 @@ import de.ellpeck.prettypipes.pressurizer.PressurizerBlockEntity; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.container.Container; @@ -20,6 +21,10 @@ import net.minecraft.inventory.container.INamedContainerProvider; import net.minecraft.item.Item; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtUtils; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.Containers; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.NBTUtil; @@ -35,6 +40,8 @@ import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TranslationTextComponent; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BaseContainerBlockEntity; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.server.ServerWorld; @@ -57,7 +64,7 @@ import java.util.function.Consumer; import java.util.stream.Collectors; import java.util.stream.Stream; -public class PipeTileEntity extends BlockEntity implements INamedContainerProvider, ITickableTileEntity, IPipeConnectable { +public class PipeBlockEntity extends BaseContainerBlockEntity implements IPipeConnectable { public final ItemStackHandler modules = new ItemStackHandler(3) { @Override @@ -65,7 +72,7 @@ public class PipeTileEntity extends BlockEntity implements INamedContainerProvid var item = stack.getItem(); if (!(item instanceof IModule module)) return false; - return PipeTileEntity.this.streamModules().allMatch(m -> module.isCompatible(stack, PipeTileEntity.this, m.getRight()) && m.getRight().isCompatible(m.getLeft(), PipeTileEntity.this, module)); + return PipeBlockEntity.this.streamModules().allMatch(m -> module.isCompatible(stack, PipeBlockEntity.this, m.getRight()) && m.getRight().isCompatible(m.getLeft(), PipeBlockEntity.this, module)); } @Override @@ -81,7 +88,7 @@ public class PipeTileEntity extends BlockEntity implements INamedContainerProvid protected List items; private int lastItemAmount; private int priority; - private final LazyOptional lazyThis = LazyOptional.of(() -> this); + private final LazyOptional lazyThis = LazyOptional.of(() -> this); private final Lazy workRandomizer = Lazy.of(() -> this.level.random.nextInt(200)); @Override @@ -338,21 +345,21 @@ public class PipeTileEntity extends BlockEntity implements INamedContainerProvid IItemHandler handler = this.getNeighborCap(dir, CapabilityItemHandler.ITEM_HANDLER_CAPABILITY); if (handler != null) return handler; - return Utility.getBlockItemHandler(this.world, this.pos.offset(dir), dir.getOpposite()); + return Utility.getBlockItemHandler(this.level, this.worldPosition.relative(dir), dir.getOpposite()); } public T getNeighborCap(Direction dir, Capability cap) { if (!this.isConnected(dir)) return null; - BlockPos pos = this.pos.offset(dir); - TileEntity tile = this.world.getTileEntity(pos); + BlockPos pos = this.worldPosition.relative(dir); + BlockEntity tile = this.level.getBlockEntity(pos); if (tile != null) return tile.getCapability(cap, dir.getOpposite()).orElse(null); return null; } public IPipeConnectable getPipeConnectable(Direction dir) { - TileEntity tile = this.world.getTileEntity(this.pos.offset(dir)); + BlockEntity tile = this.level.getBlockEntity(this.worldPosition.relative(dir)); if (tile != null) return tile.getCapability(Registry.pipeConnectableCapability, dir.getOpposite()).orElse(null); return null; @@ -367,7 +374,7 @@ public class PipeTileEntity extends BlockEntity implements INamedContainerProvid if (this.isConnectedInventory(dir)) return true; IPipeConnectable connectable = this.getPipeConnectable(dir); - if (connectable != null && connectable.allowsModules(this.pos, dir)) + if (connectable != null && connectable.allowsModules(this.worldPosition, dir)) return true; } return false; @@ -388,17 +395,17 @@ public class PipeTileEntity extends BlockEntity implements INamedContainerProvid return builder.build(); } - public void removeCover(PlayerEntity player, Hand hand) { - if (this.world.isRemote) + public void removeCover(Player player, InteractionHand hand) { + if (this.level.isRemote) return; - List drops = Block.getDrops(this.cover, (ServerWorld) this.world, this.pos, null, player, player.getHeldItem(hand)); + List drops = Block.getDrops(this.cover, (ServerLevel) this.level, this.worldPosition, null, player, player.getItemInHand(hand)); for (ItemStack drop : drops) - Block.spawnAsEntity(this.world, this.pos, drop); + Containers.dropItemStack(this.level, this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), drop); this.cover = null; } public boolean shouldWorkNow(int speed) { - return (this.world.getGameTime() + this.workRandomizer.get()) % speed == 0; + return (this.level.getGameTime() + this.workRandomizer.get()) % speed == 0; } public int getNextNode(List nodes, int index) { @@ -414,10 +421,10 @@ public class PipeTileEntity extends BlockEntity implements INamedContainerProvid } @Override - public void remove() { - super.remove(); + public void setRemoved() { + super.setRemoved(); this.getItems().clear(); - PipeNetwork network = PipeNetwork.get(this.world); + PipeNetwork network = PipeNetwork.get(this.level); for (NetworkLock lock : this.craftIngredientRequests) network.resolveNetworkLock(lock); this.lazyThis.invalidate(); @@ -431,7 +438,7 @@ public class PipeTileEntity extends BlockEntity implements INamedContainerProvid @Nullable @Override public Container createMenu(int window, PlayerInventory inv, PlayerEntity player) { - return new MainPipeContainer(Registry.pipeContainer, window, player, PipeTileEntity.this.pos); + return new MainPipeContainer(Registry.pipeContainer, window, player, PipeBlockEntity.this.pos); } @Override diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/PipeRenderer.java b/src/main/java/de/ellpeck/prettypipes/pipe/PipeRenderer.java index 1c14c1b..15c46a3 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/PipeRenderer.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/PipeRenderer.java @@ -1,54 +1,45 @@ package de.ellpeck.prettypipes.pipe; -import com.mojang.blaze3d.matrix.MatrixStack; -import com.mojang.blaze3d.vertex.IVertexBuilder; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.BlockModelRenderer; -import net.minecraft.client.renderer.IRenderTypeBuffer; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.RenderTypeLookup; -import net.minecraft.client.renderer.tileentity.TileEntityRenderer; -import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.math.BlockPos; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; +import net.minecraft.core.BlockPos; import net.minecraftforge.client.ForgeHooksClient; -import net.minecraftforge.client.model.data.EmptyModelData; +import net.minecraftforge.client.model.pipeline.ForgeBlockModelRenderer; import java.util.Random; -public class PipeRenderer extends TileEntityRenderer { +public class PipeRenderer implements BlockEntityRenderer { private final Random random = new Random(); - public PipeRenderer(TileEntityRendererDispatcher disp) { - super(disp); - } - @Override - public void render(PipeTileEntity tile, float partialTicks, MatrixStack matrixStack, IRenderTypeBuffer buffer, int light, int overlay) { + public void render(PipeBlockEntity tile, float partialTicks, PoseStack matrixStack, MultiBufferSource source, int light, int overlay) { if (!tile.getItems().isEmpty()) { - matrixStack.push(); - BlockPos tilePos = tile.getPos(); + matrixStack.pushPose(); + BlockPos tilePos = tile.getBlockPos(); matrixStack.translate(-tilePos.getX(), -tilePos.getY(), -tilePos.getZ()); for (IPipeItem item : tile.getItems()) { - matrixStack.push(); - item.render(tile, matrixStack, this.random, partialTicks, light, overlay, buffer); - matrixStack.pop(); + matrixStack.pushPose(); + item.render(tile, matrixStack, this.random, partialTicks, light, overlay); + matrixStack.popPose(); } - matrixStack.pop(); + matrixStack.popPose(); } if (tile.cover != null) { - matrixStack.push(); - BlockModelRenderer.enableCache(); - for (RenderType layer : RenderType.getBlockRenderTypes()) { + matrixStack.pushPose(); + ForgeBlockModelRenderer.enableCaching(); + // TODO figure out how to render covers, maybe finally use baked models bleh + /*for (RenderType layer : RenderType.chunkBufferLayers()) { if (!RenderTypeLookup.canRenderInLayer(tile.cover, layer)) continue; - ForgeHooksClient.setRenderLayer(layer); - Minecraft.getInstance().getBlockRendererDispatcher().renderBlock(tile.cover, matrixStack, buffer, light, overlay, EmptyModelData.INSTANCE); - } - ForgeHooksClient.setRenderLayer(null); - BlockModelRenderer.disableCache(); - matrixStack.pop(); + ForgeHooksClient.setRenderType(layer); + Minecraft.getInstance().getBlockRenderer().renderBatched(tile.cover,tile.getBlockPos(),null, matrixStack,null, light, overlay, EmptyModelData.INSTANCE); + }*/ + ForgeHooksClient.setRenderType(null); + ForgeBlockModelRenderer.clearCache(); + matrixStack.popPose(); } } + } diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/containers/AbstractPipeContainer.java b/src/main/java/de/ellpeck/prettypipes/pipe/containers/AbstractPipeContainer.java index 8a751d3..d4eb03d 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/containers/AbstractPipeContainer.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/containers/AbstractPipeContainer.java @@ -3,28 +3,28 @@ package de.ellpeck.prettypipes.pipe.containers; import de.ellpeck.prettypipes.Utility; import de.ellpeck.prettypipes.items.IModule; import de.ellpeck.prettypipes.misc.FilterSlot; -import de.ellpeck.prettypipes.pipe.PipeTileEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.inventory.container.ClickType; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.ContainerType; -import net.minecraft.inventory.container.Slot; +import de.ellpeck.prettypipes.pipe.PipeBlockEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ClickType; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; -import net.minecraft.util.math.BlockPos; import org.apache.commons.lang3.tuple.Pair; import javax.annotation.Nullable; -public abstract class AbstractPipeContainer extends Container { +public abstract class AbstractPipeContainer extends AbstractContainerMenu { - public final PipeTileEntity tile; + public final PipeBlockEntity tile; public final T module; public final int moduleIndex; public final ItemStack moduleStack; - public AbstractPipeContainer(@Nullable ContainerType type, int id, PlayerEntity player, BlockPos pos, int moduleIndex) { + public AbstractPipeContainer(@Nullable MenuType type, int id, Player player, BlockPos pos, int moduleIndex) { super(type, id); - this.tile = Utility.getBlockEntity(PipeTileEntity.class, player.world, pos); + this.tile = Utility.getBlockEntity(PipeBlockEntity.class, player.level, pos); this.moduleStack = moduleIndex < 0 ? null : this.tile.modules.getStackInSlot(moduleIndex); this.module = moduleIndex < 0 ? null : (T) this.moduleStack.getItem(); this.moduleIndex = moduleIndex; @@ -32,23 +32,18 @@ public abstract class AbstractPipeContainer extends Container // needs to be done here so transferStackInSlot works correctly, bleh this.addSlots(); - for (int l = 0; l < 3; ++l) - for (int j1 = 0; j1 < 9; ++j1) - this.addSlot(new Slot(player.inventory, j1 + l * 9 + 9, 8 + j1 * 18, 89 + l * 18 + 32)); - for (int i1 = 0; i1 < 9; ++i1) - this.addSlot(new Slot(player.inventory, i1, 8 + i1 * 18, 147 + 32)); + for (var l = 0; l < 3; ++l) + for (var j1 = 0; j1 < 9; ++j1) + this.addSlot(new Slot(player.getInventory(), j1 + l * 9 + 9, 8 + j1 * 18, 89 + l * 18 + 32)); + for (var i1 = 0; i1 < 9; ++i1) + this.addSlot(new Slot(player.getInventory(), i1, 8 + i1 * 18, 147 + 32)); } protected abstract void addSlots(); @Override - public boolean canInteractWith(PlayerEntity playerIn) { - return true; - } - - @Override - public ItemStack transferStackInSlot(PlayerEntity player, int slotIndex) { - return Utility.transferStackInSlot(this, this::mergeItemStack, player, slotIndex, stack -> { + public ItemStack quickMoveStack(Player player, int slotIndex) { + return Utility.transferStackInSlot(this, this::moveItemStackTo, player, slotIndex, stack -> { if (stack.getItem() instanceof IModule) return Pair.of(0, 3); return null; @@ -56,9 +51,14 @@ public abstract class AbstractPipeContainer extends Container } @Override - public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, PlayerEntity player) { + public void clicked(int slotId, int dragType, ClickType clickTypeIn, Player player) { if (FilterSlot.checkFilter(this, slotId, player)) - return ItemStack.EMPTY; - return super.slotClick(slotId, dragType, clickTypeIn, player); + return; + super.clicked(slotId, dragType, clickTypeIn, player); + } + + @Override + public boolean stillValid(Player player) { + return true; } } diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/containers/AbstractPipeGui.java b/src/main/java/de/ellpeck/prettypipes/pipe/containers/AbstractPipeGui.java index b5a9aad..adccff6 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/containers/AbstractPipeGui.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/containers/AbstractPipeGui.java @@ -1,16 +1,26 @@ package de.ellpeck.prettypipes.pipe.containers; import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.vertex.PoseStack; import de.ellpeck.prettypipes.PrettyPipes; import de.ellpeck.prettypipes.Registry; import de.ellpeck.prettypipes.items.IModule; import de.ellpeck.prettypipes.packets.PacketButton; import de.ellpeck.prettypipes.packets.PacketHandler; import net.minecraft.client.audio.SimpleSound; +import net.minecraft.client.gui.components.AbstractWidget; +import net.minecraft.client.gui.components.Widget; import net.minecraft.client.gui.screen.inventory.ContainerScreen; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.client.gui.screens.inventory.ContainerScreen; import net.minecraft.client.gui.widget.Widget; +import net.minecraft.client.resources.sounds.SimpleSoundInstance; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.container.Slot; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.Style; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.ItemStack; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.SoundEvents; @@ -19,16 +29,16 @@ import net.minecraft.util.text.ITextComponent; import java.util.ArrayList; import java.util.List; -public abstract class AbstractPipeGui> extends ContainerScreen { +public abstract class AbstractPipeGui> extends AbstractContainerScreen { protected static final ResourceLocation TEXTURE = new ResourceLocation(PrettyPipes.ID, "textures/gui/pipe.png"); private final List tabs = new ArrayList<>(); - private final ItemStack[] lastItems = new ItemStack[this.container.tile.modules.getSlots()]; + private final ItemStack[] lastItems = new ItemStack[this.menu.tile.modules.getSlots()]; - public AbstractPipeGui(T screenContainer, PlayerInventory inv, ITextComponent titleIn) { + public AbstractPipeGui(T screenContainer, Inventory inv, Component titleIn) { super(screenContainer, inv, titleIn); - this.xSize = 176; - this.ySize = 171 + 32; + this.imageWidth = 176; + this.imageHeight = 171 + 32; } @Override @@ -38,12 +48,12 @@ public abstract class AbstractPipeGui> extend } @Override - public void tick() { - super.tick(); + public void containerTick() { + super.containerTick(); boolean changed = false; - for (int i = 0; i < this.container.tile.modules.getSlots(); i++) { - ItemStack stack = this.container.tile.modules.getStackInSlot(i); + for (int i = 0; i < this.menu.tile.modules.getSlots(); i++) { + ItemStack stack = this.menu.tile.modules.getStackInSlot(i); if (stack != this.lastItems[i]) { this.lastItems[i] = stack; changed = true; @@ -54,28 +64,30 @@ public abstract class AbstractPipeGui> extend } @Override - public void render(MatrixStack matrix, int mouseX, int mouseY, float partialTicks) { + public void render(PoseStack matrix, int mouseX, int mouseY, float partialTicks) { this.renderBackground(matrix); super.render(matrix, mouseX, mouseY, partialTicks); - for (Widget widget : this.buttons) { - if (widget.isHovered()) - widget.renderToolTip(matrix, mouseX, mouseY); + for (Widget widget : this.renderables) { + if (widget instanceof AbstractWidget abstractWidget) { + if (abstractWidget.isHoveredOrFocused()) + abstractWidget.renderToolTip(matrix, mouseX, mouseY); + } } - this.func_230459_a_(matrix, mouseX, mouseY); + this.renderTooltip(matrix, mouseX, mouseY); } @Override - protected void drawGuiContainerForegroundLayer(MatrixStack matrix, int mouseX, int mouseY) { - this.font.drawString(matrix, this.playerInventory.getDisplayName().getString(), 8, this.ySize - 96 + 2, 4210752); - this.font.drawString(matrix, this.title.getString(), 8, 6 + 32, 4210752); + protected void renderLabels(PoseStack matrix, int mouseX, int mouseY) { + this.font.draw(matrix, this.playerInventoryTitle.getString(), 8, this.imageHeight - 96 + 2, 4210752); + this.font.draw(matrix, this.title.getString(), 8, 6 + 32, 4210752); for (Tab tab : this.tabs) tab.drawForeground(matrix, mouseX, mouseY); } @Override - protected void drawGuiContainerBackgroundLayer(MatrixStack matrix, float partialTicks, int mouseX, int mouseY) { - this.getMinecraft().getTextureManager().bindTexture(TEXTURE); - this.blit(matrix, this.guiLeft, this.guiTop + 32, 0, 0, 176, 171); + protected void renderBg(PoseStack matrix, float partialTicks, int mouseX, int mouseY) { + this.getMinecraft().getTextureManager().bindForSetup(TEXTURE); + this.blit(matrix, this.leftPos, this.topPos + 32, 0, 0, 176, 171); for (Tab tab : this.tabs) tab.draw(matrix); @@ -111,6 +123,7 @@ public abstract class AbstractPipeGui> extend } private class Tab { + private final ItemStack moduleStack; private final int index; private final int x; @@ -119,16 +132,16 @@ public abstract class AbstractPipeGui> extend public Tab(ItemStack moduleStack, int tabIndex, int index) { this.moduleStack = moduleStack; this.index = index; - this.x = AbstractPipeGui.this.guiLeft + 5 + tabIndex * 28; - this.y = AbstractPipeGui.this.guiTop; + this.x = AbstractPipeGui.this.leftPos + 5 + tabIndex * 28; + this.y = AbstractPipeGui.this.topPos; } - private void draw(MatrixStack matrix) { + private void draw(PoseStack matrix) { int y = 2; int v = 0; int height = 30; int itemOffset = 9; - if (this.index == AbstractPipeGui.this.container.moduleIndex) { + if (this.index == AbstractPipeGui.this.menu.moduleIndex) { y = 0; v = 30; height = 32; @@ -136,25 +149,25 @@ public abstract class AbstractPipeGui> extend } AbstractPipeGui.this.blit(matrix, this.x, this.y + y, 176, v, 28, height); - AbstractPipeGui.this.itemRenderer.renderItemIntoGUI(this.moduleStack, this.x + 6, this.y + itemOffset); - AbstractPipeGui.this.getMinecraft().getTextureManager().bindTexture(TEXTURE); + AbstractPipeGui.this.itemRenderer.renderGuiItem(this.moduleStack, this.x + 6, this.y + itemOffset); + AbstractPipeGui.this.getMinecraft().getTextureManager().bindForSetup(TEXTURE); } - private void drawForeground(MatrixStack matrix, int mouseX, int mouseY) { + private void drawForeground(PoseStack matrix, int mouseX, int mouseY) { if (mouseX < this.x || mouseY < this.y || mouseX >= this.x + 28 || mouseY >= this.y + 32) return; AbstractPipeGui.this.renderTooltip(matrix, this.moduleStack.getDisplayName(), mouseX - AbstractPipeGui.this.guiLeft, mouseY - AbstractPipeGui.this.guiTop); } private boolean onClicked(double mouseX, double mouseY, int button) { - if (this.index == AbstractPipeGui.this.container.moduleIndex) + if (this.index == AbstractPipeGui.this.menu.moduleIndex) return false; if (button != 0) return false; if (mouseX < this.x || mouseY < this.y || mouseX >= this.x + 28 || mouseY >= this.y + 32) return false; - PacketHandler.sendToServer(new PacketButton(AbstractPipeGui.this.container.tile.getPos(), PacketButton.ButtonResult.PIPE_TAB, this.index)); - AbstractPipeGui.this.getMinecraft().getSoundHandler().play(SimpleSound.master(SoundEvents.UI_BUTTON_CLICK, 1)); + PacketHandler.sendToServer(new PacketButton(AbstractPipeGui.this.menu.tile.getBlockPos(), PacketButton.ButtonResult.PIPE_TAB, this.index)); + AbstractPipeGui.this.getMinecraft().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1)); return true; } } diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/containers/MainPipeContainer.java b/src/main/java/de/ellpeck/prettypipes/pipe/containers/MainPipeContainer.java index d927219..035e31a 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/containers/MainPipeContainer.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/containers/MainPipeContainer.java @@ -1,15 +1,16 @@ package de.ellpeck.prettypipes.pipe.containers; import de.ellpeck.prettypipes.items.IModule; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.inventory.container.ContainerType; -import net.minecraft.util.math.BlockPos; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.MenuType; import net.minecraftforge.items.SlotItemHandler; import javax.annotation.Nullable; public class MainPipeContainer extends AbstractPipeContainer { - public MainPipeContainer(@Nullable ContainerType type, int id, PlayerEntity player, BlockPos pos) { + + public MainPipeContainer(@Nullable MenuType type, int id, Player player, BlockPos pos) { super(type, id, player, pos, -1); } diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/containers/MainPipeGui.java b/src/main/java/de/ellpeck/prettypipes/pipe/containers/MainPipeGui.java index 9a44072..9400c48 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/containers/MainPipeGui.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/containers/MainPipeGui.java @@ -1,10 +1,13 @@ package de.ellpeck.prettypipes.pipe.containers; import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.network.chat.Component; import net.minecraft.util.text.ITextComponent; +import net.minecraft.world.entity.player.Inventory; public class MainPipeGui extends AbstractPipeGui { - public MainPipeGui(MainPipeContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) { + + public MainPipeGui(MainPipeContainer screenContainer, Inventory inv, Component titleIn) { super(screenContainer, inv, titleIn); } } diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/modules/HighPriorityModuleItem.java b/src/main/java/de/ellpeck/prettypipes/pipe/modules/HighPriorityModuleItem.java index fc54367..9f69c77 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/modules/HighPriorityModuleItem.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/modules/HighPriorityModuleItem.java @@ -3,7 +3,7 @@ package de.ellpeck.prettypipes.pipe.modules; import de.ellpeck.prettypipes.items.IModule; import de.ellpeck.prettypipes.items.ModuleItem; import de.ellpeck.prettypipes.items.ModuleTier; -import de.ellpeck.prettypipes.pipe.PipeTileEntity; +import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import net.minecraft.world.item.ItemStack; public class HighPriorityModuleItem extends ModuleItem { @@ -15,17 +15,17 @@ public class HighPriorityModuleItem extends ModuleItem { } @Override - public int getPriority(ItemStack module, PipeTileEntity tile) { + public int getPriority(ItemStack module, PipeBlockEntity tile) { return this.priority; } @Override - public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) { + public boolean isCompatible(ItemStack module, PipeBlockEntity tile, IModule other) { return !(other instanceof HighPriorityModuleItem) && !(other instanceof LowPriorityModuleItem); } @Override - public boolean hasContainer(ItemStack module, PipeTileEntity tile) { + public boolean hasContainer(ItemStack module, PipeBlockEntity tile) { return false; } } diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/modules/LowPriorityModuleItem.java b/src/main/java/de/ellpeck/prettypipes/pipe/modules/LowPriorityModuleItem.java index 17f05eb..25d3e81 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/modules/LowPriorityModuleItem.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/modules/LowPriorityModuleItem.java @@ -3,7 +3,7 @@ package de.ellpeck.prettypipes.pipe.modules; import de.ellpeck.prettypipes.items.IModule; import de.ellpeck.prettypipes.items.ModuleItem; import de.ellpeck.prettypipes.items.ModuleTier; -import de.ellpeck.prettypipes.pipe.PipeTileEntity; +import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import net.minecraft.world.item.ItemStack; public class LowPriorityModuleItem extends ModuleItem { @@ -15,17 +15,17 @@ public class LowPriorityModuleItem extends ModuleItem { } @Override - public int getPriority(ItemStack module, PipeTileEntity tile) { + public int getPriority(ItemStack module, PipeBlockEntity tile) { return this.priority; } @Override - public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) { + public boolean isCompatible(ItemStack module, PipeBlockEntity tile, IModule other) { return !(other instanceof LowPriorityModuleItem) && !(other instanceof HighPriorityModuleItem); } @Override - public boolean hasContainer(ItemStack module, PipeTileEntity tile) { + public boolean hasContainer(ItemStack module, PipeBlockEntity tile) { return false; } } diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/modules/RedstoneModuleItem.java b/src/main/java/de/ellpeck/prettypipes/pipe/modules/RedstoneModuleItem.java index da334e6..ee36bb0 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/modules/RedstoneModuleItem.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/modules/RedstoneModuleItem.java @@ -2,7 +2,7 @@ package de.ellpeck.prettypipes.pipe.modules; import de.ellpeck.prettypipes.items.IModule; import de.ellpeck.prettypipes.items.ModuleItem; -import de.ellpeck.prettypipes.pipe.PipeTileEntity; +import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import net.minecraft.world.item.ItemStack; public class RedstoneModuleItem extends ModuleItem { @@ -13,17 +13,17 @@ public class RedstoneModuleItem extends ModuleItem { } @Override - public boolean canPipeWork(ItemStack module, PipeTileEntity tile) { + public boolean canPipeWork(ItemStack module, PipeBlockEntity tile) { return !tile.getWorld().isBlockPowered(tile.getPos()); } @Override - public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) { + public boolean isCompatible(ItemStack module, PipeBlockEntity tile, IModule other) { return other != this; } @Override - public boolean hasContainer(ItemStack module, PipeTileEntity tile) { + public boolean hasContainer(ItemStack module, PipeBlockEntity tile) { return false; } } diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/modules/SortingModuleItem.java b/src/main/java/de/ellpeck/prettypipes/pipe/modules/SortingModuleItem.java index b4cf00c..7deb29f 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/modules/SortingModuleItem.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/modules/SortingModuleItem.java @@ -2,7 +2,7 @@ package de.ellpeck.prettypipes.pipe.modules; import de.ellpeck.prettypipes.items.IModule; import de.ellpeck.prettypipes.items.ModuleItem; -import de.ellpeck.prettypipes.pipe.PipeTileEntity; +import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import net.minecraft.world.item.ItemStack; import net.minecraft.util.math.BlockPos; @@ -19,17 +19,17 @@ public class SortingModuleItem extends ModuleItem { } @Override - public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) { + public boolean isCompatible(ItemStack module, PipeBlockEntity tile, IModule other) { return !(other instanceof SortingModuleItem); } @Override - public boolean hasContainer(ItemStack module, PipeTileEntity tile) { + public boolean hasContainer(ItemStack module, PipeBlockEntity tile) { return false; } @Override - public Integer getCustomNextNode(ItemStack module, PipeTileEntity tile, List nodes, int index) { + public Integer getCustomNextNode(ItemStack module, PipeBlockEntity tile, List nodes, int index) { switch (this.type) { case ROUND_ROBIN: // store an ever-increasing index and choose destinations based on that diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/modules/SpeedModuleItem.java b/src/main/java/de/ellpeck/prettypipes/pipe/modules/SpeedModuleItem.java index a67cb7d..a7fa119 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/modules/SpeedModuleItem.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/modules/SpeedModuleItem.java @@ -3,7 +3,7 @@ package de.ellpeck.prettypipes.pipe.modules; import de.ellpeck.prettypipes.items.IModule; import de.ellpeck.prettypipes.items.ModuleItem; import de.ellpeck.prettypipes.items.ModuleTier; -import de.ellpeck.prettypipes.pipe.PipeTileEntity; +import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import net.minecraft.world.item.ItemStack; public class SpeedModuleItem extends ModuleItem { @@ -15,17 +15,17 @@ public class SpeedModuleItem extends ModuleItem { } @Override - public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) { + public boolean isCompatible(ItemStack module, PipeBlockEntity tile, IModule other) { return !(other instanceof SpeedModuleItem); } @Override - public boolean hasContainer(ItemStack module, PipeTileEntity tile) { + public boolean hasContainer(ItemStack module, PipeBlockEntity tile) { return false; } @Override - public float getItemSpeedIncrease(ItemStack module, PipeTileEntity tile) { + public float getItemSpeedIncrease(ItemStack module, PipeBlockEntity tile) { return this.speedIncrease; } } diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/modules/craft/CraftingModuleItem.java b/src/main/java/de/ellpeck/prettypipes/pipe/modules/craft/CraftingModuleItem.java index 4200c9c..058ba4e 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/modules/craft/CraftingModuleItem.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/modules/craft/CraftingModuleItem.java @@ -9,10 +9,10 @@ import de.ellpeck.prettypipes.misc.ItemFilter; import de.ellpeck.prettypipes.network.NetworkLocation; import de.ellpeck.prettypipes.network.NetworkLock; import de.ellpeck.prettypipes.network.PipeNetwork; -import de.ellpeck.prettypipes.pipe.PipeTileEntity; +import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer; -import de.ellpeck.prettypipes.terminal.CraftingTerminalTileEntity; -import de.ellpeck.prettypipes.terminal.ItemTerminalTileEntity; +import de.ellpeck.prettypipes.terminal.CraftingTerminalBlockEntity; +import de.ellpeck.prettypipes.terminal.ItemTerminalBlockEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.world.item.ItemStack; @@ -41,32 +41,32 @@ public class CraftingModuleItem extends ModuleItem { } @Override - public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) { + public boolean isCompatible(ItemStack module, PipeBlockEntity tile, IModule other) { return true; } @Override - public boolean hasContainer(ItemStack module, PipeTileEntity tile) { + public boolean hasContainer(ItemStack module, PipeBlockEntity tile) { return true; } @Override - public AbstractPipeContainer getContainer(ItemStack module, PipeTileEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) { + public AbstractPipeContainer getContainer(ItemStack module, PipeBlockEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) { return new CraftingModuleContainer(Registry.craftingModuleContainer, windowId, player, tile.getPos(), moduleIndex); } @Override - public boolean canNetworkSee(ItemStack module, PipeTileEntity tile) { + public boolean canNetworkSee(ItemStack module, PipeBlockEntity tile) { return false; } @Override - public boolean canAcceptItem(ItemStack module, PipeTileEntity tile, ItemStack stack) { + public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack) { return false; } @Override - public void tick(ItemStack module, PipeTileEntity tile) { + public void tick(ItemStack module, PipeBlockEntity tile) { if (!tile.shouldWorkNow(this.speed) || !tile.canWork()) return; PipeNetwork network = PipeNetwork.get(tile.getWorld()); @@ -99,7 +99,7 @@ public class CraftingModuleItem extends ModuleItem { ItemEquality[] equalityTypes = ItemFilter.getEqualityTypes(tile); for (Pair request : tile.craftResultRequests) { ItemStack remain = request.getRight().copy(); - PipeTileEntity destPipe = network.getPipe(request.getLeft()); + PipeBlockEntity destPipe = network.getPipe(request.getLeft()); if (destPipe != null) { Pair dest = destPipe.getAvailableDestinationOrConnectable(remain, true, true); if (dest == null) @@ -125,7 +125,7 @@ public class CraftingModuleItem extends ModuleItem { } @Override - public List getAllCraftables(ItemStack module, PipeTileEntity tile) { + public List getAllCraftables(ItemStack module, PipeBlockEntity tile) { List ret = new ArrayList<>(); ItemStackHandler output = this.getOutput(module); for (int i = 0; i < output.getSlots(); i++) { @@ -137,7 +137,7 @@ public class CraftingModuleItem extends ModuleItem { } @Override - public int getCraftableAmount(ItemStack module, PipeTileEntity tile, Consumer unavailableConsumer, ItemStack stack, Stack dependencyChain) { + public int getCraftableAmount(ItemStack module, PipeBlockEntity tile, Consumer unavailableConsumer, ItemStack stack, Stack dependencyChain) { PipeNetwork network = PipeNetwork.get(tile.getWorld()); List items = network.getOrderedNetworkItems(tile.getPos()); ItemEquality[] equalityTypes = ItemFilter.getEqualityTypes(tile); @@ -149,7 +149,7 @@ public class CraftingModuleItem extends ModuleItem { ItemStack out = output.getStackInSlot(i); if (!out.isEmpty() && ItemEquality.compareItems(out, stack, equalityTypes)) { // figure out how many crafting operations we can actually do with the input items we have in the network - int availableCrafts = CraftingTerminalTileEntity.getAvailableCrafts(tile, input.getSlots(), input::getStackInSlot, k -> true, s -> items, unavailableConsumer, addDependency(dependencyChain, module), equalityTypes); + int availableCrafts = CraftingTerminalBlockEntity.getAvailableCrafts(tile, input.getSlots(), input::getStackInSlot, k -> true, s -> items, unavailableConsumer, addDependency(dependencyChain, module), equalityTypes); if (availableCrafts > 0) craftable += out.getCount() * availableCrafts; } @@ -158,7 +158,7 @@ public class CraftingModuleItem extends ModuleItem { } @Override - public ItemStack craft(ItemStack module, PipeTileEntity tile, BlockPos destPipe, Consumer unavailableConsumer, ItemStack stack, Stack dependencyChain) { + public ItemStack craft(ItemStack module, PipeBlockEntity tile, BlockPos destPipe, Consumer unavailableConsumer, ItemStack stack, Stack dependencyChain) { // check if we can craft the required amount of items int craftableAmount = this.getCraftableAmount(module, tile, unavailableConsumer, stack, dependencyChain); if (craftableAmount <= 0) @@ -179,7 +179,7 @@ public class CraftingModuleItem extends ModuleItem { continue; ItemStack copy = in.copy(); copy.setCount(in.getCount() * toCraft); - Pair, ItemStack> ret = ItemTerminalTileEntity.requestItemLater(tile.getWorld(), tile.getPos(), items, unavailableConsumer, copy, addDependency(dependencyChain, module), equalityTypes); + Pair, ItemStack> ret = ItemTerminalBlockEntity.requestItemLater(tile.getWorld(), tile.getPos(), items, unavailableConsumer, copy, addDependency(dependencyChain, module), equalityTypes); tile.craftIngredientRequests.addAll(ret.getLeft()); } diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/modules/extraction/ExtractionModuleItem.java b/src/main/java/de/ellpeck/prettypipes/pipe/modules/extraction/ExtractionModuleItem.java index 88bc5df..cd9b719 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/modules/extraction/ExtractionModuleItem.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/modules/extraction/ExtractionModuleItem.java @@ -6,7 +6,7 @@ import de.ellpeck.prettypipes.items.ModuleItem; import de.ellpeck.prettypipes.items.ModuleTier; import de.ellpeck.prettypipes.misc.ItemFilter; import de.ellpeck.prettypipes.network.PipeNetwork; -import de.ellpeck.prettypipes.pipe.PipeTileEntity; +import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; @@ -30,7 +30,7 @@ public class ExtractionModuleItem extends ModuleItem { } @Override - public void tick(ItemStack module, PipeTileEntity tile) { + public void tick(ItemStack module, PipeBlockEntity tile) { if (!tile.shouldWorkNow(this.speed) || !tile.canWork()) return; ItemFilter filter = this.getItemFilter(module, tile); @@ -56,32 +56,32 @@ public class ExtractionModuleItem extends ModuleItem { } @Override - public boolean canNetworkSee(ItemStack module, PipeTileEntity tile) { + public boolean canNetworkSee(ItemStack module, PipeBlockEntity tile) { return false; } @Override - public boolean canAcceptItem(ItemStack module, PipeTileEntity tile, ItemStack stack) { + public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack) { return false; } @Override - public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) { + public boolean isCompatible(ItemStack module, PipeBlockEntity tile, IModule other) { return !(other instanceof ExtractionModuleItem); } @Override - public boolean hasContainer(ItemStack module, PipeTileEntity tile) { + public boolean hasContainer(ItemStack module, PipeBlockEntity tile) { return true; } @Override - public AbstractPipeContainer getContainer(ItemStack module, PipeTileEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) { + public AbstractPipeContainer getContainer(ItemStack module, PipeBlockEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) { return new ExtractionModuleContainer(Registry.extractionModuleContainer, windowId, player, tile.getPos(), moduleIndex); } @Override - public ItemFilter getItemFilter(ItemStack module, PipeTileEntity tile) { + public ItemFilter getItemFilter(ItemStack module, PipeBlockEntity tile) { return new ItemFilter(this.filterSlots, module, tile); } } diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/modules/filter/FilterIncreaseModuleItem.java b/src/main/java/de/ellpeck/prettypipes/pipe/modules/filter/FilterIncreaseModuleItem.java index c117acc..41b16af 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/modules/filter/FilterIncreaseModuleItem.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/modules/filter/FilterIncreaseModuleItem.java @@ -4,7 +4,7 @@ import de.ellpeck.prettypipes.Registry; import de.ellpeck.prettypipes.items.IModule; import de.ellpeck.prettypipes.items.ModuleItem; import de.ellpeck.prettypipes.misc.ItemFilter; -import de.ellpeck.prettypipes.pipe.PipeTileEntity; +import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; @@ -18,22 +18,22 @@ public class FilterIncreaseModuleItem extends ModuleItem { } @Override - public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) { + public boolean isCompatible(ItemStack module, PipeBlockEntity tile, IModule other) { return true; } @Override - public boolean hasContainer(ItemStack module, PipeTileEntity tile) { + public boolean hasContainer(ItemStack module, PipeBlockEntity tile) { return true; } @Override - public AbstractPipeContainer getContainer(ItemStack module, PipeTileEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) { + public AbstractPipeContainer getContainer(ItemStack module, PipeBlockEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) { return new FilterIncreaseModuleContainer(Registry.filterIncreaseModuleContainer, windowId, player, tile.getPos(), moduleIndex); } @Override - public ItemFilter getItemFilter(ItemStack module, PipeTileEntity tile) { + public ItemFilter getItemFilter(ItemStack module, PipeBlockEntity tile) { ItemFilter filter = new ItemFilter(18, module, tile); filter.canModifyWhitelist = false; return filter; diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/modules/insertion/FilterModuleItem.java b/src/main/java/de/ellpeck/prettypipes/pipe/modules/insertion/FilterModuleItem.java index fcd2a56..c166ec3 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/modules/insertion/FilterModuleItem.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/modules/insertion/FilterModuleItem.java @@ -5,7 +5,7 @@ import de.ellpeck.prettypipes.items.IModule; import de.ellpeck.prettypipes.items.ModuleItem; import de.ellpeck.prettypipes.items.ModuleTier; import de.ellpeck.prettypipes.misc.ItemFilter; -import de.ellpeck.prettypipes.pipe.PipeTileEntity; +import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; @@ -23,28 +23,28 @@ public class FilterModuleItem extends ModuleItem { } @Override - public boolean canAcceptItem(ItemStack module, PipeTileEntity tile, ItemStack stack) { + public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack) { ItemFilter filter = this.getItemFilter(module, tile); return filter.isAllowed(stack); } @Override - public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) { + public boolean isCompatible(ItemStack module, PipeBlockEntity tile, IModule other) { return !(other instanceof FilterModuleItem); } @Override - public boolean hasContainer(ItemStack module, PipeTileEntity tile) { + public boolean hasContainer(ItemStack module, PipeBlockEntity tile) { return true; } @Override - public AbstractPipeContainer getContainer(ItemStack module, PipeTileEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) { + public AbstractPipeContainer getContainer(ItemStack module, PipeBlockEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) { return new FilterModuleContainer(Registry.filterModuleContainer, windowId, player, tile.getPos(), moduleIndex); } @Override - public ItemFilter getItemFilter(ItemStack module, PipeTileEntity tile) { + public ItemFilter getItemFilter(ItemStack module, PipeBlockEntity tile) { ItemFilter filter = new ItemFilter(this.filterSlots, module, tile); filter.canPopulateFromInventories = this.canPopulateFromInventories; return filter; diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/modules/modifier/FilterModifierModuleItem.java b/src/main/java/de/ellpeck/prettypipes/pipe/modules/modifier/FilterModifierModuleItem.java index 00509b8..1b66d0e 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/modules/modifier/FilterModifierModuleItem.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/modules/modifier/FilterModifierModuleItem.java @@ -4,7 +4,7 @@ import de.ellpeck.prettypipes.Registry; import de.ellpeck.prettypipes.items.IModule; import de.ellpeck.prettypipes.items.ModuleItem; import de.ellpeck.prettypipes.misc.ItemEquality; -import de.ellpeck.prettypipes.pipe.PipeTileEntity; +import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer; import joptsimple.internal.Strings; import net.minecraft.client.util.ITooltipFlag; @@ -29,17 +29,17 @@ public class FilterModifierModuleItem extends ModuleItem { } @Override - public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) { + public boolean isCompatible(ItemStack module, PipeBlockEntity tile, IModule other) { return other != this; } @Override - public boolean hasContainer(ItemStack module, PipeTileEntity tile) { + public boolean hasContainer(ItemStack module, PipeBlockEntity tile) { return this.type == ItemEquality.Type.TAG; } @Override - public AbstractPipeContainer getContainer(ItemStack module, PipeTileEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) { + public AbstractPipeContainer getContainer(ItemStack module, PipeBlockEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) { return new FilterModifierModuleContainer(Registry.filterModifierModuleContainer, windowId, player, tile.getPos(), moduleIndex); } diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/modules/retrieval/RetrievalModuleItem.java b/src/main/java/de/ellpeck/prettypipes/pipe/modules/retrieval/RetrievalModuleItem.java index 0bd58f4..e4a8b25 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/modules/retrieval/RetrievalModuleItem.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/modules/retrieval/RetrievalModuleItem.java @@ -7,7 +7,7 @@ import de.ellpeck.prettypipes.items.ModuleTier; import de.ellpeck.prettypipes.misc.ItemEquality; import de.ellpeck.prettypipes.misc.ItemFilter; import de.ellpeck.prettypipes.network.PipeNetwork; -import de.ellpeck.prettypipes.pipe.PipeTileEntity; +import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; @@ -30,7 +30,7 @@ public class RetrievalModuleItem extends ModuleItem { } @Override - public void tick(ItemStack module, PipeTileEntity tile) { + public void tick(ItemStack module, PipeBlockEntity tile) { if (!tile.shouldWorkNow(this.speed) || !tile.canWork()) return; PipeNetwork network = PipeNetwork.get(tile.getWorld()); @@ -57,32 +57,32 @@ public class RetrievalModuleItem extends ModuleItem { } @Override - public boolean canNetworkSee(ItemStack module, PipeTileEntity tile) { + public boolean canNetworkSee(ItemStack module, PipeBlockEntity tile) { return false; } @Override - public boolean canAcceptItem(ItemStack module, PipeTileEntity tile, ItemStack stack) { + public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack) { return false; } @Override - public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) { + public boolean isCompatible(ItemStack module, PipeBlockEntity tile, IModule other) { return !(other instanceof RetrievalModuleItem); } @Override - public boolean hasContainer(ItemStack module, PipeTileEntity tile) { + public boolean hasContainer(ItemStack module, PipeBlockEntity tile) { return true; } @Override - public AbstractPipeContainer getContainer(ItemStack module, PipeTileEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) { + public AbstractPipeContainer getContainer(ItemStack module, PipeBlockEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) { return new RetrievalModuleContainer(Registry.retrievalModuleContainer, windowId, player, tile.getPos(), moduleIndex); } @Override - public ItemFilter getItemFilter(ItemStack module, PipeTileEntity tile) { + public ItemFilter getItemFilter(ItemStack module, PipeBlockEntity tile) { ItemFilter filter = new ItemFilter(this.filterSlots, module, tile); filter.canModifyWhitelist = false; filter.isWhitelist = true; diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/modules/stacksize/StackSizeModuleItem.java b/src/main/java/de/ellpeck/prettypipes/pipe/modules/stacksize/StackSizeModuleItem.java index f01a4c8..307142d 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/modules/stacksize/StackSizeModuleItem.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/modules/stacksize/StackSizeModuleItem.java @@ -4,7 +4,7 @@ import de.ellpeck.prettypipes.Registry; import de.ellpeck.prettypipes.items.IModule; import de.ellpeck.prettypipes.items.ModuleItem; import de.ellpeck.prettypipes.misc.ItemEquality; -import de.ellpeck.prettypipes.pipe.PipeTileEntity; +import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; @@ -42,7 +42,7 @@ public class StackSizeModuleItem extends ModuleItem { } @Override - public int getMaxInsertionAmount(ItemStack module, PipeTileEntity tile, ItemStack stack, IItemHandler destination) { + public int getMaxInsertionAmount(ItemStack module, PipeBlockEntity tile, ItemStack stack, IItemHandler destination) { int max = getMaxStackSize(module); if (getLimitToMaxStackSize(module)) max = Math.min(max, stack.getMaxStackSize()); @@ -61,17 +61,17 @@ public class StackSizeModuleItem extends ModuleItem { } @Override - public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) { + public boolean isCompatible(ItemStack module, PipeBlockEntity tile, IModule other) { return !(other instanceof StackSizeModuleItem); } @Override - public boolean hasContainer(ItemStack module, PipeTileEntity tile) { + public boolean hasContainer(ItemStack module, PipeBlockEntity tile) { return true; } @Override - public AbstractPipeContainer getContainer(ItemStack module, PipeTileEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) { + public AbstractPipeContainer getContainer(ItemStack module, PipeBlockEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) { return new StackSizeModuleContainer(Registry.stackSizeModuleContainer, windowId, player, tile.getPos(), moduleIndex); } } diff --git a/src/main/java/de/ellpeck/prettypipes/pressurizer/PressurizerBlockEntity.java b/src/main/java/de/ellpeck/prettypipes/pressurizer/PressurizerBlockEntity.java index 00f628f..803cb9d 100644 --- a/src/main/java/de/ellpeck/prettypipes/pressurizer/PressurizerBlockEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/pressurizer/PressurizerBlockEntity.java @@ -6,7 +6,7 @@ import de.ellpeck.prettypipes.Utility; import de.ellpeck.prettypipes.network.PipeNetwork; import de.ellpeck.prettypipes.pipe.ConnectionType; import de.ellpeck.prettypipes.pipe.IPipeConnectable; -import de.ellpeck.prettypipes.pipe.PipeTileEntity; +import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; @@ -129,7 +129,7 @@ public class PressurizerBlockEntity extends BlockEntity implements INamedContain for (BlockPos node : network.getOrderedNetworkNodes(offset)) { if (!this.world.isBlockLoaded(node)) continue; - PipeTileEntity pipe = network.getPipe(node); + PipeBlockEntity pipe = network.getPipe(node); if (pipe != null) pipe.pressurizer = this; } diff --git a/src/main/java/de/ellpeck/prettypipes/terminal/CraftingTerminalBlock.java b/src/main/java/de/ellpeck/prettypipes/terminal/CraftingTerminalBlock.java index 1f5155e..4afa10b 100644 --- a/src/main/java/de/ellpeck/prettypipes/terminal/CraftingTerminalBlock.java +++ b/src/main/java/de/ellpeck/prettypipes/terminal/CraftingTerminalBlock.java @@ -10,7 +10,7 @@ public class CraftingTerminalBlock extends ItemTerminalBlock { @Nullable @Override public TileEntity createNewTileEntity(IBlockReader worldIn) { - return new CraftingTerminalTileEntity(); + return new CraftingTerminalBlockEntity(); } } diff --git a/src/main/java/de/ellpeck/prettypipes/terminal/CraftingTerminalTileEntity.java b/src/main/java/de/ellpeck/prettypipes/terminal/CraftingTerminalBlockEntity.java similarity index 91% rename from src/main/java/de/ellpeck/prettypipes/terminal/CraftingTerminalTileEntity.java rename to src/main/java/de/ellpeck/prettypipes/terminal/CraftingTerminalBlockEntity.java index 1a9abca..a2e9fae 100644 --- a/src/main/java/de/ellpeck/prettypipes/terminal/CraftingTerminalTileEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/terminal/CraftingTerminalBlockEntity.java @@ -12,12 +12,13 @@ import de.ellpeck.prettypipes.network.NetworkLocation; import de.ellpeck.prettypipes.network.PipeNetwork; import de.ellpeck.prettypipes.packets.PacketGhostSlot; import de.ellpeck.prettypipes.packets.PacketHandler; -import de.ellpeck.prettypipes.pipe.PipeTileEntity; +import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import de.ellpeck.prettypipes.terminal.containers.CraftingTerminalContainer; import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.container.Container; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.nbt.CompoundTag; import net.minecraft.util.Direction; @@ -36,18 +37,18 @@ import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Predicate; -public class CraftingTerminalTileEntity extends ItemTerminalTileEntity { +public class CraftingTerminalBlockEntity extends ItemTerminalBlockEntity { public final ItemStackHandler craftItems = new ItemStackHandler(9) { @Override protected void onContentsChanged(int slot) { - for (PlayerEntity playerEntity : CraftingTerminalTileEntity.this.getLookingPlayers()) - playerEntity.openContainer.onCraftMatrixChanged(null); + for (Player playerEntity : CraftingTerminalBlockEntity.this.getLookingPlayers()) + playerEntity.containerMenu.onCraftMatrixChanged(null); } }; public final ItemStackHandler ghostItems = new ItemStackHandler(9); - public CraftingTerminalTileEntity() { + public CraftingTerminalBlockEntity() { super(Registry.craftingTerminalTileEntity); } @@ -85,7 +86,7 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity { } // check craftables if (amount <= 0 && highestAmount <= 0) { - PipeTileEntity pipe = this.getConnectedPipe(); + PipeBlockEntity pipe = this.getConnectedPipe(); if (pipe != null) amount = PipeNetwork.get(this.world).getCraftableAmount(pipe.getPos(), null, stack, new Stack<>(), ItemEquality.NBT); } @@ -107,7 +108,7 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity { } public void requestCraftingItems(PlayerEntity player, int maxAmount) { - PipeTileEntity pipe = this.getConnectedPipe(); + PipeBlockEntity pipe = this.getConnectedPipe(); if (pipe == null) return; PipeNetwork network = PipeNetwork.get(this.world); @@ -161,7 +162,7 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity { @Override public ItemStack insertItem(BlockPos pipePos, Direction direction, ItemStack remain, boolean simulate) { BlockPos pos = pipePos.offset(direction); - CraftingTerminalTileEntity tile = Utility.getBlockEntity(CraftingTerminalTileEntity.class, this.world, pos); + CraftingTerminalBlockEntity tile = Utility.getBlockEntity(CraftingTerminalBlockEntity.class, this.world, pos); if (tile != null) { remain = remain.copy(); int lowestSlot = -1; @@ -194,7 +195,7 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity { return remain; } - public static int getAvailableCrafts(PipeTileEntity tile, int slots, Function inputFunction, Predicate isGhost, Function> locationsFunction, Consumer unavailableConsumer, Stack dependencyChain, ItemEquality... equalityTypes) { + public static int getAvailableCrafts(PipeBlockEntity tile, int slots, Function inputFunction, Predicate isGhost, Function> locationsFunction, Consumer unavailableConsumer, Stack dependencyChain, ItemEquality... equalityTypes) { PipeNetwork network = PipeNetwork.get(tile.getWorld()); // the highest amount we can craft with the items we have int lowestAvailable = Integer.MAX_VALUE; diff --git a/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalBlock.java b/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalBlock.java index 98545af..ea2caa9 100644 --- a/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalBlock.java +++ b/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalBlock.java @@ -35,7 +35,7 @@ public class ItemTerminalBlock extends ContainerBlock { @Override public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult result) { - ItemTerminalTileEntity tile = Utility.getBlockEntity(ItemTerminalTileEntity.class, worldIn, pos); + ItemTerminalBlockEntity tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, worldIn, pos); if (tile == null) return ActionResultType.PASS; String reason = tile.getInvalidTerminalReason(); @@ -54,7 +54,7 @@ public class ItemTerminalBlock extends ContainerBlock { @Override public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) { if (state.getBlock() != newState.getBlock()) { - ItemTerminalTileEntity tile = Utility.getBlockEntity(ItemTerminalTileEntity.class, worldIn, pos); + ItemTerminalBlockEntity tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, worldIn, pos); if (tile != null) Utility.dropInventory(tile, tile.items); super.onReplaced(state, worldIn, pos, newState, isMoving); @@ -64,7 +64,7 @@ public class ItemTerminalBlock extends ContainerBlock { @Nullable @Override public TileEntity createNewTileEntity(IBlockReader worldIn) { - return new ItemTerminalTileEntity(); + return new ItemTerminalBlockEntity(); } @Override diff --git a/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalTileEntity.java b/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalBlockEntity.java similarity index 79% rename from src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalTileEntity.java rename to src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalBlockEntity.java index 4a1cd5e..293086f 100644 --- a/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalTileEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalBlockEntity.java @@ -13,13 +13,18 @@ import de.ellpeck.prettypipes.packets.PacketHandler; import de.ellpeck.prettypipes.packets.PacketNetworkItems; import de.ellpeck.prettypipes.pipe.ConnectionType; import de.ellpeck.prettypipes.pipe.IPipeConnectable; -import de.ellpeck.prettypipes.pipe.PipeTileEntity; +import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import de.ellpeck.prettypipes.terminal.containers.ItemTerminalContainer; +import net.minecraft.ChatFormatting; import net.minecraft.block.BlockState; +import net.minecraft.core.Direction; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.INamedContainerProvider; +import net.minecraft.network.chat.Style; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.nbt.CompoundTag; import net.minecraft.tileentity.ITickableTileEntity; @@ -32,6 +37,7 @@ import net.minecraft.util.text.Style; import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.world.World; +import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.Constants.NBT; import net.minecraftforge.common.util.LazyOptional; @@ -45,7 +51,7 @@ import java.util.*; import java.util.function.Consumer; import java.util.stream.Collectors; -public class ItemTerminalTileEntity extends TileEntity implements INamedContainerProvider, ITickableTileEntity, IPipeConnectable { +public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnectable { public final ItemStackHandler items = new ItemStackHandler(12) { @Override @@ -57,26 +63,19 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine private final Queue existingRequests = new LinkedList<>(); private final LazyOptional lazyThis = LazyOptional.of(() -> this); - protected ItemTerminalTileEntity(TileEntityType tileEntityTypeIn) { - super(tileEntityTypeIn); - } - - public ItemTerminalTileEntity() { - this(Registry.itemTerminalTileEntity); - } - - @Override + // TODO tick +/* @Override public void tick() { - if (this.world.isRemote) + if (this.level.isRemote) return; - PipeNetwork network = PipeNetwork.get(this.world); - PipeTileEntity pipe = this.getConnectedPipe(); + PipeNetwork network = PipeNetwork.get(this.level); + PipeBlockEntity pipe = this.getConnectedPipe(); if (pipe == null) return; boolean update = false; int interval = pipe.pressurizer != null ? 2 : 10; - if (this.world.getGameTime() % interval == 0) { + if (this.level.getGameTime() % interval == 0) { for (int i = 6; i < 12; i++) { ItemStack extracted = this.items.extractItem(i, Integer.MAX_VALUE, true); if (extracted.isEmpty()) @@ -96,26 +95,26 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine } } - if (this.world.getGameTime() % 100 == 0 || update) { + if (this.level.getGameTime() % 100 == 0 || update) { PlayerEntity[] lookingPlayers = this.getLookingPlayers(); if (lookingPlayers.length > 0) this.updateItems(lookingPlayers); } - } + }*/ @Override - public void remove() { - super.remove(); - PipeNetwork network = PipeNetwork.get(this.world); + public void setRemoved() { + super.setRemoved(); + PipeNetwork network = PipeNetwork.get(this.level); for (NetworkLock lock : this.existingRequests) network.resolveNetworkLock(lock); this.lazyThis.invalidate(); } public String getInvalidTerminalReason() { - PipeNetwork network = PipeNetwork.get(this.world); + PipeNetwork network = PipeNetwork.get(this.level); long pipes = Arrays.stream(Direction.values()) - .map(d -> network.getPipe(this.pos.offset(d))) + .map(d -> network.getPipe(this.worldPosition.relative(d))) .filter(Objects::nonNull).count(); if (pipes <= 0) return "info." + PrettyPipes.ID + ".no_pipe_connected"; @@ -124,43 +123,42 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine return null; } - public PipeTileEntity getConnectedPipe() { - PipeNetwork network = PipeNetwork.get(this.world); + public PipeBlockEntity getConnectedPipe() { + PipeNetwork network = PipeNetwork.get(this.level); for (Direction dir : Direction.values()) { - PipeTileEntity pipe = network.getPipe(this.pos.offset(dir)); + PipeBlockEntity pipe = network.getPipe(this.worldPosition.relative(dir)); if (pipe != null) return pipe; } return null; } - public void updateItems(PlayerEntity... playersToSync) { - PipeTileEntity pipe = this.getConnectedPipe(); + public void updateItems(Player... playersToSync) { + PipeBlockEntity pipe = this.getConnectedPipe(); if (pipe == null) return; this.networkItems = this.collectItems(ItemEquality.NBT); if (playersToSync.length > 0) { List clientItems = this.networkItems.values().stream().map(NetworkItem::asStack).collect(Collectors.toList()); - List clientCraftables = PipeNetwork.get(this.world).getAllCraftables(pipe.getPos()).stream().map(Pair::getRight).collect(Collectors.toList()); + List clientCraftables = PipeNetwork.get(this.level).getAllCraftables(pipe.getPos()).stream().map(Pair::getRight).collect(Collectors.toList()); List currentlyCrafting = this.getCurrentlyCrafting().stream().sorted(Comparator.comparingInt(ItemStack::getCount).reversed()).collect(Collectors.toList()); - for (PlayerEntity player : playersToSync) { - if (!(player.openContainer instanceof ItemTerminalContainer)) + for (Player player : playersToSync) { + if (!(player.containerMenu instanceof ItemTerminalContainer container)) continue; - ItemTerminalTileEntity tile = ((ItemTerminalContainer) player.openContainer).tile; - if (tile != this) + if (container.tile != this) continue; PacketHandler.sendTo(player, new PacketNetworkItems(clientItems, clientCraftables, currentlyCrafting)); } } } - public void requestItem(PlayerEntity player, ItemStack stack) { - PipeNetwork network = PipeNetwork.get(this.world); + public void requestItem(Player player, ItemStack stack) { + PipeNetwork network = PipeNetwork.get(this.level); network.startProfile("terminal_request_item"); this.updateItems(); int requested = this.requestItemImpl(stack, onItemUnavailable(player)); if (requested > 0) { - player.sendMessage(new TranslationTextComponent("info." + PrettyPipes.ID + ".sending", requested, stack.getDisplayName()).setStyle(Style.EMPTY.setFormatting(TextFormatting.GREEN)), UUID.randomUUID()); + player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".sending", requested, stack.getDisplayName()).setStyle(Style.EMPTY.setFormatting(TextFormatting.GREEN)), UUID.randomUUID()); } else { onItemUnavailable(player).accept(stack); } @@ -170,27 +168,27 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine public int requestItemImpl(ItemStack stack, Consumer unavailableConsumer) { NetworkItem item = this.networkItems.get(new EquatableItemStack(stack, ItemEquality.NBT)); Collection locations = item == null ? Collections.emptyList() : item.getLocations(); - Pair, ItemStack> ret = requestItemLater(this.world, this.getConnectedPipe().getPos(), locations, unavailableConsumer, stack, new Stack<>(), ItemEquality.NBT); + Pair, ItemStack> ret = requestItemLater(this.level, this.getConnectedPipe().getPos(), locations, unavailableConsumer, stack, new Stack<>(), ItemEquality.NBT); this.existingRequests.addAll(ret.getLeft()); return stack.getCount() - ret.getRight().getCount(); } - protected PlayerEntity[] getLookingPlayers() { - return this.world.getPlayers().stream() + protected Player[] getLookingPlayers() { + return this.level.getPlayers().stream() .filter(p -> p.openContainer instanceof ItemTerminalContainer) .filter(p -> ((ItemTerminalContainer) p.openContainer).tile == this) .toArray(PlayerEntity[]::new); } private Map collectItems(ItemEquality... equalityTypes) { - PipeNetwork network = PipeNetwork.get(this.world); + PipeNetwork network = PipeNetwork.get(this.level); network.startProfile("terminal_collect_items"); - PipeTileEntity pipe = this.getConnectedPipe(); + PipeBlockEntity pipe = this.getConnectedPipe(); Map items = new HashMap<>(); for (NetworkLocation location : network.getOrderedNetworkItems(pipe.getPos())) { - for (Map.Entry entry : location.getItems(this.world).entrySet()) { + for (Map.Entry entry : location.getItems(this.level).entrySet()) { // make sure we can extract from this slot to display it - if (!location.canExtract(this.world, entry.getKey())) + if (!location.canExtract(this.level, entry.getKey())) continue; EquatableItemStack equatable = new EquatableItemStack(entry.getValue(), equalityTypes); NetworkItem item = items.computeIfAbsent(equatable, NetworkItem::new); @@ -202,8 +200,8 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine } private List getCurrentlyCrafting() { - PipeNetwork network = PipeNetwork.get(this.world); - PipeTileEntity pipe = this.getConnectedPipe(); + PipeNetwork network = PipeNetwork.get(this.level); + PipeBlockEntity pipe = this.getConnectedPipe(); if (pipe == null) return Collections.emptyList(); List> crafting = network.getCurrentlyCrafting(pipe.getPos()); @@ -211,12 +209,12 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine } public void cancelCrafting() { - PipeNetwork network = PipeNetwork.get(this.world); - PipeTileEntity pipe = this.getConnectedPipe(); + PipeNetwork network = PipeNetwork.get(this.level); + PipeBlockEntity pipe = this.getConnectedPipe(); if (pipe == null) return; for (Pair craftable : network.getAllCraftables(pipe.getPos())) { - PipeTileEntity otherPipe = network.getPipe(craftable.getLeft()); + PipeBlockEntity otherPipe = network.getPipe(craftable.getLeft()); if (otherPipe != null) { for (NetworkLock lock : otherPipe.craftIngredientRequests) network.resolveNetworkLock(lock); @@ -270,7 +268,7 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine @Override public ItemStack insertItem(BlockPos pipePos, Direction direction, ItemStack stack, boolean simulate) { BlockPos pos = pipePos.offset(direction); - ItemTerminalTileEntity tile = Utility.getBlockEntity(ItemTerminalTileEntity.class, world, pos); + ItemTerminalBlockEntity tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, world, pos); if (tile != null) return ItemHandlerHelper.insertItemStacked(tile.items, stack, simulate); return stack; @@ -313,7 +311,7 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine return Pair.of(requests, remain); } - public static Consumer onItemUnavailable(PlayerEntity player) { - return s -> player.sendMessage(new TranslationTextComponent("info." + PrettyPipes.ID + ".not_found", s.getDisplayName()).setStyle(Style.EMPTY.setFormatting(TextFormatting.RED)), UUID.randomUUID()); + public static Consumer onItemUnavailable(Player player) { + return s -> player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".not_found", s.getDisplayName()).setStyle(Style.EMPTY.applyFormat(ChatFormatting.RED)), UUID.randomUUID()); } } diff --git a/src/main/java/de/ellpeck/prettypipes/terminal/containers/CraftingTerminalContainer.java b/src/main/java/de/ellpeck/prettypipes/terminal/containers/CraftingTerminalContainer.java index 13826ae..33c6a8b 100644 --- a/src/main/java/de/ellpeck/prettypipes/terminal/containers/CraftingTerminalContainer.java +++ b/src/main/java/de/ellpeck/prettypipes/terminal/containers/CraftingTerminalContainer.java @@ -1,7 +1,7 @@ package de.ellpeck.prettypipes.terminal.containers; import de.ellpeck.prettypipes.Utility; -import de.ellpeck.prettypipes.terminal.CraftingTerminalTileEntity; +import de.ellpeck.prettypipes.terminal.CraftingTerminalBlockEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.inventory.CraftResultInventory; @@ -76,7 +76,7 @@ public class CraftingTerminalContainer extends ItemTerminalContainer { return super.slotClick(slotId, dragType, clickTypeIn, player); } - public CraftingTerminalTileEntity getTile() { - return (CraftingTerminalTileEntity) this.tile; + public CraftingTerminalBlockEntity getTile() { + return (CraftingTerminalBlockEntity) this.tile; } } diff --git a/src/main/java/de/ellpeck/prettypipes/terminal/containers/CraftingTerminalGui.java b/src/main/java/de/ellpeck/prettypipes/terminal/containers/CraftingTerminalGui.java index e213091..3c39888 100644 --- a/src/main/java/de/ellpeck/prettypipes/terminal/containers/CraftingTerminalGui.java +++ b/src/main/java/de/ellpeck/prettypipes/terminal/containers/CraftingTerminalGui.java @@ -1,13 +1,10 @@ package de.ellpeck.prettypipes.terminal.containers; import com.mojang.blaze3d.matrix.MatrixStack; -import com.mojang.blaze3d.platform.GlStateManager; -import com.mojang.blaze3d.systems.RenderSystem; import de.ellpeck.prettypipes.PrettyPipes; import de.ellpeck.prettypipes.packets.PacketButton; import de.ellpeck.prettypipes.packets.PacketHandler; -import de.ellpeck.prettypipes.packets.PacketRequest; -import de.ellpeck.prettypipes.terminal.CraftingTerminalTileEntity; +import de.ellpeck.prettypipes.terminal.CraftingTerminalBlockEntity; import net.minecraft.client.gui.widget.Widget; import net.minecraft.client.gui.widget.button.Button; import net.minecraft.client.resources.I18n; @@ -40,7 +37,7 @@ public class CraftingTerminalGui extends ItemTerminalGui { @Override public void tick() { super.tick(); - CraftingTerminalTileEntity tile = this.getCraftingContainer().getTile(); + CraftingTerminalBlockEntity tile = this.getCraftingContainer().getTile(); this.requestButton.active = false; for (int i = 0; i < tile.craftItems.getSlots(); i++) { ItemStack stack = tile.getRequestedCraftItem(i); @@ -56,7 +53,7 @@ public class CraftingTerminalGui extends ItemTerminalGui { super.drawGuiContainerForegroundLayer(matrix, mouseX, mouseY); CraftingTerminalContainer container = this.getCraftingContainer(); - CraftingTerminalTileEntity tile = container.getTile(); + CraftingTerminalBlockEntity tile = container.getTile(); for (int i = 0; i < tile.ghostItems.getSlots(); i++) { if (!tile.craftItems.getStackInSlot(i).isEmpty()) continue; diff --git a/src/main/java/de/ellpeck/prettypipes/terminal/containers/ItemTerminalContainer.java b/src/main/java/de/ellpeck/prettypipes/terminal/containers/ItemTerminalContainer.java index 26f5519..947e800 100644 --- a/src/main/java/de/ellpeck/prettypipes/terminal/containers/ItemTerminalContainer.java +++ b/src/main/java/de/ellpeck/prettypipes/terminal/containers/ItemTerminalContainer.java @@ -1,40 +1,37 @@ package de.ellpeck.prettypipes.terminal.containers; import de.ellpeck.prettypipes.Utility; -import de.ellpeck.prettypipes.terminal.ItemTerminalTileEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.inventory.container.ClickType; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.ContainerType; -import net.minecraft.inventory.container.Slot; +import de.ellpeck.prettypipes.terminal.ItemTerminalBlockEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; import net.minecraftforge.items.SlotItemHandler; import org.apache.commons.lang3.tuple.Pair; import javax.annotation.Nullable; -public class ItemTerminalContainer extends Container { +public class ItemTerminalContainer extends AbstractContainerMenu { - public final ItemTerminalTileEntity tile; + public final ItemTerminalBlockEntity tile; - public ItemTerminalContainer(@Nullable ContainerType type, int id, PlayerEntity player, BlockPos pos) { + public ItemTerminalContainer(@Nullable MenuType type, int id, Player player, BlockPos pos) { super(type, id); - this.tile = Utility.getBlockEntity(ItemTerminalTileEntity.class, player.world, pos); + this.tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, player.level, pos); this.addOwnSlots(player); int off = this.getSlotXOffset(); for (int l = 0; l < 3; ++l) for (int j1 = 0; j1 < 9; ++j1) - this.addSlot(new Slot(player.inventory, j1 + l * 9 + 9, 8 + off + j1 * 18, 154 + l * 18)); + this.addSlot(new Slot(player.getInventory(), j1 + l * 9 + 9, 8 + off + j1 * 18, 154 + l * 18)); for (int i1 = 0; i1 < 9; ++i1) - this.addSlot(new Slot(player.inventory, i1, 8 + off + i1 * 18, 212)); + this.addSlot(new Slot(player.getInventory(), i1, 8 + off + i1 * 18, 212)); } - protected void addOwnSlots(PlayerEntity player) { + protected void addOwnSlots(Player player) { int off = this.getSlotXOffset(); for (int i = 0; i < 6; i++) this.addSlot(new SlotItemHandler(this.tile.items, i, 8 + off + i % 3 * 18, 102 + i / 3 * 18)); @@ -47,12 +44,12 @@ public class ItemTerminalContainer extends Container { } @Override - public ItemStack transferStackInSlot(PlayerEntity player, int slotIndex) { - return Utility.transferStackInSlot(this, this::mergeItemStack, player, slotIndex, stack -> Pair.of(6, 12)); + public ItemStack quickMoveStack(Player player, int slotIndex) { + return Utility.transferStackInSlot(this, this::moveItemStackTo, player, slotIndex, stack -> Pair.of(6, 12)); } @Override - public boolean canInteractWith(PlayerEntity playerIn) { + public boolean stillValid(Player player) { return true; } } diff --git a/src/main/java/de/ellpeck/prettypipes/terminal/containers/ItemTerminalGui.java b/src/main/java/de/ellpeck/prettypipes/terminal/containers/ItemTerminalGui.java index fcc9b9c..2a6bff8 100644 --- a/src/main/java/de/ellpeck/prettypipes/terminal/containers/ItemTerminalGui.java +++ b/src/main/java/de/ellpeck/prettypipes/terminal/containers/ItemTerminalGui.java @@ -8,13 +8,19 @@ import de.ellpeck.prettypipes.packets.PacketButton; import de.ellpeck.prettypipes.packets.PacketHandler; import de.ellpeck.prettypipes.packets.PacketRequest; import joptsimple.internal.Strings; +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.components.EditBox; import net.minecraft.client.gui.screen.inventory.ContainerScreen; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.gui.widget.TextFieldWidget; import net.minecraft.client.gui.widget.Widget; import net.minecraft.client.gui.widget.button.Button; import net.minecraft.client.resources.I18n; import net.minecraft.client.util.InputMappings; import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.ItemStack; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.math.MathHelper; @@ -27,12 +33,12 @@ import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; -public class ItemTerminalGui extends ContainerScreen { +public class ItemTerminalGui extends AbstractContainerScreen { private static final ResourceLocation TEXTURE = new ResourceLocation(PrettyPipes.ID, "textures/gui/item_terminal.png"); public List currentlyCrafting; - public TextFieldWidget search; + public EditBox search; // craftables have the second parameter set to true private final List> sortedItems = new ArrayList<>(); @@ -50,23 +56,23 @@ public class ItemTerminalGui extends ContainerScreen { private ItemStack hoveredCrafting; private boolean isScrolling; - public ItemTerminalGui(ItemTerminalContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) { + public ItemTerminalGui(ItemTerminalContainer screenContainer, Inventory inv, Component titleIn) { super(screenContainer, inv, titleIn); - this.xSize = 176 + 15; - this.ySize = 236; + this.imageWidth = 176 + 15; + this.imageHeight = 236; } @Override protected void init() { super.init(); - this.search = this.addButton(new TextFieldWidget(this.font, this.guiLeft + this.getXOffset() + 97, this.guiTop + 6, 86, 8, new StringTextComponent(""))); - this.search.setEnableBackgroundDrawing(false); + this.search = this.addWidget(new EditBox(this.font, this.leftPos + this.getXOffset() + 97, this.topPos + 6, 86, 8, new StringTextComponent(""))); + this.search.setBordered(false); this.lastSearchText = ""; if (this.items != null) this.updateWidgets(); - this.plusButton = this.addButton(new Button(this.guiLeft + this.getXOffset() + 95 - 7 + 12, this.guiTop + 103, 12, 12, new StringTextComponent("+"), button -> { + this.plusButton = this.addWidget(new Button(this.leftPos + this.getXOffset() + 95 - 7 + 12, this.topPos + 103, 12, 12, new StringTextComponent("+"), button -> { int modifier = requestModifier(); if (modifier > 1 && this.requestAmount == 1) { this.requestAmount = modifier; @@ -77,23 +83,23 @@ public class ItemTerminalGui extends ContainerScreen { if (this.requestAmount > 384) this.requestAmount = 384; })); - this.minusButton = this.addButton(new Button(this.guiLeft + this.getXOffset() + 95 - 7 - 24, this.guiTop + 103, 12, 12, new StringTextComponent("-"), button -> { + this.minusButton = this.addWidget(new Button(this.leftPos + this.getXOffset() + 95 - 7 - 24, this.topPos + 103, 12, 12, new StringTextComponent("-"), button -> { this.requestAmount -= requestModifier(); if (this.requestAmount < 1) this.requestAmount = 1; })); this.minusButton.active = false; - this.requestButton = this.addButton(new Button(this.guiLeft + this.getXOffset() + 95 - 7 - 25, this.guiTop + 115, 50, 20, new TranslationTextComponent("info." + PrettyPipes.ID + ".request"), button -> { + this.requestButton = this.addWidget(new Button(this.leftPos + this.getXOffset() + 95 - 7 - 25, this.topPos + 115, 50, 20, new TranslationTextComponent("info." + PrettyPipes.ID + ".request"), button -> { Optional widget = this.streamWidgets().filter(w -> w.selected).findFirst(); if (!widget.isPresent()) return; ItemStack stack = widget.get().stack.copy(); stack.setCount(1); - PacketHandler.sendToServer(new PacketRequest(this.container.tile.getPos(), stack, this.requestAmount)); + PacketHandler.sendToServer(new PacketRequest(this.menu.tile.getBlockPos(), stack, this.requestAmount)); this.requestAmount = 1; })); this.requestButton.active = false; - this.orderButton = this.addButton(new Button(this.guiLeft - 22, this.guiTop, 20, 20, new StringTextComponent(""), button -> { + this.orderButton = this.addWidget(new Button(this.leftPos - 22, this.topPos, 20, 20, new TextComponent(""), button -> { if (this.sortedItems == null) return; PlayerPrefs prefs = PlayerPrefs.get(); @@ -101,7 +107,7 @@ public class ItemTerminalGui extends ContainerScreen { prefs.save(); this.updateWidgets(); })); - this.ascendingButton = this.addButton(new Button(this.guiLeft - 22, this.guiTop + 22, 20, 20, new StringTextComponent(""), button -> { + this.ascendingButton = this.addButton(new Button(this.leftPos - 22, this.topPos + 22, 20, 20, new StringTextComponent(""), button -> { if (this.sortedItems == null) return; PlayerPrefs prefs = PlayerPrefs.get(); @@ -109,12 +115,12 @@ public class ItemTerminalGui extends ContainerScreen { prefs.save(); this.updateWidgets(); })); - this.cancelCraftingButton = this.addButton(new Button(this.guiLeft + this.xSize + 4, this.guiTop + 4 + 64, 54, 20, new TranslationTextComponent("info." + PrettyPipes.ID + ".cancel_all"), b -> { + this.cancelCraftingButton = this.addButton(new Button(this.leftPos + this.xSize + 4, this.topPos + 4 + 64, 54, 20, new TranslationTextComponent("info." + PrettyPipes.ID + ".cancel_all"), b -> { })); this.cancelCraftingButton.visible = false; for (int y = 0; y < 4; y++) { for (int x = 0; x < 9; x++) - this.addButton(new ItemTerminalWidget(this.guiLeft + this.getXOffset() + 8 + x * 18, this.guiTop + 18 + y * 18, x, y, this)); + this.addButton(new ItemTerminalWidget(this.leftPos + this.getXOffset() + 8 + x * 18, this.topPos + 18 + y * 18, x, y, this)); } } @@ -141,7 +147,7 @@ public class ItemTerminalGui extends ContainerScreen { @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (button == 0 && mouseX >= this.guiLeft + this.getXOffset() + 172 && this.guiTop + mouseY >= 18 && mouseX < this.guiLeft + this.getXOffset() + 172 + 12 && mouseY < this.guiTop + 18 + 70) { + if (button == 0 && mouseX >= this.leftPos + this.getXOffset() + 172 && this.topPos + mouseY >= 18 && mouseX < this.leftPos + this.getXOffset() + 172 + 12 && mouseY < this.topPos + 18 + 70) { this.isScrolling = true; return true; } @@ -172,7 +178,7 @@ public class ItemTerminalGui extends ContainerScreen { @Override public boolean mouseDragged(double mouseX, double mouseY, int i, double j, double k) { if (this.isScrolling) { - float percentage = MathHelper.clamp(((float) mouseY - (this.guiTop + 18) - 7.5F) / (70 - 15), 0, 1); + float percentage = MathHelper.clamp(((float) mouseY - (this.topPos + 18) - 7.5F) / (70 - 15), 0, 1); int offset = (int) (percentage * (float) (this.sortedItems.size() / 9 - 3)); if (offset != this.scrollOffset) { this.scrollOffset = offset; @@ -300,26 +306,26 @@ public class ItemTerminalGui extends ContainerScreen { @Override protected void drawGuiContainerBackgroundLayer(MatrixStack matrix, float partialTicks, int mouseX, int mouseY) { this.getMinecraft().getTextureManager().bindTexture(this.getTexture()); - this.blit(matrix, this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize); + this.blit(matrix, this.leftPos, this.topPos, 0, 0, this.xSize, this.ySize); if (this.sortedItems != null && this.sortedItems.size() >= 9 * 4) { float percentage = this.scrollOffset / (float) (this.sortedItems.size() / 9 - 3); - this.blit(matrix, this.guiLeft + this.getXOffset() + 172, this.guiTop + 18 + (int) (percentage * (70 - 15)), 232, 241, 12, 15); + this.blit(matrix, this.leftPos + this.getXOffset() + 172, this.topPos + 18 + (int) (percentage * (70 - 15)), 232, 241, 12, 15); } else { - this.blit(matrix, this.guiLeft + this.getXOffset() + 172, this.guiTop + 18, 244, 241, 12, 15); + this.blit(matrix, this.leftPos + this.getXOffset() + 172, this.topPos + 18, 244, 241, 12, 15); } // draw the items that are currently crafting this.hoveredCrafting = ItemStack.EMPTY; if (this.currentlyCrafting != null && !this.currentlyCrafting.isEmpty()) { this.getMinecraft().getTextureManager().bindTexture(TEXTURE); - this.blit(matrix, this.guiLeft + this.xSize, this.guiTop + 4, 191, 0, 65, 89); + this.blit(matrix, this.leftPos + this.xSize, this.topPos + 4, 191, 0, 65, 89); int x = 0; int y = 0; for (ItemStack stack : this.currentlyCrafting) { - int itemX = this.guiLeft + this.xSize + 4 + x * 18; - int itemY = this.guiTop + 4 + 16 + y * 18; + int itemX = this.leftPos + this.xSize + 4 + x * 18; + int itemY = this.topPos + 4 + 16 + y * 18; this.itemRenderer.renderItemAndEffectIntoGUI(stack, itemX, itemY); this.itemRenderer.renderItemOverlayIntoGUI(this.font, stack, itemX, itemY, String.valueOf(stack.getCount())); if (mouseX >= itemX && mouseY >= itemY && mouseX < itemX + 16 && mouseY < itemY + 18)