Compare commits

...

27 Commits

Author SHA1 Message Date
passplease 1ce7ea79ff Add Contributor 2025-05-31 09:54:22 +08:00
passplease c2ebf32914 Fix cannot start on server 2025-05-25 09:08:22 +08:00
passplease d52e3a42ec Fix bug and create workflow file 2025-05-17 16:35:05 +08:00
passplease 792dd6897f support GUI 2025-04-05 19:23:39 +08:00
passplease 2d819b1789 support AE2 2025-04-04 15:50:10 +08:00
passplease c9753f0e96 support GUI 2025-02-23 17:27:58 +08:00
passplease ecee44d58c Fix the bug about Drawer 2024-12-05 19:29:27 +08:00
passplease e24599afb6 Fix the bug that cannot start on server 2024-10-21 21:25:01 +08:00
passplease 4e44034549 Fix the bug that cannot start on server 2024-10-21 21:14:07 +08:00
passplease 9b5cf21052 Fix the bug that cannot start on server 2024-10-21 21:06:51 +08:00
passplease e89fad7690 Support CobbleForDays 2024-09-25 21:45:05 +08:00
passplease 64377531a0 Deal with bug about deserializing 2024-09-15 11:27:50 +08:00
passplease cc2f1c1c3e Deal with bug about deserializing 2024-09-14 15:06:55 +08:00
passplease 4d03c7e300 Deal with bug about deserializing 2024-09-14 15:03:42 +08:00
passplease 419f9ca6f8 support AE2 2024-08-30 20:59:16 +08:00
passplease 1489cee66a support AE2 2024-08-30 20:59:02 +08:00
passplease 3aa2e993a8 support AE2 2024-08-10 07:21:36 +08:00
passplease 5238523188 support fluid and add little function: automatically dump bucketLike(and other fluid containers) item; 2024-07-19 12:15:29 +08:00
passplease a99bf866b7 support fluid and add little function: automatically dump bucketLike(and other fluid containers) item; 2024-07-10 14:04:39 +08:00
passplease fa1972202f support fluid and add little function: automatically dump bucketLike(and other fluid containers) item; 2024-07-10 14:03:38 +08:00
passplease 83d8f82478 support more mods 2024-07-07 19:17:36 +08:00
passplease 2fb321ebbb support more mods 2024-07-07 19:17:13 +08:00
passplease ffb8b03bd0 support more mods 2024-07-07 18:55:25 +08:00
passplease 4757573098 repair bug: if there are no Drawers, the game will crash 2024-07-02 07:54:31 +08:00
passplease 5d05aec515 Update my mod and support 1.20.1 2024-07-01 21:45:20 +08:00
passplease 1de374aa74 Update my mod and support 1.20.1 2024-07-01 21:41:16 +08:00
passplease 716617e43d studying update my mod 2024-07-01 20:48:31 +08:00
68 changed files with 522 additions and 545 deletions

49
.github/workflows/publish.yml vendored Normal file
View File

@ -0,0 +1,49 @@
name: Build
on:
workflow_dispatch:
push:
branches:
- 1.20.1-forge-47.3.3
paths:
- src/*
- gradle/*
- .github/workflows/*
- build.gradle
- gradle.properties
- settings.gradle
jobs:
build:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Setup JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Set Gradle version
run: gradle wrapper --gradle-version 7.6.4
- name: Test Server
run: gradle runGameTestServer
- name: Build
run: gradle build
- uses: Kir-Antipov/mc-publish@v3.3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
github-tag: 1.20.1-Below-Create-6.0.0-Forge

11
.gitignore vendored
View File

@ -1,5 +1,6 @@
/run/
/.vscode/
/.idea/
/bin/
/build/
run/
.vscode/
.idea/
bin/
build/
.gradle/

Binary file not shown.

Binary file not shown.

View File

@ -1,2 +1,2 @@
#Wed Sep 04 13:22:40 CST 2024
#Sat Apr 05 08:05:12 CST 2025
gradle.version=8.4

Binary file not shown.

View File

@ -1,15 +1,21 @@
# Welcome to SCS !
## Download Code
If you want to download code on your computer, please change gradle version in `gradle\wrapper` or build like workflow: `publish.yml`
## Download Links
* For CurseForge: ["CurseForge"](https://www.curseforge.com/minecraft/mc-mods/smartercontraptionstorage)
* Modrinth: ["Modrinth"](https://modrinth.com/mod/smarter-contraption-storage)
* If you come from China, you can also use [MCMODS](https://www.mcmod.cn/class/15306.html)
## What Can It Do?
* It is a mod aiming at making containers on contraptions smarter. After applying this mod, you can control your each container on contraption separately when them are blocks (planning to make them act like actors)
* Secondly, it adds support to other containers those Create haven't allowed, such as [Drawers](https://www.curseforge.com/minecraft/mc-mods/storage-drawers) ,(planning) [TrashBins](https://www.curseforge.com/minecraft/mc-mods/trash-cans) and any others you request me to support
* Secondly, it adds support to other containers those Create haven't allowed, such as [Drawers](https://www.curseforge.com/minecraft/mc-mods/storage-drawers) , [TrashBins](https://www.curseforge.com/minecraft/mc-mods/trash-cans) and any others you request me to support
* Thirdly, it plans to add some interesting and useful features to create
## How to Give Me Some Advice
* First of all, GitHub is always the best place
* For Chinese, you can also find more links in [MCMODS](https://www.mcmod.cn/class/15306.html)
## About Plans
1) Support 1.21.1
- [x] Support 1.21.1
- [ ] Transplant all stuff to 1.20.1 and 1.21.1
## License
[MIT_License](https://mit-license.org/)
[MIT_License](https://mit-license.org/)
## Thanks
Thanks to [KAllFix](https://center.mcmod.cn/170204/) improves the code and offer me help.

View File

@ -1,21 +1,25 @@
buildscript {
repositories {
// These repositories are only for Gradle plugins, put any other repositories in the repository overlays further below
// These repositories are only for Gradle plugins, put any other repositories in the repository block further below
maven { url = 'https://maven.minecraftforge.net' }
maven { url = 'https://repo.spongepowered.org/repository/maven-public/' }
mavenCentral()
}
dependencies {
classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT'
classpath "org.spongepowered:mixingradle:${mixin_gradle}"
classpath "net.minecraftforge.gradle:ForgeGradle:${forge_gradle}"
classpath "org.parchmentmc:librarian:${librarian_version}"
}
}
plugins {
id 'eclipse'
id 'idea'
id 'net.minecraftforge.gradle' version '[6.0.16,6.2)'
id 'org.parchmentmc.librarian.forgegradle' version '1.+'
id 'maven-publish'
id 'net.minecraftforge.gradle' version '[6.0,6.2)'
}
apply plugin: 'org.parchmentmc.librarian.forgegradle'
apply plugin: 'org.spongepowered.mixin'
group = mod_group_id
@ -163,23 +167,18 @@ dependencies {
// If the group id is "net.minecraft" and the artifact id is one of ["client", "server", "joined"],
// then special handling is done to allow a setup of a vanilla dependency without the use of an external repository.
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
runtimeOnly fg.deobf("curse.maven:mekanism-268560:4644795")
runtimeOnly fg.deobf("curse.maven:cyclops-core-232758:4681659")
runtimeOnly fg.deobf("curse.maven:capabilityproxy-266479:3929855")
runtimeOnly fg.deobf("curse.maven:toms-storage-378609:4649846")
compileOnly fg.deobf("com.tterrag.registrate:Registrate:${registrate_version}")
implementation fg.deobf("curse.maven:create-328085:4835190")
implementation fg.deobf("curse.maven:storage-drawers-223852:5648923")
implementation fg.deobf("curse.maven:trash-cans-394535:4606893")
implementation fg.deobf("curse.maven:supermartijn642s-config-lib-438332:4715406")
implementation fg.deobf("curse.maven:supermartijn642s-core-lib-454372:4660114")
implementation fg.deobf("curse.maven:sophisticated-core-618298:5296313")
implementation fg.deobf("curse.maven:sophisticated-backpacks-422301:5194759")
implementation fg.deobf("curse.maven:titanium-287342:5356458")
implementation fg.deobf("curse.maven:functional-storage-556861:4992914")
implementation fg.deobf("curse.maven:applied-energistics-2-223794:5014801")
implementation fg.deobf("curse.maven:cobblefordays-349460:3975349")
implementation fg.deobf("curse.maven:sophisticated-storage-619320:5194750")
implementation fg.deobf("curse.maven:create-328085:4835191")
implementation fg.deobf("curse.maven:storage-drawers-223852:5152196")
implementation fg.deobf("curse.maven:trash-cans-394535:4712179")
implementation fg.deobf("curse.maven:supermartijn642s-config-lib-438332:4715408")
implementation fg.deobf("curse.maven:supermartijn642s-core-lib-454372:5102258")
implementation fg.deobf("curse.maven:sophisticated-core-618298:5326245")
implementation fg.deobf("curse.maven:sophisticated-backpacks-422301:5296475")
implementation fg.deobf("curse.maven:functional-storage-556861:5169765")
implementation fg.deobf("curse.maven:titanium-287342:5468426")
implementation fg.deobf("curse.maven:applied-energistics-2-223794:5565729")
implementation fg.deobf("curse.maven:cobblefordays-349460:4653625")
// Example mod dependency with JEI - using fg.deobf() ensures the dependency is remapped to your development mappings
// The JEI API is declared for compile time use, while the full JEI artifact is used at runtime
// compileOnly fg.deobf("mezz.jei:jei-${mc_version}-common-api:${jei_version}")
@ -198,7 +197,7 @@ dependencies {
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
}
// This overlays of code expands all declared replace properties in the specified resource targets.
// This block of code expands all declared replace properties in the specified resource targets.
// A missing property will result in an error. Properties are expanded using ${} Groovy notation.
// When "copyIdeResources" is enabled, this will also run before the game launches in IDE environments.
// See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html
@ -237,4 +236,17 @@ tasks.named('jar', Jar).configure {
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
}
publish{
repositories {
maven {
name = "GitHubPackages"
url = "https://maven.pkg.github.com/passplease/SmarterContraptionStorage"
credentials {
username = System.getenv("USERNAME")
password = System.getenv("TOKEN")
}
}
}
}

View File

@ -3,17 +3,19 @@ org.gradle.daemon=false
# The Minecraft version must agree with the Forge version to get Excludes.BuildNBTFile valid artifact
minecraft_version=1.19.2
minecraft_version=1.20.1
# The Minecraft version range can use any release version of Minecraft as bounds.
# Snapshots, pre-releases, and release candidates are not guaranteed to sort properly
# as they do not follow standard versioning conventions.
minecraft_version_range=[1.19.2,1.20)
minecraft_version_range=[1.20.1,1.20.2)
# The Forge version must agree with the Minecraft version to get Excludes.BuildNBTFile valid artifact
forge_version=43.3.0
forge_version=47.1.47
forge_gradle=6.0.16
librarian_version=1.+
# The Forge version range can use any version of Forge as bounds or match the loader version range
forge_version_range=[43,)
forge_version_range=[47,)
# The loader version range can only use the major version of Forge/FML as bounds
loader_version_range=[43,)
loader_version_range=[47,)
# The mapping channel to use for mappings.
# The default set of supported mapping channels are ["official", "snapshot", "snapshot_nodoc", "stable", "stable_nodoc"].
# Additional mapping channels can be registered through the "channelProviders" extension in Excludes.BuildNBTFile Gradle plugin.
@ -31,7 +33,7 @@ loader_version_range=[43,)
mapping_channel=parchment
# The mapping version to query from the mapping channel.
# This must match the format required by the mapping channel.
mapping_version=2022.08.14-1.19.2
mapping_version=2023.06.26-1.20.1
# The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [Excludes.BuildNBTFile-z][Excludes.BuildNBTFile-z0-9_]{1,63}
@ -42,7 +44,7 @@ mod_name=SmarterContraptionStorage
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=MIT_License
# The mod version. See https://semver.org/
mod_version=1.19.2-1.3
mod_version=1.20.1-1.3.2
# The group ID for the mod. It is only important when publishing as an artifact to Excludes.BuildNBTFile Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
@ -51,6 +53,7 @@ mod_group_id=net
mod_authors=No Name
# The description of the mod. This is Excludes.BuildNBTFile simple multiline text string that is used for display purposes in the mod list.
mod_description=A mod to make Contraption's storage smarter
registrate_version=MC1.19-1.1.5
flywheel_version=0.6.10-20
ATFile=src/main/resources/META-INF/accesstransformer.cfg
registrate_version=MC1.20-1.3.3
flywheel_version=0.6.10-7
ATFile=src/main/resources/META-INF/accesstransformer.cfg
mixin_gradle=0.7-SNAPSHOT

Binary file not shown.

View File

@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
# Should change to 7.* (for example 7.6.4), but for no reason I couldn't download this version on my computer even 8.* can use.
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME

20
gradlew.bat vendored
View File

@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail

View File

@ -1,5 +1,6 @@
package net.smartercontraptionstorage.AddStorage;
import appeng.api.networking.IGridNode;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.IActionSource;
import net.minecraft.world.entity.player.Player;
@ -7,6 +8,9 @@ import net.minecraft.world.entity.player.Player;
import java.util.Optional;
public record AE2ContraptionSource(IActionHost host) implements IActionSource {
public static AE2ContraptionSource create(IGridNode extractNode) {
return new AE2ContraptionSource(() -> extractNode);
}
@Override
public Optional<Player> player() {
return Optional.empty();

View File

@ -1,7 +1,7 @@
package net.smartercontraptionstorage.AddStorage.GUI.BlockEntityMenu;
import com.mojang.blaze3d.vertex.PoseStack;
import com.simibubi.create.foundation.utility.Pair;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.MenuAccess;
import net.minecraft.core.BlockPos;
@ -71,6 +71,7 @@ public interface HelperMenuProvider<T extends StorageHandlerHelper> extends Cont
ContraptionMenuProvider.super.error();
}
@OnlyIn(Dist.CLIENT)
<U extends Screen & MenuAccess<?>> U createScreen(MovingBlockEntityMenu menu, Inventory inventory, Component component);
default void writeToBuffer(@NotNull FriendlyByteBuf buffer) {
@ -109,16 +110,23 @@ public interface HelperMenuProvider<T extends StorageHandlerHelper> extends Cont
}
default boolean shouldClickScreen(MovingBlockEntityMenu menu, int index, int flag, ClickType type, Player player){
return !player.level.isClientSide();
return !player.level().isClientSide();
}
@OnlyIn(Dist.CLIENT)
default boolean shouldClickScreen(MovingBlockEntityScreen screen, double mouseX, double mouseY, int button){
return true;
}
@OnlyIn(Dist.CLIENT)
default void render(MovingBlockEntityScreen screen, PoseStack poseStack, int mouseX, int mouseY, float partialTick){}
default void render(MovingBlockEntityScreen screen, GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick){}
@OnlyIn(Dist.CLIENT)
default void renderWithTooltip(MovingBlockEntityScreen screen, GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick){
render(screen, guiGraphics, mouseX, mouseY, partialTick);
}
@OnlyIn(Dist.CLIENT)
default boolean slotClicked(MovingBlockEntityScreen screen, Slot slot, int slotId, int button, ClickType type){
return true;
}

View File

@ -3,8 +3,11 @@ package net.smartercontraptionstorage.AddStorage.GUI.BlockEntityMenu;
import com.simibubi.create.foundation.utility.Pair;
import com.simibubi.create.foundation.utility.worldWrappers.WrappedWorld;
import net.minecraft.client.Minecraft;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.smartercontraptionstorage.Message.MenuLevelPacket;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
@ -25,10 +28,13 @@ public class MenuLevel extends WrappedWorld {
private static Level tickingLevel;
public static MenuLevel level = new MenuLevel();
private static ClientMenuLevel clientLevel = null;
private MenuLevel() {
super(Minecraft.getInstance().level);
// @OnlyIn(Dist.CLIENT)
// public static MenuLevel clientLevel = new MenuLevel(Minecraft.getInstance().level);
private MenuLevel(Level level) {
super(level);
}
public static Map<Pair<Integer, Long>, BlockEntity> getBlocks(){
@ -59,26 +65,35 @@ public class MenuLevel extends WrappedWorld {
return blocks.get(pair);
}
public static MenuLevel tickingBlockEntity(Pair<Integer, Long> pair,boolean isClient) {
private static MenuLevel clientLevel(){
if(clientLevel == null){
clientLevel = new ClientMenuLevel();
}
return clientLevel.clientLevel;
}
public static MenuLevel level(Level level) {
if(level.isClientSide()) {
return clientLevel();
}
else if(level instanceof ServerLevel){
return new MenuLevel(level);
}else throw new RuntimeException("Open menu get null server level !");
}
public static MenuLevel tickingBlockEntity(Pair<Integer, Long> pair,Level level){
if(tickingBlockEntity != null){
tickingBlockEntity.setLevel(tickingLevel);
}
if(blocks.containsKey(pair)) {
tickingBlockEntity = blocks.get(pair);
tickingLevel = tickingBlockEntity.getLevel();
tickingBlockEntity.setLevel(level);
MenuLevel menuLevel = level(level);
tickingBlockEntity.setLevel(menuLevel);
return menuLevel;
} else {
tickingBlockEntity = null;
tickingLevel = null;
throw new IllegalArgumentException("Pair is not found ! Pair: " + pair);
}
level.isClientSide = isClient;
return level;
}
public static MenuLevel tickingBlockEntity(Pair<Integer, Long> pair,Level level){
MenuLevel value = tickingBlockEntity(pair, level.isClientSide());
tickingLevel = level;
return value;
}
private static void setTickingBlockEntity(BlockEntity blockEntity){
@ -104,7 +119,12 @@ public class MenuLevel extends WrappedWorld {
@Override
public boolean addFreshEntity(Entity entityIn) {
entityIn.level = tickingLevel;
entityIn.setLevel(tickingLevel);
return tickingLevel.addFreshEntity(entityIn);
}
private static class ClientMenuLevel{
@OnlyIn(Dist.CLIENT)
protected MenuLevel clientLevel = new MenuLevel(Minecraft.getInstance().level);
}
}

View File

@ -55,7 +55,7 @@ public class MovingBlockEntityMenu extends AbstractContainerMenu {
public ItemStack quickMoveStack(Player player, int i) {
Level level = setPlayerLevel(player);
ItemStack itemStack = getMenu().quickMoveStack(player, i);
player.level = level;
player.setLevel(level);
return itemStack;
}
@ -63,7 +63,7 @@ public class MovingBlockEntityMenu extends AbstractContainerMenu {
public boolean stillValid(Player player) {
Level level = setPlayerLevel(player);
boolean value = getHelper().stillValid(player, this);
player.level = level;
player.setLevel(level);
return value;
}
@ -81,8 +81,8 @@ public class MovingBlockEntityMenu extends AbstractContainerMenu {
}
protected Level setPlayerLevel(Player player) {
Level level = player.level;
player.level = MenuLevel.tickingBlockEntity(getHelper().getPair(),level);
Level level = player.level();
player.setLevel(MenuLevel.tickingBlockEntity(getHelper().getPair(),level));
return level;
}
@ -95,7 +95,7 @@ public class MovingBlockEntityMenu extends AbstractContainerMenu {
public boolean clickMenuButton(Player player, int id) {
Level level = setPlayerLevel(player);
boolean value = getMenu().clickMenuButton(player, id);
player.level = level;
player.setLevel(level);
return value;
}
@ -110,7 +110,7 @@ public class MovingBlockEntityMenu extends AbstractContainerMenu {
// Client will be synchronized
Level level = setPlayerLevel(player);
getMenu().clicked(index, flag, type, player);
player.level = level;
player.setLevel(level);
}
}
@ -124,7 +124,7 @@ public class MovingBlockEntityMenu extends AbstractContainerMenu {
Level level = setPlayerLevel(player);
getMenu().removed(player);
super.removed(player);
player.level = level;
player.setLevel(level);
getHelper().removed(this, player);
}

View File

@ -3,6 +3,7 @@ package net.smartercontraptionstorage.AddStorage.GUI.BlockEntityMenu;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.locale.Language;
import net.minecraft.network.chat.Component;
@ -52,13 +53,13 @@ public class MovingBlockEntityScreen extends AbstractContainerScreen<MovingBlock
}
@Override
public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTick) {
getScreen().render(poseStack, mouseX, mouseY, partialTick);
getMenu().getHelper().render(this,poseStack,mouseX,mouseY,partialTick);
public void render(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
getScreen().render(pGuiGraphics, pMouseX, pMouseY, pPartialTick);
getMenu().getHelper().render(this,pGuiGraphics,pMouseX,pMouseY,pPartialTick);
}
@Override
protected void renderBg(PoseStack poseStack, float v, int i, int i1) {
protected void renderBg(GuiGraphics guiGraphics, float v, int i, int i1) {
throw new IllegalCallerException("This method should not be called !");
}
@ -89,78 +90,17 @@ public class MovingBlockEntityScreen extends AbstractContainerScreen<MovingBlock
}
@Override
public void renderTooltip(PoseStack poseStack, List<? extends FormattedCharSequence> lines, int x, int y, Font font) {
getScreen().renderTooltip(poseStack, lines, x, y, font);
public void renderWithTooltip(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
getScreen().renderWithTooltip(pGuiGraphics, pMouseX, pMouseY, pPartialTick);
getMenu().getHelper().renderWithTooltip(this,pGuiGraphics,pMouseX,pMouseY,pPartialTick);
}
@Override
public void renderTooltip(PoseStack pPoseStack, List<? extends FormattedCharSequence> pTooltips, int pMouseX, int pMouseY) {
getScreen().renderTooltip(pPoseStack, pTooltips, pMouseX, pMouseY);
public void drawContent(GuiGraphics guiGraphics,String key,int x,int y,Object... objects) {
guiGraphics.renderTooltip(font,Component.translatable(key,objects),x,y);
}
@Override
public void renderTooltip(PoseStack pPoseStack, Component pText, int pMouseX, int pMouseY) {
getScreen().renderTooltip(pPoseStack, pText, pMouseX, pMouseY);
}
@Override
public void renderTooltip(PoseStack poseStack, List<Component> textComponents, Optional<TooltipComponent> tooltipComponent, int x, int y, @Nullable Font font) {
getScreen().renderTooltip(poseStack, textComponents, tooltipComponent, x, y, font);
}
@Override
public void renderTooltip(PoseStack pPoseStack, List<Component> pTooltips, Optional<TooltipComponent> pVisualTooltipComponent, int pMouseX, int pMouseY) {
getScreen().renderTooltip(pPoseStack,pTooltips,pVisualTooltipComponent,pMouseX,pMouseY);
}
@Override
public void renderTooltip(PoseStack poseStack, List<Component> textComponents, Optional<TooltipComponent> tooltipComponent, int x, int y, ItemStack stack) {
getScreen().renderTooltip(poseStack,textComponents,tooltipComponent,x,y);
}
@Override
public void renderTooltip(PoseStack poseStack, List<Component> textComponents, Optional<TooltipComponent> tooltipComponent, int x, int y, @Nullable Font font, ItemStack stack) {
getScreen().renderTooltip(poseStack,textComponents,tooltipComponent,x,y);
}
@Override
public List<Component> getTooltipFromItem(ItemStack pItemStack) {
return getScreen().getTooltipFromItem(pItemStack);
}
@Override
public void renderBackground(PoseStack pPoseStack) {
getScreen().renderBackground(pPoseStack);
}
@Override
public void renderBackground(PoseStack pPoseStack, int pVOffset) {
getScreen().renderBackground(pPoseStack,pVOffset);
}
@Override
public void renderComponentTooltip(PoseStack pPoseStack, List<Component> pTooltips, int pMouseX, int pMouseY) {
getScreen().renderComponentTooltip(pPoseStack,pTooltips,pMouseX,pMouseY);
}
@Override
public void renderComponentTooltip(PoseStack poseStack, List<? extends FormattedText> tooltips, int mouseX, int mouseY, @Nullable Font font) {
getScreen().renderComponentTooltip(poseStack,tooltips,mouseX,mouseY,font);
}
@Override
public void renderComponentTooltip(PoseStack poseStack, List<? extends FormattedText> tooltips, int mouseX, int mouseY, ItemStack stack) {
getScreen().renderComponentTooltip(poseStack,tooltips,mouseX,mouseY,stack);
}
@Override
public void renderComponentTooltip(PoseStack poseStack, List<? extends FormattedText> tooltips, int mouseX, int mouseY, @Nullable Font font, ItemStack stack) {
getScreen().renderComponentTooltip(poseStack,tooltips,mouseX,mouseY,font,stack);
}
@Override
public void renderDirtBackground(int pVOffset) {
getScreen().renderDirtBackground(pVOffset);
public Font getFont() {
return font;
}
@Override

View File

@ -12,11 +12,14 @@ import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.smartercontraptionstorage.Utils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public interface ContraptionMenuProvider<T extends AbstractContainerMenu> extends MenuProvider {
@OnlyIn(Dist.CLIENT)
@Override
@NotNull T createMenu(int i, Inventory inventory, Player player);
@ -47,7 +50,7 @@ public interface ContraptionMenuProvider<T extends AbstractContainerMenu> extend
void writeToBuffer(@NotNull FriendlyByteBuf buffer);
default void playSound(Level level){
level.playSound(null, new BlockPos(getSoundPos()), SoundEvents.BARREL_OPEN, SoundSource.BLOCKS, 0.75f, 1.0f);
level.playSound(null, BlockPos.containing(getSoundPos()), SoundEvents.BARREL_OPEN, SoundSource.BLOCKS, 0.75f, 1.0f);
}
default Vec3 getSoundPos(){

View File

@ -85,12 +85,12 @@ public abstract class AbstractMovingMenu<T extends ItemStackHandler & MovingMenu
}
public void playSound(@NotNull Player player, SoundEvent soundEvent) {
player.level.playSound(player,player,soundEvent, SoundSource.BLOCKS,0.75f,1f);
player.getCommandSenderWorld().playSound(player,player,soundEvent, SoundSource.BLOCKS,0.75f,1f);
}
@Override
public void removed(Player pPlayer) {
super.removed(pPlayer);
getHandler().removed(this, pPlayer);
public void removed(Player player) {
super.removed(player);
getHandler().removed(this, player);
}
}

View File

@ -2,16 +2,20 @@ package net.smartercontraptionstorage.AddStorage.GUI.NormalMenu;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
import com.mojang.math.Matrix4f;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import org.jetbrains.annotations.NotNull;
import org.joml.Matrix4f;
import javax.annotation.Nullable;
public abstract class AbstractMovingScreen<T extends AbstractMovingMenu<?>> extends AbstractContainerScreen<T>{
@Nullable private ResourceLocation bindTexture;
public AbstractMovingScreen(T menu, Inventory inventory, Component title) {
super(menu, inventory, title);
}
@ -24,28 +28,27 @@ public abstract class AbstractMovingScreen<T extends AbstractMovingMenu<?>> exte
}
@Override
protected void renderBg(@NotNull PoseStack poseStack, float v, int mouseX, int mouseY) {
renderBackground(poseStack);
poseStack.pushPose();
protected void renderBg(GuiGraphics guiGraphics, float v, int mouseX, int mouseY) {
renderBackground(guiGraphics);
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
drawTexture(getBackground(),poseStack,leftPos,topPos,width() + leftPos,height() + topPos,getTextureLeft(),getTextureTop(),getTextureLeft() + getTextureWidth(),getTextureTop() + getTextureHeight());
renderScreen(poseStack, v, mouseX, mouseY);
drawTexture(getBackground(),guiGraphics,leftPos,topPos,width() + leftPos,height() + topPos,getTextureLeft(),getTextureTop(),getTextureLeft() + getTextureWidth(),getTextureTop() + getTextureHeight());
renderScreen(guiGraphics, v, mouseX, mouseY);
}
@Override
public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTick) {
super.render(poseStack, mouseX, mouseY, partialTick);
renderTooltip(poseStack, mouseX, mouseY);
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
super.render(guiGraphics, mouseX, mouseY, partialTick);
renderTooltip(guiGraphics, mouseX, mouseY);
}
protected abstract void renderScreen(PoseStack poseStack, float partialTicks, int mouseX, int mouseY);
protected abstract void renderScreen(GuiGraphics guiGraphics, float partialTicks, int mouseX, int mouseY);
public void drawTexture(ResourceLocation texture,PoseStack poseStack, float left, float top, float right, float bottom, float textureLeft, float textureTop, float textureRight, float textureBottom) {
public void drawTexture(ResourceLocation texture,GuiGraphics guiGraphics, float left, float top, float right, float bottom, float textureLeft, float textureTop, float textureRight, float textureBottom) {
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
bindTexture(texture);
Matrix4f matrix = poseStack.last().pose();
Matrix4f matrix = guiGraphics.pose().last().pose();
Tesselator tesselator = Tesselator.getInstance();
BufferBuilder buffer = tesselator.getBuilder();
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX);
@ -56,12 +59,15 @@ public abstract class AbstractMovingScreen<T extends AbstractMovingMenu<?>> exte
tesselator.end();
}
public void bindTexture(ResourceLocation location) {
RenderSystem.setShaderTexture(0, location);
public void bindTexture(@Nullable ResourceLocation location) {
if (location != null)
RenderSystem.setShaderTexture(0, location);
bindTexture = location;
}
public void blit(int x, int y, float u, float v, int width, int height, int textureWidth, int textureHeight,PoseStack poseStack){
blit(poseStack, getXofScreen(x), getYofScreen(y), u, v, width, height, textureWidth, textureHeight);
public void blit(int x, int y, float u, float v, int width, int height, int textureWidth, int textureHeight,GuiGraphics guiGraphics){
if(bindTexture != null)
guiGraphics.blit(bindTexture,x,y,u,v,width,height,textureWidth,textureHeight);
}
public abstract ResourceLocation getBackground();
@ -71,8 +77,8 @@ public abstract class AbstractMovingScreen<T extends AbstractMovingMenu<?>> exte
titleLabelY = y;
}
public void drawContent(PoseStack poseStack,String key,float x,float y,Object... objects) {
font.draw(poseStack,Component.translatable(key,objects),x,y,4210752);
public void drawContent(GuiGraphics guiGraphics,String key,float x,float y,Object... objects) {
guiGraphics.drawString(font,Component.translatable(key,objects).getString(),x,y,4210752,false);
}
public int getCenterX(){

View File

@ -6,7 +6,7 @@ import net.minecraft.world.entity.player.Player;
import net.smartercontraptionstorage.AddStorage.ItemHandler.CompactingHandlerHelper;
import org.jetbrains.annotations.NotNull;
public class MovingCompactingDrawerMenu extends MovingDrawerMenu{
public class MovingCompactingDrawerMenu extends MovingDrawerMenu {
public MovingCompactingDrawerMenu(CompactingHandlerHelper.@NotNull CompactingHandler handler, int pContainerId, @NotNull Player player) {
super(handler, pContainerId, player);
}

View File

@ -1,6 +1,6 @@
package net.smartercontraptionstorage.AddStorage.GUI.NormalMenu;
import com.jaquadro.minecraft.storagedrawers.client.renderer.StorageRenderItem;
import com.jaquadro.minecraft.storagedrawers.client.gui.StorageGuiGraphics;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
@ -17,11 +17,11 @@ import java.util.function.Function;
public class MovingDrawerMenu extends AbstractMovingMenu<DrawersHandlerHelper.NormalDrawerHandler>{
@OnlyIn(Dist.CLIENT)
public StorageRenderItem activeRenderItem;
public StorageGuiGraphics storageGuiGraphics;
private final boolean isClient;
public MovingDrawerMenu(@NotNull DrawersHandlerHelper.NormalDrawerHandler handler, int pContainerId, @NotNull Player player) {
super(handler, pContainerId, player);
isClient = player.level.isClientSide();
isClient = player.getCommandSenderWorld().isClientSide();
}
public MovingDrawerMenu(int id, Inventory inventory, FriendlyByteBuf buf) {
@ -30,7 +30,7 @@ public class MovingDrawerMenu extends AbstractMovingMenu<DrawersHandlerHelper.No
public MovingDrawerMenu(int id, Inventory inventory, FriendlyByteBuf buf, Function<FriendlyByteBuf,DrawersHandlerHelper.NormalDrawerHandler> getHandler){
super(id,inventory,buf,getHandler);
isClient = inventory.player.level.isClientSide();
isClient = inventory.player.getCommandSenderWorld().isClientSide();
}
@Override
@ -62,7 +62,7 @@ public class MovingDrawerMenu extends AbstractMovingMenu<DrawersHandlerHelper.No
for (int column = 0; column < 7; column++) {
h = new ItemStackHandler();
h.setStackInSlot(0,getHandler().getUpgrades(column));
addSlot(new UnchangeableSlot(h,0,26 + column * 18, 86));
addSlot(new net.smartercontraptionstorage.AddStorage.GUI.UnchangeableSlot(h,0,26 + column * 18, 86));
}
}
@ -76,8 +76,8 @@ public class MovingDrawerMenu extends AbstractMovingMenu<DrawersHandlerHelper.No
}
public void setLastAccessedItem(ItemStack stack) {
if (this.isClient() && this.activeRenderItem != null) {
this.activeRenderItem.overrideStack = stack;
if (this.isClient() && this.storageGuiGraphics != null) {
this.storageGuiGraphics.overrideStack = stack;
}
}

View File

@ -1,8 +1,9 @@
package net.smartercontraptionstorage.AddStorage.GUI.NormalMenu;
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
import com.jaquadro.minecraft.storagedrawers.client.renderer.StorageRenderItem;
import com.jaquadro.minecraft.storagedrawers.client.gui.StorageGuiGraphics;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.Component;
@ -17,7 +18,7 @@ public class MovingDrawerScreen extends AbstractMovingScreen<MovingDrawerMenu>{
public static final ResourceLocation BACKGROUND_4 = new ResourceLocation(StorageDrawers.MOD_ID,"textures/gui/drawers_4.png");
protected static StorageRenderItem storageItemRender;
protected static StorageGuiGraphics storageGuiGraphics;
public MovingDrawerScreen(MovingDrawerMenu menu, Inventory inventory, Component title) {
super(menu, inventory, title);
@ -30,38 +31,31 @@ public class MovingDrawerScreen extends AbstractMovingScreen<MovingDrawerMenu>{
titleLabelY = 6;
inventoryLabelX = 8;
inventoryLabelY = 105;
if(storageItemRender == null && minecraft != null)
storageItemRender = new StorageRenderItem(minecraft.getTextureManager(), minecraft.getItemRenderer().getItemModelShaper().getModelManager(), minecraft.getItemColors());
if(storageGuiGraphics == null && minecraft != null)
storageGuiGraphics = new StorageGuiGraphics(minecraft,minecraft.renderBuffers().bufferSource());
}
@Override
public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTicks) {
ItemRenderer preRender = setItemRender(storageItemRender);
menu.activeRenderItem = storageItemRender;
super.render(poseStack, mouseX, mouseY, partialTicks);
menu.activeRenderItem = null;
storageItemRender.overrideStack = ItemStack.EMPTY;
setItemRender(preRender);
}
protected ItemRenderer setItemRender(ItemRenderer renderItem) {
ItemRenderer prev = this.itemRenderer;
this.itemRenderer = renderItem;
return prev;
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
menu.storageGuiGraphics = storageGuiGraphics;
super.render(guiGraphics, mouseX, mouseY, partialTick);
menu.storageGuiGraphics = null;
storageGuiGraphics.overrideStack = ItemStack.EMPTY;
}
@Override
protected void renderScreen(PoseStack poseStack, float partialTicks, int mouseX, int mouseY) {}
protected void renderScreen(GuiGraphics guiGraphics, float partialTicks, int mouseX, int mouseY) {}
@Override
protected void renderLabels(PoseStack poseStack, int mouseX, int mouseY) {
super.renderLabels(poseStack, mouseX, mouseY);
drawContent(poseStack,"container.storagedrawers.upgrades",8f,75f);
protected void renderLabels(GuiGraphics guiGraphics, int mouseX, int mouseY) {
super.renderLabels(guiGraphics, mouseX, mouseY);
drawContent(guiGraphics,"container.storagedrawers.upgrades",8f,75f);
}
@Override
public void drawContent(PoseStack poseStack, String key, float x, float y, Object... objects) {
font.draw(poseStack, I18n.get(key,objects), x, y, 4210752);
public void drawContent(GuiGraphics guiGraphics, String key, float x, float y, Object... objects) {
guiGraphics.drawString(font,I18n.get("container.storagedrawers.upgrades", objects),x,y,4210752,false);
}
@Override

View File

@ -23,11 +23,11 @@ public class MovingFunctionalCompactingMenu extends AbstractMovingMenu<Functiona
@Override
public void addSlots() {
addSlot(UnchangeableSlot.create(getHandler().upgrades.get(0),10,70));
addSlot(UnchangeableSlot.create(getHandler().upgrades.get(1),28,70));
addSlot(UnchangeableSlot.create(getHandler().upgrades.get(2),46,70));
addSlot(UnchangeableSlot.create(getHandler().upgrades.get(3),114,70));
addSlot(UnchangeableSlot.create(getHandler().upgrades.get(4),132,70));
addSlot(net.smartercontraptionstorage.AddStorage.GUI.UnchangeableSlot.create(getHandler().upgrades.get(0),10,70));
addSlot(net.smartercontraptionstorage.AddStorage.GUI.UnchangeableSlot.create(getHandler().upgrades.get(1),28,70));
addSlot(net.smartercontraptionstorage.AddStorage.GUI.UnchangeableSlot.create(getHandler().upgrades.get(2),46,70));
addSlot(net.smartercontraptionstorage.AddStorage.GUI.UnchangeableSlot.create(getHandler().upgrades.get(3),114,70));
addSlot(net.smartercontraptionstorage.AddStorage.GUI.UnchangeableSlot.create(getHandler().upgrades.get(4),132,70));
addSlot(UnchangeableSlot.create(getHandler().upgrades.get(5),150,70));
}

View File

@ -2,7 +2,7 @@ package net.smartercontraptionstorage.AddStorage.GUI.NormalMenu;
import com.buuz135.functionalstorage.FunctionalStorage;
import com.buuz135.functionalstorage.client.gui.DrawerInfoGuiAddon;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;
@ -10,7 +10,7 @@ import net.smartercontraptionstorage.Utils;
import org.apache.commons.lang3.tuple.Pair;
public class MovingFunctionalCompactingScreen extends AbstractMovingScreen<MovingFunctionalCompactingMenu>{
public static final ResourceLocation TEXTURE = new ResourceLocation(FunctionalStorage.MOD_ID, "textures/blocks/compacting_drawer_front.png");
public static final ResourceLocation TEXTURE = new ResourceLocation(FunctionalStorage.MOD_ID, "textures/block/compacting_drawer_front.png");
public DrawerInfoGuiAddon inventorySlot;
public MovingFunctionalCompactingScreen(MovingFunctionalCompactingMenu menu, Inventory inventory, Component title) {
super(menu, inventory, title);
@ -44,16 +44,16 @@ public class MovingFunctionalCompactingScreen extends AbstractMovingScreen<Movin
}
@Override
protected void renderScreen(PoseStack poseStack, float partialTicks, int mouseX, int mouseY) {
protected void renderScreen(GuiGraphics guiGraphics, float partialTicks, int mouseX, int mouseY) {
if (inventorySlot != null) {
inventorySlot.drawBackgroundLayer(poseStack,this,null,getGuiLeft(),getGuiTop(),mouseX,mouseY,partialTicks);
inventorySlot.drawBackgroundLayer(guiGraphics,this,null,getGuiLeft(),getGuiTop(),mouseX,mouseY,partialTicks);
}
bindTexture(MovingFunctionalDrawerScreen.BACKGROUND);
for (int slot = 0; slot < 3; slot++) {
blit(8 + slot * 18,68,0f,height(),20,20,256,256,poseStack);
blit(getXofScreen(8 + slot * 18),getYofScreen(68),0f,height(),20,20,256,256,guiGraphics);
}
for (int slot = 0; slot < 3; slot++) {
blit(112 + slot * 18,68,0f,height(),20,20,256,256,poseStack);
blit(getXofScreen(112 + slot * 18),getYofScreen(68),0f,height(),20,20,256,256,guiGraphics);
}
}
@ -63,13 +63,13 @@ public class MovingFunctionalCompactingScreen extends AbstractMovingScreen<Movin
}
@Override
protected void renderLabels(PoseStack poseStack, int mouseX, int mouseY) {
super.renderLabels(poseStack, mouseX, mouseY);
protected void renderLabels(GuiGraphics guiGraphics, int mouseX, int mouseY) {
super.renderLabels(guiGraphics, mouseX, mouseY);
if(inventorySlot != null) {
inventorySlot.drawForegroundLayer(poseStack,this,null,getGuiLeft(),getGuiTop(),mouseX,mouseY,this.minecraft.getDeltaFrameTime());
inventorySlot.drawForegroundLayer(guiGraphics,this,null,getGuiLeft(),getGuiTop(),mouseX,mouseY,this.minecraft.getDeltaFrameTime());
}
drawContent(poseStack,"key.categories.storage",10,59);
drawContent(poseStack,"key.categories.utility",114,59);
drawContent(guiGraphics,"key.categories.storage",10,59);
drawContent(guiGraphics,"key.categories.utility",114,59);
}
@Override

View File

@ -25,15 +25,15 @@ public class MovingFunctionalDrawerMenu extends AbstractMovingMenu<FunctionalDra
@Override
public void addSlots() {
for (int slot = 0; slot < getHandlerSlot(); slot++) {
// to synchronizeToClient handler
// to synchronize handler
addSlot(new SlotItemHandler(getHandler(),slot,Integer.MAX_VALUE,Integer.MAX_VALUE));
}
addSlot(UnchangeableSlot.create(getHandler().upgrades.get(0),10,70));
addSlot(UnchangeableSlot.create(getHandler().upgrades.get(1),28,70));
addSlot(UnchangeableSlot.create(getHandler().upgrades.get(2),46,70));
addSlot(UnchangeableSlot.create(getHandler().upgrades.get(3),64,70));
addSlot(UnchangeableSlot.create(getHandler().upgrades.get(4),114,70));
addSlot(UnchangeableSlot.create(getHandler().upgrades.get(5),132,70));
addSlot(net.smartercontraptionstorage.AddStorage.GUI.UnchangeableSlot.create(getHandler().upgrades.get(0),10,70));
addSlot(net.smartercontraptionstorage.AddStorage.GUI.UnchangeableSlot.create(getHandler().upgrades.get(1),28,70));
addSlot(net.smartercontraptionstorage.AddStorage.GUI.UnchangeableSlot.create(getHandler().upgrades.get(2),46,70));
addSlot(net.smartercontraptionstorage.AddStorage.GUI.UnchangeableSlot.create(getHandler().upgrades.get(3),64,70));
addSlot(net.smartercontraptionstorage.AddStorage.GUI.UnchangeableSlot.create(getHandler().upgrades.get(4),114,70));
addSlot(net.smartercontraptionstorage.AddStorage.GUI.UnchangeableSlot.create(getHandler().upgrades.get(5),132,70));
addSlot(UnchangeableSlot.create(getHandler().upgrades.get(6),150,70));
}

View File

@ -4,6 +4,7 @@ import com.buuz135.functionalstorage.FunctionalStorage;
import com.buuz135.functionalstorage.client.gui.DrawerInfoGuiAddon;
import com.hrznstudio.titanium.Titanium;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;
@ -12,7 +13,7 @@ import org.apache.commons.lang3.tuple.Pair;
public class MovingFunctionalDrawerScreen extends AbstractMovingScreen<MovingFunctionalDrawerMenu>{
public static final ResourceLocation BACKGROUND = new ResourceLocation(Titanium.MODID, "textures/gui/background.png");
public static final ResourceLocation TEXTURE = new ResourceLocation(FunctionalStorage.MOD_ID,"textures/blocks/oak_front_1.png");
public static final ResourceLocation TEXTURE = new ResourceLocation(FunctionalStorage.MOD_ID,"textures/block/oak_front_1.png");
public DrawerInfoGuiAddon inventorySlot;
public MovingFunctionalDrawerScreen(MovingFunctionalDrawerMenu menu, Inventory inventory, Component title) {
super(menu, inventory, title);
@ -50,27 +51,27 @@ public class MovingFunctionalDrawerScreen extends AbstractMovingScreen<MovingFun
}
@Override
protected void renderScreen(PoseStack poseStack, float partialTicks, int mouseX, int mouseY) {
protected void renderScreen(GuiGraphics guiGraphics, float partialTicks, int mouseX, int mouseY) {
if (inventorySlot != null) {
inventorySlot.drawBackgroundLayer(poseStack,this,null,getGuiLeft(),getGuiTop(),mouseX,mouseY,partialTicks);
inventorySlot.drawBackgroundLayer(guiGraphics,this,null,getGuiLeft(),getGuiTop(),mouseX,mouseY,partialTicks);
}
bindTexture(BACKGROUND);
for (int slot = 0; slot < 4; slot++) {
blit(8 + slot * 18,68,0f,height(),20,20,256,256,poseStack);
blit(getXofScreen(8 + slot * 18),getYofScreen(68),0f,height(),20,20,256,256,guiGraphics);
}
for (int slot = 0; slot < 3; slot++) {
blit(112 + slot * 18,68,0f,height(),20,20,256,256,poseStack);
blit(getXofScreen(112 + slot * 18),getYofScreen(68),0f,height(),20,20,256,256,guiGraphics);
}
}
@Override
protected void renderLabels(PoseStack poseStack, int mouseX, int mouseY) {
super.renderLabels(poseStack, mouseX, mouseY);
protected void renderLabels(GuiGraphics guiGraphics, int mouseX, int mouseY) {
super.renderLabels(guiGraphics, mouseX, mouseY);
if(inventorySlot != null) {
inventorySlot.drawForegroundLayer(poseStack,this,null,getGuiLeft(),getGuiTop(),mouseX,mouseY,this.minecraft.getDeltaFrameTime());
inventorySlot.drawForegroundLayer(guiGraphics,this,null,getGuiLeft(),getGuiTop(),mouseX,mouseY,this.minecraft.getDeltaFrameTime());
}
drawContent(poseStack,"key.categories.storage",10,59);
drawContent(poseStack,"key.categories.utility",114,59);
drawContent(guiGraphics,"key.categories.storage",10,59);
drawContent(guiGraphics,"key.categories.utility",114,59);
}
@Override

View File

@ -1,7 +1,9 @@
package net.smartercontraptionstorage.AddStorage.GUI.NormalMenu;
import com.mojang.blaze3d.vertex.*;
import com.supermartijn642.core.gui.widget.MutableWidgetRenderContext;
import com.supermartijn642.trashcans.screen.WhitelistButton;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;
@ -14,6 +16,8 @@ public class MovingTrashCanScreen extends AbstractMovingScreen<MovingTrashCanMen
public static final int BUTTON_Y_IN_SCREEN = MovingTrashCanMenu.height - 118;
private static final MutableWidgetRenderContext widgetRender = MutableWidgetRenderContext.create();
public WhitelistButton BUTTON;
public MovingTrashCanScreen(MovingTrashCanMenu menu, Inventory inventory, Component title) {
@ -32,20 +36,20 @@ public class MovingTrashCanScreen extends AbstractMovingScreen<MovingTrashCanMen
}
@Override
protected void renderScreen(PoseStack poseStack, float partialTicks, int mouseX, int mouseY) {
protected void renderScreen(GuiGraphics guiGraphics, float partialTicks, int mouseX, int mouseY) {
BUTTON.setFocused(checkButtonFocused(mouseX,mouseY));
BUTTON.render(poseStack, mouseX, mouseY);
BUTTON.render(getWidgetRender(guiGraphics, partialTicks), mouseX, mouseY);
}
@Override
protected void renderLabels(PoseStack poseStack, int mouseX, int mouseY) {
super.renderLabels(poseStack, mouseX, mouseY);
protected void renderLabels(GuiGraphics guiGraphics, int mouseX, int mouseY) {
super.renderLabels(guiGraphics, mouseX, mouseY);
if(menu.getToolboxNumber() == 0) {
MutableComponent text = Component.translatable("trashcans.gui.liquid_trash_can.filter");
if(!menu.getHandler().toolboxItem.isEmpty())
text.append(Component.translatable("smartercontraptionstorage.moving_container.trashcans.scrolling"));
font.draw(poseStack, text, 8f, 52f, 4210752);
} else drawContent(poseStack,"smartercontraptionstorage.moving_container.trashcans.toolbox",8f,52f,menu.getToolboxNumber());
guiGraphics.drawString(font,text.getString(),8f,52f,4210752,false);
} else drawContent(guiGraphics,"smartercontraptionstorage.moving_container.trashcans.toolbox",8f,52f,menu.getToolboxNumber());
}
protected boolean checkButtonFocused(double mouseX, double mouseY) {
@ -97,4 +101,9 @@ public class MovingTrashCanScreen extends AbstractMovingScreen<MovingTrashCanMen
}
return true;
}
public static MutableWidgetRenderContext getWidgetRender(GuiGraphics guiGraphics, float partialTicks){
widgetRender.update(guiGraphics, partialTicks);
return widgetRender;
}
}

View File

@ -0,0 +1,30 @@
package net.smartercontraptionstorage.AddStorage.GUI.NormalMenu;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemStackHandler;
import net.minecraftforge.items.SlotItemHandler;
import org.jetbrains.annotations.NotNull;
public class UnchangeableSlot extends SlotItemHandler {
public UnchangeableSlot(IItemHandler itemHandler, int index, int xPosition, int yPosition) {
super(itemHandler, index, xPosition, yPosition);
}
public static UnchangeableSlot create(ItemStack stack, int xPosition, int yPosition) {
ItemStackHandler handler = new ItemStackHandler();
handler.setStackInSlot(0, stack);
return new UnchangeableSlot(handler, 0, xPosition, yPosition);
}
@Override
public boolean mayPickup(Player playerIn) {
return false;
}
@Override
public boolean mayPlace(@NotNull ItemStack stack) {
return false;
}
}

View File

@ -1,12 +1,10 @@
package net.smartercontraptionstorage.AddStorage.ItemHandler;
import appeng.api.config.Actionable;
import appeng.api.features.Locatables;
import appeng.api.implementations.parts.ICablePart;
import appeng.api.inventories.InternalInventory;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridNode;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.storage.IStorageService;
import appeng.api.parts.IPart;
import appeng.api.stacks.AEItemKey;
@ -37,7 +35,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.OptionalLong;
public class AE2BusBlockHelper extends StorageHandlerHelper{
@Override
@ -50,49 +47,55 @@ public class AE2BusBlockHelper extends StorageHandlerHelper{
@Override
public @NotNull ItemStackHandler createHandler(BlockEntity entity) {
assert canCreateHandler(entity);
assert this.canCreateHandler(entity);
CableBusBlockEntity bus = (CableBusBlockEntity)entity;
ICablePart center = (ICablePart)bus.getPart(null);
if(center == null || center.getCableConnectionType() != AECableType.COVERED)
return NULL_HANDLER;// Must use covered_cable
ConfigInventory config;
AEKey key;
ItemStack item;
WirelessCraftingTerminalItem terminal;
OptionalLong id;
IActionHost host,exportHost = null,importHost = null;
ICablePart center = (ICablePart)bus.getPart((Direction)null);
if (center != null && center.getCableConnectionType() == AECableType.COVERED) {
IGridNode exportHost = null;
IGridNode importHost = null;
for(IPart part : getAllPart(bus)){
if(part instanceof IOBusPart){
if(!checkUpgrade(((IOBusPart) part).getUpgrades(), AEItems.SPEED_CARD.asItem()))
continue;// Must use 4 speed_cards
config = ((IOBusPart)part).getConfig();
key = config.getKey(0);
if (key != null) {
item = key.wrapForDisplayOrFilter();
for(IPart part : getAllPart(bus)) {
if (part instanceof IOBusPart) {
if (!checkUpgrade(((IOBusPart)part).getUpgrades(), AEItems.SPEED_CARD.asItem(), 3)) {
continue;
}
if (item.getItem() instanceof WirelessCraftingTerminalItem) {
terminal = (WirelessCraftingTerminalItem) item.getItem();
if(!checkUpgrade(terminal.getUpgrades(item), AEItems.ENERGY_CARD.asItem()))
continue;// Must use 2 energy_cards
id = terminal.getGridKey(item);
if (id.isPresent()) {
host = Locatables.securityStations().get(entity.getLevel(), id.getAsLong());
if(host == null)
ConfigInventory config = ((IOBusPart)part).getConfig();
AEKey key = config.getKey(0);
if (key != null) {
ItemStack item = key.wrapForDisplayOrFilter();
if (item.getItem() instanceof WirelessCraftingTerminalItem terminal) {
if (!checkUpgrade(terminal.getUpgrades(item), AEItems.ENERGY_CARD.asItem(),3)) {
continue;
if(part instanceof ExportBusPart)
exportHost = host;
else
importHost = host;
}
IGrid id = terminal.getLinkedGrid(item, entity.getLevel(), null);
if (id != null) {
IGridNode host = id.getPivot();
if (host == null) {
continue;
}
if (part instanceof ExportBusPart) {
exportHost = host;
} else {
importHost = host;
}
}
}
}
}
if (exportHost != null && importHost != null) {
return AE2HandlerHelper.create(exportHost, importHost);
}
}
if(exportHost != null && importHost != null)
return AE2HandlerHelper.create(exportHost,importHost);
return exportHost == null && importHost == null ? NULL_HANDLER : AE2HandlerHelper.create(exportHost, importHost);
} else {
return NULL_HANDLER;
}
return exportHost == null && importHost == null ? NULL_HANDLER : AE2HandlerHelper.create(exportHost,importHost);
}
private static IPart[] getAllPart(CableBusBlockEntity bus){
@ -106,16 +109,21 @@ public class AE2BusBlockHelper extends StorageHandlerHelper{
return iParts;
}
public static boolean checkUpgrade(InternalInventory upgrade, Item targetUpgrade){
ItemStack item;
for(int i = upgrade.size() - 1;i >= 0;i--){
item = upgrade.getStackInSlot(i);
if(item == null || !item.is(targetUpgrade))
public static boolean checkUpgrade(InternalInventory upgrade, Item targetUpgrade, int size) {
for(int i = size; i >= 0; --i) {
ItemStack item = upgrade.getStackInSlot(i);
if (item.isEmpty() || !item.is(targetUpgrade)) {
return false;
}
}
return true;
}
public static boolean checkUpgrade(InternalInventory upgrade, Item targetUpgrade) {
return checkUpgrade(upgrade, targetUpgrade, upgrade.size() - 1);
}
@Override
public boolean allowControl(Item comparedItem) {
return false;
@ -149,23 +157,22 @@ public class AE2BusBlockHelper extends StorageHandlerHelper{
private boolean canWork = false;
private final AE2ContraptionSource extractSource;
private final AE2ContraptionSource importSource;
private AE2HandlerHelper(int size,@Nullable IActionHost extractHost,@Nullable IActionHost importHost) {
private AE2HandlerHelper(int size, @Nullable IGridNode extractNode, @Nullable IGridNode importNode) {
super(size);
this.extractNode = extractHost == null ? null : extractHost.getActionableNode();
this.importNode = importHost == null ? null : importHost.getActionableNode();
extractSource = new AE2ContraptionSource(extractHost);
importSource = new AE2ContraptionSource(importHost);
this.extractNode = extractNode;
this.importNode = importNode;
this.extractSource = AE2ContraptionSource.create(extractNode);
this.importSource = AE2ContraptionSource.create(importNode);
}
public static AE2HandlerHelper create(@Nullable IActionHost extractHost,@Nullable IActionHost importHost){
public static AE2HandlerHelper create(@Nullable IGridNode extractNode, @Nullable IGridNode importNode) {
IStorageService extractNet = null;
if(extractHost != null) {
IGridNode extractNode = extractHost.getActionableNode();
extractNet = extractNode == null ? null : extractNode.getGrid().getStorageService();
if (extractNode != null) {
extractNet = extractNode.getGrid().getStorageService();
}
int size = extractNet == null ? 1 : extractNet.getInventory().getAvailableStacks().size();
return new AE2HandlerHelper(size,extractHost,importHost);
int size = extractNet == null ? 1 : extractNet.getInventory().getAvailableStacks().size();
return new AE2HandlerHelper(size, extractNode, importNode);
}
public boolean canWork(boolean extractOrImport,boolean simulate){
@ -243,7 +250,7 @@ public class AE2BusBlockHelper extends StorageHandlerHelper{
return ItemStack.EMPTY;
}
public void refreshStack(@Nullable MEStorage extractStorage){// synchronizeToClient stored items in AE Net
public void refreshStack(@Nullable MEStorage extractStorage){// synchronize stored items in AE Net
if(hasFilter)
return;
extractKeys.clear();

View File

@ -73,7 +73,11 @@ public class FunctionalCompactingHandlerHelper extends StorageHandlerHelper{
@Override
public boolean allowControl(Item comparedItem) {
return comparedItem instanceof CompactingDrawerBlock.CompactingDrawerItem;
try{
return comparedItem instanceof CompactingDrawerBlock.CompactingDrawerItem;
}catch (Exception e){
return false;
}
}
@Override

View File

@ -66,7 +66,11 @@ public class FunctionalDrawersHandlerHelper extends StorageHandlerHelper{
@Override
public boolean allowControl(Item comparedItem) {
return comparedItem instanceof DrawerBlock.DrawerItem;
try{
return comparedItem instanceof DrawerBlock.DrawerItem;
}catch (Exception e){
return false;
}
}
@Override

View File

@ -1,8 +1,8 @@
package net.smartercontraptionstorage.AddStorage.ItemHandler;
import com.mojang.blaze3d.vertex.PoseStack;
import com.simibubi.create.content.contraptions.AbstractContraptionEntity;
import com.simibubi.create.foundation.utility.Pair;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
@ -15,6 +15,8 @@ import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.items.ItemStackHandler;
import net.p3pp3rf1y.sophisticatedbackpacks.backpack.BackpackBlock;
import net.p3pp3rf1y.sophisticatedbackpacks.backpack.BackpackBlockEntity;
@ -105,10 +107,10 @@ public class SBackPacksHandlerHelper extends StorageHandlerHelper implements Hel
public AbstractContainerMenu createMenu(int i, Player player, Inventory inventory) {
return MenuLevel.levelRun((setter) -> {
setter.accept(getBlockEntity());
Level level = player.level;
player.level = MenuLevel.level;
Level level = player.level();
player.setLevel(MenuLevel.level(level));
BackpackContainer container = new BackpackContainer(i, player, new BackpackContext.Block(getBlockEntity().getBlockPos()));
player.level = level;
player.setLevel(level);
return container;
});
}
@ -118,6 +120,7 @@ public class SBackPacksHandlerHelper extends StorageHandlerHelper implements Hel
return menu.getMenu() instanceof BackpackContainer;
}
@OnlyIn(Dist.CLIENT)
@Override
public BackpackScreen createScreen(MovingBlockEntityMenu menu, Inventory inventory, Component component) {
return new BackpackScreen((BackpackContainer) menu.getMenu(), inventory, component);
@ -176,18 +179,21 @@ public class SBackPacksHandlerHelper extends StorageHandlerHelper implements Hel
return getBlockEntity().getBackpackWrapper().getDisplayName();
}
@OnlyIn(Dist.CLIENT)
@Override
public boolean shouldClickScreen(MovingBlockEntityScreen screen, double mouseX, double mouseY, int button) {
return false;
}
@OnlyIn(Dist.CLIENT)
@Override
public boolean shouldClickScreen(MovingBlockEntityMenu menu, int index, int flag, ClickType type, Player player) {
return true;
}
@OnlyIn(Dist.CLIENT)
@Override
public void render(MovingBlockEntityScreen screen, PoseStack poseStack, int mouseX, int mouseY, float partialTick) {
screen.renderTooltip(poseStack,Component.translatable("smartercontraptionstorage.moving_container.backpack.reminder"), 0, screen.getScreen().getGuiTop() - 10);
public void render(MovingBlockEntityScreen screen, GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
screen.drawContent(guiGraphics,"smartercontraptionstorage.moving_container.backpack.reminder", 0, Math.max(screen.getScreen().getGuiTop() - 10,0));
}
}

View File

@ -1,185 +0,0 @@
package net.smartercontraptionstorage.AddStorage.ItemHandler;
import com.simibubi.create.content.contraptions.AbstractContraptionEntity;
import com.simibubi.create.foundation.utility.Pair;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
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.Item;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.items.ItemStackHandler;
import net.p3pp3rf1y.sophisticatedcore.inventory.InventoryHandler;
import net.p3pp3rf1y.sophisticatedcore.util.BlockItemBase;
import net.p3pp3rf1y.sophisticatedstorage.block.LimitedBarrelBlock;
import net.p3pp3rf1y.sophisticatedstorage.block.StorageBlockBase;
import net.p3pp3rf1y.sophisticatedstorage.block.StorageBlockEntity;
import net.p3pp3rf1y.sophisticatedstorage.client.gui.LimitedBarrelScreen;
import net.p3pp3rf1y.sophisticatedstorage.client.gui.StorageScreen;
import net.p3pp3rf1y.sophisticatedstorage.common.gui.LimitedBarrelContainerMenu;
import net.p3pp3rf1y.sophisticatedstorage.common.gui.StorageContainerMenu;
import net.smartercontraptionstorage.AddStorage.GUI.BlockEntityMenu.HelperMenuProvider;
import net.smartercontraptionstorage.AddStorage.GUI.BlockEntityMenu.MenuLevel;
import net.smartercontraptionstorage.AddStorage.GUI.BlockEntityMenu.MovingBlockEntityMenu;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Objects;
@Deprecated
public class SStorageBlockHelper extends StorageHandlerHelper implements HelperMenuProvider<SStorageBlockHelper> {
public static final SStorageBlockHelper INSTANCE = new SStorageBlockHelper();
@Override
public boolean canCreateHandler(BlockEntity entity) {
return entity instanceof StorageBlockEntity;
}
@Override
public void addStorageToWorld(BlockEntity entity, ItemStackHandler handler) {
assert canCreateHandler(entity);
((InventoryHandler)handler).changeSlots(0);
((StorageBlockEntity)entity).getStorageWrapper().getInventoryHandler().deserializeNBT(handler.serializeNBT());
}
@Override
public @NotNull ItemStackHandler createHandler(BlockEntity entity) {
assert canCreateHandler(entity);
return ((StorageBlockEntity)entity).getStorageWrapper().getInventoryHandler();
}
@Override
public boolean allowControl(Item comparedItem) {
return comparedItem instanceof BlockItemBase;
}
@Override
public boolean allowControl(Block block) {
return block instanceof StorageBlockBase;
}
@Override
public String getName() {
return "SStorageBlockHelper";
}
@Override
public @NotNull ItemStackHandler deserialize(CompoundTag nbt) throws IllegalAccessException {
throw new IllegalAccessException();
}
@Override
public boolean canDeserialize() {
return false;
}
@Override
public HelperMenuProvider<SStorageBlockHelper> get() {
return new SStorageBlockHelper();
}
@Override
public SStorageBlockHelper getHelper() {
return INSTANCE;
}
private StorageBlockEntity blockEntity;
@Override
public void setBlockEntity(@Nullable BlockEntity blockEntity) {
if(blockEntity instanceof StorageBlockEntity)
this.blockEntity = (StorageBlockEntity)blockEntity;
else this.blockEntity = null;
}
@Override
public StorageBlockEntity getBlockEntity() {
return blockEntity;
}
public boolean isLimitedBarrelBlock() {
return getBlockEntity().getBlockState().getBlock() instanceof LimitedBarrelBlock;
}
@Override
public AbstractContainerMenu createMenu(int i, Player player, Inventory inventory) {
StorageContainerMenu menu = null;
if(getPair() != null) {
MenuLevel.tickingBlockEntity(getPair(),player.level);
Level level = player.level;
player.level = MenuLevel.level;
menu = isLimitedBarrelBlock() ? new LimitedBarrelContainerMenu(i, player, getBlockEntity().getBlockPos()) : new StorageContainerMenu(i,player,getBlockEntity().getBlockPos());
player.level = level;
}
return menu;
}
@Override
public boolean checkMenu(MovingBlockEntityMenu menu) {
return isLimitedBarrelBlock() ? menu.getMenu() instanceof LimitedBarrelContainerMenu : menu.getMenu() instanceof StorageContainerMenu;
}
@Override
public StorageScreen createScreen(MovingBlockEntityMenu menu, Inventory inventory, Component component) {
if(isLimitedBarrelBlock()) {
return new LimitedBarrelScreen((StorageContainerMenu)menu.getMenu(),inventory,component);
}else return StorageScreen.constructScreen((StorageContainerMenu)menu.getMenu(),inventory,component);
}
private Pair<Integer, Long> pair;
@Override
public void rememberPair(Pair<Integer, Long> pair) {
this.pair = pair;
}
@Override
public Pair<Integer, Long> getPair() {
return pair;
}
private AbstractContraptionEntity contraption;
private BlockPos localPos;
@Override
public void setContraption(AbstractContraptionEntity contraption) {
this.contraption = contraption;
}
@Override
public AbstractContraptionEntity getContraption() {
return contraption;
}
@Override
public void setLocalPos(BlockPos localPos) {
this.localPos = localPos;
}
@Override
public BlockPos getLocalPos() {
return localPos;
}
private ServerPlayer player;
@Override
public void rememberPlayer(ServerPlayer player) {
this.player = player;
}
@Override
public @NotNull ServerPlayer getPlayer() {
return Objects.requireNonNull(player);
}
@Override
public @NotNull Component getDisplayName() {
return getBlockEntity().getDisplayName();
}
}

View File

@ -16,6 +16,8 @@ import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
import net.minecraftforge.items.ItemStackHandler;
import net.smartercontraptionstorage.AddStorage.GUI.BlockEntityMenu.HelperMenuProvider;
@ -45,6 +47,7 @@ public class ToolboxHandlerHelper extends StorageHandlerHelper implements NeedDe
assert canCreateHandler(entity);
return (ItemStackHandler) entity.getCapability(ForgeCapabilities.ITEM_HANDLER).orElse(NULL_HANDLER);
}
@Override
public boolean allowControl(Item comparedItem) {
return false;
@ -124,6 +127,7 @@ public class ToolboxHandlerHelper extends StorageHandlerHelper implements NeedDe
return pair;
}
@OnlyIn(Dist.CLIENT)
@Override
public ToolboxScreen createScreen(MovingBlockEntityMenu menu, Inventory inventory, Component component) {
return new ToolboxScreen((ToolboxMenu) menu.getMenu(),inventory,component);
@ -171,7 +175,7 @@ public class ToolboxHandlerHelper extends StorageHandlerHelper implements NeedDe
@Override
public void playSound(Level level) {
BlockPos soundPos = new BlockPos(getSoundPos());
BlockPos soundPos = BlockPos.containing(getSoundPos());
level.playSound(null,soundPos, SoundEvents.IRON_DOOR_OPEN, SoundSource.BLOCKS, 0.25f, level.random.nextFloat() * 0.1F + 1.2F);
level.playSound(null,soundPos,SoundEvents.CHEST_OPEN, SoundSource.BLOCKS, 0.1F, level.random.nextFloat() * 0.1F + 1.1F);
}
@ -179,9 +183,9 @@ public class ToolboxHandlerHelper extends StorageHandlerHelper implements NeedDe
@Override
public void removed(MovingBlockEntityMenu menu, Player player) {
if(check()) {
BlockPos soundPos = new BlockPos(getSoundPos());
player.level.playSound(null,soundPos, SoundEvents.CHEST_CLOSE, SoundSource.BLOCKS, 0.1F, player.level.random.nextFloat() * 0.1F + 1.1F);
player.level.playSound(null,soundPos, SoundEvents.IRON_DOOR_CLOSE, SoundSource.BLOCKS, 0.25F, player.level.random.nextFloat() * 0.1F + 1.2F);
BlockPos soundPos = BlockPos.containing(getSoundPos());
player.level().playSound(null,soundPos, SoundEvents.CHEST_CLOSE, SoundSource.BLOCKS, 0.1F, player.level().random.nextFloat() * 0.1F + 1.1F);
player.level().playSound(null,soundPos, SoundEvents.IRON_DOOR_CLOSE, SoundSource.BLOCKS, 0.25F, player.level().random.nextFloat() * 0.1F + 1.2F);
}
HelperMenuProvider.super.removed(menu, player);
}

View File

@ -15,7 +15,6 @@ import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.items.ItemStackHandler;
import net.minecraftforge.registries.RegistryObject;
import net.smartercontraptionstorage.AddStorage.GUI.NormalMenu.AbstractMovingMenu;
import net.smartercontraptionstorage.AddStorage.GUI.NormalMenu.MovingTrashCanMenu;
import net.smartercontraptionstorage.AddStorage.NeedDealWith;
import net.smartercontraptionstorage.Utils;
@ -67,7 +66,7 @@ public class TrashHandlerHelper extends StorageHandlerHelper{
return new TrashHandler(nbt);
}
public static class TrashHandler extends HandlerHelper implements NeedDealWith {
public static class TrashHandler extends HandlerHelper implements NeedDealWith{
public boolean whiteOrBlack;
public List<ItemStack> toolboxItem;
// false : black
@ -136,7 +135,7 @@ public class TrashHandlerHelper extends StorageHandlerHelper{
}
@Override
public @NotNull AbstractMovingMenu<?> createMenu(int i, Inventory inventory, Player player) {
public @NotNull MovingTrashCanMenu createMenu(int i, Inventory inventory, Player player) {
return new MovingTrashCanMenu(this,i,player);
}
@Override

View File

@ -0,0 +1,21 @@
package net.smartercontraptionstorage.AddStorage;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.items.ItemStackHandler;
import org.jetbrains.annotations.Nullable;
@Deprecated
// Cannot open GUI in each inheritor, and I don't know how to solve this.
// But I can open Minecraft's GUI such as CraftingTable and so on (replace the proper GUI it should be).
public interface MenuSupportHandler {
@Deprecated
default boolean canHandlerCreateMenu(){
return false;
}
@Deprecated
@Nullable
default MenuProvider createHandlerMenu(BlockEntity entity, ItemStackHandler handler, @Nullable Player player){
return null;
}
}

View File

@ -58,7 +58,7 @@ public abstract class ContraptionMixin implements Gettable {
List<BlockPos> list = smarterContraptionStorage$orderedBlocks.get(overlay);
if(list != null)
for (BlockPos blockPos : list) {
Optional<MutablePair<StructureTemplate.StructureBlockInfo, MovementContext>> actor = actors.stream().filter((act) -> act.getLeft().pos.equals(blockPos)).findFirst();
Optional<MutablePair<StructureTemplate.StructureBlockInfo, MovementContext>> actor = actors.stream().filter((act) -> act.getLeft().pos().equals(blockPos)).findFirst();
// I think there is no any block could be used as actor and container at the same time
// So use if-else to reduce computation
// * Toolbox and Backpack could be used both two
@ -129,7 +129,7 @@ public abstract class ContraptionMixin implements Gettable {
protected Block smarterContraptionStorage$getBlockAt(Level level, BlockPos pos){
BlockPos localPos = this.toLocalPos(pos);
if(this.blocks.containsKey(localPos))
return this.blocks.get(localPos).state.getBlock();
return this.blocks.get(localPos).state().getBlock();
else return level.getBlockState(pos).getBlock();
}
@ -140,19 +140,29 @@ public abstract class ContraptionMixin implements Gettable {
try {
if(spawnData) {
BlockPos localPos = toLocalPos(pos);
return presentBlockEntities.get(localPos);
BlockEntity entity = presentBlockEntities.get(localPos);
if(entity.getLevel() == null)
entity.setLevel(world);
return entity;
} else {
StructureTemplate.StructureBlockInfo info = blocks.get(pos);
CompoundTag tag = info.nbt;
CompoundTag tag = info.nbt();
if(tag != null) {
tag.putInt("x", info.pos.getX());
tag.putInt("y", info.pos.getY());
tag.putInt("z", info.pos.getZ());
return BlockEntity.loadStatic(info.pos,info.state,tag);
tag.putInt("x", info.pos().getX());
tag.putInt("y", info.pos().getY());
tag.putInt("z", info.pos().getZ());
BlockEntity entity = BlockEntity.loadStatic(info.pos(),info.state(),tag);
if (entity != null) {
entity.setLevel(world);
}
return entity;
} else return null;
}
} catch (Exception e) {
return presentBlockEntities.values().stream().filter(blockEntity -> blockEntity.getBlockPos().equals(pos)).findFirst().orElse(null);
BlockEntity entity = presentBlockEntities.values().stream().filter(blockEntity -> blockEntity.getBlockPos().equals(pos)).findFirst().orElse(null);
if(entity != null && entity.getLevel() == null)
entity.setLevel(world);
return entity;
}
};
}

View File

@ -127,7 +127,7 @@ public abstract class MountedStorageManagerMixin implements Changeable {
if(provider.check()){
provider.rememberPlayer((ServerPlayer) player);
NetworkHooks.openScreen((ServerPlayer) player,provider,provider::writeToBuffer);
provider.playSound(player.level);
provider.playSound(player.level());
cir.setReturnValue(true);
}else provider.error();
}

View File

@ -48,11 +48,12 @@ public enum Overlay {
TextureAtlasSprite uv;
@NotNull public final ResourceLocation location;
@NotNull public final DyeItem item;
static void register(TextureStitchEvent.Pre event){
for(Overlay overlay : Overlay.values()){
event.addSprite(overlay.getResourceLocation());
}
}
// register by json file
// static void register(TextureStitchEvent.Pre event){
// for(Overlay overlay : Overlay.values()){
// event.addSprite(overlay.getResourceLocation());
// }
// }
static void setUV(TextureStitchEvent.Post event){
TextureAtlas atlas = event.getAtlas();
for(Overlay overlay : Overlay.values()){

View File

@ -9,12 +9,13 @@ import net.smartercontraptionstorage.SmarterContraptionStorage;
@Mod.EventBusSubscriber(modid = SmarterContraptionStorage.MODID,value = {Dist.CLIENT}, bus = Mod.EventBusSubscriber.Bus.MOD)
public class Textures {
@SubscribeEvent
public static void register(TextureStitchEvent.Pre event){
if(event.getAtlas().location().equals(InventoryMenu.BLOCK_ATLAS)){
Overlay.register(event);
}
}
// register by json file
// @SubscribeEvent
// public static void register(TextureStitchEvent.Pre event){
// if(event.getAtlas().location().equals(InventoryMenu.BLOCK_ATLAS)){
// Overlay.register(event);
// }
// }
@SubscribeEvent
public static void setValue(TextureStitchEvent.Post event){
if(event.getAtlas().location().equals(InventoryMenu.BLOCK_ATLAS)){

View File

@ -0,0 +1,13 @@
package net.smartercontraptionstorage;
import java.util.Arrays;
public interface Settable {
void set(Object object);
default void set(String parameterName, Object object){
set(object);
}
default void set(Object... objects){
Arrays.stream(objects).forEach(this::set);
}
}

View File

@ -6,6 +6,8 @@ import com.simibubi.create.AllMovementBehaviours;
import com.simibubi.create.content.equipment.toolbox.ToolboxBlock;
import com.simibubi.create.foundation.ponder.PonderRegistry;
import com.tterrag.registrate.util.entry.BlockEntry;
import net.minecraftforge.registries.RegistryObject;
import net.p3pp3rf1y.sophisticatedbackpacks.backpack.BackpackBlock;
import net.smartercontraptionstorage.Message.MenuLevelPacket;
import net.smartercontraptionstorage.Message.ModMessage;
import net.minecraft.client.gui.screens.MenuScreens;
@ -39,6 +41,8 @@ import net.smartercontraptionstorage.AddStorage.ItemHandler.UnstorageHelper.MESt
import net.smartercontraptionstorage.Ponder.SCS_Ponder;
import net.smartercontraptionstorage.AddActor.ToolboxBehaviour;
import java.lang.reflect.Field;
import static net.smartercontraptionstorage.AddStorage.ItemHandler.StorageHandlerHelper.register;
import static net.smartercontraptionstorage.AddStorage.FluidHander.FluidHandlerHelper.register;
import static net.smartercontraptionstorage.Ponder.SCS_Ponder.CONTROLLABLE_CONTAINERS;
@ -103,14 +107,18 @@ public class SmarterContraptionStorage {
register(new SBackPacksFluidHandlerHelper());
BackpackBehaviour backpackBehaviour = new BackpackBehaviour();
AllMovementBehaviours.registerBehaviour(net.p3pp3rf1y.sophisticatedbackpacks.init.ModBlocks.BACKPACK.get(),backpackBehaviour);
AllMovementBehaviours.registerBehaviour(net.p3pp3rf1y.sophisticatedbackpacks.init.ModBlocks.COPPER_BACKPACK.get(),backpackBehaviour);
AllMovementBehaviours.registerBehaviour(net.p3pp3rf1y.sophisticatedbackpacks.init.ModBlocks.IRON_BACKPACK.get(),backpackBehaviour);
AllMovementBehaviours.registerBehaviour(net.p3pp3rf1y.sophisticatedbackpacks.init.ModBlocks.GOLD_BACKPACK.get(),backpackBehaviour);
AllMovementBehaviours.registerBehaviour(net.p3pp3rf1y.sophisticatedbackpacks.init.ModBlocks.DIAMOND_BACKPACK.get(),backpackBehaviour);
AllMovementBehaviours.registerBehaviour(net.p3pp3rf1y.sophisticatedbackpacks.init.ModBlocks.NETHERITE_BACKPACK.get(),backpackBehaviour);
try {// Old version of backpack didn't have copper backpack
Field copperBackpack = net.p3pp3rf1y.sophisticatedbackpacks.init.ModBlocks.class.getDeclaredField("COPPER_BACKPACK");
AllMovementBehaviours.registerBehaviour(((RegistryObject<BackpackBlock>)copperBackpack.get(net.p3pp3rf1y.sophisticatedbackpacks.init.ModBlocks.class)).get(),backpackBehaviour);
} catch (NoSuchFieldException e) {
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
// if(list.isLoaded("sophisticatedstorage"))
// register(SStorageBlockHelper.INSTANCE);
if(list.isLoaded("functionalstorage")){
register(new FunctionalDrawersHandlerHelper());
register(new FunctionalCompactingHandlerHelper());
@ -140,14 +148,18 @@ public class SmarterContraptionStorage {
// Some client setup code
ModList list = ModList.get();
if(list.isLoaded("create")){
MenuScreens.register(MovingBlockEntityMenu.BlockEntityMenu.get(), MovingBlockEntityScreen::new);
register(ToolboxHandlerHelper.INSTANCE);
SCS_Ponder.register();
if(list.isLoaded("trashcans")) {
MenuScreens.register(TrashHandlerHelper.TrashHandler.TrashCanMenu.get(), MovingTrashCanScreen::new);
register(new TrashHandlerHelper());
register(new TrashcanFluidHelper());
SCS_Ponder.registerTrashCan();
}
if(list.isLoaded("storagedrawers")) {
MenuScreens.register(DrawersHandlerHelper.NormalDrawerHandler.DrawerMenu.get(), MovingDrawerScreen::new);
MenuScreens.register(CompactingHandlerHelper.CompactingHandler.CompactingDrawerMenu.get(), MovingCompactingDrawerScreen::new);
register(new DrawersHandlerHelper());
register(new CompactingHandlerHelper());
PonderRegistry.TAGS.forTag(CONTROLLABLE_CONTAINERS).add(ModBlocks.CONTROLLER.get());
@ -166,30 +178,14 @@ public class SmarterContraptionStorage {
register(SBackPacksHandlerHelper.INSTANCE);
register(new SBackPacksFluidHandlerHelper());
}
// if(list.isLoaded("sophisticatedstorage"))
// register(SStorageBlockHelper.INSTANCE);
if(list.isLoaded("functionalstorage")){
MenuScreens.register(FunctionalDrawersHandlerHelper.FDrawersHandler.MENU_TYPE.get(),MovingFunctionalDrawerScreen::new);
MenuScreens.register(FunctionalCompactingHandlerHelper.FCDrawersHandler.MENU_TYPE.get(),MovingFunctionalCompactingScreen::new);
register(new FunctionalDrawersHandlerHelper());
register(new FunctionalCompactingHandlerHelper());
register(new FunctionalFluidHandlerHelper());
}
}
event.enqueueWork(() -> {
if(list.isLoaded("create")){
MenuScreens.register(MovingBlockEntityMenu.BlockEntityMenu.get(), MovingBlockEntityScreen::new);
if(list.isLoaded("trashcans")) {
MenuScreens.register(TrashHandlerHelper.TrashHandler.TrashCanMenu.get(), MovingTrashCanScreen::new);
}
if(list.isLoaded("storagedrawers")){
MenuScreens.register(DrawersHandlerHelper.NormalDrawerHandler.DrawerMenu.get(), MovingDrawerScreen::new);
MenuScreens.register(CompactingHandlerHelper.CompactingHandler.CompactingDrawerMenu.get(), MovingCompactingDrawerScreen::new);
}
if(list.isLoaded("functionalstorage")){
MenuScreens.register(FunctionalDrawersHandlerHelper.FDrawersHandler.MENU_TYPE.get(),MovingFunctionalDrawerScreen::new);
MenuScreens.register(FunctionalCompactingHandlerHelper.FCDrawersHandler.MENU_TYPE.get(),MovingFunctionalCompactingScreen::new);
}
}
});
}
}
}

View File

@ -6,7 +6,6 @@ public class SmarterContraptionStorageConfig {
public static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
public static final ForgeConfigSpec SPEC;
public static final ForgeConfigSpec.BooleanValue DEFAULT_OPEN;
public static final ForgeConfigSpec.BooleanValue CHECK_ADJACENT_BLOCK;
public static final ForgeConfigSpec.BooleanValue AUTO_DUMPING;
public static final ForgeConfigSpec.ConfigValue<Integer> SEARCH_RANGE;
public static final ForgeConfigSpec.BooleanValue AE2SUPPORT;
@ -20,7 +19,6 @@ public class SmarterContraptionStorageConfig {
If you set it false, your block will close by default,also,as the result you can't open it until they become block.
And in any circumstances you can use Contraption Control Block to change the action it performed
""").define("DefaultOpen",true);
CHECK_ADJACENT_BLOCK = BUILDER.comment("Check neighboring storage block automatically (such as Vault):").define("CheckAdjacentBlock",true);
SEARCH_RANGE = BUILDER.comment("Search range for neighboring block (best bigger than 9, because Vault maxsize is 9)").define("SearchRange",10);
AUTO_DUMPING = BUILDER.comment("""
When contraption want to store any item which can save fluid (such as water bucket),

View File

@ -2,8 +2,6 @@ package net.smartercontraptionstorage;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Matrix4f;
import com.mojang.math.Quaternion;
import com.simibubi.create.content.logistics.vault.ItemVaultBlock;
import com.simibubi.create.content.logistics.vault.ItemVaultItem;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
@ -31,6 +29,8 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.joml.Matrix4f;
import org.joml.Quaternionf;
import java.awt.*;
import java.util.*;
@ -224,7 +224,7 @@ public final class Utils {
}
public static void rotate(PoseStack poseStack, Direction direction,float degrees){
poseStack.translate(0.5f,0.5f,0.5f);
poseStack.mulPose(new Quaternion(direction.step(),degrees,true));
poseStack.mulPose(new Quaternionf().fromAxisAngleDeg(direction.step(),degrees));
poseStack.translate(-0.5f,-0.5f,-0.5f);
}
public static int calcHorizonDegrees(Direction tragetDirection,Direction facing){

View File

@ -1,4 +1,6 @@
public-f net.minecraft.client.gui.screens.Screen m_6575_(Lnet/minecraft/client/Minecraft;II)V # init
public-f net.minecraft.client.gui.screens.inventory.AbstractContainerScreen m_86600_()V # tick
public net.minecraft.client.gui.screens.Screen f_96541_ # minecraft
public-f net.minecraft.world.level.Level f_46443_ # isClientSide
public-f net.minecraft.world.level.Level f_46443_ # isClientSide
public net.minecraft.world.entity.Entity m_284535_(Lnet/minecraft/world/level/Level;)V # setLevel
public-f net.minecraft.client.gui.screens.Screen m_280264_(Lnet/minecraft/client/gui/GuiGraphics;IIF)V # renderWithTooltip

View File

@ -0,0 +1,9 @@
{
"sources": [
{
"type": "directory",
"source": "overlays",
"prefix": "overlays/"
}
]
}

View File

@ -8,11 +8,11 @@
"Contraption.ContraptionControlsBlockEntityMixin",
"Contraption.ContraptionMixin",
"Contraption.MountedStorageManagerMixin",
"Render.RenderMixin",
"Storage.MountedFluidStorageMixin",
"Storage.MountedStorageMixin"
],
"client": [
"Render.RenderMixin"
],
"injectors": {
"defaultRequire": 1