mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-22 19:58:35 +01:00
allow modules to be inserted into pipes by right-clicking
This commit is contained in:
parent
718cef5c4e
commit
544e383974
1 changed files with 12 additions and 2 deletions
|
@ -2,6 +2,7 @@ package de.ellpeck.prettypipes.pipe;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import de.ellpeck.prettypipes.Utility;
|
import de.ellpeck.prettypipes.Utility;
|
||||||
|
import de.ellpeck.prettypipes.items.IModule;
|
||||||
import de.ellpeck.prettypipes.network.PipeItem;
|
import de.ellpeck.prettypipes.network.PipeItem;
|
||||||
import de.ellpeck.prettypipes.network.PipeNetwork;
|
import de.ellpeck.prettypipes.network.PipeNetwork;
|
||||||
import net.minecraft.block.*;
|
import net.minecraft.block.*;
|
||||||
|
@ -32,6 +33,7 @@ import net.minecraft.world.World;
|
||||||
import net.minecraftforge.fml.network.NetworkHooks;
|
import net.minecraftforge.fml.network.NetworkHooks;
|
||||||
import net.minecraftforge.items.CapabilityItemHandler;
|
import net.minecraftforge.items.CapabilityItemHandler;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
|
import net.minecraftforge.items.ItemHandlerHelper;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -67,13 +69,21 @@ public class PipeBlock extends ContainerBlock implements IPipeConnectable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult result) {
|
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult result) {
|
||||||
if (!player.getHeldItem(handIn).isEmpty())
|
|
||||||
return ActionResultType.PASS;
|
|
||||||
PipeTileEntity tile = Utility.getTileEntity(PipeTileEntity.class, worldIn, pos);
|
PipeTileEntity tile = Utility.getTileEntity(PipeTileEntity.class, worldIn, pos);
|
||||||
if (tile == null)
|
if (tile == null)
|
||||||
return ActionResultType.PASS;
|
return ActionResultType.PASS;
|
||||||
if (!tile.canHaveModules())
|
if (!tile.canHaveModules())
|
||||||
return ActionResultType.PASS;
|
return ActionResultType.PASS;
|
||||||
|
ItemStack stack = player.getHeldItem(handIn);
|
||||||
|
if (stack.getItem() instanceof IModule) {
|
||||||
|
ItemStack copy = stack.copy();
|
||||||
|
copy.setCount(1);
|
||||||
|
ItemStack remain = ItemHandlerHelper.insertItem(tile.modules, copy, false);
|
||||||
|
if (remain.isEmpty()) {
|
||||||
|
stack.shrink(1);
|
||||||
|
return ActionResultType.SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!worldIn.isRemote)
|
if (!worldIn.isRemote)
|
||||||
NetworkHooks.openGui((ServerPlayerEntity) player, tile, pos);
|
NetworkHooks.openGui((ServerPlayerEntity) player, tile, pos);
|
||||||
return ActionResultType.SUCCESS;
|
return ActionResultType.SUCCESS;
|
||||||
|
|
Loading…
Reference in a new issue