mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-11 13:04:19 +01:00
Drop and Dispense in inventories
This commit is contained in:
parent
f1cad974aa
commit
25712f8b39
@ -4,7 +4,9 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Mov
|
|||||||
import com.simibubi.create.foundation.utility.VecHelper;
|
import com.simibubi.create.foundation.utility.VecHelper;
|
||||||
import net.minecraft.block.DispenserBlock;
|
import net.minecraft.block.DispenserBlock;
|
||||||
import net.minecraft.entity.item.ItemEntity;
|
import net.minecraft.entity.item.ItemEntity;
|
||||||
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.tileentity.HopperTileEntity;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.Direction;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
@ -35,10 +37,18 @@ public class MovedDefaultDispenseItemBehaviour implements IMovedDispenseItemBeha
|
|||||||
facingVec = VecHelper.rotate(facingVec, context.rotation.x, context.rotation.y, context.rotation.z);
|
facingVec = VecHelper.rotate(facingVec, context.rotation.x, context.rotation.y, context.rotation.z);
|
||||||
facingVec.normalize();
|
facingVec.normalize();
|
||||||
|
|
||||||
ItemStack itemstack = this.dispenseStack(itemStack, context, pos, facingVec);
|
Direction closestToFacing = getClosestFacingDirection(facingVec);
|
||||||
|
BlockPos interactAt = pos.offset(closestToFacing);
|
||||||
|
IInventory iinventory = HopperTileEntity.getInventoryAtPosition(context.world, interactAt);
|
||||||
|
if (iinventory == null) {
|
||||||
this.playDispenseSound(context.world, pos);
|
this.playDispenseSound(context.world, pos);
|
||||||
this.spawnDispenseParticles(context.world, pos, facingVec);
|
this.spawnDispenseParticles(context.world, pos, closestToFacing);
|
||||||
return itemstack;
|
return this.dispenseStack(itemStack, context, pos, facingVec);
|
||||||
|
} else {
|
||||||
|
if (HopperTileEntity.putStackInInventoryAllSlots(null, iinventory, itemStack.copy().split(1), closestToFacing.getOpposite()).isEmpty())
|
||||||
|
itemStack.shrink(1);
|
||||||
|
return itemStack;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,9 +71,14 @@ public class MovedDefaultDispenseItemBehaviour implements IMovedDispenseItemBeha
|
|||||||
* Order clients to display dispense particles from the specified block and facing.
|
* Order clients to display dispense particles from the specified block and facing.
|
||||||
*/
|
*/
|
||||||
protected void spawnDispenseParticles(IWorld world, BlockPos pos, Vec3d facing) {
|
protected void spawnDispenseParticles(IWorld world, BlockPos pos, Vec3d facing) {
|
||||||
|
spawnDispenseParticles(world, pos, getClosestFacingDirection(facing));
|
||||||
world.playEvent(2000, pos, getClosestFacingDirection(facing).getIndex());
|
world.playEvent(2000, pos, getClosestFacingDirection(facing).getIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void spawnDispenseParticles(IWorld world, BlockPos pos, Direction direction) {
|
||||||
|
world.playEvent(2000, pos, direction.getIndex());
|
||||||
|
}
|
||||||
|
|
||||||
protected Direction getClosestFacingDirection(Vec3d exactFacing) {
|
protected Direction getClosestFacingDirection(Vec3d exactFacing) {
|
||||||
return Direction.getFacingFromVector(exactFacing.x, exactFacing.y, exactFacing.z);
|
return Direction.getFacingFromVector(exactFacing.x, exactFacing.y, exactFacing.z);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user