mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-19 03:39:17 +00:00
Partially restore bauble box
This commit is contained in:
1 parent
eb0c2e6521
commit
b8b2ed5ff3
5 files changed
+31
-117
No files matched your search
@@ -18,15 +18,14 @@ import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
import net.minecraftforge.items.SlotItemHandler;
|
||||
import net.minecraftforge.registries.ObjectHolder;
|
||||
import vazkii.botania.client.gui.SlotLocked;
|
||||
import vazkii.botania.common.core.handler.EquipmentHandler;
|
||||
import vazkii.botania.common.lib.LibItemNames;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
|
||||
public class ContainerBaubleBox extends Container {
|
||||
@ObjectHolder("botania:" + LibItemNames.BAUBLE_BOX)
|
||||
@@ -37,7 +36,7 @@ public class ContainerBaubleBox extends Container {
|
||||
return new ContainerBaubleBox(windowId, inv, inv.player.getHeldItem(hand));
|
||||
}
|
||||
|
||||
private final InventoryBaubleBox baubleBoxInv;
|
||||
private final ItemStack box;
|
||||
public IItemHandlerModifiable baubles;
|
||||
|
||||
public ContainerBaubleBox(int windowId, PlayerInventory playerInv, ItemStack box) {
|
||||
@@ -45,9 +44,10 @@ public class ContainerBaubleBox extends Container {
|
||||
int i;
|
||||
int j;
|
||||
|
||||
baubleBoxInv = new InventoryBaubleBox(box);
|
||||
this.box = box;
|
||||
IItemHandlerModifiable baubleBoxInv = (IItemHandlerModifiable) box.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElse(null);
|
||||
|
||||
/* todo 1.13
|
||||
/* todo 1.13 remove these slots from the gui texture and provide a button to open curios gui instead
|
||||
baubles = BaublesApi.getBaublesHandler(player);
|
||||
|
||||
addSlotToContainer(new SlotBauble(player, baubles, 0, 8, 8 + 0 * 18));
|
||||
@@ -58,37 +58,28 @@ public class ContainerBaubleBox extends Container {
|
||||
addSlotToContainer(new SlotBauble(player, baubles, 4, 27, 8 + 0 * 18));
|
||||
addSlotToContainer(new SlotBauble(player, baubles, 5, 27, 8 + 1 * 18));
|
||||
addSlotToContainer(new SlotBauble(player, baubles, 6, 27, 8 + 2 * 18));
|
||||
*/
|
||||
|
||||
for(i = 0; i < 4; ++i)
|
||||
for(j = 0; j < 6; ++j) {
|
||||
int k = j + i * 6;
|
||||
addSlotToContainer(new SlotItemHandler(baubleBoxInv, k, 62 + j * 18, 8 + i * 18));
|
||||
addSlot(new SlotItemHandler(baubleBoxInv, k, 62 + j * 18, 8 + i * 18));
|
||||
}
|
||||
*/
|
||||
|
||||
for(i = 0; i < 3; ++i)
|
||||
for(j = 0; j < 9; ++j)
|
||||
addSlot(new Slot(playerInv, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
|
||||
|
||||
for(i = 0; i < 9; ++i) {
|
||||
if(playerInv.getStackInSlot(i) == baubleBoxInv.box)
|
||||
addSlot(new SlotLocked(playerInv, i, 8 + i * 18, 142));
|
||||
else addSlot(new Slot(playerInv, i, 8 + i * 18, 142));
|
||||
addSlot(new Slot(playerInv, i, 8 + i * 18, 142));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(@Nonnull PlayerEntity player) {
|
||||
return player.getHeldItemMainhand() == baubleBoxInv.box
|
||||
|| player.getHeldItemOffhand() == baubleBoxInv.box;
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@Override
|
||||
public void setAll(List<ItemStack> l) {
|
||||
// todo 1.13 baubles.setEventBlock(true);
|
||||
super.setAll(l);
|
||||
return player.getHeldItemMainhand() == box
|
||||
|| player.getHeldItemOffhand() == box;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -101,7 +92,7 @@ public class ContainerBaubleBox extends Container {
|
||||
ItemStack itemstack1 = slot.getStack();
|
||||
itemstack = itemstack1.copy();
|
||||
|
||||
int boxStart = 7;
|
||||
int boxStart = 0;
|
||||
int boxEnd = boxStart + 24;
|
||||
int invEnd = boxEnd + 36;
|
||||
|
||||
@@ -109,7 +100,7 @@ public class ContainerBaubleBox extends Container {
|
||||
if(!mergeItemStack(itemstack1, boxEnd, invEnd, true))
|
||||
return ItemStack.EMPTY;
|
||||
} else {
|
||||
// todo 1.13 if(!itemstack1.isEmpty() && (itemstack1.getItem() instanceof IBauble || itemstack1.getItem() instanceof IManaItem) && !mergeItemStack(itemstack1, boxStart, boxEnd, false))
|
||||
if(!itemstack1.isEmpty() && EquipmentHandler.instance.isAccessory(itemstack1) && !mergeItemStack(itemstack1, boxStart, boxEnd, false))
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
/**
|
||||
* This class was created by <Vazkii>. It's distributed as
|
||||
* part of the Botania Mod. Get the Source Code in github:
|
||||
* https://github.com/Vazkii/Botania
|
||||
*
|
||||
* Botania is Open Source and distributed under the
|
||||
* Botania License: http://botaniamod.net/license.php
|
||||
*
|
||||
* File Created @ [25/11/2015, 19:59:16 (GMT)]
|
||||
*/
|
||||
package vazkii.botania.client.gui.box;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class InventoryBaubleBox implements IItemHandlerModifiable {
|
||||
|
||||
private final IItemHandlerModifiable boxInv;
|
||||
final ItemStack box;
|
||||
|
||||
public InventoryBaubleBox(ItemStack box) {
|
||||
this.box = box;
|
||||
boxInv = (IItemHandlerModifiable) box.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackInSlot(int slot, @Nonnull ItemStack stack) {
|
||||
boxInv.setStackInSlot(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots() {
|
||||
return boxInv.getSlots();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
return boxInv.getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
|
||||
return boxInv.insertItem(slot, stack, simulate);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||
return boxInv.extractItem(slot, amount, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit(int slot) {
|
||||
return boxInv.getSlotLimit(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(int slot, @Nonnull ItemStack stack) {
|
||||
return boxInv.isItemValid(slot, stack);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
import net.minecraftforge.items.wrapper.InvWrapper;
|
||||
import net.minecraftforge.items.wrapper.RangedWrapper;
|
||||
import vazkii.botania.api.mana.IManaItem;
|
||||
import vazkii.botania.common.Botania;
|
||||
import vazkii.botania.common.integration.curios.CurioIntegration;
|
||||
import vazkii.botania.common.item.equipment.bauble.ItemBauble;
|
||||
@@ -34,7 +35,7 @@ import java.util.WeakHashMap;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public abstract class EquipmentHandler {
|
||||
private static EquipmentHandler instance;
|
||||
public static EquipmentHandler instance;
|
||||
|
||||
public static void init() { //todo maybe support baubles when/if that gets released
|
||||
if(Botania.curiosLoaded) {
|
||||
@@ -74,6 +75,10 @@ public abstract class EquipmentHandler {
|
||||
|
||||
protected abstract ICapabilityProvider initCap(ItemStack stack);
|
||||
|
||||
public boolean isAccessory(ItemStack stack) {
|
||||
return stack.getItem() instanceof ItemBauble || stack.getItem() instanceof IManaItem;
|
||||
}
|
||||
|
||||
// Fallback equipment handler for curios-less (or baubles-less) installs.
|
||||
static class InventoryEquipmentHandler extends EquipmentHandler {
|
||||
private final Map<PlayerEntity, ItemStack[]> map = new WeakHashMap<>();
|
||||
|
||||
@@ -83,6 +83,11 @@ public class CurioIntegration extends EquipmentHandler {
|
||||
return new Provider(new Wrapper(stack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccessory(ItemStack stack) {
|
||||
return super.isAccessory(stack) || stack.getCapability(CuriosCapability.ITEM).isPresent();
|
||||
}
|
||||
|
||||
private static class Wrapper implements ICurio {
|
||||
private final ItemStack stack;
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
import net.minecraft.inventory.container.SimpleNamedContainerProvider;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.INBT;
|
||||
@@ -33,6 +34,7 @@ import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
import vazkii.botania.client.gui.box.ContainerBaubleBox;
|
||||
import vazkii.botania.common.core.handler.EquipmentHandler;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -55,13 +57,10 @@ public class ItemBaubleBox extends ItemMod {
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack insertItem(int slot, @Nonnull ItemStack toInsert, boolean simulate) {
|
||||
/* todo 1.13
|
||||
if(!toInsert.isEmpty()) {
|
||||
boolean isBauble = toInsert.getCapability(BaublesCapabilities.CAPABILITY_ITEM_BAUBLE).isPresent();
|
||||
if(toInsert.getItem() instanceof IManaItem || isBauble)
|
||||
if(EquipmentHandler.instance.isAccessory(toInsert))
|
||||
return super.insertItem(slot, toInsert, simulate);
|
||||
}
|
||||
*/
|
||||
return toInsert;
|
||||
}
|
||||
};
|
||||
@@ -88,31 +87,12 @@ public class ItemBaubleBox extends ItemMod {
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, @Nonnull Hand hand) {
|
||||
if(!world.isRemote) {
|
||||
NetworkHooks.openGui((ServerPlayerEntity) player, new ContainerProvider(player.getHeldItem(hand)), b -> {
|
||||
ItemStack stack = player.getHeldItem(hand);
|
||||
INamedContainerProvider container = new SimpleNamedContainerProvider((w, p, pl) -> new ContainerBaubleBox(w, p, stack), stack.getDisplayName());
|
||||
NetworkHooks.openGui((ServerPlayerEntity) player, container, b -> {
|
||||
b.writeBoolean(hand == Hand.MAIN_HAND);
|
||||
});
|
||||
}
|
||||
return ActionResult.newResult(ActionResultType.SUCCESS, player.getHeldItem(hand));
|
||||
}
|
||||
|
||||
private static class ContainerProvider implements INamedContainerProvider {
|
||||
private final ItemStack stack;
|
||||
|
||||
private ContainerProvider(ItemStack stack) {
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ITextComponent getDisplayName() {
|
||||
return stack.getDisplayName();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Container createMenu(int windowId, PlayerInventory playerInv, PlayerEntity player) {
|
||||
return new ContainerBaubleBox(windowId, playerInv, stack);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user