fixed backpack rendering

This commit is contained in:
Jottyfan
2023-07-01 18:37:53 +02:00
parent 69c52f5bb8
commit 2c9aaea4c8
6 changed files with 90 additions and 90 deletions

View File

@ -9,7 +9,7 @@
loader_version=0.14.21
# Mod Properties
mod_version = 1.20.1.0
mod_version = 1.20.1.1
maven_group = de.jottyfan.minecraft
archives_base_name = quickiefabric

View File

@ -21,5 +21,6 @@ public class QuickieFabric implements ModInitializer {
RegistryManager.registerContainer();
RegistryManager.registerLootings();
RegistryManager.registerTags();
RegistryManager.registerItemGroup();
}
}

View File

@ -1,7 +1,5 @@
package de.jottyfan.minecraft.quickiefabric.container;
import com.mojang.blaze3d.systems.RenderSystem;
import de.jottyfan.minecraft.quickiefabric.init.RegistryManager;
import de.jottyfan.minecraft.quickiefabric.items.ItemBackpack;
import net.fabricmc.api.EnvType;
@ -27,21 +25,20 @@ public class BackpackScreen extends HandledScreen<BackpackScreenHandler>
private final Integer containerWidth = 176;
public BackpackScreen(BackpackScreenHandler handler, PlayerInventory inventory, Text text) {
super(handler, inventory, Text.translatable("container.quickiefabric.backpack"));
super(handler, inventory, Text.empty());
}
@Override
protected void init() {
super.init();
this.titleX = (this.width - this.containerWidth) / 2;
this.playerInventoryTitleY = -1000;
}
private void drawSlots(DrawContext context, int guiX, int guiY) {
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.setShaderTexture(0, SLOT_TEXTURE);
context.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
for (int y = 0; y < (ItemBackpack.SLOTSIZE / 9); y++) {
for (int x = 0; x < 9; x++) {
this.drawSlots(context, guiX, guiY);
context.drawTexture(SLOT_TEXTURE, guiX + 7 + (x * 18), guiY + 17 + (y * 18), 0, 0, 18, 18);
}
}
}
@ -55,12 +52,10 @@ public class BackpackScreen extends HandledScreen<BackpackScreenHandler>
@Override
protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) {
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.setShaderTexture(0, TEXTURE);
int guiX = this.titleX;
context.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
int guiX = (this.width - this.containerWidth) / 2;
int guiY = (this.height - this.containerHeight) / 2;
super.renderBackground(context);
context.drawTexture(TEXTURE, guiX, guiY, 0, 0, containerWidth, containerHeight);
drawSlots(context, guiX, guiY);
}
}

View File

@ -99,11 +99,9 @@ public class BackpackScreenHandler extends ScreenHandler {
} else {
super.onSlotClick(slotId, quickCraftData, actionType, playerEntity);
}
} else {
if (playerEntity.getEntityWorld().isClient) {
playerEntity.getEntityWorld().playSound(null, BlockPos.ofFloored(playerEntity.getPos()), SoundEvents.ENTITY_VILLAGER_NO,
SoundCategory.PLAYERS, 1f, 1f);
}
} else if (playerEntity.getEntityWorld().isClient) {
playerEntity.getEntityWorld().playSound(null, BlockPos.ofFloored(playerEntity.getPos()),
SoundEvents.ENTITY_VILLAGER_NO, SoundCategory.PLAYERS, 1f, 1f);
}
}

View File

@ -1,7 +1,5 @@
package de.jottyfan.minecraft.quickiefabric.container;
import com.mojang.blaze3d.systems.RenderSystem;
import de.jottyfan.minecraft.quickiefabric.init.RegistryManager;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@ -21,6 +19,8 @@ import net.minecraft.util.Identifier;
public class BlockStackerScreen extends HandledScreen<BlockStackerScreenHandler>
implements ScreenHandlerProvider<BlockStackerScreenHandler> {
private final static Identifier TEXTURE = new Identifier(RegistryManager.QUICKIEFABRIC, "textures/gui/blockstacker.png");
private final Integer containerHeight = 222;
private final Integer containerWidth = 176;
public BlockStackerScreen(BlockStackerScreenHandler handler, PlayerInventory inventory, Text text) {
super(handler, inventory, text);
@ -29,7 +29,6 @@ public class BlockStackerScreen extends HandledScreen<BlockStackerScreenHandler>
@Override
protected void init() {
super.init();
this.titleX = (backgroundWidth - textRenderer.getWidth(title)) / 2;
}
@Override
@ -40,9 +39,11 @@ public class BlockStackerScreen extends HandledScreen<BlockStackerScreenHandler>
}
@Override
protected void drawBackground(DrawContext drawContext, float delta, int mouseX, int mouseY) {
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.setShaderTexture(0, TEXTURE);
super.renderBackground(drawContext);
protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) {
context.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
int guiX = (this.width - this.containerWidth) / 2;
int guiY = (this.height - this.containerHeight) / 2;
context.drawTexture(TEXTURE, guiX, guiY, 0, 0, containerWidth, containerHeight);
super.renderBackground(context);
}
}

View File

@ -42,6 +42,7 @@ import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.screen.ScreenHandlerType;
@ -66,10 +67,13 @@ public class RegistryManager {
public static final ScreenHandlerType<BlockStackerScreenHandler> BLOCKSTACKER_SCREEN_HANDLER = ScreenHandlerRegistry
.registerSimple(RegistryManager.STACKER_IDENTIFIER, BlockStackerScreenHandler::new);
public static final ItemGroup QUICKIEFABRIC_GROUP = FabricItemGroup.builder()
.displayName(Text.literal(QUICKIEFABRIC))
.icon(() -> new ItemStack(QuickieItems.SPEEDPOWDER))
.entries((enabledFeatures, stacks) -> {
public static final RegistryKey<ItemGroup> QUICKIEFABRIC_GROUP = RegistryKey.of(RegistryKeys.ITEM_GROUP,
new Identifier(QUICKIEFABRIC, "itemgroups"));
public static final void registerItemGroup() {
Registry.register(Registries.ITEM_GROUP, QUICKIEFABRIC_GROUP,
FabricItemGroup.builder().icon(() -> new ItemStack(QuickieItems.SPEEDPOWDER))
.displayName(Text.literal(QUICKIEFABRIC)).entries((enabledFeatures, stacks) -> {
stacks.add(new ItemStack(QuickieItems.SALPETER));
stacks.add(new ItemStack(QuickieItems.SULPHOR));
stacks.add(new ItemStack(QuickieItems.SPEEDPOWDER));
@ -128,7 +132,8 @@ public class RegistryManager {
stacks.add(new ItemStack(QuickieBlocks.BLOCKSTACKERNORTH));
stacks.add(new ItemStack(QuickieBlocks.BLOCKSTACKERSOUTH));
stacks.add(new ItemStack(QuickieBlocks.BLOCKSPREADER));
}).build();
}).build());
}
private static final void registerBlock(Block block, String name) {
Registry.register(Registries.BLOCK, new Identifier(QUICKIEFABRIC, name), block);
@ -274,8 +279,8 @@ public class RegistryManager {
BiomeSelectors.foundInOverworld(), FeaturesManager.overworldOres());
// Nether features
BiomeModifications.create(new Identifier(QUICKIEFABRIC, "nether_features"))
.add(ModificationPhase.ADDITIONS, BiomeSelectors.foundInTheNether(), FeaturesManager.netherOres());
BiomeModifications.create(new Identifier(QUICKIEFABRIC, "nether_features")).add(ModificationPhase.ADDITIONS,
BiomeSelectors.foundInTheNether(), FeaturesManager.netherOres());
}
public static final void registerLootings() {