-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix compact drawer item duping on break and item loss if slot invento…
…ry > 64.
- Loading branch information
Showing
2 changed files
with
67 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/com/jaquadro/minecraft/storagedrawers/inventory/DrawerInventoryHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.jaquadro.minecraft.storagedrawers.inventory; | ||
|
||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer; | ||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroup; | ||
import net.minecraft.entity.item.EntityItem; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.nbt.NBTTagCompound; | ||
import net.minecraft.util.BlockPos; | ||
import net.minecraft.world.World; | ||
|
||
import java.util.Random; | ||
|
||
public class DrawerInventoryHelper | ||
{ | ||
private static final Random RANDOM = new Random(); | ||
|
||
public static void dropInventoryItems (World world, BlockPos pos, IDrawerGroup group) { | ||
for (int i = 0; i < group.getDrawerCount(); i++) { | ||
if (!group.isDrawerEnabled(i)) | ||
continue; | ||
|
||
IDrawer drawer = group.getDrawer(i); | ||
while (drawer.getStoredItemCount() > 0) { | ||
ItemStack stack = drawer.getStoredItemCopy(); | ||
if (stack == null || stack.stackSize == 0) | ||
break; | ||
|
||
spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), stack); | ||
drawer.setStoredItemCount(0); | ||
} | ||
} | ||
} | ||
|
||
private static void spawnItemStack (World world, double x, double y, double z, ItemStack stack) | ||
{ | ||
float xOff = RANDOM.nextFloat() * 0.8F + 0.1F; | ||
float yOff = RANDOM.nextFloat() * 0.8F + 0.1F; | ||
float zOff = RANDOM.nextFloat() * 0.8F + 0.1F; | ||
|
||
while (stack.stackSize > 0) | ||
{ | ||
int dropAmt = RANDOM.nextInt(21) + 10; | ||
|
||
if (dropAmt > stack.stackSize) | ||
{ | ||
dropAmt = stack.stackSize; | ||
} | ||
|
||
stack.stackSize -= dropAmt; | ||
EntityItem entityitem = new EntityItem(world, x + (double)xOff, y + (double)yOff, z + (double)zOff, new ItemStack(stack.getItem(), dropAmt, stack.getMetadata())); | ||
|
||
if (stack.hasTagCompound()) | ||
{ | ||
entityitem.getEntityItem().setTagCompound((NBTTagCompound)stack.getTagCompound().copy()); | ||
} | ||
|
||
float velocity = 0.05F; | ||
entityitem.motionX = RANDOM.nextGaussian() * (double)velocity; | ||
entityitem.motionY = RANDOM.nextGaussian() * (double)velocity + 0.20000000298023224D; | ||
entityitem.motionZ = RANDOM.nextGaussian() * (double)velocity; | ||
|
||
world.spawnEntityInWorld(entityitem); | ||
} | ||
} | ||
} |