2016-06-22 23:49:47 -04:00
|
|
|
/*
|
|
|
|
|
* Minecraft Forge
|
2019-02-10 17:57:03 -05:00
|
|
|
* Copyright (c) 2016-2019.
|
2016-06-22 23:49:47 -04:00
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation version 2.1
|
|
|
|
|
* of the License.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
*/
|
|
|
|
|
|
2016-01-17 16:41:34 +00:00
|
|
|
package net.minecraftforge.items;
|
|
|
|
|
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
2019-05-23 16:02:15 -07:00
|
|
|
import net.minecraft.tileentity.HopperTileEntity;
|
2016-01-17 16:41:34 +00:00
|
|
|
import net.minecraftforge.items.wrapper.InvWrapper;
|
|
|
|
|
|
2016-11-13 17:09:54 -05:00
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
|
|
2016-01-17 16:41:34 +00:00
|
|
|
public class VanillaHopperItemHandler extends InvWrapper
|
|
|
|
|
{
|
2019-05-23 16:02:15 -07:00
|
|
|
private final HopperTileEntity hopper;
|
2016-01-17 16:41:34 +00:00
|
|
|
|
2019-05-23 16:02:15 -07:00
|
|
|
public VanillaHopperItemHandler(HopperTileEntity hopper)
|
2016-01-17 16:41:34 +00:00
|
|
|
{
|
|
|
|
|
super(hopper);
|
|
|
|
|
this.hopper = hopper;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2016-11-13 17:09:54 -05:00
|
|
|
@Nonnull
|
|
|
|
|
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate)
|
2016-01-17 16:41:34 +00:00
|
|
|
{
|
2016-11-23 12:45:07 -08:00
|
|
|
if (simulate)
|
|
|
|
|
{
|
2016-11-18 14:42:22 -08:00
|
|
|
return super.insertItem(slot, stack, simulate);
|
2016-11-23 12:45:07 -08:00
|
|
|
}
|
|
|
|
|
else
|
2016-11-18 14:42:22 -08:00
|
|
|
{
|
2016-12-21 15:52:30 -08:00
|
|
|
boolean wasEmpty = getInv().isEmpty();
|
2016-11-23 12:45:07 -08:00
|
|
|
|
2016-12-21 15:52:30 -08:00
|
|
|
int originalStackSize = stack.getCount();
|
2016-11-23 12:45:07 -08:00
|
|
|
stack = super.insertItem(slot, stack, simulate);
|
|
|
|
|
|
2016-12-21 15:52:30 -08:00
|
|
|
if (wasEmpty && originalStackSize > stack.getCount())
|
2016-11-23 12:45:07 -08:00
|
|
|
{
|
|
|
|
|
if (!hopper.mayTransfer())
|
|
|
|
|
{
|
|
|
|
|
// This cooldown is always set to 8 in vanilla with one exception:
|
|
|
|
|
// Hopper -> Hopper transfer sets this cooldown to 7 when this hopper
|
|
|
|
|
// has not been updated as recently as the one pushing items into it.
|
|
|
|
|
// This vanilla behavior is preserved by VanillaInventoryCodeHooks#insertStack,
|
|
|
|
|
// the cooldown is set properly by the hopper that is pushing items into this one.
|
|
|
|
|
hopper.setTransferCooldown(8);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return stack;
|
2016-11-18 14:42:22 -08:00
|
|
|
}
|
2016-01-17 16:41:34 +00:00
|
|
|
}
|
|
|
|
|
}
|