Skip to content

Commit acb7a0a

Browse files
[update] Throw item to Mechanical Grindstone to process it
1 parent 67c19f9 commit acb7a0a

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
### Create: Enchantment Industry 2.1.2
22

3-
#### Update
4-
* Improve English grammar. clarity, and consistency (by @Zain)
3+
Require Create: Dragons Plus 1.5.0, which contains significant code changes.
54

6-
#### Fix
7-
*
5+
#### Update
6+
* Now you can throw item to Mechanical Grindstone to process it
7+
* Improve English grammar. clarity, and consistency (by @Zain)

src/main/java/plus/dragons/createenchantmentindustry/common/kinetics/grindstone/GrindstoneDrainBlock.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
import net.minecraft.core.Direction.Axis;
3333
import net.minecraft.world.InteractionHand;
3434
import net.minecraft.world.ItemInteractionResult;
35+
import net.minecraft.world.entity.Entity;
3536
import net.minecraft.world.entity.LivingEntity;
37+
import net.minecraft.world.entity.item.ItemEntity;
3638
import net.minecraft.world.entity.player.Player;
3739
import net.minecraft.world.item.ItemStack;
3840
import net.minecraft.world.item.context.BlockPlaceContext;
@@ -46,6 +48,8 @@
4648
import net.minecraft.world.phys.HitResult;
4749
import net.minecraft.world.phys.shapes.CollisionContext;
4850
import net.minecraft.world.phys.shapes.VoxelShape;
51+
import net.neoforged.neoforge.capabilities.Capabilities;
52+
import net.neoforged.neoforge.items.IItemHandler;
4953
import org.jetbrains.annotations.Nullable;
5054
import plus.dragons.createdragonsplus.common.advancements.AdvancementBehaviour;
5155
import plus.dragons.createenchantmentindustry.common.registry.CEIBlockEntities;
@@ -68,6 +72,33 @@ protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Lev
6872
return super.useItemOn(stack, state, level, pos, player, hand, hitResult);
6973
}
7074

75+
@Override
76+
public void updateEntityAfterFallOn(BlockGetter worldIn, Entity entityIn) {
77+
super.updateEntityAfterFallOn(worldIn, entityIn);
78+
79+
if (entityIn.level().isClientSide)
80+
return;
81+
if (!(entityIn instanceof ItemEntity itemEntity))
82+
return;
83+
if (!entityIn.isAlive())
84+
return;
85+
GrindstoneDrainBlockEntity drain = getBlockEntity(worldIn, entityIn.blockPosition());
86+
if (drain == null)
87+
return;
88+
89+
IItemHandler capability = drain.getLevel().getCapability(Capabilities.ItemHandler.BLOCK, drain.getBlockPos(), null);
90+
if (capability == null)
91+
return;
92+
93+
ItemStack remainder = capability
94+
.insertItem(0, itemEntity.getItem(), false);
95+
if (remainder.isEmpty())
96+
itemEntity.discard();
97+
if (remainder.getCount() < itemEntity.getItem()
98+
.getCount())
99+
itemEntity.setItem(remainder);
100+
}
101+
71102
@Override
72103
protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
73104
return SHAPE;

0 commit comments

Comments
 (0)