mirror of
https://github.com/GTNewHorizons/StorageDrawers.git
synced 2026-11-12 00:17:57 +00:00
Breaking a drawer will drop fewer items (#17)
* Break drawers and drop fewer items. * Excess items will enter Avaritia's Matter Cluster. * Break drawer drop mechanism modified Add the Drop item configuration option. Add drop a single EntityItem with a big stack size. (The EntityItem cannot be saved to the archive.) four modes: default: Modify the previous way merge: A small amount of EntityItem destroy: Destroy too many items cluster: Drop Avaritia's Matter Cluster
This commit is contained in:
3 files changed
+102
-9
No files matched your search
@@ -5,6 +5,7 @@ dependencies {
|
||||
compileOnly('com.github.GTNewHorizons:GT5-Unofficial:5.09.40.33:dev') {transitive=false}
|
||||
compileOnly('com.github.GTNewHorizons:NotEnoughItems:2.2.6-GTNH:dev') {transitive=false}
|
||||
compileOnly('com.github.GTNewHorizons:waila:1.5.18:dev') {transitive=false}
|
||||
compileOnly('com.github.GTNewHorizons:Avaritia:1.30:dev') {transitive=false}
|
||||
|
||||
compileOnly('thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev')
|
||||
compileOnly('curse.maven:refined-relocation-75811:2262970')
|
||||
|
||||
@@ -26,6 +26,8 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
@@ -558,6 +560,23 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
return super.removedByPlayer(world, player, x, y, z);
|
||||
}
|
||||
|
||||
private void dropBigStackInWord(World world, int x, int y, int z, ItemStack stack) {
|
||||
if (stack == null) return;
|
||||
Random rand = world.rand;
|
||||
|
||||
float ex = rand.nextFloat() * .8f + .1f;
|
||||
float ey = rand.nextFloat() * .8f + .1f;
|
||||
float ez = rand.nextFloat() * .8f + .1f;
|
||||
|
||||
if (stack.stackSize > 0) {
|
||||
EntityItem entity = new EntityItem(world, x + ex, y + ey, z + ez, stack);
|
||||
if (stack.hasTagCompound())
|
||||
entity.getEntityItem()
|
||||
.setTagCompound((NBTTagCompound) stack.getTagCompound().copy());
|
||||
world.spawnEntityInWorld(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
|
||||
TileEntityDrawers tile = getTileEntity(world, x, y, z);
|
||||
@@ -572,16 +591,81 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
}
|
||||
|
||||
if (!tile.isVending()) {
|
||||
for (int i = 0; i < tile.getDrawerCount(); i++) {
|
||||
if (!tile.isDrawerEnabled(i)) continue;
|
||||
switch (StorageDrawers.config.cache.breakDrawerDropMode) {
|
||||
case "merge":
|
||||
/* Only a minimum number of ItemStack are dropped */
|
||||
for (int i = 0; i < tile.getDrawerCount(); i++) {
|
||||
if (!tile.isDrawerEnabled(i)) continue;
|
||||
dropBigStackInWord(world, x, y, z, tile.getDrawer(i).getStoredItemCopy());
|
||||
}
|
||||
break;
|
||||
case "destroy":
|
||||
/* Destroy excess items */
|
||||
int maxDropNum = 2048 / tile.getDrawerCount();
|
||||
for (int i = 0; i < tile.getDrawerCount(); i++) {
|
||||
if (!tile.isDrawerEnabled(i)) continue;
|
||||
IDrawer drawer = tile.getDrawer(i);
|
||||
if (drawer.getStoredItemCount() > maxDropNum) drawer.setStoredItemCount(maxDropNum);
|
||||
while (drawer.getStoredItemCount() > 0) {
|
||||
ItemStack stack = tile.takeItemsFromSlot(i, drawer.getStoredItemStackSize());
|
||||
if (stack == null || stack.stackSize == 0) break;
|
||||
|
||||
IDrawer drawer = tile.getDrawer(i);
|
||||
while (drawer.getStoredItemCount() > 0) {
|
||||
ItemStack stack = tile.takeItemsFromSlot(i, drawer.getStoredItemStackSize());
|
||||
if (stack == null || stack.stackSize == 0) break;
|
||||
dropStackInBatches(world, x, y, z, stack);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "cluster":
|
||||
/* System.out.println("hello"); */
|
||||
if (cpw.mods.fml.common.Loader.isModLoaded("Avaritia")) {
|
||||
try {
|
||||
Class<?> itemMatterClusterClass =
|
||||
Class.forName("fox.spiteful.avaritia.items.ItemMatterCluster");
|
||||
Method method = itemMatterClusterClass.getMethod("makeClusters", List.class);
|
||||
/* May not be used */
|
||||
for (int i = 0; i < tile.getDrawerCount(); i++) {
|
||||
IDrawer drawer = tile.getDrawer(i);
|
||||
List<ItemStack> stacks = new ArrayList<>();
|
||||
while (drawer.getStoredItemCount() > 0) {
|
||||
ItemStack stack = tile.takeItemsFromSlot(i, drawer.getStoredItemStackSize());
|
||||
if (stack == null || stack.stackSize == 0) break;
|
||||
|
||||
dropStackInBatches(world, x, y, z, stack);
|
||||
}
|
||||
stacks.add(stack);
|
||||
}
|
||||
|
||||
List<ItemStack> clusters =
|
||||
(List<ItemStack>) method.invoke(itemMatterClusterClass, stacks);
|
||||
for (ItemStack stack : clusters) {
|
||||
dropStackInBatches(world, x, y, z, stack);
|
||||
}
|
||||
}
|
||||
break; /* switch */
|
||||
} catch (NoSuchMethodException
|
||||
| InvocationTargetException
|
||||
| IllegalAccessException
|
||||
| ClassNotFoundException e) {
|
||||
StorageDrawers.config.cache.breakDrawerDropMode = "default";
|
||||
FMLLog.log(
|
||||
StorageDrawers.MOD_ID,
|
||||
Level.INFO,
|
||||
"Avaritia does not exist or cannot build a cluster!");
|
||||
if (StorageDrawers.config.cache.debugTrace)
|
||||
FMLLog.log(StorageDrawers.MOD_ID, Level.INFO, e.getMessage());
|
||||
// :P
|
||||
}
|
||||
}
|
||||
case "default":
|
||||
default:
|
||||
for (int i = 0; i < tile.getDrawerCount(); i++) {
|
||||
if (!tile.isDrawerEnabled(i)) continue;
|
||||
|
||||
IDrawer drawer = tile.getDrawer(i);
|
||||
while (drawer.getStoredItemCount() > 0) {
|
||||
ItemStack stack = tile.takeItemsFromSlot(i, drawer.getStoredItemStackSize());
|
||||
if (stack == null || stack.stackSize == 0) break;
|
||||
|
||||
dropStackInBatches(world, x, y, z, stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -630,7 +714,6 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
@Override
|
||||
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest) {
|
||||
if (willHarvest) return true;
|
||||
|
||||
return super.removedByPlayer(world, player, x, y, z, willHarvest);
|
||||
}
|
||||
|
||||
|
||||
@@ -62,6 +62,7 @@ public class ConfigManager {
|
||||
public boolean renderStorageUpgrades;
|
||||
public boolean enableDrawerUI;
|
||||
public String itemRenderType;
|
||||
public String breakDrawerDropMode;
|
||||
public boolean creativeTabVanillaWoods;
|
||||
public boolean enableSidedInput;
|
||||
public boolean enableSidedOutput;
|
||||
@@ -334,6 +335,14 @@ public class ConfigManager {
|
||||
"Writes additional log messages while using the mod. Mainly for debug purposes. Should be kept disabled unless instructed otherwise.")
|
||||
.setLanguageKey(LANG_PREFIX + "prop.enableDebugLogging")
|
||||
.getBoolean();
|
||||
cache.breakDrawerDropMode = config.get(
|
||||
Configuration.CATEGORY_GENERAL,
|
||||
"breakDrawerDropMode",
|
||||
"merge",
|
||||
"Select: default, merge, destroy and cluster. ",
|
||||
new String[] {"default", "destroy", "merge", "cluster"})
|
||||
.setLanguageKey(LANG_PREFIX + "prop.breakDrawerDropMode")
|
||||
.getString();
|
||||
|
||||
cache.enableAE2Integration = config.get(sectionIntegration.getQualifiedName(), "enableAE2", true)
|
||||
.setLanguageKey(LANG_PREFIX + "integration.enableAE2")
|
||||
|
||||
Reference in new issue
Block a user