mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-10-30 06:10:51 +01:00
Fix Enervator and Energizer gui crashing
This commit is contained in:
parent
6aceee7365
commit
556fa487be
5 changed files with 62 additions and 58 deletions
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.inventory;
|
package de.ellpeck.actuallyadditions.mod.inventory;
|
||||||
|
|
||||||
import com.mojang.datafixers.util.Pair;
|
import de.ellpeck.actuallyadditions.mod.inventory.slot.ArmorSlot;
|
||||||
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
|
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
|
||||||
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotOutput;
|
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotOutput;
|
||||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityEnergizer;
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityEnergizer;
|
||||||
|
@ -22,12 +22,8 @@ import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
import net.minecraft.world.inventory.InventoryMenu;
|
import net.minecraft.world.inventory.InventoryMenu;
|
||||||
import net.minecraft.world.inventory.Slot;
|
import net.minecraft.world.inventory.Slot;
|
||||||
import net.minecraft.world.item.ArmorItem;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.enchantment.EnchantmentEffectComponents;
|
|
||||||
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
|
||||||
import net.neoforged.neoforge.capabilities.Capabilities;
|
import net.neoforged.neoforge.capabilities.Capabilities;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@ -63,29 +59,8 @@ public class ContainerEnergizer extends AbstractContainerMenu {
|
||||||
|
|
||||||
for (int k = 0; k < 4; ++k) {
|
for (int k = 0; k < 4; ++k) {
|
||||||
EquipmentSlot slot = VALID_EQUIPMENT_SLOTS[k];
|
EquipmentSlot slot = VALID_EQUIPMENT_SLOTS[k];
|
||||||
this.addSlot(new Slot(inventory, 36 + 3 - k, 102, 19 + k * 18) {
|
ResourceLocation resourcelocation = InventoryMenu.TEXTURE_EMPTY_SLOTS.get(slot);
|
||||||
@Override
|
this.addSlot(new ArmorSlot(inventory, slot, 36 + 3 - k, 102, 19 + k * 18, resourcelocation));
|
||||||
public int getMaxStackSize() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mayPlace(ItemStack stack) {
|
|
||||||
return !stack.isEmpty() && stack.getItem() instanceof ArmorItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mayPickup(Player player) {
|
|
||||||
ItemStack itemstack = this.getItem();
|
|
||||||
return (itemstack.isEmpty() || player.isCreative() || !EnchantmentHelper.has(itemstack, EnchantmentEffectComponents.PREVENT_ARMOR_CHANGE)) && super.mayPickup(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public Pair<ResourceLocation, ResourceLocation> getNoItemIcon() {
|
|
||||||
return Pair.of(InventoryMenu.BLOCK_ATLAS, InventoryMenu.TEXTURE_EMPTY_SLOTS.get(slot.getIndex()));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.inventory;
|
package de.ellpeck.actuallyadditions.mod.inventory;
|
||||||
|
|
||||||
import com.mojang.datafixers.util.Pair;
|
import de.ellpeck.actuallyadditions.mod.inventory.slot.ArmorSlot;
|
||||||
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
|
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
|
||||||
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotOutput;
|
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotOutput;
|
||||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityEnervator;
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityEnervator;
|
||||||
|
@ -23,10 +23,8 @@ import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
import net.minecraft.world.inventory.InventoryMenu;
|
import net.minecraft.world.inventory.InventoryMenu;
|
||||||
import net.minecraft.world.inventory.Slot;
|
import net.minecraft.world.inventory.Slot;
|
||||||
import net.minecraft.world.item.ArmorItem;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.neoforged.neoforge.capabilities.Capabilities;
|
import net.neoforged.neoforge.capabilities.Capabilities;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@ -56,24 +54,8 @@ public class ContainerEnervator extends AbstractContainerMenu {
|
||||||
|
|
||||||
for (int k = 0; k < 4; ++k) {
|
for (int k = 0; k < 4; ++k) {
|
||||||
EquipmentSlot slot = ContainerEnergizer.VALID_EQUIPMENT_SLOTS[k];
|
EquipmentSlot slot = ContainerEnergizer.VALID_EQUIPMENT_SLOTS[k];
|
||||||
this.addSlot(new Slot(inventory, 36 + 3 - k, 102, 19 + k * 18) {
|
ResourceLocation resourcelocation = InventoryMenu.TEXTURE_EMPTY_SLOTS.get(slot);
|
||||||
@Override
|
this.addSlot(new ArmorSlot(inventory, slot, 36 + 3 - k, 102, 19 + k * 18, resourcelocation));
|
||||||
public int getMaxStackSize() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: [port] validate that this is correct
|
|
||||||
@Override
|
|
||||||
public boolean mayPlace(ItemStack stack) {
|
|
||||||
return StackUtil.isValid(stack) && stack.getItem() instanceof ArmorItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public Pair<ResourceLocation, ResourceLocation> getNoItemIcon() {
|
|
||||||
return Pair.of(InventoryMenu.BLOCK_ATLAS, InventoryMenu.TEXTURE_EMPTY_SLOTS.get(slot.getIndex()));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.inventory.gui;
|
package de.ellpeck.actuallyadditions.mod.inventory.gui;
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import de.ellpeck.actuallyadditions.mod.inventory.ContainerEnergizer;
|
import de.ellpeck.actuallyadditions.mod.inventory.ContainerEnergizer;
|
||||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityEnergizer;
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityEnergizer;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
||||||
|
@ -21,7 +20,6 @@ import net.minecraft.world.entity.player.Inventory;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
|
||||||
public class GuiEnergizer extends AAScreen<ContainerEnergizer> {
|
public class GuiEnergizer extends AAScreen<ContainerEnergizer> {
|
||||||
|
|
||||||
private static final ResourceLocation RES_LOC = AssetUtil.getGuiLocation("gui_energizer");
|
private static final ResourceLocation RES_LOC = AssetUtil.getGuiLocation("gui_energizer");
|
||||||
|
@ -49,8 +47,6 @@ public class GuiEnergizer extends AAScreen<ContainerEnergizer> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderBg(GuiGraphics guiGraphics, float f, int x, int y) {
|
public void renderBg(GuiGraphics guiGraphics, float f, int x, int y) {
|
||||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
|
||||||
|
|
||||||
guiGraphics.blit(AssetUtil.GUI_INVENTORY_LOCATION, this.leftPos, this.topPos + 93, 0, 0, 176, 86);
|
guiGraphics.blit(AssetUtil.GUI_INVENTORY_LOCATION, this.leftPos, this.topPos + 93, 0, 0, 176, 86);
|
||||||
|
|
||||||
guiGraphics.blit(RES_LOC, this.leftPos, this.topPos, 0, 0, 176, 93);
|
guiGraphics.blit(RES_LOC, this.leftPos, this.topPos, 0, 0, 176, 93);
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.inventory.gui;
|
package de.ellpeck.actuallyadditions.mod.inventory.gui;
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import de.ellpeck.actuallyadditions.mod.inventory.ContainerEnervator;
|
import de.ellpeck.actuallyadditions.mod.inventory.ContainerEnervator;
|
||||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityEnervator;
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityEnervator;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
||||||
|
@ -21,8 +20,6 @@ import net.minecraft.world.entity.player.Inventory;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class GuiEnervator extends AAScreen<ContainerEnervator> {
|
public class GuiEnervator extends AAScreen<ContainerEnervator> {
|
||||||
|
|
||||||
private static final ResourceLocation RES_LOC = AssetUtil.getGuiLocation("gui_energizer");
|
private static final ResourceLocation RES_LOC = AssetUtil.getGuiLocation("gui_energizer");
|
||||||
|
@ -50,8 +47,6 @@ public class GuiEnervator extends AAScreen<ContainerEnervator> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderBg(GuiGraphics guiGraphics, float f, int x, int y) {
|
public void renderBg(GuiGraphics guiGraphics, float f, int x, int y) {
|
||||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
|
||||||
|
|
||||||
guiGraphics.blit(AssetUtil.GUI_INVENTORY_LOCATION, this.leftPos, this.topPos + 93, 0, 0, 176, 86);
|
guiGraphics.blit(AssetUtil.GUI_INVENTORY_LOCATION, this.leftPos, this.topPos + 93, 0, 0, 176, 86);
|
||||||
|
|
||||||
guiGraphics.blit(RES_LOC, this.leftPos, this.topPos, 0, 0, 176, 93);
|
guiGraphics.blit(RES_LOC, this.leftPos, this.topPos, 0, 0, 176, 93);
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
package de.ellpeck.actuallyadditions.mod.inventory.slot;
|
||||||
|
|
||||||
|
import com.mojang.datafixers.util.Pair;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.Container;
|
||||||
|
import net.minecraft.world.entity.EquipmentSlot;
|
||||||
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.inventory.InventoryMenu;
|
||||||
|
import net.minecraft.world.inventory.Slot;
|
||||||
|
import net.minecraft.world.item.ArmorItem;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.enchantment.EnchantmentEffectComponents;
|
||||||
|
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A copy of vanilla's ArmorSlot without the owner entity
|
||||||
|
* Vanilla's ArmorSlot class is not public, so we have to copy it
|
||||||
|
*/
|
||||||
|
public class ArmorSlot extends Slot {
|
||||||
|
private final EquipmentSlot slot;
|
||||||
|
@Nullable
|
||||||
|
private final ResourceLocation emptyIcon;
|
||||||
|
|
||||||
|
public ArmorSlot(
|
||||||
|
Container container, EquipmentSlot slot, int slotIndex, int x, int y, @Nullable ResourceLocation emptyIcon
|
||||||
|
) {
|
||||||
|
super(container, slotIndex, x, y);
|
||||||
|
this.slot = slot;
|
||||||
|
this.emptyIcon = emptyIcon;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxStackSize() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mayPlace(ItemStack stack) {
|
||||||
|
return !stack.isEmpty() && stack.getItem() instanceof ArmorItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mayPickup(Player player) {
|
||||||
|
ItemStack itemstack = this.getItem();
|
||||||
|
return !itemstack.isEmpty() && !player.isCreative() && EnchantmentHelper.has(itemstack, EnchantmentEffectComponents.PREVENT_ARMOR_CHANGE)
|
||||||
|
? false
|
||||||
|
: super.mayPickup(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Pair<ResourceLocation, ResourceLocation> getNoItemIcon() {
|
||||||
|
return this.emptyIcon != null ? Pair.of(InventoryMenu.BLOCK_ATLAS, this.emptyIcon) : super.getNoItemIcon();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue