Compare commits

...

3 Commits

Author SHA1 Message Date
Eugene Rybalkin a991e01721 modified: src/main/java/com/youpe/test/Testing.java
modified:   src/main/java/com/youpe/test/TestingClient.java
	modified:   src/main/java/com/youpe/test/client/CustomAbstractInventoryScreen.java
	new file:   src/main/java/com/youpe/test/client/CustomCraftingScreenHandler.java
	modified:   src/main/java/com/youpe/test/client/CustomHandledScreen.java
	modified:   src/main/java/com/youpe/test/client/CustomInventoryScreen.java
	new file:   src/main/java/com/youpe/test/client/CustomPlayerScreenHandler.java
	new file:   src/main/java/com/youpe/test/client/TestScreenHandler.java
	modified:   src/main/java/com/youpe/test/event/DirtBrokenAfter.java
	modified:   src/main/java/com/youpe/test/event/KeyInputHandler.java
	modified:   src/main/java/com/youpe/test/item/custom/CustomItem.java
	modified:   src/main/java/com/youpe/test/networking/ModNetworkingManager.java
2024-04-16 22:45:37 +03:00
corkscrew 08af1ac255 ok 2024-04-16 02:56:15 +03:00
corkscrew ccca7f55dd test gui init 2024-04-16 01:50:43 +03:00
13 changed files with 1409 additions and 18 deletions

View File

@ -1,30 +1,33 @@
package com.youpe.test;
import com.youpe.test.client.TestScreenHandler;
import com.youpe.test.event.DirtBrokenAfter;
import com.youpe.test.event.JoinServerHandler;
import com.youpe.test.item.ModItems;
import com.youpe.test.networking.ModNetworkingManager;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.block.Blocks;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.youpe.test.server.PlayerData;
import com.youpe.test.server.StateSaverAndLoader;
public class Testing implements ModInitializer {
public static final String MOD_ID = "testing";
public static final ScreenHandlerType<TestScreenHandler> BOX_SCREEN_HANDLER;
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
static {
Registry.register(Registries.SCREEN_HANDLER, new Identifier(Testing.MOD_ID, name), item);
BOX_SCREEN_HANDLER = ScreenHandlerRegistry.registerSimple(BOX, BoxScreenHandler::new)
}
@Override
public void onInitialize() {

View File

@ -6,8 +6,7 @@ import com.youpe.test.event.TestHudRender;
import com.youpe.test.networking.ModNetworkingManager;
import com.youpe.test.server.PlayerData;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.text.Text;
import net.minecraft.client.MinecraftClient;
public class TestingClient implements ClientModInitializer{
@ -22,6 +21,8 @@ public class TestingClient implements ClientModInitializer{
TestHudRender.registerModRenders();
MinecraftClient client = MinecraftClient.getInstance();
}
}

View File

@ -0,0 +1,123 @@
package com.youpe.test.client;
import com.google.common.collect.Ordering;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.texture.StatusEffectSpriteManager;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffectUtil;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.PlayerScreenHandler;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
public abstract class CustomAbstractInventoryScreen <T extends ScreenHandler> extends CustomHandledScreen<T> {
public CustomAbstractInventoryScreen(PlayerScreenHandler screenHandler, PlayerInventory inventory, Text title) {
super(screenHandler, inventory, title);
}
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
super.render(context, mouseX, mouseY, delta);
}
public boolean hideStatusEffectHud() {
int i = this.x + this.backgroundWidth + 2;
int j = this.width - i;
return j >= 32;
}
@SuppressWarnings("unused")
private void drawStatusEffects(DrawContext context, int mouseX, int mouseY) {
int i = this.x + this.backgroundWidth + 2;
int j = this.width - i;
Collection<StatusEffectInstance> collection = this.client.player.getStatusEffects();
if (!collection.isEmpty() && j >= 32) {
boolean bl = j >= 120;
int k = 33;
if (collection.size() > 5) {
k = 132 / (collection.size() - 1);
}
Iterable<StatusEffectInstance> iterable = Ordering.natural().sortedCopy(collection);
this.drawStatusEffectBackgrounds(context, i, k, iterable, bl);
this.drawStatusEffectSprites(context, i, k, iterable, bl);
if (bl) {
this.drawStatusEffectDescriptions(context, i, k, iterable);
} else if (mouseX >= i && mouseX <= i + 33) {
int l = this.y;
StatusEffectInstance statusEffectInstance = null;
for(Iterator<StatusEffectInstance> var12 = iterable.iterator(); var12.hasNext(); l += k) {
StatusEffectInstance statusEffectInstance2 = (StatusEffectInstance)var12.next();
if (mouseY >= l && mouseY <= l + k) {
statusEffectInstance = statusEffectInstance2;
}
}
if (statusEffectInstance != null) {
List<Text> list = List.of(this.getStatusEffectDescription(statusEffectInstance), StatusEffectUtil.getDurationText(statusEffectInstance, 1.0F));
context.drawTooltip(this.textRenderer, list, Optional.empty(), mouseX, mouseY);
}
}
}
}
private void drawStatusEffectBackgrounds(DrawContext context, int x, int height, Iterable<StatusEffectInstance> statusEffects, boolean wide) {
int i = this.y;
for(Iterator<StatusEffectInstance> var7 = statusEffects.iterator(); var7.hasNext(); i += height) {
if (wide) {
context.drawTexture(BACKGROUND_TEXTURE, x, i, 0, 166, 120, 32);
} else {
context.drawTexture(BACKGROUND_TEXTURE, x, i, 0, 198, 32, 32);
}
}
}
private void drawStatusEffectSprites(DrawContext context, int x, int height, Iterable<StatusEffectInstance> statusEffects, boolean wide) {
StatusEffectSpriteManager statusEffectSpriteManager = this.client.getStatusEffectSpriteManager();
int i = this.y;
for(Iterator<StatusEffectInstance> var8 = statusEffects.iterator(); var8.hasNext(); i += height) {
StatusEffectInstance statusEffectInstance = (StatusEffectInstance)var8.next();
StatusEffect statusEffect = statusEffectInstance.getEffectType();
Sprite sprite = statusEffectSpriteManager.getSprite(statusEffect);
context.drawSprite(x + (wide ? 6 : 7), i + 7, 0, 18, 18, sprite);
}
}
private void drawStatusEffectDescriptions(DrawContext context, int x, int height, Iterable<StatusEffectInstance> statusEffects) {
int i = this.y;
for(Iterator<StatusEffectInstance> var6 = statusEffects.iterator(); var6.hasNext(); i += height) {
StatusEffectInstance statusEffectInstance = (StatusEffectInstance)var6.next();
Text text = this.getStatusEffectDescription(statusEffectInstance);
context.drawTextWithShadow(this.textRenderer, text, x + 10 + 18, i + 6, 16777215);
Text text2 = StatusEffectUtil.getDurationText(statusEffectInstance, 1.0F);
context.drawTextWithShadow(this.textRenderer, text2, x + 10 + 18, i + 6 + 10, 8355711);
}
}
private Text getStatusEffectDescription(StatusEffectInstance statusEffect) {
MutableText mutableText = statusEffect.getEffectType().getName().copy();
if (statusEffect.getAmplifier() >= 1 && statusEffect.getAmplifier() <= 9) {
MutableText var10000 = mutableText.append(ScreenTexts.SPACE);
int var10001 = statusEffect.getAmplifier();
var10000.append(Text.translatable("enchantment.level." + (var10001 + 1)));
}
return mutableText;
}
}

View File

@ -0,0 +1,199 @@
// Source code is decompiled from a .class file using FernFlower decompiler.
package com.youpe.test.client;
import java.util.Optional;
import net.minecraft.block.Blocks;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.CraftingInventory;
import net.minecraft.inventory.CraftingResultInventory;
import net.minecraft.inventory.Inventory;
import net.minecraft.inventory.RecipeInputInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket;
import net.minecraft.recipe.CraftingRecipe;
import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.RecipeMatcher;
import net.minecraft.recipe.RecipeType;
import net.minecraft.recipe.book.RecipeBookCategory;
import net.minecraft.screen.AbstractRecipeScreenHandler;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.ScreenHandlerContext;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.screen.slot.CraftingResultSlot;
import net.minecraft.screen.slot.Slot;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.world.World;
public class CustomCraftingScreenHandler extends AbstractRecipeScreenHandler<RecipeInputInventory> {
public static final int field_30781 = 0;
private static final int field_30782 = 1;
private static final int field_30783 = 10;
private static final int field_30784 = 10;
private static final int field_30785 = 37;
private static final int field_30786 = 37;
private static final int field_30787 = 46;
private final RecipeInputInventory input;
private final CraftingResultInventory result;
private final ScreenHandlerContext context;
private final PlayerEntity player;
public CustomCraftingScreenHandler(int syncId, PlayerInventory playerInventory) {
this(syncId, playerInventory, ScreenHandlerContext.EMPTY);
}
public CustomCraftingScreenHandler(int syncId, PlayerInventory playerInventory, ScreenHandlerContext context) {
super(ScreenHandlerType.CRAFTING, syncId);
this.input = new CraftingInventory(this, 3, 3);
this.result = new CraftingResultInventory();
this.context = context;
this.player = playerInventory.player;
this.addSlot(new CraftingResultSlot(playerInventory.player, this.input, this.result, 0, 124, 35));
int i;
int j;
for(i = 0; i < 3; ++i) {
for(j = 0; j < 3; ++j) {
this.addSlot(new Slot(this.input, j + i * 3, 30 + j * 18, 17 + i * 18));
}
}
for(i = 0; i < 3; ++i) {
for(j = 0; j < 9; ++j) {
this.addSlot(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
for(i = 0; i < 9; ++i) {
this.addSlot(new Slot(playerInventory, i, 8 + i * 18, 142));
}
}
protected static void updateResult(ScreenHandler handler, World world, PlayerEntity player, RecipeInputInventory craftingInventory, CraftingResultInventory resultInventory) {
if (!world.isClient) {
ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity)player;
ItemStack itemStack = ItemStack.EMPTY;
Optional<CraftingRecipe> optional = world.getServer().getRecipeManager().getFirstMatch(RecipeType.CRAFTING, craftingInventory, world);
if (optional.isPresent()) {
CraftingRecipe craftingRecipe = (CraftingRecipe)optional.get();
if (resultInventory.shouldCraftRecipe(world, serverPlayerEntity, craftingRecipe)) {
ItemStack itemStack2 = craftingRecipe.craft(craftingInventory, world.getRegistryManager());
if (itemStack2.isItemEnabled(world.getEnabledFeatures())) {
itemStack = itemStack2;
}
}
}
resultInventory.setStack(0, itemStack);
handler.setPreviousTrackedSlot(0, itemStack);
serverPlayerEntity.networkHandler.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(handler.syncId, handler.nextRevision(), 0, itemStack));
}
}
public void onContentChanged(Inventory inventory) {
this.context.run((world, pos) -> {
updateResult(this, world, this.player, this.input, this.result);
});
}
public void populateRecipeFinder(RecipeMatcher finder) {
this.input.provideRecipeInputs(finder);
}
public void clearCraftingSlots() {
this.input.clear();
this.result.clear();
}
public boolean matches(Recipe<? super RecipeInputInventory> recipe) {
return recipe.matches(this.input, this.player.getWorld());
}
public void onClosed(PlayerEntity player) {
super.onClosed(player);
this.context.run((world, pos) -> {
this.dropInventory(player, this.input);
});
}
public boolean canUse(PlayerEntity player) {
return canUse(this.context, player, Blocks.CRAFTING_TABLE);
}
public ItemStack quickMove(PlayerEntity player, int slot) {
ItemStack itemStack = ItemStack.EMPTY;
Slot slot2 = (Slot)this.slots.get(slot);
if (slot2 != null && slot2.hasStack()) {
ItemStack itemStack2 = slot2.getStack();
itemStack = itemStack2.copy();
if (slot == 0) {
this.context.run((world, pos) -> {
itemStack2.getItem().onCraft(itemStack2, world, player);
});
if (!this.insertItem(itemStack2, 10, 46, true)) {
return ItemStack.EMPTY;
}
slot2.onQuickTransfer(itemStack2, itemStack);
} else if (slot >= 10 && slot < 46) {
if (!this.insertItem(itemStack2, 1, 10, false)) {
if (slot < 37) {
if (!this.insertItem(itemStack2, 37, 46, false)) {
return ItemStack.EMPTY;
}
} else if (!this.insertItem(itemStack2, 10, 37, false)) {
return ItemStack.EMPTY;
}
}
} else if (!this.insertItem(itemStack2, 10, 46, false)) {
return ItemStack.EMPTY;
}
if (itemStack2.isEmpty()) {
slot2.setStack(ItemStack.EMPTY);
} else {
slot2.markDirty();
}
if (itemStack2.getCount() == itemStack.getCount()) {
return ItemStack.EMPTY;
}
slot2.onTakeItem(player, itemStack2);
if (slot == 0) {
player.dropItem(itemStack2, false);
}
}
return itemStack;
}
public boolean canInsertIntoSlot(ItemStack stack, Slot slot) {
return slot.inventory != this.result && super.canInsertIntoSlot(stack, slot);
}
public int getCraftingResultSlotIndex() {
return 0;
}
public int getCraftingWidth() {
return this.input.getWidth();
}
public int getCraftingHeight() {
return this.input.getHeight();
}
public int getCraftingSlotCount() {
return 10;
}
public RecipeBookCategory getCategory() {
return RecipeBookCategory.CRAFTING;
}
public boolean canInsertIntoSlot(int index) {
return index != this.getCraftingResultSlotIndex();
}
}

View File

@ -0,0 +1,618 @@
package com.youpe.test.client;
import com.google.common.collect.Sets;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.datafixers.util.Pair;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.util.InputUtil;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.PlayerScreenHandler;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.slot.Slot;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
import net.minecraft.util.math.MathHelper;
import org.jetbrains.annotations.Nullable;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@Environment(EnvType.CLIENT)
public abstract class CustomHandledScreen<T extends ScreenHandler> extends Screen implements ScreenHandlerProvider<T> {
// public static final Identifier BACKGROUND_TEXTURE = new Identifier("testing:textures/inventory.png");
public static final Identifier BACKGROUND_TEXTURE = new Identifier("textures/gui/container/inventory.png");
private static final float field_32318 = 100.0F;
private static final int field_32319 = 500;
public static final int field_32322 = 100;
private static final int field_32321 = 200;
protected int backgroundWidth = 176;
protected int backgroundHeight = 166;
protected int titleX;
protected int titleY;
protected int playerInventoryTitleX;
protected int playerInventoryTitleY;
protected final PlayerScreenHandler handler;
protected final Text playerInventoryTitle;
@Nullable
protected Slot focusedSlot;
@Nullable
private Slot touchDragSlotStart;
@Nullable
private Slot touchDropOriginSlot;
@Nullable
private Slot touchHoveredSlot;
@Nullable
private Slot lastClickedSlot;
protected int x;
protected int y;
private boolean touchIsRightClickDrag;
private ItemStack touchDragStack;
private int touchDropX;
private int touchDropY;
private long touchDropTime;
private ItemStack touchDropReturningStack;
private long touchDropTimer;
protected final Set<Slot> cursorDragSlots;
protected boolean cursorDragging;
private int heldButtonType;
private int heldButtonCode;
private boolean cancelNextRelease;
private int draggedStackRemainder;
private long lastButtonClickTime;
private int lastClickedButton;
private boolean doubleClicking;
private ItemStack quickMovingStack;
public CustomHandledScreen(PlayerScreenHandler screenHandler, PlayerInventory inventory, Text title) {
super(title);
this.touchDragStack = ItemStack.EMPTY;
this.touchDropReturningStack = ItemStack.EMPTY;
this.cursorDragSlots = Sets.newHashSet();
this.quickMovingStack = ItemStack.EMPTY;
this.handler = screenHandler;
this.playerInventoryTitle = inventory.getDisplayName();
this.cancelNextRelease = true;
this.titleX = 8;
this.titleY = 6;
this.playerInventoryTitleX = 8;
this.playerInventoryTitleY = this.backgroundHeight - 94;
}
protected void init() {
this.x = (this.width - this.backgroundWidth) / 2;
this.y = (this.height - this.backgroundHeight) / 2;
}
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
int i = this.x;
int j = this.y;
this.drawBackground(context, delta, mouseX, mouseY);
RenderSystem.disableDepthTest();
super.render(context, mouseX, mouseY, delta);
context.getMatrices().push();
context.getMatrices().translate((float)i, (float)j, 0.0F);
this.focusedSlot = null;
int l;
int m;
for(int k = 0; k < this.handler.slots.size(); ++k) {
Slot slot = (Slot)this.handler.slots.get(k);
if (slot.isEnabled()) {
this.drawSlot(context, slot);
}
if (this.isPointOverSlot(slot, (double)mouseX, (double)mouseY) && slot.isEnabled()) {
this.focusedSlot = slot;
l = slot.x;
m = slot.y;
if (this.focusedSlot.method_51306()) {
drawSlotHighlight(context, l, m, 0);
}
}
}
this.drawForeground(context, mouseX, mouseY);
ItemStack itemStack = this.touchDragStack.isEmpty() ? this.handler.getCursorStack() : this.touchDragStack;
if (!itemStack.isEmpty()) {
l = this.touchDragStack.isEmpty() ? 8 : 16;
String string = null;
if (!this.touchDragStack.isEmpty() && this.touchIsRightClickDrag) {
itemStack = itemStack.copyWithCount(MathHelper.ceil((float)itemStack.getCount() / 2.0F));
} else if (this.cursorDragging && this.cursorDragSlots.size() > 1) {
itemStack = itemStack.copyWithCount(this.draggedStackRemainder);
if (itemStack.isEmpty()) {
string = Formatting.YELLOW + "0";
}
}
this.drawItem(context, itemStack, mouseX - i - 8, mouseY - j - l, string);
}
if (!this.touchDropReturningStack.isEmpty()) {
float f = (float)(Util.getMeasuringTimeMs() - this.touchDropTime) / 100.0F;
if (f >= 1.0F) {
f = 1.0F;
this.touchDropReturningStack = ItemStack.EMPTY;
}
l = this.touchDropOriginSlot.x - this.touchDropX;
m = this.touchDropOriginSlot.y - this.touchDropY;
int o = this.touchDropX + (int)((float)l * f);
int p = this.touchDropY + (int)((float)m * f);
this.drawItem(context, this.touchDropReturningStack, o, p, (String)null);
}
context.getMatrices().pop();
RenderSystem.enableDepthTest();
}
public static void drawSlotHighlight(DrawContext context, int x, int y, int z) {
context.fillGradient(RenderLayer.getGuiOverlay(), x, y, x + 16, y + 16, -2130706433, -2130706433, z);
}
protected void drawMouseoverTooltip(DrawContext context, int x, int y) {
if (this.handler.getCursorStack().isEmpty() && this.focusedSlot != null && this.focusedSlot.hasStack()) {
ItemStack itemStack = this.focusedSlot.getStack();
context.drawTooltip(this.textRenderer, this.getTooltipFromItem(itemStack), itemStack.getTooltipData(), x, y);
}
}
protected List<Text> getTooltipFromItem(ItemStack stack) {
return getTooltipFromItem(this.client, stack);
}
private void drawItem(DrawContext context, ItemStack stack, int x, int y, String amountText) {
context.getMatrices().push();
context.getMatrices().translate(0.0F, 0.0F, 232.0F);
context.drawItem(stack, x, y);
context.drawItemInSlot(this.textRenderer, stack, x, y - (this.touchDragStack.isEmpty() ? 0 : 8), amountText);
context.getMatrices().pop();
}
protected void drawForeground(DrawContext context, int mouseX, int mouseY) {
context.drawText(this.textRenderer, this.title, this.titleX, this.titleY, 4210752, false);
context.drawText(this.textRenderer, this.playerInventoryTitle, this.playerInventoryTitleX, this.playerInventoryTitleY, 4210752, false);
}
protected abstract void drawBackground(DrawContext context, float delta, int mouseX, int mouseY);
private void drawSlot(DrawContext context, Slot slot) {
int i = slot.x;
int j = slot.y;
ItemStack itemStack = slot.getStack();
boolean bl = false;
boolean bl2 = slot == this.touchDragSlotStart && !this.touchDragStack.isEmpty() && !this.touchIsRightClickDrag;
ItemStack itemStack2 = this.handler.getCursorStack();
String string = null;
if (slot == this.touchDragSlotStart && !this.touchDragStack.isEmpty() && this.touchIsRightClickDrag && !itemStack.isEmpty()) {
itemStack = itemStack.copyWithCount(itemStack.getCount() / 2);
} else if (this.cursorDragging && this.cursorDragSlots.contains(slot) && !itemStack2.isEmpty()) {
if (this.cursorDragSlots.size() == 1) {
return;
}
if (ScreenHandler.canInsertItemIntoSlot(slot, itemStack2, true) && this.handler.canInsertIntoSlot(slot)) {
bl = true;
int k = Math.min(itemStack2.getMaxCount(), slot.getMaxItemCount(itemStack2));
int l = slot.getStack().isEmpty() ? 0 : slot.getStack().getCount();
int m = ScreenHandler.calculateStackSize(this.cursorDragSlots, this.heldButtonType, itemStack2) + l;
if (m > k) {
m = k;
String var10000 = Formatting.YELLOW.toString();
string = var10000 + k;
}
itemStack = itemStack2.copyWithCount(m);
} else {
this.cursorDragSlots.remove(slot);
this.calculateOffset();
}
}
context.getMatrices().push();
context.getMatrices().translate(0.0F, 0.0F, 100.0F);
if (itemStack.isEmpty() && slot.isEnabled()) {
Pair<Identifier, Identifier> pair = slot.getBackgroundSprite();
if (pair != null) {
Sprite sprite = (Sprite)this.client.getSpriteAtlas((Identifier)pair.getFirst()).apply((Identifier)pair.getSecond());
context.drawSprite(i, j, 0, 16, 16, sprite);
bl2 = true;
}
}
if (!bl2) {
if (bl) {
context.fill(i, j, i + 16, j + 16, -2130706433);
}
context.drawItem(itemStack, i, j, slot.x + slot.y * this.backgroundWidth);
context.drawItemInSlot(this.textRenderer, itemStack, i, j, string);
}
context.getMatrices().pop();
}
private void calculateOffset() {
ItemStack itemStack = this.handler.getCursorStack();
if (!itemStack.isEmpty() && this.cursorDragging) {
if (this.heldButtonType == 2) {
this.draggedStackRemainder = itemStack.getMaxCount();
} else {
this.draggedStackRemainder = itemStack.getCount();
int i;
int k;
for(Iterator<Slot> var2 = this.cursorDragSlots.iterator(); var2.hasNext(); this.draggedStackRemainder -= k - i) {
Slot slot = (Slot)var2.next();
ItemStack itemStack2 = slot.getStack();
i = itemStack2.isEmpty() ? 0 : itemStack2.getCount();
int j = Math.min(itemStack.getMaxCount(), slot.getMaxItemCount(itemStack));
k = Math.min(ScreenHandler.calculateStackSize(this.cursorDragSlots, this.heldButtonType, itemStack) + i, j);
}
}
}
}
@Nullable
private Slot getSlotAt(double x, double y) {
for(int i = 0; i < this.handler.slots.size(); ++i) {
Slot slot = (Slot)this.handler.slots.get(i);
if (this.isPointOverSlot(slot, x, y) && slot.isEnabled()) {
return slot;
}
}
return null;
}
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (super.mouseClicked(mouseX, mouseY, button)) {
return true;
} else {
boolean bl = this.client.options.pickItemKey.matchesMouse(button) && this.client.interactionManager.hasCreativeInventory();
Slot slot = this.getSlotAt(mouseX, mouseY);
long l = Util.getMeasuringTimeMs();
this.doubleClicking = this.lastClickedSlot == slot && l - this.lastButtonClickTime < 250L && this.lastClickedButton == button;
this.cancelNextRelease = false;
if (button != 0 && button != 1 && !bl) {
this.onMouseClick(button);
} else {
int i = this.x;
int j = this.y;
boolean bl2 = this.isClickOutsideBounds(mouseX, mouseY, i, j, button);
int k = -1;
if (slot != null) {
k = slot.id;
}
if (bl2) {
k = -999;
}
if ((Boolean)this.client.options.getTouchscreen().getValue() && bl2 && this.handler.getCursorStack().isEmpty()) {
this.close();
return true;
}
if (k != -1) {
if ((Boolean)this.client.options.getTouchscreen().getValue()) {
if (slot != null && slot.hasStack()) {
this.touchDragSlotStart = slot;
this.touchDragStack = ItemStack.EMPTY;
this.touchIsRightClickDrag = button == 1;
} else {
this.touchDragSlotStart = null;
}
} else if (!this.cursorDragging) {
if (this.handler.getCursorStack().isEmpty()) {
if (bl) {
this.onMouseClick(slot, k, button, SlotActionType.CLONE);
} else {
boolean bl3 = k != -999 && (InputUtil.isKeyPressed(MinecraftClient.getInstance().getWindow().getHandle(), 340) || InputUtil.isKeyPressed(MinecraftClient.getInstance().getWindow().getHandle(), 344));
SlotActionType slotActionType = SlotActionType.PICKUP;
if (bl3) {
this.quickMovingStack = slot != null && slot.hasStack() ? slot.getStack().copy() : ItemStack.EMPTY;
slotActionType = SlotActionType.QUICK_MOVE;
} else if (k == -999) {
slotActionType = SlotActionType.THROW;
}
this.onMouseClick(slot, k, button, slotActionType);
}
this.cancelNextRelease = true;
} else {
this.cursorDragging = true;
this.heldButtonCode = button;
this.cursorDragSlots.clear();
if (button == 0) {
this.heldButtonType = 0;
} else if (button == 1) {
this.heldButtonType = 1;
} else if (bl) {
this.heldButtonType = 2;
}
}
}
}
}
this.lastClickedSlot = slot;
this.lastButtonClickTime = l;
this.lastClickedButton = button;
return true;
}
}
private void onMouseClick(int button) {
if (this.focusedSlot != null && this.handler.getCursorStack().isEmpty()) {
if (this.client.options.swapHandsKey.matchesMouse(button)) {
this.onMouseClick(this.focusedSlot, this.focusedSlot.id, 40, SlotActionType.SWAP);
return;
}
for(int i = 0; i < 9; ++i) {
if (this.client.options.hotbarKeys[i].matchesMouse(button)) {
this.onMouseClick(this.focusedSlot, this.focusedSlot.id, i, SlotActionType.SWAP);
}
}
}
}
protected boolean isClickOutsideBounds(double mouseX, double mouseY, int left, int top, int button) {
return mouseX < (double)left || mouseY < (double)top || mouseX >= (double)(left + this.backgroundWidth) || mouseY >= (double)(top + this.backgroundHeight);
}
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
Slot slot = this.getSlotAt(mouseX, mouseY);
ItemStack itemStack = this.handler.getCursorStack();
if (this.touchDragSlotStart != null && (Boolean)this.client.options.getTouchscreen().getValue()) {
if (button == 0 || button == 1) {
if (this.touchDragStack.isEmpty()) {
if (slot != this.touchDragSlotStart && !this.touchDragSlotStart.getStack().isEmpty()) {
this.touchDragStack = this.touchDragSlotStart.getStack().copy();
}
} else if (this.touchDragStack.getCount() > 1 && slot != null && ScreenHandler.canInsertItemIntoSlot(slot, this.touchDragStack, false)) {
long l = Util.getMeasuringTimeMs();
if (this.touchHoveredSlot == slot) {
if (l - this.touchDropTimer > 500L) {
this.onMouseClick(this.touchDragSlotStart, this.touchDragSlotStart.id, 0, SlotActionType.PICKUP);
this.onMouseClick(slot, slot.id, 1, SlotActionType.PICKUP);
this.onMouseClick(this.touchDragSlotStart, this.touchDragSlotStart.id, 0, SlotActionType.PICKUP);
this.touchDropTimer = l + 750L;
this.touchDragStack.decrement(1);
}
} else {
this.touchHoveredSlot = slot;
this.touchDropTimer = l;
}
}
}
} else if (this.cursorDragging && slot != null && !itemStack.isEmpty() && (itemStack.getCount() > this.cursorDragSlots.size() || this.heldButtonType == 2) && ScreenHandler.canInsertItemIntoSlot(slot, itemStack, true) && slot.canInsert(itemStack) && this.handler.canInsertIntoSlot(slot)) {
this.cursorDragSlots.add(slot);
this.calculateOffset();
}
return true;
}
public boolean mouseReleased(double mouseX, double mouseY, int button) {
Slot slot = this.getSlotAt(mouseX, mouseY);
int i = this.x;
int j = this.y;
boolean bl = this.isClickOutsideBounds(mouseX, mouseY, i, j, button);
int k = -1;
if (slot != null) {
k = slot.id;
}
if (bl) {
k = -999;
}
Slot slot2;
Iterator<Slot> var13;
if (this.doubleClicking && slot != null && button == 0 && this.handler.canInsertIntoSlot(ItemStack.EMPTY, slot)) {
if (hasShiftDown()) {
if (!this.quickMovingStack.isEmpty()) {
var13 = this.handler.slots.iterator();
while(var13.hasNext()) {
slot2 = (Slot)var13.next();
if (slot2 != null && slot2.canTakeItems(this.client.player) && slot2.hasStack() && slot2.inventory == slot.inventory && ScreenHandler.canInsertItemIntoSlot(slot2, this.quickMovingStack, true)) {
this.onMouseClick(slot2, slot2.id, button, SlotActionType.QUICK_MOVE);
}
}
}
} else {
this.onMouseClick(slot, k, button, SlotActionType.PICKUP_ALL);
}
this.doubleClicking = false;
this.lastButtonClickTime = 0L;
} else {
if (this.cursorDragging && this.heldButtonCode != button) {
this.cursorDragging = false;
this.cursorDragSlots.clear();
this.cancelNextRelease = true;
return true;
}
if (this.cancelNextRelease) {
this.cancelNextRelease = false;
return true;
}
boolean bl2;
if (this.touchDragSlotStart != null && (Boolean)this.client.options.getTouchscreen().getValue()) {
if (button == 0 || button == 1) {
if (this.touchDragStack.isEmpty() && slot != this.touchDragSlotStart) {
this.touchDragStack = this.touchDragSlotStart.getStack();
}
bl2 = ScreenHandler.canInsertItemIntoSlot(slot, this.touchDragStack, false);
if (k != -1 && !this.touchDragStack.isEmpty() && bl2) {
this.onMouseClick(this.touchDragSlotStart, this.touchDragSlotStart.id, button, SlotActionType.PICKUP);
this.onMouseClick(slot, k, 0, SlotActionType.PICKUP);
if (this.handler.getCursorStack().isEmpty()) {
this.touchDropReturningStack = ItemStack.EMPTY;
} else {
this.onMouseClick(this.touchDragSlotStart, this.touchDragSlotStart.id, button, SlotActionType.PICKUP);
this.touchDropX = MathHelper.floor(mouseX - (double)i);
this.touchDropY = MathHelper.floor(mouseY - (double)j);
this.touchDropOriginSlot = this.touchDragSlotStart;
this.touchDropReturningStack = this.touchDragStack;
this.touchDropTime = Util.getMeasuringTimeMs();
}
} else if (!this.touchDragStack.isEmpty()) {
this.touchDropX = MathHelper.floor(mouseX - (double)i);
this.touchDropY = MathHelper.floor(mouseY - (double)j);
this.touchDropOriginSlot = this.touchDragSlotStart;
this.touchDropReturningStack = this.touchDragStack;
this.touchDropTime = Util.getMeasuringTimeMs();
}
this.endTouchDrag();
}
} else if (this.cursorDragging && !this.cursorDragSlots.isEmpty()) {
this.onMouseClick((Slot)null, -999, ScreenHandler.packQuickCraftData(0, this.heldButtonType), SlotActionType.QUICK_CRAFT);
var13 = this.cursorDragSlots.iterator();
while(var13.hasNext()) {
slot2 = (Slot)var13.next();
this.onMouseClick(slot2, slot2.id, ScreenHandler.packQuickCraftData(1, this.heldButtonType), SlotActionType.QUICK_CRAFT);
}
this.onMouseClick((Slot)null, -999, ScreenHandler.packQuickCraftData(2, this.heldButtonType), SlotActionType.QUICK_CRAFT);
} else if (!this.handler.getCursorStack().isEmpty()) {
if (this.client.options.pickItemKey.matchesMouse(button)) {
this.onMouseClick(slot, k, button, SlotActionType.CLONE);
} else {
bl2 = k != -999 && (InputUtil.isKeyPressed(MinecraftClient.getInstance().getWindow().getHandle(), 340) || InputUtil.isKeyPressed(MinecraftClient.getInstance().getWindow().getHandle(), 344));
if (bl2) {
this.quickMovingStack = slot != null && slot.hasStack() ? slot.getStack().copy() : ItemStack.EMPTY;
}
this.onMouseClick(slot, k, button, bl2 ? SlotActionType.QUICK_MOVE : SlotActionType.PICKUP);
}
}
}
if (this.handler.getCursorStack().isEmpty()) {
this.lastButtonClickTime = 0L;
}
this.cursorDragging = false;
return true;
}
public void endTouchDrag() {
this.touchDragStack = ItemStack.EMPTY;
this.touchDragSlotStart = null;
}
private boolean isPointOverSlot(Slot slot, double pointX, double pointY) {
return this.isPointWithinBounds(slot.x, slot.y, 16, 16, pointX, pointY);
}
protected boolean isPointWithinBounds(int x, int y, int width, int height, double pointX, double pointY) {
int i = this.x;
int j = this.y;
pointX -= (double)i;
pointY -= (double)j;
return pointX >= (double)(x - 1) && pointX < (double)(x + width + 1) && pointY >= (double)(y - 1) && pointY < (double)(y + height + 1);
}
protected void onMouseClick(Slot slot, int slotId, int button, SlotActionType actionType) {
if (slot != null) {
slotId = slot.id;
}
this.client.interactionManager.clickSlot(this.handler.syncId, slotId, button, actionType, this.client.player);
}
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (super.keyPressed(keyCode, scanCode, modifiers)) {
return true;
} else if (this.client.options.inventoryKey.matchesKey(keyCode, scanCode)) {
this.close();
return true;
} else {
this.handleHotbarKeyPressed(keyCode, scanCode);
if (this.focusedSlot != null && this.focusedSlot.hasStack()) {
if (this.client.options.pickItemKey.matchesKey(keyCode, scanCode)) {
this.onMouseClick(this.focusedSlot, this.focusedSlot.id, 0, SlotActionType.CLONE);
} else if (this.client.options.dropKey.matchesKey(keyCode, scanCode)) {
this.onMouseClick(this.focusedSlot, this.focusedSlot.id, hasControlDown() ? 1 : 0, SlotActionType.THROW);
}
}
return true;
}
}
protected boolean handleHotbarKeyPressed(int keyCode, int scanCode) {
if (this.handler.getCursorStack().isEmpty() && this.focusedSlot != null) {
if (this.client.options.swapHandsKey.matchesKey(keyCode, scanCode)) {
this.onMouseClick(this.focusedSlot, this.focusedSlot.id, 40, SlotActionType.SWAP);
return true;
}
for(int i = 0; i < 9; ++i) {
if (this.client.options.hotbarKeys[i].matchesKey(keyCode, scanCode)) {
this.onMouseClick(this.focusedSlot, this.focusedSlot.id, i, SlotActionType.SWAP);
return true;
}
}
}
return false;
}
public void removed() {
if (this.client.player != null) {
this.handler.onClosed(this.client.player);
}
}
public boolean shouldPause() {
return false;
}
public final void tick() {
super.tick();
if (this.client.player.isAlive() && !this.client.player.isRemoved()) {
this.handledScreenTick();
} else {
this.client.player.closeHandledScreen();
}
}
protected void handledScreenTick() {
}
public PlayerScreenHandler getScreenHandler() {
return this.handler;
}
public void close() {
this.client.player.closeHandledScreen();
super.close();
}
}

View File

@ -0,0 +1,131 @@
package com.youpe.test.client;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen;
import net.minecraft.client.render.DiffuseLighting;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.screen.PlayerScreenHandler;
import net.minecraft.screen.slot.Slot;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.text.Text;
import org.jetbrains.annotations.Nullable;
import org.joml.Matrix4f;
import org.joml.Quaternionf;
public class CustomInventoryScreen extends CustomAbstractInventoryScreen<CustomPlayerScreenHandler> {
private float mouseX;
private float mouseY;
private boolean mouseDown;
public CustomInventoryScreen(PlayerEntity player) {
super(new CustomPlayerScreenHandler(player.getInventory(), !player.getWorld().isClient(), player), player.getInventory(), Text.translatable("container.crafting"));
this.titleX = 97;
}
public void handledScreenTick() {
if (this.client.interactionManager.hasCreativeInventory()) {
this.client.setScreen(new CreativeInventoryScreen(this.client.player, this.client.player.networkHandler.getEnabledFeatures(), (Boolean)this.client.options.getOperatorItemsTab().getValue()));
}
}
protected void init() {
if (this.client.interactionManager.hasCreativeInventory()) {
this.client.setScreen(new CreativeInventoryScreen(this.client.player, this.client.player.networkHandler.getEnabledFeatures(), (Boolean)this.client.options.getOperatorItemsTab().getValue()));
} else {
super.init();
}
}
protected void drawForeground(DrawContext context, int mouseX, int mouseY) {
context.drawText(this.textRenderer, this.title, this.titleX, this.titleY, 4210752, false);
}
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
this.renderBackground(context);
this.drawBackground(context, delta, mouseX, mouseY);
super.render(context, mouseX, mouseY, delta);
this.drawMouseoverTooltip(context, mouseX, mouseY);
this.mouseX = (float)mouseX;
this.mouseY = (float)mouseY;
}
protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) {
int i = this.x;
int j = this.y;
context.drawTexture(BACKGROUND_TEXTURE, i, j, 0, 0, this.backgroundWidth, this.backgroundHeight);
drawEntity(context, i + 51, j + 75, 50, (float)(i + 51) - this.mouseX, (float)(j + 75 - 50) - this.mouseY, this.client.player);
}
public static void drawEntity(DrawContext context, int x, int y, int size, float mouseX, float mouseY, LivingEntity entity) {
float f = (float)Math.atan((double)(mouseX / 40.0F));
float g = (float)Math.atan((double)(mouseY / 40.0F));
Quaternionf quaternionf = (new Quaternionf()).rotateZ(3.1415927F);
Quaternionf quaternionf2 = (new Quaternionf()).rotateX(g * 20.0F * 0.017453292F);
quaternionf.mul(quaternionf2);
float h = entity.bodyYaw;
float i = entity.getYaw();
float j = entity.getPitch();
float k = entity.prevHeadYaw;
float l = entity.headYaw;
entity.bodyYaw = 180.0F + f * 20.0F;
entity.setYaw(180.0F + f * 40.0F);
entity.setPitch(-g * 20.0F);
entity.headYaw = entity.getYaw();
entity.prevHeadYaw = entity.getYaw();
drawEntity(context, x, y, size, quaternionf, quaternionf2, entity);
entity.bodyYaw = h;
entity.setYaw(i);
entity.setPitch(j);
entity.prevHeadYaw = k;
entity.headYaw = l;
}
@SuppressWarnings("deprecation")
public static void drawEntity(DrawContext context, int x, int y, int size, Quaternionf quaternionf, @Nullable Quaternionf quaternionf2, LivingEntity entity) {
context.getMatrices().push();
context.getMatrices().translate((double)x, (double)y, 50.0);
context.getMatrices().multiplyPositionMatrix((new Matrix4f()).scaling((float)size, (float)size, (float)(-size)));
context.getMatrices().multiply(quaternionf);
DiffuseLighting.method_34742();
EntityRenderDispatcher entityRenderDispatcher = MinecraftClient.getInstance().getEntityRenderDispatcher();
if (quaternionf2 != null) {
quaternionf2.conjugate();
entityRenderDispatcher.setRotation(quaternionf2);
}
entityRenderDispatcher.setRenderShadows(false);
RenderSystem.runAsFancy(() -> {
entityRenderDispatcher.render(entity, 0.0, 0.0, 0.0, 0.0F, 1.0F, context.getMatrices(), context.getVertexConsumers(), 15728880);
});
context.draw();
entityRenderDispatcher.setRenderShadows(true);
context.getMatrices().pop();
DiffuseLighting.enableGuiDepthLighting();
}
protected boolean isPointWithinBounds(int x, int y, int width, int height, double pointX, double pointY) {
return super.isPointWithinBounds(x, y, width, height, pointX, pointY);
}
public boolean mouseClicked(double mouseX, double mouseY, int button) {
return super.mouseClicked(mouseX, mouseY, button);
}
public boolean mouseReleased(double mouseX, double mouseY, int button) {
if (this.mouseDown) {
this.mouseDown = false;
return true;
} else {
return super.mouseReleased(mouseX, mouseY, button);
}
}
protected void onMouseClick(Slot slot, int slotId, int button, SlotActionType actionType) {
super.onMouseClick(slot, slotId, button, actionType);
}
}

View File

@ -0,0 +1,258 @@
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package com.youpe.test.client;
import com.mojang.datafixers.util.Pair;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.EquipmentSlot.Type;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.CraftingInventory;
import net.minecraft.inventory.CraftingResultInventory;
import net.minecraft.inventory.Inventory;
import net.minecraft.inventory.RecipeInputInventory;
import net.minecraft.item.Equipment;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.RecipeMatcher;
import net.minecraft.recipe.book.RecipeBookCategory;
import net.minecraft.screen.AbstractRecipeScreenHandler;
import net.minecraft.screen.CraftingScreenHandler;
import net.minecraft.screen.PlayerScreenHandler;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.screen.slot.CraftingResultSlot;
import net.minecraft.screen.slot.Slot;
import net.minecraft.util.Identifier;
public class CustomPlayerScreenHandler extends PlayerScreenHandler {
public static final int field_30802 = 0;
public static final int field_30803 = 0;
public static final int field_30804 = 1;
public static final int field_30805 = 5;
public static final int field_30806 = 5;
public static final int field_30807 = 9;
public static final int field_30808 = 9;
public static final int field_30809 = 36;
public static final int field_30810 = 36;
public static final int field_30811 = 45;
public static final int field_30812 = 45;
public static final Identifier BLOCK_ATLAS_TEXTURE = new Identifier("textures/atlas/blocks.png");
public static final Identifier EMPTY_HELMET_SLOT_TEXTURE = new Identifier("item/empty_armor_slot_helmet");
public static final Identifier EMPTY_CHESTPLATE_SLOT_TEXTURE = new Identifier("item/empty_armor_slot_chestplate");
public static final Identifier EMPTY_LEGGINGS_SLOT_TEXTURE = new Identifier("item/empty_armor_slot_leggings");
public static final Identifier EMPTY_BOOTS_SLOT_TEXTURE = new Identifier("item/empty_armor_slot_boots");
public static final Identifier EMPTY_OFFHAND_ARMOR_SLOT = new Identifier("item/empty_armor_slot_shield");
static final Identifier[] EMPTY_ARMOR_SLOT_TEXTURES;
private static final EquipmentSlot[] EQUIPMENT_SLOT_ORDER;
private final RecipeInputInventory craftingInput = new CraftingInventory(this, 2, 2);
private final CraftingResultInventory craftingResult = new CraftingResultInventory();
public final boolean onServer;
private final PlayerEntity owner;
public CustomPlayerScreenHandler(PlayerInventory inventory, boolean onServer, PlayerEntity owner) {
super(inventory, onServer, owner);
this.onServer = onServer;
this.owner = owner;
this.addSlot(new CraftingResultSlot(inventory.player, this.craftingInput, this.craftingResult, 0, 154, 28));
int i;
int j;
for(i = 0; i < 2; ++i) {
for(j = 0; j < 2; ++j) {
this.addSlot(new Slot(this.craftingInput, j + i * 2, 130 + j * 18, 18 + i * 18));
}
}
for(i = 0; i < 4; ++i) {
final EquipmentSlot equipmentSlot = EQUIPMENT_SLOT_ORDER[i];
this.addSlot(new Slot(inventory, 39 - i, 8, 8 + i * 18) {
public void setStack(ItemStack stack) {
CustomPlayerScreenHandler.onEquipStack(owner, equipmentSlot, stack, this.getStack());
super.setStack(stack);
}
public int getMaxItemCount() {
return 1;
}
public boolean canInsert(ItemStack stack) {
return equipmentSlot == MobEntity.getPreferredEquipmentSlot(stack);
}
public boolean canTakeItems(PlayerEntity playerEntity) {
ItemStack itemStack = this.getStack();
return !itemStack.isEmpty() && !playerEntity.isCreative() && EnchantmentHelper.hasBindingCurse(itemStack) ? false : super.canTakeItems(playerEntity);
}
public Pair<Identifier, Identifier> getBackgroundSprite() {
return Pair.of(CustomPlayerScreenHandler.BLOCK_ATLAS_TEXTURE, CustomPlayerScreenHandler.EMPTY_ARMOR_SLOT_TEXTURES[equipmentSlot.getEntitySlotId()]);
}
});
}
for(i = 0; i < 3; ++i) {
for(j = 0; j < 9; ++j) {
this.addSlot(new Slot(inventory, j + (i + 1) * 9, 8 + j * 18, 84 + i * 18));
}
}
for(i = 0; i < 9; ++i) {
this.addSlot(new Slot(inventory, i, 8 + i * 18, 142));
}
this.addSlot(new Slot(inventory, 40, 77, 62) {
public void setStack(ItemStack stack) {
CustomPlayerScreenHandler.onEquipStack(owner, EquipmentSlot.OFFHAND, stack, this.getStack());
super.setStack(stack);
}
public Pair<Identifier, Identifier> getBackgroundSprite() {
return Pair.of(CustomPlayerScreenHandler.BLOCK_ATLAS_TEXTURE, CustomPlayerScreenHandler.EMPTY_OFFHAND_ARMOR_SLOT);
}
});
}
static void onEquipStack(PlayerEntity player, EquipmentSlot slot, ItemStack newStack, ItemStack currentStack) {
Equipment equipment = Equipment.fromStack(newStack);
if (equipment != null) {
player.onEquipStack(slot, currentStack, newStack);
}
}
public static boolean isInHotbar(int slot) {
return slot >= 36 && slot < 45 || slot == 45;
}
public void populateRecipeFinder(RecipeMatcher finder) {
this.craftingInput.provideRecipeInputs(finder);
}
public void clearCraftingSlots() {
this.craftingResult.clear();
this.craftingInput.clear();
}
public boolean matches(Recipe<? super RecipeInputInventory> recipe) {
return recipe.matches(this.craftingInput, this.owner.getWorld());
}
public void onContentChanged(Inventory inventory) {
CustomCraftingScreenHandler.updateResult(this, this.owner.getWorld(), this.owner, this.craftingInput, this.craftingResult);
}
@SuppressWarnings("resource")
public void onClosed(PlayerEntity player) {
super.onClosed(player);
this.craftingResult.clear();
if (!player.getWorld().isClient) {
this.dropInventory(player, this.craftingInput);
}
}
public boolean canUse(PlayerEntity player) {
return true;
}
public ItemStack quickMove(PlayerEntity player, int slot) {
ItemStack itemStack = ItemStack.EMPTY;
Slot slot2 = (Slot)this.slots.get(slot);
if (slot2.hasStack()) {
ItemStack itemStack2 = slot2.getStack();
itemStack = itemStack2.copy();
EquipmentSlot equipmentSlot = MobEntity.getPreferredEquipmentSlot(itemStack);
if (slot == 0) {
if (!this.insertItem(itemStack2, 9, 45, true)) {
return ItemStack.EMPTY;
}
slot2.onQuickTransfer(itemStack2, itemStack);
} else if (slot >= 1 && slot < 5) {
if (!this.insertItem(itemStack2, 9, 45, false)) {
return ItemStack.EMPTY;
}
} else if (slot >= 5 && slot < 9) {
if (!this.insertItem(itemStack2, 9, 45, false)) {
return ItemStack.EMPTY;
}
} else if (equipmentSlot.getType() == Type.ARMOR && !((Slot)this.slots.get(8 - equipmentSlot.getEntitySlotId())).hasStack()) {
int i = 8 - equipmentSlot.getEntitySlotId();
if (!this.insertItem(itemStack2, i, i + 1, false)) {
return ItemStack.EMPTY;
}
} else if (equipmentSlot == EquipmentSlot.OFFHAND && !((Slot)this.slots.get(45)).hasStack()) {
if (!this.insertItem(itemStack2, 45, 46, false)) {
return ItemStack.EMPTY;
}
} else if (slot >= 9 && slot < 36) {
if (!this.insertItem(itemStack2, 36, 45, false)) {
return ItemStack.EMPTY;
}
} else if (slot >= 36 && slot < 45) {
if (!this.insertItem(itemStack2, 9, 36, false)) {
return ItemStack.EMPTY;
}
} else if (!this.insertItem(itemStack2, 9, 45, false)) {
return ItemStack.EMPTY;
}
if (itemStack2.isEmpty()) {
slot2.setStack(ItemStack.EMPTY);
} else {
slot2.markDirty();
}
if (itemStack2.getCount() == itemStack.getCount()) {
return ItemStack.EMPTY;
}
slot2.onTakeItem(player, itemStack2);
if (slot == 0) {
player.dropItem(itemStack2, false);
}
}
return itemStack;
}
public boolean canInsertIntoSlot(ItemStack stack, Slot slot) {
return slot.inventory != this.craftingResult && super.canInsertIntoSlot(stack, slot);
}
public int getCraftingResultSlotIndex() {
return 0;
}
public int getCraftingWidth() {
return this.craftingInput.getWidth();
}
public int getCraftingHeight() {
return this.craftingInput.getHeight();
}
public int getCraftingSlotCount() {
return 5;
}
public RecipeInputInventory getCraftingInput() {
return this.craftingInput;
}
public RecipeBookCategory getCategory() {
return RecipeBookCategory.CRAFTING;
}
public boolean canInsertIntoSlot(int index) {
return index != this.getCraftingResultSlotIndex();
}
static {
EMPTY_ARMOR_SLOT_TEXTURES = new Identifier[]{EMPTY_BOOTS_SLOT_TEXTURE, EMPTY_LEGGINGS_SLOT_TEXTURE, EMPTY_CHESTPLATE_SLOT_TEXTURE, EMPTY_HELMET_SLOT_TEXTURE};
EQUIPMENT_SLOT_ORDER = new EquipmentSlot[]{EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.LEGS, EquipmentSlot.FEET};
}
}

View File

@ -0,0 +1,61 @@
package com.youpe.test.client;
import com.youpe.test.Testing;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventory;
import net.minecraft.inventory.SimpleInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.screen.slot.Slot;
public class TestScreenHandler extends ScreenHandler {
private final Inventory inventory;
public TestScreenHandler(int syncId, PlayerInventory playerInventory) {
this(syncId, playerInventory, new SimpleInventory(9));
}
public TestScreenHandler(int syncId, PlayerInventory playerInventory, SimpleInventory simpleInventory) {
super(Testing.BOX_SCREEN_HANDLER, syncId);
checkSize(inventory, 9);
this.inventory = inventory;
//some inventories do custom logic when a player opens it.
inventory.onOpen(playerInventory.player);
//This will place the slot in the correct locations for a 3x3 Grid. The slots exist on both server and client!
//This will not render the background of the slots however, this is the Screens job
int m;
int l;
//Our inventory
for (m = 0; m < 3; ++m) {
for (l = 0; l < 3; ++l) {
this.addSlot(new Slot(inventory, l + m * 3, 62 + l * 18, 17 + m * 18));
}
}
//The player inventory
for (m = 0; m < 3; ++m) {
for (l = 0; l < 9; ++l) {
this.addSlot(new Slot(playerInventory, l + m * 9 + 9, 8 + l * 18, 84 + m * 18));
}
}
//The player Hotbar
for (m = 0; m < 9; ++m) {
this.addSlot(new Slot(playerInventory, m, 8 + m * 18, 142));
}
}
@Override
public boolean canUse(PlayerEntity player) {
throw new UnsupportedOperationException("Unimplemented method 'canUse'");
}
@Override
public ItemStack quickMove(PlayerEntity player, int slot) {
throw new UnsupportedOperationException("Unimplemented method 'quickMove'");
}
}

View File

@ -3,7 +3,6 @@ package com.youpe.test.event;
import com.youpe.test.networking.ModNetworkingManager;
import com.youpe.test.server.PlayerData;
import com.youpe.test.server.StateSaverAndLoader;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;

View File

@ -1,10 +1,9 @@
package com.youpe.test.event;
import com.youpe.test.Testing;
import com.youpe.test.client.CustomInventoryScreen;
import org.lwjgl.glfw.GLFW;
import com.youpe.test.client.GUI;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.MinecraftClient;
@ -19,13 +18,14 @@ public class KeyInputHandler {
public static KeyBinding modkey;
@SuppressWarnings("resource")
public static void registerKeyInputs() {
registerKeyBindings();
ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (modkey.wasPressed()) {
Testing.LOGGER.info("NAZHAL PIZDEC BLYA");
client.player.sendMessage(Text.literal("PIZDEC"));
MinecraftClient.getInstance().setScreen(new GUI(Text.empty()));
client.player.sendMessage(Text.literal("PIZDEC2"));
MinecraftClient.getInstance().setScreen(new CustomInventoryScreen(MinecraftClient.getInstance().player));
}
});
}

View File

@ -7,7 +7,6 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

View File

@ -5,7 +5,6 @@ import com.youpe.test.Testing;
import com.youpe.test.networking.packet.DirtBrokenS2CPacket;
import com.youpe.test.networking.packet.InitSyncS2CPacket;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.util.Identifier;
public class ModNetworkingManager {

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB