|
2 | 2 |
|
3 | 3 | import com.gregtechceu.gtceu.api.GTValues; |
4 | 4 | import com.gregtechceu.gtceu.api.block.MaterialPipeBlock; |
5 | | -import com.gregtechceu.gtceu.api.capability.ICoverable; |
6 | | -import com.gregtechceu.gtceu.api.capability.IToolable; |
7 | 5 | import com.gregtechceu.gtceu.api.cover.CoverBehavior; |
8 | 6 | import com.gregtechceu.gtceu.api.data.chemical.material.Material; |
9 | 7 | import com.gregtechceu.gtceu.api.data.tag.TagPrefix; |
|
18 | 16 | import com.gregtechceu.gtceu.api.sync_system.annotations.SyncToClient; |
19 | 17 | import com.gregtechceu.gtceu.common.data.GTMaterialBlocks; |
20 | 18 | import com.gregtechceu.gtceu.common.data.GTMaterials; |
| 19 | +import com.gregtechceu.gtceu.utils.ExtendedUseOnContext; |
21 | 20 | import com.gregtechceu.gtceu.utils.GTUtil; |
22 | 21 |
|
23 | 22 | import com.lowdragmc.lowdraglib.gui.texture.ResourceTexture; |
|
32 | 31 | import net.minecraft.world.InteractionResult; |
33 | 32 | import net.minecraft.world.entity.player.Player; |
34 | 33 | import net.minecraft.world.item.ItemStack; |
35 | | -import net.minecraft.world.item.context.UseOnContext; |
36 | 34 | import net.minecraft.world.level.Level; |
37 | 35 | import net.minecraft.world.level.block.Block; |
38 | 36 | import net.minecraft.world.level.block.entity.BlockEntity; |
39 | 37 | import net.minecraft.world.level.block.entity.BlockEntityType; |
40 | 38 | import net.minecraft.world.level.block.state.BlockState; |
41 | | -import net.minecraft.world.phys.BlockHitResult; |
42 | 39 |
|
43 | 40 | import com.mojang.datafixers.util.Pair; |
44 | 41 | import lombok.Getter; |
|
55 | 52 | @MethodsReturnNonnullByDefault |
56 | 53 | public abstract class PipeBlockEntity<PipeType extends Enum<PipeType> & IPipeType<NodeDataType>, NodeDataType> |
57 | 54 | extends ManagedSyncBlockEntity |
58 | | - implements IPipeNode<PipeType, NodeDataType>, IToolGridHighlight, IToolable, |
| 55 | + implements IPipeNode<PipeType, NodeDataType>, IToolGridHighlight, |
59 | 56 | ICopyable { |
60 | 57 |
|
61 | 58 | private final long offset = GTValues.RNG.nextInt(20); |
@@ -350,56 +347,41 @@ public ResourceTexture getPipeTexture(boolean isBlock) { |
350 | 347 | return null; |
351 | 348 | } |
352 | 349 |
|
353 | | - @Override |
354 | | - public Pair<@Nullable GTToolType, InteractionResult> onToolClick(Set<GTToolType> toolTypes, ItemStack itemStack, |
355 | | - UseOnContext context) { |
| 350 | + public Pair<@Nullable GTToolType, InteractionResult> onToolClick(ExtendedUseOnContext context) { |
356 | 351 | // the side hit from the machine grid |
357 | | - var playerIn = context.getPlayer(); |
358 | | - if (playerIn == null) return Pair.of(null, InteractionResult.PASS); |
359 | | - |
360 | | - var hand = context.getHand(); |
361 | | - var hitResult = new BlockHitResult(context.getClickLocation(), context.getClickedFace(), |
362 | | - context.getClickedPos(), false); |
363 | | - Direction gridSide = ICoverable.determineGridSideHit(hitResult); |
364 | | - CoverBehavior coverBehavior = gridSide == null ? null : coverContainer.getCoverAtSide(gridSide); |
365 | | - if (gridSide == null) gridSide = hitResult.getDirection(); |
366 | | - |
367 | | - // Prioritize covers where they apply (Screwdriver, Soft Mallet) |
368 | | - if (toolTypes.isEmpty() && playerIn.isShiftKeyDown()) { |
369 | | - if (coverBehavior != null) { |
370 | | - return Pair.of(null, coverBehavior.onScrewdriverClick(playerIn, hand, hitResult)); |
| 352 | + var player = context.getPlayer(); |
| 353 | + var toolType = context.getToolType(); |
| 354 | + var gridSide = context.getGridSide(); |
| 355 | + |
| 356 | + if (player == null) return Pair.of(null, InteractionResult.PASS); |
| 357 | + |
| 358 | + // Prioritize covers |
| 359 | + var cover = getCoverContainer().getCoverAtSide(context.getClickedFace()); |
| 360 | + if (cover != null) { |
| 361 | + var result = cover.onToolClick(context); |
| 362 | + if (result.getSecond() != InteractionResult.PASS) return result; |
| 363 | + |
| 364 | + if (toolType.contains(GTToolType.CROWBAR) && !isRemote()) { |
| 365 | + getCoverContainer().removeCover(context.getGridSide(), player); |
| 366 | + return Pair.of(GTToolType.CROWBAR, InteractionResult.SUCCESS); |
371 | 367 | } |
372 | 368 | } |
373 | | - if (toolTypes.contains(GTToolType.SCREWDRIVER)) { |
374 | | - if (coverBehavior != null) { |
375 | | - return Pair.of(GTToolType.SCREWDRIVER, coverBehavior.onScrewdriverClick(playerIn, hand, hitResult)); |
376 | | - } |
377 | | - } else if (toolTypes.contains(GTToolType.SOFT_MALLET)) { |
378 | | - if (coverBehavior != null) { |
379 | | - return Pair.of(GTToolType.SOFT_MALLET, coverBehavior.onSoftMalletClick(playerIn, hand, hitResult)); |
380 | | - } |
381 | | - } else if (toolTypes.contains(getPipeTuneTool())) { |
382 | | - if (playerIn.isShiftKeyDown() && this.canHaveBlockedFaces()) { |
| 369 | + |
| 370 | + if (toolType.contains(getPipeTuneTool())) { |
| 371 | + if (player.isShiftKeyDown() && this.canHaveBlockedFaces()) { |
383 | 372 | boolean isBlocked = this.isBlocked(gridSide); |
384 | 373 | this.setBlocked(gridSide, !isBlocked); |
385 | 374 | } else { |
386 | 375 | boolean isOpen = this.isConnected(gridSide); |
387 | 376 | this.setConnection(gridSide, !isOpen, false); |
388 | 377 | } |
389 | | - return Pair.of(getPipeTuneTool(), InteractionResult.sidedSuccess(playerIn.level().isClientSide)); |
390 | | - } else if (toolTypes.contains(GTToolType.CROWBAR)) { |
391 | | - if (coverBehavior != null) { |
392 | | - if (!isRemote()) { |
393 | | - getCoverContainer().removeCover(gridSide, playerIn); |
394 | | - return Pair.of(GTToolType.CROWBAR, InteractionResult.sidedSuccess(playerIn.level().isClientSide)); |
395 | | - } |
396 | | - } else { |
397 | | - if (!frameMaterial.isNull()) { |
398 | | - Block.popResource(getLevel(), this.getBlockPos(), |
399 | | - GTMaterialBlocks.MATERIAL_BLOCKS.get(TagPrefix.frameGt, frameMaterial).asStack()); |
400 | | - frameMaterial = GTMaterials.NULL; |
401 | | - return Pair.of(GTToolType.CROWBAR, InteractionResult.sidedSuccess(playerIn.level().isClientSide)); |
402 | | - } |
| 378 | + return Pair.of(getPipeTuneTool(), InteractionResult.sidedSuccess(isRemote())); |
| 379 | + } else if (toolType.contains(GTToolType.CROWBAR)) { |
| 380 | + if (!frameMaterial.isNull()) { |
| 381 | + Block.popResource(context.getLevel(), this.getBlockPos(), |
| 382 | + GTMaterialBlocks.MATERIAL_BLOCKS.get(TagPrefix.frameGt, frameMaterial).asStack()); |
| 383 | + frameMaterial = GTMaterials.NULL; |
| 384 | + return Pair.of(GTToolType.CROWBAR, InteractionResult.sidedSuccess(isRemote())); |
403 | 385 | } |
404 | 386 | } |
405 | 387 |
|
|
0 commit comments