Skip to content

Commit

Permalink
Fixed tiles not dropping items, closes InnovativeOnlineIndustries/Ind…
Browse files Browse the repository at this point in the history
  • Loading branch information
Buuz135 committed Feb 4, 2021
1 parent 01ed87f commit 65dd629
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions src/main/java/com/hrznstudio/titanium/block/BasicBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.hrznstudio.titanium.api.IFactory;
import com.hrznstudio.titanium.api.IRecipeProvider;
import com.hrznstudio.titanium.api.raytrace.DistanceRayTraceResult;
import com.hrznstudio.titanium.block.tile.ActiveTile;
import com.hrznstudio.titanium.component.inventory.InventoryComponent;
import com.hrznstudio.titanium.datagenerator.loot.block.BasicBlockLootTables;
import com.hrznstudio.titanium.datagenerator.loot.block.IBlockLootTableProvider;
import com.hrznstudio.titanium.module.api.IAlternativeEntries;
Expand All @@ -36,7 +38,6 @@
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import net.minecraftforge.items.CapabilityItemHandler;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -158,7 +159,7 @@ public void registerRecipe(Consumer<IFinishedRecipe> consumer) {
@Override
@SuppressWarnings("deprecation")
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
if (state.getBlock() != newState.getBlock()) {
if (!state.isIn(newState.getBlock())) {
InventoryHelper.dropItems(worldIn, pos, getDynamicDrops(state, worldIn, pos, newState, isMoving));
worldIn.updateComparatorOutputLevel(pos, this);
}
Expand All @@ -168,12 +169,12 @@ public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState
public NonNullList<ItemStack> getDynamicDrops(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
NonNullList<ItemStack> stacks = NonNullList.create();
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity != null) {
tileentity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).ifPresent(iItemHandler -> {
for (int i = 0; i < iItemHandler.getSlots(); i++) {
stacks.add(iItemHandler.getStackInSlot(i));
if (tileentity instanceof ActiveTile) {
for (InventoryComponent<?> inventoryHandler : ((ActiveTile<?>) tileentity).getMultiInventoryComponent().getInventoryHandlers()) {
for (int i = 0; i < inventoryHandler.getSlots(); i++) {
stacks.add(inventoryHandler.getStackInSlot(i));
}
});
}
}
return stacks;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public void invalidateCaps() {
if (this.multiInventoryComponent != null) this.multiInventoryComponent.getLazyOptionals().forEach(LazyOptional::invalidate);
if (this.multiTankComponent != null) this.multiTankComponent.getLazyOptionals().forEach(LazyOptional::invalidate);
}

public boolean canInteract() {
return this.world.getTileEntity(this.pos) == this;
}
Expand Down

0 comments on commit 65dd629

Please sign in to comment.