Skip to content

Commit

Permalink
Fixed Architect's Table not dropping its contents when mined
Browse files Browse the repository at this point in the history
  • Loading branch information
kill05 committed Jun 11, 2024
1 parent c327658 commit c8a8562
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.kill05.blocks.architectstation.part.PartModeGui;
import com.github.kill05.config.ArchitectConfig;
import com.github.kill05.utils.InventoryUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.core.block.BlockTileEntity;
import net.minecraft.core.block.entity.TileEntity;
Expand Down Expand Up @@ -29,4 +30,12 @@ public boolean blockActivated(World world, int x, int y, int z, EntityPlayer pla
return true;
}


@Override
public void onBlockRemoved(World world, int x, int y, int z, int data) {
ArchitectTableTileEntity tile = ((ArchitectTableTileEntity) world.getBlockTileEntity(x, y, z));
InventoryUtils.dropInventoryContents(tile.getPartInventory(), world, x, y, z);
InventoryUtils.dropInventoryContents(tile.getToolInventory(), world, x, y, z);
super.onBlockRemoved(world, x, y, z, data);
}
}
17 changes: 17 additions & 0 deletions src/main/java/com/github/kill05/utils/InventoryUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import com.mojang.nbt.CompoundTag;
import com.mojang.nbt.ListTag;
import com.mojang.nbt.Tag;
import net.minecraft.core.entity.EntityItem;
import net.minecraft.core.item.ItemStack;
import net.minecraft.core.player.inventory.IInventory;
import net.minecraft.core.world.World;

public final class InventoryUtils {

Expand Down Expand Up @@ -39,4 +41,19 @@ public static IInventory loadInventory(IInventory inv, ListTag list) {
return inv;
}


public static void dropInventoryContents(IInventory inventory, World world, int x, int y, int z) {
for(int i = 0; i < inventory.getSizeInventory(); ++i) {
ItemStack itemStack = inventory.getStackInSlot(i);
if (itemStack != null) {
EntityItem item = world.dropItem(x, y, z, itemStack);
item.xd *= 0.5;
item.yd *= 0.5;
item.zd *= 0.5;
item.delayBeforeCanPickup = 0;
}
}

}

}

0 comments on commit c8a8562

Please sign in to comment.