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
This commit is contained in:
parent
08af1ac255
commit
a991e01721
|
@ -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() {
|
||||
|
|
|
@ -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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ 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;
|
||||
|
@ -20,12 +21,11 @@ import java.util.Optional;
|
|||
|
||||
public abstract class CustomAbstractInventoryScreen <T extends ScreenHandler> extends CustomHandledScreen<T> {
|
||||
|
||||
public CustomAbstractInventoryScreen(T screenHandler, PlayerInventory inventory, Text title) {
|
||||
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);
|
||||
this.drawStatusEffects(context, mouseX, mouseY);
|
||||
}
|
||||
|
||||
public boolean hideStatusEffectHud() {
|
||||
|
@ -34,6 +34,7 @@ public abstract class CustomAbstractInventoryScreen <T extends ScreenHandler> ex
|
|||
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;
|
||||
|
@ -54,7 +55,7 @@ public abstract class CustomAbstractInventoryScreen <T extends ScreenHandler> ex
|
|||
int l = this.y;
|
||||
StatusEffectInstance statusEffectInstance = null;
|
||||
|
||||
for(Iterator var12 = iterable.iterator(); var12.hasNext(); l += k) {
|
||||
for(Iterator<StatusEffectInstance> var12 = iterable.iterator(); var12.hasNext(); l += k) {
|
||||
StatusEffectInstance statusEffectInstance2 = (StatusEffectInstance)var12.next();
|
||||
if (mouseY >= l && mouseY <= l + k) {
|
||||
statusEffectInstance = statusEffectInstance2;
|
||||
|
@ -73,8 +74,7 @@ public abstract class CustomAbstractInventoryScreen <T extends ScreenHandler> ex
|
|||
private void drawStatusEffectBackgrounds(DrawContext context, int x, int height, Iterable<StatusEffectInstance> statusEffects, boolean wide) {
|
||||
int i = this.y;
|
||||
|
||||
for(Iterator var7 = statusEffects.iterator(); var7.hasNext(); i += height) {
|
||||
StatusEffectInstance statusEffectInstance = (StatusEffectInstance)var7.next();
|
||||
for(Iterator<StatusEffectInstance> var7 = statusEffects.iterator(); var7.hasNext(); i += height) {
|
||||
if (wide) {
|
||||
context.drawTexture(BACKGROUND_TEXTURE, x, i, 0, 166, 120, 32);
|
||||
} else {
|
||||
|
@ -88,7 +88,7 @@ public abstract class CustomAbstractInventoryScreen <T extends ScreenHandler> ex
|
|||
StatusEffectSpriteManager statusEffectSpriteManager = this.client.getStatusEffectSpriteManager();
|
||||
int i = this.y;
|
||||
|
||||
for(Iterator var8 = statusEffects.iterator(); var8.hasNext(); i += height) {
|
||||
for(Iterator<StatusEffectInstance> var8 = statusEffects.iterator(); var8.hasNext(); i += height) {
|
||||
StatusEffectInstance statusEffectInstance = (StatusEffectInstance)var8.next();
|
||||
StatusEffect statusEffect = statusEffectInstance.getEffectType();
|
||||
Sprite sprite = statusEffectSpriteManager.getSprite(statusEffect);
|
||||
|
@ -100,7 +100,7 @@ public abstract class CustomAbstractInventoryScreen <T extends ScreenHandler> ex
|
|||
private void drawStatusEffectDescriptions(DrawContext context, int x, int height, Iterable<StatusEffectInstance> statusEffects) {
|
||||
int i = this.y;
|
||||
|
||||
for(Iterator var6 = statusEffects.iterator(); var6.hasNext(); i += height) {
|
||||
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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -14,6 +14,7 @@ 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;
|
||||
|
@ -30,7 +31,8 @@ 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("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;
|
||||
|
@ -41,7 +43,7 @@ public abstract class CustomHandledScreen<T extends ScreenHandler> extends Scree
|
|||
protected int titleY;
|
||||
protected int playerInventoryTitleX;
|
||||
protected int playerInventoryTitleY;
|
||||
protected final T handler;
|
||||
protected final PlayerScreenHandler handler;
|
||||
protected final Text playerInventoryTitle;
|
||||
@Nullable
|
||||
protected Slot focusedSlot;
|
||||
|
@ -73,13 +75,13 @@ public abstract class CustomHandledScreen<T extends ScreenHandler> extends Scree
|
|||
private boolean doubleClicking;
|
||||
private ItemStack quickMovingStack;
|
||||
|
||||
public CustomHandledScreen(T handler, PlayerInventory inventory, Text title) {
|
||||
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 = handler;
|
||||
this.handler = screenHandler;
|
||||
this.playerInventoryTitle = inventory.getDisplayName();
|
||||
this.cancelNextRelease = true;
|
||||
this.titleX = 8;
|
||||
|
@ -124,7 +126,6 @@ public abstract class CustomHandledScreen<T extends ScreenHandler> extends Scree
|
|||
this.drawForeground(context, mouseX, mouseY);
|
||||
ItemStack itemStack = this.touchDragStack.isEmpty() ? this.handler.getCursorStack() : this.touchDragStack;
|
||||
if (!itemStack.isEmpty()) {
|
||||
boolean n = true;
|
||||
l = this.touchDragStack.isEmpty() ? 8 : 16;
|
||||
String string = null;
|
||||
if (!this.touchDragStack.isEmpty() && this.touchIsRightClickDrag) {
|
||||
|
@ -188,7 +189,7 @@ public abstract class CustomHandledScreen<T extends ScreenHandler> extends Scree
|
|||
|
||||
protected abstract void drawBackground(DrawContext context, float delta, int mouseX, int mouseY);
|
||||
|
||||
private void drawSlot(DrawContext context, Slot slot) {
|
||||
private void drawSlot(DrawContext context, Slot slot) {
|
||||
int i = slot.x;
|
||||
int j = slot.y;
|
||||
ItemStack itemStack = slot.getStack();
|
||||
|
@ -254,7 +255,7 @@ public abstract class CustomHandledScreen<T extends ScreenHandler> extends Scree
|
|||
|
||||
int i;
|
||||
int k;
|
||||
for(Iterator var2 = this.cursorDragSlots.iterator(); var2.hasNext(); this.draggedStackRemainder -= k - i) {
|
||||
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();
|
||||
|
@ -425,7 +426,7 @@ public abstract class CustomHandledScreen<T extends ScreenHandler> extends Scree
|
|||
}
|
||||
|
||||
Slot slot2;
|
||||
Iterator var13;
|
||||
Iterator<Slot> var13;
|
||||
if (this.doubleClicking && slot != null && button == 0 && this.handler.canInsertIntoSlot(ItemStack.EMPTY, slot)) {
|
||||
if (hasShiftDown()) {
|
||||
if (!this.quickMovingStack.isEmpty()) {
|
||||
|
@ -606,7 +607,7 @@ public abstract class CustomHandledScreen<T extends ScreenHandler> extends Scree
|
|||
protected void handledScreenTick() {
|
||||
}
|
||||
|
||||
public T getScreenHandler() {
|
||||
public PlayerScreenHandler getScreenHandler() {
|
||||
return this.handler;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,14 +16,13 @@ import org.jetbrains.annotations.Nullable;
|
|||
import org.joml.Matrix4f;
|
||||
import org.joml.Quaternionf;
|
||||
|
||||
public class CustomInventoryScreen extends CustomAbstractInventoryScreen<PlayerScreenHandler> {
|
||||
public class CustomInventoryScreen extends CustomAbstractInventoryScreen<CustomPlayerScreenHandler> {
|
||||
private float mouseX;
|
||||
private float mouseY;
|
||||
private boolean narrow;
|
||||
private boolean mouseDown;
|
||||
|
||||
public CustomInventoryScreen(PlayerEntity player) {
|
||||
super(player.playerScreenHandler, player.getInventory(), Text.translatable("container.crafting"));
|
||||
super(new CustomPlayerScreenHandler(player.getInventory(), !player.getWorld().isClient(), player), player.getInventory(), Text.translatable("container.crafting"));
|
||||
this.titleX = 97;
|
||||
}
|
||||
|
||||
|
@ -47,6 +46,7 @@ public class CustomInventoryScreen extends CustomAbstractInventoryScreen<PlayerS
|
|||
|
||||
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);
|
||||
|
@ -58,7 +58,7 @@ public class CustomInventoryScreen extends CustomAbstractInventoryScreen<PlayerS
|
|||
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, 30, (float)(i + 51) - this.mouseX, (float)(j + 75 - 50) - this.mouseY, this.client.player);
|
||||
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) {
|
||||
|
@ -85,6 +85,7 @@ public class CustomInventoryScreen extends CustomAbstractInventoryScreen<PlayerS
|
|||
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);
|
||||
|
|
|
@ -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};
|
||||
}
|
||||
}
|
|
@ -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'");
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -4,8 +4,6 @@ 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;
|
||||
|
@ -20,6 +18,7 @@ public class KeyInputHandler {
|
|||
|
||||
public static KeyBinding modkey;
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
public static void registerKeyInputs() {
|
||||
registerKeyBindings();
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue