This repository has been archived by the owner on Oct 4, 2024. It is now read-only.
generated from GregTech-Intergalactical/ExampleMod
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
...main/java/io/github/gregtechintergalactical/gtcore/blockentity/BlockEntityPlasticBin.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,71 @@ | ||
package io.github.gregtechintergalactical.gtcore.blockentity; | ||
|
||
import io.github.gregtechintergalactical.gtcore.data.SlotTypes; | ||
import io.github.gregtechintergalactical.gtcore.machine.MassStorageMachine; | ||
import muramasa.antimatter.data.AntimatterDefaultTools; | ||
import muramasa.antimatter.tool.AntimatterToolType; | ||
import muramasa.antimatter.util.Utils; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.InteractionResult; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.phys.BlockHitResult; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class BlockEntityPlasticBin extends BlockEntityMassStorage { | ||
int maxLimit = 128; | ||
public BlockEntityPlasticBin(MassStorageMachine type, BlockPos pos, BlockState state) { | ||
super(type, pos, state); | ||
|
||
} | ||
|
||
public int getMaxLimit() { | ||
return maxLimit; | ||
} | ||
|
||
@Override | ||
public InteractionResult onInteractServer(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit, @Nullable AntimatterToolType type) { | ||
if (type == AntimatterDefaultTools.WIRE_CUTTER){ | ||
int addition = player.isCrouching() ? -64 : 64; | ||
maxLimit += addition; | ||
if (maxLimit == 0) { | ||
maxLimit = 1024; | ||
} | ||
if (maxLimit > 1024) { | ||
maxLimit = 64; | ||
} | ||
//TODO: translation component | ||
player.sendMessage(Utils.literal("Max capacity set to: " + maxLimit), player.getUUID()); | ||
Utils.damageStack(player.getItemInHand(hand), hand, player); | ||
var handler = itemHandler.map(i -> i.getHandler(SlotTypes.UNLIMITED)).orElse(null); | ||
int amountToExtract = handler.getItem(0).getCount() - maxLimit; | ||
if (amountToExtract > 0) { | ||
ItemStack stored = handler.getItem(0); | ||
if (!stored.isEmpty()) { | ||
if (amountToExtract > stored.getMaxStackSize()){ | ||
int toExtract = amountToExtract; | ||
while (toExtract > 0){ | ||
ItemStack toAdd = Utils.ca(Math.min(stored.getMaxStackSize(), toExtract), stored); | ||
toExtract -= toAdd.getCount(); | ||
if (!player.addItem(toAdd)){ | ||
player.drop(toAdd, true); | ||
} | ||
} | ||
} else { | ||
ItemStack toAdd = Utils.ca(amountToExtract, stored); | ||
if (!player.addItem(toAdd)){ | ||
player.drop(toAdd, true); | ||
} | ||
} | ||
handler.extractItem(0, amountToExtract, false); | ||
} | ||
} | ||
|
||
return InteractionResult.SUCCESS; | ||
} | ||
return super.onInteractServer(state, world, pos, player, hand, hit, type); | ||
} | ||
} |
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
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