make server gui inv unmodifiable by normal (vanilla) means
This commit is contained in:
parent
38ad375f20
commit
8429e36aee
@ -6,10 +6,10 @@ import io.github.flemmli97.flan.claim.Claim;
|
||||
import io.github.flemmli97.flan.claim.ClaimStorage;
|
||||
import io.github.flemmli97.flan.claim.PermHelper;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.gui.inv.SeparateInv;
|
||||
import io.github.flemmli97.flan.player.PlayerClaimData;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.screen.NamedScreenHandlerFactory;
|
||||
@ -45,44 +45,44 @@ public class ClaimMenuScreenHandler extends ServerOnlyScreenHandler<Claim> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillInventoryWith(PlayerEntity player, Inventory inv, Claim claim) {
|
||||
protected void fillInventoryWith(PlayerEntity player, SeparateInv inv, Claim claim) {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
ItemStack close = new ItemStack(Items.TNT);
|
||||
close.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenClose, Formatting.DARK_RED));
|
||||
inv.setStack(i, close);
|
||||
inv.updateStack(i, close);
|
||||
break;
|
||||
case 2:
|
||||
ItemStack perm = new ItemStack(Items.BEACON);
|
||||
perm.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenMenuGlobal, Formatting.GOLD));
|
||||
if (player instanceof ServerPlayerEntity && !this.hasEditPerm(claim, (ServerPlayerEntity) player))
|
||||
ServerScreenHelper.addLore(perm, ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenNoPerm, Formatting.DARK_RED));
|
||||
inv.setStack(i, perm);
|
||||
inv.updateStack(i, perm);
|
||||
break;
|
||||
case 3:
|
||||
ItemStack group = new ItemStack(Items.WRITABLE_BOOK);
|
||||
group.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenMenuGroup, Formatting.GOLD));
|
||||
if (player instanceof ServerPlayerEntity && !this.hasEditPerm(claim, (ServerPlayerEntity) player))
|
||||
ServerScreenHelper.addLore(group, ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenNoPerm, Formatting.DARK_RED));
|
||||
inv.setStack(i, group);
|
||||
inv.updateStack(i, group);
|
||||
break;
|
||||
case 4:
|
||||
ItemStack potions = new ItemStack(Items.POTION);
|
||||
potions.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenMenuPotion, Formatting.GOLD));
|
||||
if (player instanceof ServerPlayerEntity && !this.hasPerm(claim, (ServerPlayerEntity) player, PermissionRegistry.EDITPOTIONS))
|
||||
ServerScreenHelper.addLore(potions, ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenNoPerm, Formatting.DARK_RED));
|
||||
inv.setStack(i, potions);
|
||||
inv.updateStack(i, potions);
|
||||
break;
|
||||
case 8:
|
||||
ItemStack delete = new ItemStack(Items.BARRIER);
|
||||
delete.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenMenuDelete, Formatting.RED));
|
||||
if (player instanceof ServerPlayerEntity && !this.hasPerm(claim, (ServerPlayerEntity) player, PermissionRegistry.EDITCLAIM))
|
||||
ServerScreenHelper.addLore(delete, ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenNoPerm, Formatting.DARK_RED));
|
||||
inv.setStack(i, delete);
|
||||
inv.updateStack(i, delete);
|
||||
break;
|
||||
default:
|
||||
inv.setStack(i, ServerScreenHelper.emptyFiller());
|
||||
inv.updateStack(i, ServerScreenHelper.emptyFiller());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,9 @@ package io.github.flemmli97.flan.gui;
|
||||
|
||||
import io.github.flemmli97.flan.claim.PermHelper;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.gui.inv.SeparateInv;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.screen.NamedScreenHandlerFactory;
|
||||
@ -42,21 +42,21 @@ public class ConfirmScreenHandler extends ServerOnlyScreenHandler<Object> {
|
||||
|
||||
|
||||
@Override
|
||||
protected void fillInventoryWith(PlayerEntity player, Inventory inv, Object additionalData) {
|
||||
protected void fillInventoryWith(PlayerEntity player, SeparateInv inv, Object additionalData) {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
switch (i) {
|
||||
case 3:
|
||||
ItemStack yes = new ItemStack(Items.GREEN_WOOL);
|
||||
yes.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenYes, Formatting.GREEN));
|
||||
inv.setStack(i, yes);
|
||||
inv.updateStack(i, yes);
|
||||
break;
|
||||
case 5:
|
||||
ItemStack no = new ItemStack(Items.RED_WOOL);
|
||||
no.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenNo, Formatting.RED));
|
||||
inv.setStack(i, no);
|
||||
inv.updateStack(i, no);
|
||||
break;
|
||||
default:
|
||||
inv.setStack(i, ServerScreenHelper.emptyFiller());
|
||||
inv.updateStack(i, ServerScreenHelper.emptyFiller());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,10 +4,10 @@ import com.mojang.authlib.GameProfile;
|
||||
import io.github.flemmli97.flan.claim.Claim;
|
||||
import io.github.flemmli97.flan.claim.PermHelper;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.gui.inv.SeparateInv;
|
||||
import net.minecraft.block.entity.SkullBlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
@ -61,24 +61,24 @@ public class GroupPlayerScreenHandler extends ServerOnlyScreenHandler<ClaimGroup
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillInventoryWith(PlayerEntity player, Inventory inv, ClaimGroup additionalData) {
|
||||
protected void fillInventoryWith(PlayerEntity player, SeparateInv inv, ClaimGroup additionalData) {
|
||||
Claim claim = additionalData.getClaim();
|
||||
List<String> players = claim.playersFromGroup(player.getServer(), additionalData.getGroup());
|
||||
for (int i = 0; i < 54; i++) {
|
||||
if (i == 0) {
|
||||
ItemStack close = new ItemStack(Items.TNT);
|
||||
close.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenBack, Formatting.DARK_RED));
|
||||
inv.setStack(i, close);
|
||||
inv.updateStack(i, close);
|
||||
} else if (i == 3) {
|
||||
ItemStack stack = new ItemStack(Items.ANVIL);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenAdd, Formatting.DARK_GREEN));
|
||||
inv.setStack(i, stack);
|
||||
inv.updateStack(i, stack);
|
||||
} else if (i == 4) {
|
||||
ItemStack stack = new ItemStack(Items.REDSTONE_BLOCK);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText(String.format(ConfigHandler.lang.screenRemoveMode, this.removeMode), Formatting.DARK_RED));
|
||||
inv.setStack(i, stack);
|
||||
inv.updateStack(i, stack);
|
||||
} else if (i < 9 || i > 44 || i % 9 == 0 || i % 9 == 8)
|
||||
inv.setStack(i, ServerScreenHelper.emptyFiller());
|
||||
inv.updateStack(i, ServerScreenHelper.emptyFiller());
|
||||
else {
|
||||
int row = i / 9 - 1;
|
||||
int id = (i % 9) + row * 7 - 1;
|
||||
@ -87,7 +87,7 @@ public class GroupPlayerScreenHandler extends ServerOnlyScreenHandler<ClaimGroup
|
||||
GameProfile gameProfile = new GameProfile(null, players.get(id));
|
||||
gameProfile = SkullBlockEntity.loadProperties(gameProfile);
|
||||
group.getOrCreateTag().put("SkullOwner", NbtHelper.fromGameProfile(new CompoundTag(), gameProfile));
|
||||
inv.setStack(i, group);
|
||||
inv.updateStack(i, group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,9 @@ package io.github.flemmli97.flan.gui;
|
||||
import io.github.flemmli97.flan.api.PermissionRegistry;
|
||||
import io.github.flemmli97.flan.claim.Claim;
|
||||
import io.github.flemmli97.flan.claim.PermHelper;
|
||||
import io.github.flemmli97.flan.gui.inv.SeparateInv;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.screen.NamedScreenHandlerFactory;
|
||||
@ -45,22 +45,22 @@ public class GroupScreenHandler extends ServerOnlyScreenHandler<Claim> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillInventoryWith(PlayerEntity player, Inventory inv, Claim claim) {
|
||||
protected void fillInventoryWith(PlayerEntity player, SeparateInv inv, Claim claim) {
|
||||
for (int i = 0; i < 54; i++) {
|
||||
if (i == 0) {
|
||||
ItemStack close = new ItemStack(Items.TNT);
|
||||
close.setCustomName(ServerScreenHelper.coloredGuiText("Back", Formatting.DARK_RED));
|
||||
inv.setStack(i, close);
|
||||
inv.updateStack(i, close);
|
||||
} else if (i == 3) {
|
||||
ItemStack stack = new ItemStack(Items.ANVIL);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText("Add", Formatting.DARK_GREEN));
|
||||
inv.setStack(i, stack);
|
||||
inv.updateStack(i, stack);
|
||||
} else if (i == 4) {
|
||||
ItemStack stack = new ItemStack(Items.REDSTONE_BLOCK);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText("Remove Mode: " + this.removeMode, Formatting.DARK_RED));
|
||||
inv.setStack(i, stack);
|
||||
inv.updateStack(i, stack);
|
||||
} else if (i < 9 || i > 44 || i % 9 == 0 || i % 9 == 8)
|
||||
inv.setStack(i, ServerScreenHelper.emptyFiller());
|
||||
inv.updateStack(i, ServerScreenHelper.emptyFiller());
|
||||
else {
|
||||
List<String> groups = claim.groups();
|
||||
int row = i / 9 - 1;
|
||||
@ -68,7 +68,7 @@ public class GroupScreenHandler extends ServerOnlyScreenHandler<Claim> {
|
||||
if (id < groups.size()) {
|
||||
ItemStack group = new ItemStack(Items.PAPER);
|
||||
group.setCustomName(ServerScreenHelper.coloredGuiText(groups.get(id), Formatting.DARK_BLUE));
|
||||
inv.setStack(i, group);
|
||||
inv.updateStack(i, group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,9 @@ import io.github.flemmli97.flan.api.PermissionRegistry;
|
||||
import io.github.flemmli97.flan.claim.Claim;
|
||||
import io.github.flemmli97.flan.claim.PermHelper;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.gui.inv.SeparateInv;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.screen.NamedScreenHandlerFactory;
|
||||
@ -59,7 +59,7 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler<ClaimGroup>
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillInventoryWith(PlayerEntity player, Inventory inv, ClaimGroup additionalData) {
|
||||
protected void fillInventoryWith(PlayerEntity player, SeparateInv inv, ClaimGroup additionalData) {
|
||||
List<ClaimPermission> perms = new ArrayList<>(PermissionRegistry.getPerms());
|
||||
if (this.group != null)
|
||||
perms.removeAll(PermissionRegistry.globalPerms());
|
||||
@ -68,22 +68,22 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler<ClaimGroup>
|
||||
if (i == 0) {
|
||||
ItemStack close = new ItemStack(Items.TNT);
|
||||
close.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenBack, Formatting.DARK_RED));
|
||||
inv.setStack(i, close);
|
||||
inv.updateStack(i, close);
|
||||
} else if (page == 1 && i == 47) {
|
||||
ItemStack close = new ItemStack(Items.ARROW);
|
||||
close.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenPrevious, Formatting.WHITE));
|
||||
inv.setStack(i, close);
|
||||
inv.updateStack(i, close);
|
||||
} else if (page == 0 && i == 51) {
|
||||
ItemStack close = new ItemStack(Items.ARROW);
|
||||
close.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenNext, Formatting.WHITE));
|
||||
inv.setStack(i, close);
|
||||
inv.updateStack(i, close);
|
||||
} else if (i < 9 || i > 44 || i % 9 == 0 || i % 9 == 8)
|
||||
inv.setStack(i, ServerScreenHelper.emptyFiller());
|
||||
inv.updateStack(i, ServerScreenHelper.emptyFiller());
|
||||
else {
|
||||
int row = i / 9 - 1;
|
||||
int id = (i % 9) + row * 7 - 1 + page * 28;
|
||||
if (id < perms.size())
|
||||
inv.setStack(i, ServerScreenHelper.fromPermission(additionalData.getClaim(), perms.get(id), additionalData.getGroup() == null ? null : additionalData.getGroup()));
|
||||
inv.updateStack(i, ServerScreenHelper.fromPermission(additionalData.getClaim(), perms.get(id), additionalData.getGroup() == null ? null : additionalData.getGroup()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -92,7 +92,7 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler<ClaimGroup>
|
||||
List<ClaimPermission> perms = new ArrayList<>(PermissionRegistry.getPerms());
|
||||
if (this.group != null)
|
||||
perms.removeAll(PermissionRegistry.globalPerms());
|
||||
int maxPages = perms.size() / 28;
|
||||
int maxPages = (perms.size() - 1) / 28;
|
||||
for (int i = 0; i < 54; i++) {
|
||||
if (i == 0) {
|
||||
ItemStack close = new ItemStack(Items.TNT);
|
||||
|
@ -3,10 +3,10 @@ package io.github.flemmli97.flan.gui;
|
||||
import io.github.flemmli97.flan.api.PermissionRegistry;
|
||||
import io.github.flemmli97.flan.claim.PermHelper;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.gui.inv.SeparateInv;
|
||||
import io.github.flemmli97.flan.player.PlayerClaimData;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.screen.NamedScreenHandlerFactory;
|
||||
@ -44,24 +44,24 @@ public class PersonalGroupScreenHandler extends ServerOnlyScreenHandler<Object>
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillInventoryWith(PlayerEntity player, Inventory inv, Object additionalData) {
|
||||
protected void fillInventoryWith(PlayerEntity player, SeparateInv inv, Object additionalData) {
|
||||
if (!(player instanceof ServerPlayerEntity))
|
||||
return;
|
||||
for (int i = 0; i < 54; i++) {
|
||||
if (i == 0) {
|
||||
ItemStack close = new ItemStack(Items.TNT);
|
||||
close.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenBack, Formatting.DARK_RED));
|
||||
inv.setStack(i, close);
|
||||
inv.updateStack(i, close);
|
||||
} else if (i == 3) {
|
||||
ItemStack stack = new ItemStack(Items.ANVIL);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenAdd, Formatting.DARK_GREEN));
|
||||
inv.setStack(i, stack);
|
||||
inv.updateStack(i, stack);
|
||||
} else if (i == 4) {
|
||||
ItemStack stack = new ItemStack(Items.REDSTONE_BLOCK);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText(String.format(ConfigHandler.lang.screenRemoveMode, this.removeMode), Formatting.DARK_RED));
|
||||
inv.setStack(i, stack);
|
||||
inv.updateStack(i, stack);
|
||||
} else if (i < 9 || i > 44 || i % 9 == 0 || i % 9 == 8)
|
||||
inv.setStack(i, ServerScreenHelper.emptyFiller());
|
||||
inv.updateStack(i, ServerScreenHelper.emptyFiller());
|
||||
else {
|
||||
List<String> groups = new ArrayList<>(PlayerClaimData.get((ServerPlayerEntity) player).playerDefaultGroups().keySet());
|
||||
groups.sort(null);
|
||||
@ -70,7 +70,7 @@ public class PersonalGroupScreenHandler extends ServerOnlyScreenHandler<Object>
|
||||
if (id < groups.size()) {
|
||||
ItemStack group = new ItemStack(Items.PAPER);
|
||||
group.setCustomName(ServerScreenHelper.coloredGuiText(groups.get(id), Formatting.DARK_BLUE));
|
||||
inv.setStack(i, group);
|
||||
inv.updateStack(i, group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,10 +4,10 @@ import io.github.flemmli97.flan.api.ClaimPermission;
|
||||
import io.github.flemmli97.flan.api.PermissionRegistry;
|
||||
import io.github.flemmli97.flan.claim.PermHelper;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.gui.inv.SeparateInv;
|
||||
import io.github.flemmli97.flan.player.PlayerClaimData;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.screen.NamedScreenHandlerFactory;
|
||||
@ -51,7 +51,7 @@ public class PersonalPermissionScreenHandler extends ServerOnlyScreenHandler<Str
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillInventoryWith(PlayerEntity player, Inventory inv, String group) {
|
||||
protected void fillInventoryWith(PlayerEntity player, SeparateInv inv, String group) {
|
||||
if (!(player instanceof ServerPlayerEntity))
|
||||
return;
|
||||
List<ClaimPermission> perms = new ArrayList<>(PermissionRegistry.getPerms());
|
||||
@ -62,22 +62,22 @@ public class PersonalPermissionScreenHandler extends ServerOnlyScreenHandler<Str
|
||||
if (i == 0) {
|
||||
ItemStack close = new ItemStack(Items.TNT);
|
||||
close.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenBack, Formatting.DARK_RED));
|
||||
inv.setStack(i, close);
|
||||
inv.updateStack(i, close);
|
||||
} else if (page == 1 && i == 47) {
|
||||
ItemStack close = new ItemStack(Items.ARROW);
|
||||
close.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenPrevious, Formatting.WHITE));
|
||||
inv.setStack(i, close);
|
||||
inv.updateStack(i, close);
|
||||
} else if (page == 0 && i == 51) {
|
||||
ItemStack close = new ItemStack(Items.ARROW);
|
||||
close.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenNext, Formatting.WHITE));
|
||||
inv.setStack(i, close);
|
||||
inv.updateStack(i, close);
|
||||
} else if (i < 9 || i > 44 || i % 9 == 0 || i % 9 == 8)
|
||||
inv.setStack(i, ServerScreenHelper.emptyFiller());
|
||||
inv.updateStack(i, ServerScreenHelper.emptyFiller());
|
||||
else {
|
||||
int row = i / 9 - 1;
|
||||
int id = (i % 9) + row * 7 - 1 + page * 28;
|
||||
if (id < perms.size())
|
||||
inv.setStack(i, ServerScreenHelper.getFromPersonal((ServerPlayerEntity) player, perms.get(id), group));
|
||||
inv.updateStack(i, ServerScreenHelper.getFromPersonal((ServerPlayerEntity) player, perms.get(id), group));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,12 +4,12 @@ import com.google.common.collect.Lists;
|
||||
import io.github.flemmli97.flan.CrossPlatformStuff;
|
||||
import io.github.flemmli97.flan.claim.Claim;
|
||||
import io.github.flemmli97.flan.claim.PermHelper;
|
||||
import io.github.flemmli97.flan.gui.inv.SeparateInv;
|
||||
import net.minecraft.entity.effect.StatusEffect;
|
||||
import net.minecraft.entity.effect.StatusEffectInstance;
|
||||
import net.minecraft.entity.effect.StatusEffects;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.potion.PotionUtil;
|
||||
@ -56,7 +56,7 @@ public class PotionEditScreenHandler extends ServerOnlyScreenHandler<Claim> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillInventoryWith(PlayerEntity player, Inventory inv, Claim claim) {
|
||||
protected void fillInventoryWith(PlayerEntity player, SeparateInv inv, Claim claim) {
|
||||
Map<StatusEffect, Integer> potions = claim.getPotions();
|
||||
List<StatusEffect> key = Lists.newArrayList(potions.keySet());
|
||||
key.sort(Comparator.comparing(eff -> CrossPlatformStuff.registryStatusEffects().getIDFrom(eff).toString()));
|
||||
@ -64,17 +64,17 @@ public class PotionEditScreenHandler extends ServerOnlyScreenHandler<Claim> {
|
||||
if (i == 0) {
|
||||
ItemStack close = new ItemStack(Items.TNT);
|
||||
close.setCustomName(ServerScreenHelper.coloredGuiText("Back", Formatting.DARK_RED));
|
||||
inv.setStack(i, close);
|
||||
inv.updateStack(i, close);
|
||||
} else if (i == 3) {
|
||||
ItemStack stack = new ItemStack(Items.ANVIL);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText("Add", Formatting.DARK_GREEN));
|
||||
inv.setStack(i, stack);
|
||||
inv.updateStack(i, stack);
|
||||
} else if (i == 4) {
|
||||
ItemStack stack = new ItemStack(Items.REDSTONE_BLOCK);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText("Remove Mode: " + this.removeMode, Formatting.DARK_RED));
|
||||
inv.setStack(i, stack);
|
||||
inv.updateStack(i, stack);
|
||||
} else if (i < 9 || i > 44 || i % 9 == 0 || i % 9 == 8)
|
||||
inv.setStack(i, ServerScreenHelper.emptyFiller());
|
||||
inv.updateStack(i, ServerScreenHelper.emptyFiller());
|
||||
else {
|
||||
int row = i / 9 - 1;
|
||||
int id = (i % 9) + row * 7 - 1;
|
||||
@ -86,7 +86,7 @@ public class PotionEditScreenHandler extends ServerOnlyScreenHandler<Claim> {
|
||||
effectStack.getOrCreateTag().putString("FlanEffect", CrossPlatformStuff.registryStatusEffects().getIDFrom(effect).toString());
|
||||
effectStack.getTag().putInt("CustomPotionColor", PotionUtil.getColor(inst));
|
||||
effectStack.setCustomName(txt.setStyle(txt.getStyle().withItalic(false).withFormatting(Formatting.DARK_BLUE)).append(ServerScreenHelper.coloredGuiText("-" + potions.get(effect), Formatting.DARK_BLUE)));
|
||||
inv.setStack(i, effectStack);
|
||||
inv.updateStack(i, effectStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
package io.github.flemmli97.flan.gui;
|
||||
|
||||
import io.github.flemmli97.flan.gui.inv.SeparateInv;
|
||||
import io.github.flemmli97.flan.gui.inv.SeparateInvImpl;
|
||||
import io.github.flemmli97.flan.gui.inv.SlotDelegate;
|
||||
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.GenericContainerScreenHandler;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
@ -18,30 +19,51 @@ import java.util.List;
|
||||
|
||||
public abstract class ServerOnlyScreenHandler<T> extends ScreenHandler {
|
||||
|
||||
private final Inventory inventory;
|
||||
private final SeparateInvImpl inventory;
|
||||
private final List<ScreenHandlerListener> listeners = new ArrayList<>();
|
||||
private boolean update = true;
|
||||
|
||||
protected ServerOnlyScreenHandler(int syncId, PlayerInventory playerInventory, int rows, T additionalData) {
|
||||
super(fromRows(rows), syncId);
|
||||
int i = (rows - 4) * 18;
|
||||
this.inventory = new SimpleInventory(rows * 9);
|
||||
this.inventory = new SeparateInvImpl(rows * 9);
|
||||
this.fillInventoryWith(playerInventory.player, this.inventory, additionalData);
|
||||
int n;
|
||||
int m;
|
||||
for (n = 0; n < rows; ++n) {
|
||||
for (m = 0; m < 9; ++m) {
|
||||
this.addSlot(new Slot(this.inventory, m + n * 9, 8 + m * 18, 18 + n * 18));
|
||||
this.addSlot(new SlotDelegate(this.inventory, m + n * 9, 8 + m * 18, 18 + n * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for (n = 0; n < 3; ++n) {
|
||||
for (m = 0; m < 9; ++m) {
|
||||
this.addSlot(new Slot(playerInventory, m + n * 9 + 9, 8 + m * 18, 103 + n * 18 + i));
|
||||
this.addSlot(new Slot(playerInventory, m + n * 9 + 9, 8 + m * 18, 103 + n * 18 + i) {
|
||||
@Override
|
||||
public boolean canInsert(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeItems(PlayerEntity playerEntity) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (n = 0; n < 9; ++n) {
|
||||
this.addSlot(new Slot(playerInventory, n, 8 + n * 18, 161 + i));
|
||||
this.addSlot(new Slot(playerInventory, n, 8 + n * 18, 161 + i) {
|
||||
@Override
|
||||
public boolean canInsert(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeItems(PlayerEntity playerEntity) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,7 +83,7 @@ public abstract class ServerOnlyScreenHandler<T> extends ScreenHandler {
|
||||
return ScreenHandlerType.GENERIC_9X1;
|
||||
}
|
||||
|
||||
protected abstract void fillInventoryWith(PlayerEntity player, Inventory inv, T additionalData);
|
||||
protected abstract void fillInventoryWith(PlayerEntity player, SeparateInv inv, T additionalData);
|
||||
|
||||
@Override
|
||||
public boolean canUse(PlayerEntity player) {
|
||||
@ -89,19 +111,27 @@ public abstract class ServerOnlyScreenHandler<T> extends ScreenHandler {
|
||||
Slot slot = this.slots.get(index);
|
||||
if (this.isRightSlot(index))
|
||||
this.handleSlotClicked((ServerPlayerEntity) player, index, slot, 0);
|
||||
this.sendContentUpdates();
|
||||
return slot.getStack().copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(ScreenHandlerListener listener) {
|
||||
this.update = false;
|
||||
super.addListener(listener);
|
||||
if (!this.listeners.contains(listener)) {
|
||||
this.listeners.add(listener);
|
||||
listener.onHandlerRegistered(this, this.getStacks());
|
||||
this.update = true;
|
||||
this.sendContentUpdates();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendContentUpdates() {
|
||||
if (this.update)
|
||||
super.sendContentUpdates();
|
||||
}
|
||||
|
||||
protected abstract boolean isRightSlot(int slot);
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,14 @@
|
||||
package io.github.flemmli97.flan.gui.inv;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* This ensures that other mods will never be able to modify and get items from the inventory.
|
||||
* For inventory management mods that also do things on the server (e.g. Quark)
|
||||
*/
|
||||
public interface SeparateInv {
|
||||
|
||||
void updateStack(int slot, ItemStack stack);
|
||||
|
||||
ItemStack getActualStack(int slot);
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package io.github.flemmli97.flan.gui.inv;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.SimpleInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SeparateInvImpl extends SimpleInventory implements SeparateInv {
|
||||
|
||||
public SeparateInvImpl(int size) {
|
||||
super(size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStack(int slot) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> clearToList() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStack(int slot, int amount) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItem(Item item, int count) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addStack(ItemStack stack) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsert(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStack(int slot) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStack(int slot, ItemStack stack) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlayerUse(PlayerEntity player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStack(int slot, ItemStack stack) {
|
||||
super.setStack(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getActualStack(int slot) {
|
||||
return super.getStack(slot);
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package io.github.flemmli97.flan.gui.inv;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
|
||||
public class SlotDelegate extends Slot {
|
||||
|
||||
private final int index;
|
||||
|
||||
public SlotDelegate(SeparateInvImpl inventory, int index, int x, int y) {
|
||||
super(inventory, index, x, y);
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStack(ItemStack stack) {
|
||||
((SeparateInvImpl) this.inventory).updateStack(this.index, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStack() {
|
||||
return ((SeparateInvImpl) this.inventory).getActualStack(this.index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsert(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeItems(PlayerEntity playerEntity) {
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user