Skip to content

Commit

Permalink
Merge branch '1.18.2' into 1.19.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Thutmose committed Oct 11, 2022
2 parents 50c228b + da73f44 commit 0743f85
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ public void init()
parent.renderTooltip(pose, tooltip, x, y);
}));

this.guard.setFGColor(guarding ? 0xFF00FF00 : 0xFFFF0000);
this.sit.setFGColor(sitting ? 0xFF00FF00 : 0xFFFF0000);
this.stay.setFGColor(staying ? 0xFF00FF00 : 0xFFFF0000);

final int k = (this.width - this.imageWidth) / 2;
final int l = (this.height - this.imageHeight) / 2;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void init()
this.addRenderableWidget(new TooltipArea(k + 64, l + 54, 16, 16,
TComponent.translatable("pokemob.gui.slot.storage.off_hand"), (x, y) ->
{
Slot offhand_slot = menu.slots.get(0);
Slot offhand_slot = menu.slots.get(3);
if (offhand_slot.hasItem()) return false;
return PokecubeCore.getConfig().pokemobGuiTooltips;
}, (b, pose, x, y) -> {
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/pokecube/core/inventory/CustomSlot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package pokecube.core.inventory;

import net.minecraft.world.Container;
import net.minecraft.world.inventory.Slot;

public class CustomSlot extends Slot
{
private boolean active = true;

public CustomSlot(final Container inventoryIn, final int index, final int xPosition, final int yPosition)
{
super(inventoryIn, index, xPosition, yPosition);
}

public void setActive(boolean active)
{
this.active = active;
}

@Override
public boolean isActive()
{
return active;
}
}
3 changes: 1 addition & 2 deletions src/main/java/pokecube/core/inventory/TexturedSlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.Container;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;

public class TexturedSlot extends Slot
public class TexturedSlot extends CustomSlot
{
public TexturedSlot(final Container inventoryIn, final int index, final int xPosition, final int yPosition,
final String texture)
Expand Down
168 changes: 93 additions & 75 deletions src/main/java/pokecube/core/inventory/pokemob/PokemobContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import pokecube.api.entity.pokemob.IPokemob;
import pokecube.api.entity.pokemob.PokemobCaps;
import pokecube.core.PokecubeItems;
import pokecube.core.client.Resources;
import pokecube.core.init.MenuTypes;
import pokecube.core.inventory.CustomSlot;
import pokecube.core.inventory.TexturedSlot;
import pokecube.core.network.pokemobs.PacketPokemobGui;
import pokecube.core.utils.EntityTools;
Expand Down Expand Up @@ -48,98 +48,116 @@ public PokemobContainer(final int id, final Inventory playerInv, final FriendlyB
this.data = data;
this.pokemobInv.startOpen(playerInv.player);
this.playerInv = playerInv;
this.initSlots();
this.setMode(this.mode);
}

private void initSlots()
{
int offhand = pokemobInv.getContainerSize() - 1;

this.addSlot(new CustomSlot(this.pokemobInv, 0, 64, 18)
{
/**
* Check if the stack is a valid item for this slot. Always true
* beside for the armor slots.
*/
@Override
public boolean mayPlace(final ItemStack stack)
{
return super.mayPlace(stack) && stack.getItem() == Items.SADDLE;
}
});
this.addSlot(new CustomSlot(this.pokemobInv, 1, 64, 36)
{
/**
* Returns the maximum stack size for a given slot (usually the same
* as getInventoryStackLimit(), but 1 in the case of armor slots)
*/
@Override
public int getMaxStackSize()
{
return 1;
}

/**
* Check if the stack is a valid item for this slot. Always true
* beside for the armor slots.
*/
@Override
public boolean mayPlace(final ItemStack stack)
{
return !pokemob.getPokedexEntry().stock || PokecubeItems.isValidHeldItem(stack);
}

@Override
public void onTake(final Player playerIn, final ItemStack stack)
{
final ItemStack old = this.getItem();
if (ThutCore.proxy.isServerSide()) PokemobContainer.this.pokemob.getPokedexEntry()
.onHeldItemChange(stack, old, PokemobContainer.this.pokemob);
super.onTake(playerIn, stack);
}

/** Helper method to put a stack in the slot. */
@Override
public void set(final ItemStack stack)
{
// ItemStack old = getStack();
super.set(stack);
if (ThutCore.proxy.isServerSide()) PokemobContainer.this.pokemob.setHeldItem(stack);
}
});
this.addSlot(new TexturedSlot(this.pokemobInv, offhand, 64, 54, Resources.SLOT_ICON_BOOK));
for (int k = 0; k < 5; ++k) this.addSlot(new CustomSlot(this.pokemobInv, 2 + k, 83 + k * 18, 18)
{
/**
* Check if the stack is a valid item for this slot. Always true
* beside for the armor slots.
*/
@Override
public boolean mayPlace(final ItemStack stack)
{
return true;// ItemList.isValidHeldItem(stack);
}
});

this.bindPlayerInventory(this.playerInv, -19);
}

public void setMode(final int mode)
{

if (mode != this.mode && playerInv.player.level.isClientSide())
{
PacketPokemobGui.sendPagePacket((byte) mode, pokemob.getEntity().getId());
}

this.mode = (byte) mode;

this.slots.clear();
this.lastSlots.clear();

int offhand = pokemobInv.getContainerSize() - 1;

if (mode == PacketPokemobGui.STORAGE)
// Toggle activation of slots based on mode.
if (mode == PacketPokemobGui.MAIN)
{
this.addSlot(new TexturedSlot(this.pokemobInv, offhand, 64, 54, Resources.SLOT_ICON_BOOK));
// Main has all of them active
this.slots.forEach(s -> {
if (s instanceof CustomSlot slot) slot.setActive(true);
});
}
else if (this.mode == PacketPokemobGui.MAIN)
else if (mode == PacketPokemobGui.STORAGE)
{
this.addSlot(new Slot(this.pokemobInv, 0, 64, 18)
{
/**
* Check if the stack is a valid item for this slot. Always true
* beside for the armor slots.
*/
@Override
public boolean mayPlace(final ItemStack stack)
{
return super.mayPlace(stack) && stack.getItem() == Items.SADDLE;
}
int offhand = pokemobInv.getContainerSize() - 1;
// Storage only has the offhand active
this.slots.forEach(s -> {
if (s instanceof CustomSlot slot) slot.setActive(s.getSlotIndex() == offhand);
});
this.addSlot(new Slot(this.pokemobInv, 1, 64, 36)
{
/**
* Returns the maximum stack size for a given slot (usually the
* same as getInventoryStackLimit(), but 1 in the case of armor
* slots)
*/
@Override
public int getMaxStackSize()
{
return 1;
}

/**
* Check if the stack is a valid item for this slot. Always true
* beside for the armor slots.
*/
@Override
public boolean mayPlace(final ItemStack stack)
{
return !pokemob.getPokedexEntry().stock || PokecubeItems.isValidHeldItem(stack);
}

@Override
public void onTake(final Player playerIn, final ItemStack stack)
{
final ItemStack old = this.getItem();
if (ThutCore.proxy.isServerSide()) PokemobContainer.this.pokemob.getPokedexEntry()
.onHeldItemChange(stack, old, PokemobContainer.this.pokemob);
super.onTake(playerIn, stack);
}

/** Helper method to put a stack in the slot. */
@Override
public void set(final ItemStack stack)
{
// ItemStack old = getStack();
super.set(stack);
if (ThutCore.proxy.isServerSide()) PokemobContainer.this.pokemob.setHeldItem(stack);
}
});
this.addSlot(new TexturedSlot(this.pokemobInv, offhand, 64, 54, Resources.SLOT_ICON_BOOK));
for (int k = 0; k < 5; ++k) this.addSlot(new Slot(this.pokemobInv, 2 + k, 83 + k * 18, 18)
{
/**
* Check if the stack is a valid item for this slot. Always true
* beside for the armor slots.
*/
@Override
public boolean mayPlace(final ItemStack stack)
{
return true;// ItemList.isValidHeldItem(stack);
}
}
else
{
// The rest have none active
this.slots.forEach(s -> {
if (s instanceof CustomSlot slot) slot.setActive(false);
});
}

this.bindPlayerInventory(this.playerInv, -19);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void sendOpenPacket(Entity target, ServerPlayer player, byte mode)
buffer.writeByte(mode);

IPokemob pokemob = PokemobCaps.getPokemobFor(target);
if (pokemob != null)
if (pokemob != null && !(player.containerMenu instanceof PokemobContainer))
{
StoreTask ai = null;
for (final IAIRunnable run : pokemob.getTasks()) if (run instanceof StoreTask task) ai = task;
Expand Down

0 comments on commit 0743f85

Please sign in to comment.