mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-20 20:22:33 +00:00
Primal Reversion: IItemHandler -> IInventory in tile entities
This commit is contained in:
1 parent
30e91eec9b
commit
1980958c67
22 files changed
+202
-296
No files matched your search
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
package vazkii.botania.api.item;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
@@ -20,10 +21,8 @@ public interface IAvatarTile extends IManaReceiver {
|
||||
|
||||
/**
|
||||
* Gets the avatar's inventory
|
||||
*
|
||||
* @return An IItemhandler representing the avatar's inventory
|
||||
*/
|
||||
public IItemHandler getInventory();
|
||||
public IInventory getInventory();
|
||||
|
||||
/**
|
||||
* Gets the avatar's facing.
|
||||
|
||||
@@ -66,11 +66,11 @@ public class BlockAvatar extends BlockModWaterloggable implements ITileEntityPro
|
||||
ItemStack stackOnAvatar = avatar.getItemHandler().getStackInSlot(0);
|
||||
ItemStack stackOnPlayer = player.getHeldItem(hand);
|
||||
if (!stackOnAvatar.isEmpty()) {
|
||||
avatar.getItemHandler().setStackInSlot(0, ItemStack.EMPTY);
|
||||
avatar.getItemHandler().setInventorySlotContents(0, ItemStack.EMPTY);
|
||||
ItemHandlerHelper.giveItemToPlayer(player, stackOnAvatar);
|
||||
return ActionResultType.SUCCESS;
|
||||
} else if (!stackOnPlayer.isEmpty() && stackOnPlayer.getItem() instanceof IAvatarWieldable) {
|
||||
avatar.getItemHandler().setStackInSlot(0, stackOnPlayer.split(1));
|
||||
avatar.getItemHandler().setInventorySlotContents(0, stackOnPlayer.split(1));
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -88,12 +88,12 @@ public class BlockHourglass extends BlockModWaterloggable implements IManaTrigge
|
||||
}
|
||||
|
||||
if (hgStack.isEmpty() && TileHourglass.getStackItemTime(stack) > 0) {
|
||||
hourglass.getItemHandler().setStackInSlot(0, stack.copy());
|
||||
hourglass.getItemHandler().setInventorySlotContents(0, stack.copy());
|
||||
stack.setCount(0);
|
||||
return ActionResultType.SUCCESS;
|
||||
} else if (!hgStack.isEmpty()) {
|
||||
ItemHandlerHelper.giveItemToPlayer(player, hgStack);
|
||||
hourglass.getItemHandler().setStackInSlot(0, ItemStack.EMPTY);
|
||||
hourglass.getItemHandler().setInventorySlotContents(0, ItemStack.EMPTY);
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ public class BlockIncensePlate extends BlockModWaterloggable implements ITileEnt
|
||||
}
|
||||
|
||||
if (plateStack.isEmpty() && plate.acceptsItem(stack)) {
|
||||
plate.getItemHandler().setStackInSlot(0, stack.copy());
|
||||
plate.getItemHandler().setInventorySlotContents(0, stack.copy());
|
||||
stack.shrink(1);
|
||||
did = true;
|
||||
} else if (!plateStack.isEmpty() && !plate.burning) {
|
||||
@@ -80,7 +80,7 @@ public class BlockIncensePlate extends BlockModWaterloggable implements ITileEnt
|
||||
did = true;
|
||||
} else {
|
||||
ItemHandlerHelper.giveItemToPlayer(player, plateStack);
|
||||
plate.getItemHandler().setStackInSlot(0, ItemStack.EMPTY);
|
||||
plate.getItemHandler().setInventorySlotContents(0, ItemStack.EMPTY);
|
||||
|
||||
did = true;
|
||||
}
|
||||
|
||||
@@ -73,11 +73,11 @@ public class BlockSparkChanger extends BlockModWaterloggable implements ITileEnt
|
||||
ItemStack pstack = player.getHeldItem(hand);
|
||||
ItemStack cstack = changer.getItemHandler().getStackInSlot(0);
|
||||
if (!cstack.isEmpty()) {
|
||||
changer.getItemHandler().setStackInSlot(0, ItemStack.EMPTY);
|
||||
changer.getItemHandler().setInventorySlotContents(0, ItemStack.EMPTY);
|
||||
ItemHandlerHelper.giveItemToPlayer(player, cstack);
|
||||
return ActionResultType.SUCCESS;
|
||||
} else if (!pstack.isEmpty() && pstack.getItem() instanceof ItemSparkUpgrade) {
|
||||
changer.getItemHandler().setStackInSlot(0, pstack.split(1));
|
||||
changer.getItemHandler().setInventorySlotContents(0, pstack.split(1));
|
||||
changer.markDirty();
|
||||
|
||||
return ActionResultType.SUCCESS;
|
||||
|
||||
@@ -77,10 +77,10 @@ public class BlockPrism extends BlockModWaterloggable implements ITileEntityProv
|
||||
player.setHeldItem(hand, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
prism.getItemHandler().setStackInSlot(0, heldItem.copy());
|
||||
prism.getItemHandler().setInventorySlotContents(0, heldItem.copy());
|
||||
} else if (!lens.isEmpty()) {
|
||||
ItemHandlerHelper.giveItemToPlayer(player, lens);
|
||||
prism.getItemHandler().setStackInSlot(0, ItemStack.EMPTY);
|
||||
prism.getItemHandler().setInventorySlotContents(0, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
return ActionResultType.SUCCESS;
|
||||
|
||||
@@ -146,10 +146,10 @@ public class BlockSpreader extends BlockModWaterloggable implements ITileEntityP
|
||||
player.setHeldItem(hand, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
spreader.getItemHandler().setStackInSlot(0, heldItem.copy());
|
||||
spreader.getItemHandler().setInventorySlotContents(0, heldItem.copy());
|
||||
} else if (!lens.isEmpty() && !wool) {
|
||||
ItemHandlerHelper.giveItemToPlayer(player, lens);
|
||||
spreader.getItemHandler().setStackInSlot(0, ItemStack.EMPTY);
|
||||
spreader.getItemHandler().setInventorySlotContents(0, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
if (wool && spreader.paddingColor == null) {
|
||||
|
||||
@@ -20,6 +20,8 @@ import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.FishBucketItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
@@ -40,6 +42,7 @@ import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandlerItem;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
import net.minecraftforge.items.wrapper.InvWrapper;
|
||||
import net.minecraftforge.items.wrapper.RecipeWrapper;
|
||||
|
||||
import vazkii.botania.api.internal.VanillaPacketDispatcher;
|
||||
@@ -140,18 +143,17 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
|
||||
}
|
||||
|
||||
if (SEED_PATTERN.matcher(stack.getTranslationKey()).find()) {
|
||||
RecipeWrapper inv = getRecipeWrapper();
|
||||
Optional<IPetalRecipe> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.PETAL_TYPE, inv, world);
|
||||
Optional<IPetalRecipe> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.PETAL_TYPE, getItemHandler(), world);
|
||||
maybeRecipe.ifPresent(recipe -> {
|
||||
saveLastRecipe();
|
||||
ItemStack output = recipe.getCraftingResult(getItemHandler());
|
||||
|
||||
for (int i = 0; i < getSizeInventory(); i++) {
|
||||
itemHandler.setStackInSlot(i, ItemStack.EMPTY);
|
||||
getItemHandler().setInventorySlotContents(i, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
stack.shrink(1);
|
||||
|
||||
ItemStack output = recipe.getCraftingResult(inv);
|
||||
ItemEntity outputItem = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 1.5, pos.getZ() + 0.5, output);
|
||||
outputItem.addTag(ITEM_TAG_APOTHECARY_SPAWNED);
|
||||
world.addEntity(outputItem);
|
||||
@@ -162,13 +164,13 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
|
||||
});
|
||||
return maybeRecipe.isPresent();
|
||||
} else if (!hasFluidCapability && !item.getTags().contains(ITEM_TAG_APOTHECARY_SPAWNED)) {
|
||||
if (!itemHandler.getStackInSlot(getSizeInventory() - 1).isEmpty()) {
|
||||
if (!getItemHandler().getStackInSlot(getSizeInventory() - 1).isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < getSizeInventory(); i++) {
|
||||
if (itemHandler.getStackInSlot(i).isEmpty()) {
|
||||
itemHandler.setStackInSlot(i, stack.split(1));
|
||||
if (getItemHandler().getStackInSlot(i).isEmpty()) {
|
||||
getItemHandler().setInventorySlotContents(i, stack.split(1));
|
||||
world.playSound(null, pos, SoundEvents.ENTITY_GENERIC_SPLASH, SoundCategory.BLOCKS, 0.1F, 10F);
|
||||
return true;
|
||||
}
|
||||
@@ -190,7 +192,7 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
|
||||
public void saveLastRecipe() {
|
||||
lastRecipe = new ArrayList<>();
|
||||
for (int i = 0; i < getSizeInventory(); i++) {
|
||||
ItemStack stack = itemHandler.getStackInSlot(i);
|
||||
ItemStack stack = getItemHandler().getStackInSlot(i);
|
||||
if (stack.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
@@ -201,13 +203,13 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
|
||||
}
|
||||
|
||||
public void trySetLastRecipe(PlayerEntity player) {
|
||||
tryToSetLastRecipe(player, itemHandler, lastRecipe);
|
||||
tryToSetLastRecipe(player, getItemHandler(), lastRecipe);
|
||||
if (!isEmpty()) {
|
||||
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static void tryToSetLastRecipe(PlayerEntity player, IItemHandlerModifiable inv, List<ItemStack> lastRecipe) {
|
||||
public static void tryToSetLastRecipe(PlayerEntity player, IInventory inv, List<ItemStack> lastRecipe) {
|
||||
if (lastRecipe == null || lastRecipe.isEmpty() || player.world.isRemote) {
|
||||
return;
|
||||
}
|
||||
@@ -222,7 +224,7 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
|
||||
for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
|
||||
ItemStack pstack = player.inventory.getStackInSlot(i);
|
||||
if (player.isCreative() || (!pstack.isEmpty() && pstack.isItemEqual(stack) && ItemStack.areItemStackTagsEqual(stack, pstack))) {
|
||||
inv.setStackInSlot(index, player.isCreative() ? stack.copy() : pstack.split(1));
|
||||
inv.setInventorySlotContents(index, player.isCreative() ? stack.copy() : pstack.split(1));
|
||||
didAny = true;
|
||||
index++;
|
||||
break;
|
||||
@@ -239,7 +241,7 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
|
||||
|
||||
public boolean isEmpty() {
|
||||
for (int i = 0; i < getSizeInventory(); i++) {
|
||||
if (!itemHandler.getStackInSlot(i).isEmpty()) {
|
||||
if (!getItemHandler().getStackInSlot(i).isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -262,7 +264,7 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < getSizeInventory(); i++) {
|
||||
ItemStack stackAt = itemHandler.getStackInSlot(i);
|
||||
ItemStack stackAt = getItemHandler().getStackInSlot(i);
|
||||
if (stackAt.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
@@ -337,15 +339,10 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SimpleItemStackHandler createItemHandler() {
|
||||
return new SimpleItemStackHandler(this, false) {
|
||||
protected Inventory createItemHandler() {
|
||||
return new Inventory(16) {
|
||||
@Override
|
||||
protected int getStackLimit(int slot, @Nonnull ItemStack stack) {
|
||||
public int getInventoryStackLimit() {
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
@@ -373,7 +370,7 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
|
||||
int radius = 24;
|
||||
int amt = 0;
|
||||
for (int i = 0; i < getSizeInventory(); i++) {
|
||||
if (itemHandler.getStackInSlot(i).isEmpty()) {
|
||||
if (getItemHandler().getStackInSlot(i).isEmpty()) {
|
||||
break;
|
||||
}
|
||||
amt++;
|
||||
@@ -381,15 +378,14 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
|
||||
|
||||
if (amt > 0) {
|
||||
float anglePer = 360F / amt;
|
||||
RecipeWrapper inv = getRecipeWrapper();
|
||||
|
||||
Optional<IPetalRecipe> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.PETAL_TYPE, inv, world);
|
||||
Optional<IPetalRecipe> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.PETAL_TYPE, getItemHandler(), world);
|
||||
maybeRecipe.ifPresent(recipe -> {
|
||||
RenderSystem.color4f(1F, 1F, 1F, 1F);
|
||||
mc.textureManager.bindTexture(HUDHandler.manaBar);
|
||||
RenderHelper.drawTexturedModalRect(ms, xc + radius + 9, yc - 8, 0, 8, 22, 15);
|
||||
|
||||
ItemStack stack = recipe.getCraftingResult(inv);
|
||||
ItemStack stack = recipe.getCraftingResult(getItemHandler());
|
||||
|
||||
mc.getItemRenderer().renderItemIntoGUI(stack, xc + radius + 32, yc - 8);
|
||||
mc.getItemRenderer().renderItemIntoGUI(new ItemStack(Items.WHEAT_SEEDS), xc + radius + 16, yc + 6);
|
||||
@@ -400,7 +396,7 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
|
||||
double xPos = xc + Math.cos(angle * Math.PI / 180D) * radius - 8;
|
||||
double yPos = yc + Math.sin(angle * Math.PI / 180D) * radius - 8;
|
||||
RenderSystem.translated(xPos, yPos, 0);
|
||||
mc.getItemRenderer().renderItemIntoGUI(itemHandler.getStackInSlot(i), 0, 0);
|
||||
mc.getItemRenderer().renderItemIntoGUI(getItemHandler().getStackInSlot(i), 0, 0);
|
||||
RenderSystem.translated(-xPos, -yPos, 0);
|
||||
|
||||
angle += anglePer;
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
*/
|
||||
package vazkii.botania.common.block.tile;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
@@ -50,7 +52,7 @@ public class TileAvatar extends TileSimpleInventory implements IAvatarTile, ITic
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack stack = itemHandler.getStackInSlot(0);
|
||||
ItemStack stack = getItemHandler().getStackInSlot(0);
|
||||
if (!stack.isEmpty() && stack.getItem() instanceof IAvatarWieldable) {
|
||||
IAvatarWieldable wieldable = (IAvatarWieldable) stack.getItem();
|
||||
wieldable.onAvatarUpdate(this, stack);
|
||||
@@ -78,15 +80,10 @@ public class TileAvatar extends TileSimpleInventory implements IAvatarTile, ITic
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SimpleItemStackHandler createItemHandler() {
|
||||
return new SimpleItemStackHandler(this, false) {
|
||||
protected Inventory createItemHandler() {
|
||||
return new Inventory(1) {
|
||||
@Override
|
||||
protected int getStackLimit(int slot, @Nonnull ItemStack stack) {
|
||||
public int getInventoryStackLimit() {
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
@@ -104,7 +101,7 @@ public class TileAvatar extends TileSimpleInventory implements IAvatarTile, ITic
|
||||
|
||||
@Override
|
||||
public boolean canReceiveManaFromBursts() {
|
||||
return !itemHandler.getStackInSlot(0).isEmpty();
|
||||
return !getItemHandler().getStackInSlot(0).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -113,7 +110,7 @@ public class TileAvatar extends TileSimpleInventory implements IAvatarTile, ITic
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getInventory() {
|
||||
public IInventory getInventory() {
|
||||
return getItemHandler();
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
@@ -54,18 +55,18 @@ public class TileBrewery extends TileSimpleInventory implements IManaReceiver, I
|
||||
}
|
||||
|
||||
public boolean addItem(@Nullable PlayerEntity player, ItemStack stack, @Nullable Hand hand) {
|
||||
if (recipe != null || stack.isEmpty() || stack.getItem() instanceof IBrewItem && ((IBrewItem) stack.getItem()).getBrew(stack) != null && ((IBrewItem) stack.getItem()).getBrew(stack) != ModBrews.fallbackBrew || itemHandler.getStackInSlot(0).isEmpty() != stack.getItem() instanceof IBrewContainer) {
|
||||
if (recipe != null || stack.isEmpty() || stack.getItem() instanceof IBrewItem && ((IBrewItem) stack.getItem()).getBrew(stack) != null && ((IBrewItem) stack.getItem()).getBrew(stack) != ModBrews.fallbackBrew || getItemHandler().getStackInSlot(0).isEmpty() != stack.getItem() instanceof IBrewContainer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean did = false;
|
||||
|
||||
for (int i = 0; i < getSizeInventory(); i++) {
|
||||
if (itemHandler.getStackInSlot(i).isEmpty()) {
|
||||
if (getItemHandler().getStackInSlot(i).isEmpty()) {
|
||||
did = true;
|
||||
ItemStack stackToAdd = stack.copy();
|
||||
stackToAdd.setCount(1);
|
||||
itemHandler.setStackInSlot(i, stackToAdd);
|
||||
getItemHandler().setInventorySlotContents(i, stackToAdd);
|
||||
|
||||
if (player == null || !player.abilities.isCreativeMode) {
|
||||
stack.shrink(1);
|
||||
@@ -87,7 +88,7 @@ public class TileBrewery extends TileSimpleInventory implements IManaReceiver, I
|
||||
}
|
||||
|
||||
private void findRecipe() {
|
||||
Optional<IBrewRecipe> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.BREW_TYPE, getRecipeWrapper(), world);
|
||||
Optional<IBrewRecipe> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.BREW_TYPE, getItemHandler(), world);
|
||||
maybeRecipe.ifPresent(recipeBrew -> {
|
||||
this.recipe = recipeBrew;
|
||||
world.setBlockState(pos, ModBlocks.brewery.getDefaultState().with(BlockStateProperties.POWERED, true));
|
||||
@@ -118,14 +119,14 @@ public class TileBrewery extends TileSimpleInventory implements IManaReceiver, I
|
||||
}
|
||||
|
||||
if (recipe != null) {
|
||||
if (!recipe.matches(getRecipeWrapper(), world)) {
|
||||
if (!recipe.matches(getItemHandler(), world)) {
|
||||
recipe = null;
|
||||
world.setBlockState(pos, ModBlocks.brewery.getDefaultState());
|
||||
}
|
||||
|
||||
if (recipe != null) {
|
||||
if (mana != manaLastTick) {
|
||||
int color = recipe.getBrew().getColor(itemHandler.getStackInSlot(0));
|
||||
int color = recipe.getBrew().getColor(getItemHandler().getStackInSlot(0));
|
||||
float r = (color >> 16 & 0xFF) / 255F;
|
||||
float g = (color >> 8 & 0xFF) / 255F;
|
||||
float b = (color & 0xFF) / 255F;
|
||||
@@ -143,13 +144,13 @@ public class TileBrewery extends TileSimpleInventory implements IManaReceiver, I
|
||||
int mana = getManaCost();
|
||||
receiveMana(-mana);
|
||||
|
||||
ItemStack output = recipe.getOutput(itemHandler.getStackInSlot(0));
|
||||
ItemStack output = recipe.getOutput(getItemHandler().getStackInSlot(0));
|
||||
ItemEntity outputItem = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 1.5, pos.getZ() + 0.5, output);
|
||||
world.addEntity(outputItem);
|
||||
world.addBlockEvent(getPos(), ModBlocks.brewery, CRAFT_EFFECT_EVENT, recipe.getBrew().getColor(output));
|
||||
|
||||
for (int i = 0; i < getSizeInventory(); i++) {
|
||||
itemHandler.setStackInSlot(i, ItemStack.EMPTY);
|
||||
getItemHandler().setInventorySlotContents(i, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -192,7 +193,7 @@ public class TileBrewery extends TileSimpleInventory implements IManaReceiver, I
|
||||
}
|
||||
|
||||
public int getManaCost() {
|
||||
ItemStack stack = itemHandler.getStackInSlot(0);
|
||||
ItemStack stack = getItemHandler().getStackInSlot(0);
|
||||
if (recipe == null || stack.isEmpty() || !(stack.getItem() instanceof IBrewContainer)) {
|
||||
return 0;
|
||||
}
|
||||
@@ -214,11 +215,6 @@ public class TileBrewery extends TileSimpleInventory implements IManaReceiver, I
|
||||
mana = tag.getInt(TAG_MANA);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return 7;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
@@ -226,10 +222,10 @@ public class TileBrewery extends TileSimpleInventory implements IManaReceiver, I
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SimpleItemStackHandler createItemHandler() {
|
||||
return new SimpleItemStackHandler(this, false) {
|
||||
protected Inventory createItemHandler() {
|
||||
return new Inventory(7) {
|
||||
@Override
|
||||
protected int getStackLimit(int slot, @Nonnull ItemStack stack) {
|
||||
public int getInventoryStackLimit() {
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
@@ -265,7 +261,7 @@ public class TileBrewery extends TileSimpleInventory implements IManaReceiver, I
|
||||
return;
|
||||
}
|
||||
|
||||
RenderHelper.renderProgressPie(ms, x, y, (float) mana / (float) manaToGet, recipe.getOutput(itemHandler.getStackInSlot(0)));
|
||||
RenderHelper.renderProgressPie(ms, x, y, (float) mana / (float) manaToGet, recipe.getOutput(getItemHandler().getStackInSlot(0)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ package vazkii.botania.common.block.tile;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.CraftingInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -34,8 +35,6 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class TileCraftCrate extends TileOpenCrate {
|
||||
private static final String TAG_PATTERN = "pattern";
|
||||
|
||||
private int signal = 0;
|
||||
|
||||
public TileCraftCrate() {
|
||||
@@ -43,26 +42,17 @@ public class TileCraftCrate extends TileOpenCrate {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SimpleItemStackHandler createItemHandler() {
|
||||
return new SimpleItemStackHandler(this, true) {
|
||||
protected Inventory createItemHandler() {
|
||||
// todo 1.16 expose
|
||||
return new Inventory(10) {
|
||||
@Override
|
||||
protected int getStackLimit(int slot, @Nonnull ItemStack stack) {
|
||||
public int getInventoryStackLimit() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
|
||||
if (slot != 9 && !isLocked(slot)) {
|
||||
return super.insertItem(slot, stack, simulate);
|
||||
} else {
|
||||
return stack;
|
||||
}
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||
return slot != 9 && !isLocked(slot);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -92,7 +82,7 @@ public class TileCraftCrate extends TileOpenCrate {
|
||||
int newSignal = 0;
|
||||
for (; newSignal < 9; newSignal++) // dis for loop be derpy
|
||||
{
|
||||
if (!isLocked(newSignal) && itemHandler.getStackInSlot(newSignal).isEmpty()) {
|
||||
if (!isLocked(newSignal) && getItemHandler().getStackInSlot(newSignal).isEmpty()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -115,7 +105,7 @@ public class TileCraftCrate extends TileOpenCrate {
|
||||
}
|
||||
}, 3, 3);
|
||||
for (int i = 0; i < craft.getSizeInventory(); i++) {
|
||||
ItemStack stack = itemHandler.getStackInSlot(i);
|
||||
ItemStack stack = getItemHandler().getStackInSlot(i);
|
||||
|
||||
if (stack.isEmpty() || isLocked(i) || stack.getItem() == ModItems.placeholder) {
|
||||
continue;
|
||||
@@ -126,16 +116,16 @@ public class TileCraftCrate extends TileOpenCrate {
|
||||
|
||||
Optional<ICraftingRecipe> matchingRecipe = world.getRecipeManager().getRecipe(IRecipeType.CRAFTING, craft, world);
|
||||
matchingRecipe.ifPresent(recipe -> {
|
||||
itemHandler.setStackInSlot(9, recipe.getCraftingResult(craft));
|
||||
getItemHandler().setInventorySlotContents(9, recipe.getCraftingResult(craft));
|
||||
|
||||
List<ItemStack> remainders = recipe.getRemainingItems(craft);
|
||||
for (int i = 0; i < craft.getSizeInventory(); i++) {
|
||||
ItemStack s = remainders.get(i);
|
||||
if (!itemHandler.getStackInSlot(i).isEmpty()
|
||||
&& itemHandler.getStackInSlot(i).getItem() == ModItems.placeholder) {
|
||||
if (!getItemHandler().getStackInSlot(i).isEmpty()
|
||||
&& getItemHandler().getStackInSlot(i).getItem() == ModItems.placeholder) {
|
||||
continue;
|
||||
}
|
||||
itemHandler.setStackInSlot(i, s);
|
||||
getItemHandler().setInventorySlotContents(i, s);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -144,7 +134,7 @@ public class TileCraftCrate extends TileOpenCrate {
|
||||
|
||||
boolean isFull() {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
if (!isLocked(i) && itemHandler.getStackInSlot(i).isEmpty()) {
|
||||
if (!isLocked(i) && getItemHandler().getStackInSlot(i).isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -154,11 +144,11 @@ public class TileCraftCrate extends TileOpenCrate {
|
||||
|
||||
private void ejectAll() {
|
||||
for (int i = 0; i < getSizeInventory(); ++i) {
|
||||
ItemStack stack = itemHandler.getStackInSlot(i);
|
||||
ItemStack stack = getItemHandler().getStackInSlot(i);
|
||||
if (!stack.isEmpty()) {
|
||||
eject(stack, false);
|
||||
}
|
||||
itemHandler.setStackInSlot(i, ItemStack.EMPTY);
|
||||
getItemHandler().setInventorySlotContents(i, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
@@ -55,7 +56,7 @@ public class TileHourglass extends TileSimpleInventory implements ITickableTileE
|
||||
}
|
||||
|
||||
private boolean isDust() {
|
||||
ItemStack stack = itemHandler.getStackInSlot(0);
|
||||
ItemStack stack = getItemHandler().getStackInSlot(0);
|
||||
return !stack.isEmpty() && stack.getItem() == ModItems.manaPowder;
|
||||
}
|
||||
|
||||
@@ -112,7 +113,7 @@ public class TileHourglass extends TileSimpleInventory implements ITickableTileE
|
||||
}
|
||||
|
||||
public int getTotalTime() {
|
||||
ItemStack stack = itemHandler.getStackInSlot(0);
|
||||
ItemStack stack = getItemHandler().getStackInSlot(0);
|
||||
if (stack.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
@@ -140,7 +141,7 @@ public class TileHourglass extends TileSimpleInventory implements ITickableTileE
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
ItemStack stack = itemHandler.getStackInSlot(0);
|
||||
ItemStack stack = getItemHandler().getStackInSlot(0);
|
||||
if (stack.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
@@ -161,33 +162,29 @@ public class TileHourglass extends TileSimpleInventory implements ITickableTileE
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SimpleItemStackHandler createItemHandler() {
|
||||
return new SimpleItemStackHandler(this, true) {
|
||||
@Nonnull
|
||||
protected Inventory createItemHandler() {
|
||||
// todo 1.16 expose
|
||||
return new Inventory(1) {
|
||||
@Override
|
||||
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
|
||||
if (!stack.isEmpty() && (stack.getItem() == Blocks.SAND.asItem()
|
||||
public boolean isItemValidForSlot(int index, ItemStack stack) {
|
||||
return !stack.isEmpty() && (stack.getItem() == Blocks.SAND.asItem()
|
||||
|| stack.getItem() == Blocks.RED_SAND.asItem()
|
||||
|| stack.getItem() == Blocks.SOUL_SAND.asItem()
|
||||
|| stack.getItem() == ModItems.manaPowder)) {
|
||||
return super.insertItem(slot, stack, simulate);
|
||||
} else {
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContentsChanged(int slot) {
|
||||
super.onContentsChanged(slot);
|
||||
if (!TileHourglass.this.world.isRemote) {
|
||||
time = 0;
|
||||
timeFraction = 0F;
|
||||
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(TileHourglass.this);
|
||||
}
|
||||
|| stack.getItem() == ModItems.manaPowder);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
super.markDirty();
|
||||
if (!world.isRemote) {
|
||||
time = 0;
|
||||
timeFraction = 0F;
|
||||
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(TileHourglass.this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writePacketNBT(CompoundNBT tag) {
|
||||
super.writePacketNBT(tag);
|
||||
@@ -210,18 +207,13 @@ public class TileHourglass extends TileSimpleInventory implements ITickableTileE
|
||||
lock = tag.getBoolean(TAG_LOCK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void renderHUD(MatrixStack ms) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
int x = mc.getMainWindow().getScaledWidth() / 2 + 10;
|
||||
int y = mc.getMainWindow().getScaledHeight() / 2 - 10;
|
||||
|
||||
ItemStack stack = itemHandler.getStackInSlot(0);
|
||||
ItemStack stack = getItemHandler().getStackInSlot(0);
|
||||
if (!stack.isEmpty()) {
|
||||
mc.getItemRenderer().renderItemIntoGUI(stack, x, y);
|
||||
mc.getItemRenderer().renderItemOverlays(mc.fontRenderer, stack, x, y);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
package vazkii.botania.common.block.tile;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.particles.ParticleTypes;
|
||||
@@ -51,7 +52,7 @@ public class TileIncensePlate extends TileSimpleInventory implements ITickableTi
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
ItemStack stack = itemHandler.getStackInSlot(0);
|
||||
ItemStack stack = getItemHandler().getStackInSlot(0);
|
||||
if (!stack.isEmpty() && burning) {
|
||||
if (getBlockState().get(BlockStateProperties.WATERLOGGED) && timeLeft > 1) {
|
||||
timeLeft = 1;
|
||||
@@ -92,7 +93,7 @@ public class TileIncensePlate extends TileSimpleInventory implements ITickableTi
|
||||
world.addParticle(data, x - (Math.random() - 0.5) * 0.2, y - (Math.random() - 0.5) * 0.2, z - (Math.random() - 0.5) * 0.2, 0.005F - (float) Math.random() * 0.01F, 0.01F + (float) Math.random() * 0.001F, 0.005F - (float) Math.random() * 0.01F);
|
||||
}
|
||||
} else {
|
||||
itemHandler.setStackInSlot(0, ItemStack.EMPTY);
|
||||
getItemHandler().setInventorySlotContents(0, ItemStack.EMPTY);
|
||||
burning = false;
|
||||
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(this);
|
||||
}
|
||||
@@ -128,7 +129,7 @@ public class TileIncensePlate extends TileSimpleInventory implements ITickableTi
|
||||
}
|
||||
|
||||
public void ignite() {
|
||||
ItemStack stack = itemHandler.getStackInSlot(0);
|
||||
ItemStack stack = getItemHandler().getStackInSlot(0);
|
||||
|
||||
if (stack.isEmpty() || burning) {
|
||||
return;
|
||||
@@ -144,11 +145,6 @@ public class TileIncensePlate extends TileSimpleInventory implements ITickableTi
|
||||
timeLeft = brew.getPotionEffects(stack).get(0).getDuration() * ItemIncenseStick.TIME_MULTIPLIER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writePacketNBT(CompoundNBT tag) {
|
||||
super.writePacketNBT(tag);
|
||||
@@ -168,22 +164,12 @@ public class TileIncensePlate extends TileSimpleInventory implements ITickableTi
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SimpleItemStackHandler createItemHandler() {
|
||||
return new SimpleItemStackHandler(this, true) {
|
||||
@Nonnull
|
||||
protected Inventory createItemHandler() {
|
||||
// todo 1.16 expose, prevent extract
|
||||
return new Inventory(1) {
|
||||
@Override
|
||||
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
|
||||
if (acceptsItem(stack)) {
|
||||
return super.insertItem(slot, stack, simulate);
|
||||
} else {
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||
return ItemStack.EMPTY;
|
||||
public boolean isItemValidForSlot(int index, ItemStack stack) {
|
||||
return acceptsItem(stack);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ package vazkii.botania.common.block.tile;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.ITickableTileEntity;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
@@ -33,8 +34,9 @@ public class TileOpenCrate extends TileSimpleInventory implements ITickableTileE
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return 1;
|
||||
protected Inventory createItemHandler() {
|
||||
// todo 1.16 expose
|
||||
return new Inventory(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,7 +55,7 @@ public class TileOpenCrate extends TileSimpleInventory implements ITickableTileE
|
||||
}
|
||||
|
||||
if (canEject()) {
|
||||
ItemStack stack = itemHandler.getStackInSlot(0);
|
||||
ItemStack stack = getItemHandler().getStackInSlot(0);
|
||||
if (!stack.isEmpty()) {
|
||||
eject(stack, redstone);
|
||||
}
|
||||
@@ -77,7 +79,7 @@ public class TileOpenCrate extends TileSimpleInventory implements ITickableTileE
|
||||
item.age = -200;
|
||||
}
|
||||
|
||||
itemHandler.setStackInSlot(0, ItemStack.EMPTY);
|
||||
getItemHandler().setInventorySlotContents(0, ItemStack.EMPTY);
|
||||
world.addEntity(item);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
@@ -23,6 +24,7 @@ import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraftforge.items.wrapper.InvWrapper;
|
||||
import net.minecraftforge.items.wrapper.RecipeWrapper;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
@@ -94,11 +96,11 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver,
|
||||
boolean did = false;
|
||||
|
||||
for (int i = 0; i < getSizeInventory(); i++) {
|
||||
if (itemHandler.getStackInSlot(i).isEmpty()) {
|
||||
if (getItemHandler().getStackInSlot(i).isEmpty()) {
|
||||
did = true;
|
||||
ItemStack stackToAdd = stack.copy();
|
||||
stackToAdd.setCount(1);
|
||||
itemHandler.setStackInSlot(i, stackToAdd);
|
||||
getItemHandler().setInventorySlotContents(i, stackToAdd);
|
||||
|
||||
if (player == null || !player.abilities.isCreativeMode) {
|
||||
stack.shrink(1);
|
||||
@@ -204,7 +206,7 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver,
|
||||
if (currentRecipe != null) {
|
||||
this.manaToGet = currentRecipe.getManaUsage();
|
||||
} else {
|
||||
Optional<IRuneAltarRecipe> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.RUNE_TYPE, getRecipeWrapper(), world);
|
||||
Optional<IRuneAltarRecipe> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.RUNE_TYPE, getItemHandler(), world);
|
||||
if (maybeRecipe.isPresent()) {
|
||||
this.manaToGet = maybeRecipe.get().getManaUsage();
|
||||
break getMana;
|
||||
@@ -222,7 +224,7 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver,
|
||||
private void saveLastRecipe() {
|
||||
lastRecipe = new ArrayList<>();
|
||||
for (int i = 0; i < getSizeInventory(); i++) {
|
||||
ItemStack stack = itemHandler.getStackInSlot(i);
|
||||
ItemStack stack = getItemHandler().getStackInSlot(i);
|
||||
if (stack.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
@@ -233,7 +235,7 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver,
|
||||
}
|
||||
|
||||
public void trySetLastRecipe(PlayerEntity player) {
|
||||
TileAltar.tryToSetLastRecipe(player, itemHandler, lastRecipe);
|
||||
TileAltar.tryToSetLastRecipe(player, getItemHandler(), lastRecipe);
|
||||
if (!isEmpty()) {
|
||||
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(this);
|
||||
}
|
||||
@@ -249,7 +251,7 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver,
|
||||
if (currentRecipe != null) {
|
||||
recipe = currentRecipe;
|
||||
} else {
|
||||
Optional<IRuneAltarRecipe> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.RUNE_TYPE, getRecipeWrapper(), world);
|
||||
Optional<IRuneAltarRecipe> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.RUNE_TYPE, getItemHandler(), world);
|
||||
if (maybeRecipe.isPresent()) {
|
||||
recipe = maybeRecipe.get();
|
||||
}
|
||||
@@ -268,7 +270,7 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver,
|
||||
if (livingrock != null) {
|
||||
int mana = recipe.getManaUsage();
|
||||
receiveMana(-mana);
|
||||
ItemStack output = recipe.getCraftingResult(getRecipeWrapper());
|
||||
ItemStack output = recipe.getCraftingResult(getItemHandler());
|
||||
ItemEntity outputItem = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 1.5, pos.getZ() + 0.5, output);
|
||||
world.addEntity(outputItem);
|
||||
currentRecipe = null;
|
||||
@@ -277,14 +279,14 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver,
|
||||
|
||||
saveLastRecipe();
|
||||
for (int i = 0; i < getSizeInventory(); i++) {
|
||||
ItemStack stack = itemHandler.getStackInSlot(i);
|
||||
ItemStack stack = getItemHandler().getStackInSlot(i);
|
||||
if (!stack.isEmpty()) {
|
||||
if (stack.getItem() instanceof ItemRune && (player == null || !player.abilities.isCreativeMode)) {
|
||||
ItemEntity outputRune = new ItemEntity(world, getPos().getX() + 0.5, getPos().getY() + 1.5, getPos().getZ() + 0.5, stack.copy());
|
||||
world.addEntity(outputRune);
|
||||
}
|
||||
|
||||
itemHandler.setStackInSlot(i, ItemStack.EMPTY);
|
||||
getItemHandler().setInventorySlotContents(i, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,7 +297,7 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver,
|
||||
|
||||
public boolean isEmpty() {
|
||||
for (int i = 0; i < getSizeInventory(); i++) {
|
||||
if (!itemHandler.getStackInSlot(i).isEmpty()) {
|
||||
if (!getItemHandler().getStackInSlot(i).isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -319,11 +321,6 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver,
|
||||
manaToGet = tag.getInt(TAG_MANA_TO_GET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return 16;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
@@ -331,10 +328,10 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver,
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SimpleItemStackHandler createItemHandler() {
|
||||
return new SimpleItemStackHandler(this, false) {
|
||||
protected Inventory createItemHandler() {
|
||||
return new Inventory(16) {
|
||||
@Override
|
||||
protected int getStackLimit(int slot, @Nonnull ItemStack stack) {
|
||||
public int getInventoryStackLimit() {
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
@@ -368,7 +365,7 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver,
|
||||
int radius = 24;
|
||||
int amt = 0;
|
||||
for (int i = 0; i < getSizeInventory(); i++) {
|
||||
if (itemHandler.getStackInSlot(i).isEmpty()) {
|
||||
if (getItemHandler().getStackInSlot(i).isEmpty()) {
|
||||
break;
|
||||
}
|
||||
amt++;
|
||||
@@ -376,8 +373,7 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver,
|
||||
|
||||
if (amt > 0) {
|
||||
float anglePer = 360F / amt;
|
||||
RecipeWrapper inv = getRecipeWrapper();
|
||||
world.getRecipeManager().getRecipe(ModRecipeTypes.RUNE_TYPE, inv, world).ifPresent(recipe -> {
|
||||
world.getRecipeManager().getRecipe(ModRecipeTypes.RUNE_TYPE, getItemHandler(), world).ifPresent(recipe -> {
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.enableRescaleNormal();
|
||||
RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
@@ -395,7 +391,7 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver,
|
||||
ms.translate(0, 0, -100);
|
||||
}
|
||||
|
||||
RenderHelper.renderProgressPie(ms, xc + radius + 32, yc - 8, progress, recipe.getCraftingResult(inv));
|
||||
RenderHelper.renderProgressPie(ms, xc + radius + 32, yc - 8, progress, recipe.getCraftingResult(getItemHandler()));
|
||||
|
||||
if (progress == 1F) {
|
||||
mc.fontRenderer.func_238421_b_(ms, "+", xc + radius + 14, yc + 12, 0xFFFFFF);
|
||||
@@ -406,7 +402,7 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver,
|
||||
double xPos = xc + Math.cos(angle * Math.PI / 180D) * radius - 8;
|
||||
double yPos = yc + Math.sin(angle * Math.PI / 180D) * radius - 8;
|
||||
ms.translate(xPos, yPos, 0);
|
||||
mc.getItemRenderer().renderItemIntoGUI(itemHandler.getStackInSlot(i), 0, 0);
|
||||
mc.getItemRenderer().renderItemIntoGUI(getItemHandler().getStackInSlot(i), 0, 0);
|
||||
ms.translate(-xPos, -yPos, 0);
|
||||
|
||||
angle += anglePer;
|
||||
|
||||
@@ -8,96 +8,67 @@
|
||||
*/
|
||||
package vazkii.botania.common.block.tile;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.inventory.ItemStackHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
import net.minecraftforge.items.wrapper.RecipeWrapper;
|
||||
import net.minecraftforge.items.wrapper.InvWrapper;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public abstract class TileSimpleInventory extends TileMod {
|
||||
|
||||
protected SimpleItemStackHandler itemHandler = createItemHandler();
|
||||
private final LazyOptional<IItemHandler> automationItemHandler = LazyOptional.of(() -> itemHandler);
|
||||
private final Inventory itemHandler = createItemHandler();
|
||||
|
||||
public TileSimpleInventory(TileEntityType<?> type) {
|
||||
super(type);
|
||||
itemHandler.addListener(i -> markDirty());
|
||||
}
|
||||
|
||||
private static void copyToInv(NonNullList<ItemStack> src, IInventory dest) {
|
||||
Preconditions.checkArgument(src.size() == dest.getSizeInventory());
|
||||
for (int i = 0; i < src.size(); i++) {
|
||||
dest.setInventorySlotContents(i, src.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
private static NonNullList<ItemStack> copyFromInv(IInventory inv) {
|
||||
NonNullList<ItemStack> ret = NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY);
|
||||
for (int i = 0; i < inv.getSizeInventory(); i++) {
|
||||
ret.set(i, inv.getStackInSlot(i));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readPacketNBT(CompoundNBT tag) {
|
||||
itemHandler = createItemHandler();
|
||||
itemHandler.deserializeNBT(tag);
|
||||
NonNullList<ItemStack> tmp = NonNullList.withSize(getSizeInventory(), ItemStack.EMPTY);
|
||||
ItemStackHelper.loadAllItems(tag, tmp);
|
||||
copyToInv(tmp, itemHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writePacketNBT(CompoundNBT tag) {
|
||||
tag.merge(itemHandler.serializeNBT());
|
||||
ItemStackHelper.saveAllItems(tag, copyFromInv(itemHandler));
|
||||
}
|
||||
|
||||
public abstract int getSizeInventory();
|
||||
|
||||
protected SimpleItemStackHandler createItemHandler() {
|
||||
return new SimpleItemStackHandler(this, true);
|
||||
public final int getSizeInventory() {
|
||||
return getItemHandler().getSizeInventory();
|
||||
}
|
||||
|
||||
public final IItemHandlerModifiable getItemHandler() {
|
||||
protected abstract Inventory createItemHandler();
|
||||
|
||||
public final IInventory getItemHandler() {
|
||||
return itemHandler;
|
||||
}
|
||||
|
||||
public final RecipeWrapper getRecipeWrapper() {
|
||||
return new RecipeWrapper(getItemHandler());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, Direction side) {
|
||||
return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.orEmpty(cap, automationItemHandler);
|
||||
}
|
||||
|
||||
/* Extension of ItemStackHandler that uses our own slot array, allows for control of writing,
|
||||
allows control over stack limits, and allows for itemstack-slot validation */
|
||||
protected static class SimpleItemStackHandler extends ItemStackHandler {
|
||||
|
||||
private final boolean allowWrite;
|
||||
private final TileSimpleInventory tile;
|
||||
|
||||
public SimpleItemStackHandler(TileSimpleInventory inv, boolean allowWrite) {
|
||||
super(inv.getSizeInventory());
|
||||
this.allowWrite = allowWrite;
|
||||
tile = inv;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
|
||||
if (allowWrite) {
|
||||
return super.insertItem(slot, stack, simulate);
|
||||
} else {
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||
if (allowWrite) {
|
||||
return super.extractItem(slot, amount, simulate);
|
||||
} else {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContentsChanged(int slot) {
|
||||
tile.markDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
package vazkii.botania.common.block.tile;
|
||||
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
@@ -38,7 +39,7 @@ public class TileSparkChanger extends TileSimpleInventory {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack changeStack = itemHandler.getStackInSlot(0);
|
||||
ItemStack changeStack = getItemHandler().getStackInSlot(0);
|
||||
List<ISparkAttachable> attachables = new ArrayList<>();
|
||||
for (Direction dir : Direction.Plane.HORIZONTAL) {
|
||||
TileEntity tile = world.getTileEntity(pos.offset(dir));
|
||||
@@ -66,31 +67,22 @@ public class TileSparkChanger extends TileSimpleInventory {
|
||||
if (transfers != null) {
|
||||
transfers.clear();
|
||||
}
|
||||
itemHandler.setStackInSlot(0, sparkStack);
|
||||
getItemHandler().setInventorySlotContents(0, sparkStack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SimpleItemStackHandler createItemHandler() {
|
||||
return new SimpleItemStackHandler(this, true) {
|
||||
protected Inventory createItemHandler() {
|
||||
// todo 1.16 expose
|
||||
return new Inventory(1) {
|
||||
@Override
|
||||
protected int getStackLimit(int slot, @Nonnull ItemStack stack) {
|
||||
public int getInventoryStackLimit() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
|
||||
if (!stack.isEmpty() && stack.getItem() instanceof ItemSparkUpgrade) {
|
||||
return super.insertItem(slot, stack, simulate);
|
||||
} else {
|
||||
return stack;
|
||||
}
|
||||
public boolean isItemValidForSlot(int index, ItemStack stack) {
|
||||
return !stack.isEmpty() && stack.getItem() instanceof ItemSparkUpgrade;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ package vazkii.botania.common.block.tile;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.ITickableTileEntity;
|
||||
@@ -49,7 +50,7 @@ public class TileTinyPotato extends TileSimpleInventory implements ITickableTile
|
||||
ItemStack stackAt = getItemHandler().getStackInSlot(index);
|
||||
if (!stackAt.isEmpty() && stack.isEmpty()) {
|
||||
player.setHeldItem(hand, stackAt);
|
||||
getItemHandler().setStackInSlot(index, ItemStack.EMPTY);
|
||||
getItemHandler().setInventorySlotContents(index, ItemStack.EMPTY);
|
||||
} else if (!stack.isEmpty()) {
|
||||
ItemStack copy = stack.split(1);
|
||||
|
||||
@@ -59,7 +60,7 @@ public class TileTinyPotato extends TileSimpleInventory implements ITickableTile
|
||||
ItemHandlerHelper.giveItemToPlayer(player, stackAt);
|
||||
}
|
||||
|
||||
getItemHandler().setStackInSlot(index, copy);
|
||||
getItemHandler().setInventorySlotContents(index, copy);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,8 +135,9 @@ public class TileTinyPotato extends TileSimpleInventory implements ITickableTile
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return 6;
|
||||
protected Inventory createItemHandler() {
|
||||
// todo 1.16 expose
|
||||
return new Inventory(6);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
package vazkii.botania.common.block.tile.corporea;
|
||||
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
|
||||
import vazkii.botania.api.corporea.CorporeaHelper;
|
||||
@@ -15,6 +16,8 @@ import vazkii.botania.api.corporea.ICorporeaSpark;
|
||||
import vazkii.botania.common.block.tile.TileSimpleInventory;
|
||||
|
||||
public abstract class TileCorporeaBase extends TileSimpleInventory {
|
||||
private static final Inventory EMPTY = new Inventory(0);
|
||||
|
||||
public TileCorporeaBase(TileEntityType<?> type) {
|
||||
super(type);
|
||||
}
|
||||
@@ -22,8 +25,8 @@ public abstract class TileCorporeaBase extends TileSimpleInventory {
|
||||
// These TE's only extend TileSimpleInventory to give sparks an inventory to attach to
|
||||
// TODO make sparks able to detect corporea blocks and not require them to have an inventory
|
||||
@Override
|
||||
public final int getSizeInventory() {
|
||||
return 0;
|
||||
protected final Inventory createItemHandler() {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
public ICorporeaSpark getSpark() {
|
||||
|
||||
@@ -10,6 +10,7 @@ package vazkii.botania.common.block.tile.mana;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
@@ -35,7 +36,7 @@ public class TilePrism extends TileSimpleInventory {
|
||||
}
|
||||
|
||||
public void onBurstCollision(IManaBurst burst) {
|
||||
ItemStack lens = itemHandler.getStackInSlot(0);
|
||||
ItemStack lens = getItemHandler().getStackInSlot(0);
|
||||
boolean active = !getBlockState().get(BlockStateProperties.POWERED);
|
||||
boolean valid = !lens.isEmpty() && lens.getItem() instanceof ILens && (!(lens.getItem() instanceof ITinyPlanetExcempt) || ((ITinyPlanetExcempt) lens.getItem()).shouldPull(lens));
|
||||
|
||||
@@ -63,21 +64,12 @@ public class TilePrism extends TileSimpleInventory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SimpleItemStackHandler createItemHandler() {
|
||||
return new SimpleItemStackHandler(this, true) {
|
||||
@Nonnull
|
||||
protected Inventory createItemHandler() {
|
||||
// todo 1.16 expose
|
||||
return new Inventory(1) {
|
||||
@Override
|
||||
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
|
||||
if (!stack.isEmpty() && stack.getItem() instanceof ILens) {
|
||||
return super.insertItem(slot, stack, simulate);
|
||||
} else {
|
||||
return stack;
|
||||
}
|
||||
public boolean isItemValidForSlot(int index, ItemStack stack) {
|
||||
return !stack.isEmpty() && stack.getItem() instanceof ILens;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -88,7 +80,7 @@ public class TilePrism extends TileSimpleInventory {
|
||||
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(this);
|
||||
if (world != null && !world.isRemote) {
|
||||
BlockState state = getBlockState();
|
||||
boolean hasLens = !itemHandler.getStackInSlot(0).isEmpty();
|
||||
boolean hasLens = !getItemHandler().getStackInSlot(0).isEmpty();
|
||||
if (state.getBlock() != ModBlocks.prism || state.get(BotaniaStateProps.HAS_LENS) != hasLens) {
|
||||
BlockState base = state.getBlock() == ModBlocks.prism ? state : ModBlocks.prism.getDefaultState();
|
||||
world.setBlockState(pos, base.with(BotaniaStateProps.HAS_LENS, hasLens));
|
||||
|
||||
@@ -17,6 +17,7 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.projectile.ThrowableEntity;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.DyeColor;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -233,7 +234,7 @@ public class TileSpreader extends TileSimpleInventory implements IManaCollector,
|
||||
shouldShoot = ((IKeyLocked) receiver).getInputKey().equals(getOutputKey());
|
||||
}
|
||||
|
||||
ItemStack lens = itemHandler.getStackInSlot(0);
|
||||
ItemStack lens = getItemHandler().getStackInSlot(0);
|
||||
ILensControl control = getLensController(lens);
|
||||
if (control != null) {
|
||||
if (isredstone) {
|
||||
@@ -462,7 +463,7 @@ public class TileSpreader extends TileSimpleInventory implements IManaCollector,
|
||||
}
|
||||
|
||||
public void checkForReceiver() {
|
||||
ItemStack stack = itemHandler.getStackInSlot(0);
|
||||
ItemStack stack = getItemHandler().getStackInSlot(0);
|
||||
ILensControl control = getLensController(stack);
|
||||
if (control != null && !control.allowBurstShooting(stack, this, false)) {
|
||||
return;
|
||||
@@ -495,7 +496,7 @@ public class TileSpreader extends TileSimpleInventory implements IManaCollector,
|
||||
float gravity = 0F;
|
||||
BurstProperties props = new BurstProperties(variant.burstMana, variant.preLossTicks, variant.lossPerTick, gravity, variant.motionModifier, variant.color);
|
||||
|
||||
ItemStack lens = itemHandler.getStackInSlot(0);
|
||||
ItemStack lens = getItemHandler().getStackInSlot(0);
|
||||
if (!lens.isEmpty() && lens.getItem() instanceof ILensEffect) {
|
||||
((ILensEffect) lens.getItem()).apply(lens, props);
|
||||
}
|
||||
@@ -544,7 +545,7 @@ public class TileSpreader extends TileSimpleInventory implements IManaCollector,
|
||||
int color = getVariant().hudColor;
|
||||
BotaniaAPIClient.instance().drawSimpleManaHUD(ms, color, getCurrentMana(), getMaxMana(), name);
|
||||
|
||||
ItemStack lens = itemHandler.getStackInSlot(0);
|
||||
ItemStack lens = getItemHandler().getStackInSlot(0);
|
||||
if (!lens.isEmpty()) {
|
||||
String lensName = lens.getDisplayName().getString();
|
||||
int width = 16 + mc.fontRenderer.getStringWidth(lensName) / 2;
|
||||
@@ -589,26 +590,17 @@ public class TileSpreader extends TileSimpleInventory implements IManaCollector,
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SimpleItemStackHandler createItemHandler() {
|
||||
return new SimpleItemStackHandler(this, true) {
|
||||
protected Inventory createItemHandler() {
|
||||
// todo 1.16 expose
|
||||
return new Inventory(1) {
|
||||
@Override
|
||||
protected int getStackLimit(int slot, @Nonnull ItemStack stack) {
|
||||
public int getInventoryStackLimit() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
|
||||
if (!stack.isEmpty() && stack.getItem() instanceof ILens) {
|
||||
return super.insertItem(slot, stack, simulate);
|
||||
} else {
|
||||
return stack;
|
||||
}
|
||||
public boolean isItemValidForSlot(int index, ItemStack stack) {
|
||||
return !stack.isEmpty() && stack.getItem() instanceof ILens;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public class InventoryHelper {
|
||||
if (!stackAt.isEmpty()) {
|
||||
ItemStack copy = stackAt.copy();
|
||||
ItemHandlerHelper.giveItemToPlayer(player, copy);
|
||||
inv.getItemHandler().setStackInSlot(i, ItemStack.EMPTY);
|
||||
inv.getItemHandler().setInventorySlotContents(i, ItemStack.EMPTY);
|
||||
player.world.updateComparatorOutputLevel(inv.getPos(), null);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user