Search in sources :

Example 1 with TileLogic

use of mods.railcraft.common.blocks.TileLogic in project Railcraft by Railcraft.

the class TileRockCrusher method placeRockCrusher.

public static void placeRockCrusher(World world, BlockPos pos, int patternIndex, @Nullable List<ItemStack> input, @Nullable List<ItemStack> output) {
    StructurePattern pattern = TileRockCrusher.patterns.get(patternIndex);
    Char2ObjectMap<IBlockState> blockMapping = new Char2ObjectOpenHashMap<>();
    IBlockState state = RailcraftBlocks.ROCK_CRUSHER.getState(null);
    blockMapping.put('B', state);
    blockMapping.put('D', state);
    blockMapping.put('a', state);
    blockMapping.put('b', state);
    blockMapping.put('c', state);
    blockMapping.put('d', state);
    blockMapping.put('e', state);
    blockMapping.put('f', state);
    blockMapping.put('h', state);
    Optional<TileLogic> tile = pattern.placeStructure(world, pos, blockMapping);
    tile.flatMap(t -> t.getLogic(StructureLogic.class)).ifPresent(structure -> {
        structure.getFunctionalLogic(InventoryLogic.class).ifPresent(logic -> {
            for (int slot = 0; slot < 9; slot++) {
                if (input != null && slot < input.size())
                    logic.setInventorySlotContents(RockCrusherLogic.SLOT_INPUT + slot, input.get(slot));
                if (output != null && slot < output.size())
                    logic.setInventorySlotContents(RockCrusherLogic.SLOT_OUTPUT + slot, output.get(slot));
            }
        });
    });
}
Also used : Blocks(net.minecraft.init.Blocks) EntitySearcher(mods.railcraft.common.util.entity.EntitySearcher) ArrayList(java.util.ArrayList) ICON(mods.railcraft.common.blocks.structures.BlockRockCrusher.ICON) EnumGui(mods.railcraft.common.gui.EnumGui) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d) ClientEffects(mods.railcraft.client.util.effects.ClientEffects) InvTools(mods.railcraft.common.util.inventory.InvTools) EntityItem(net.minecraft.entity.item.EntityItem) mods.railcraft.common.blocks.logic(mods.railcraft.common.blocks.logic) World(net.minecraft.world.World) RailcraftDamageSource(mods.railcraft.common.util.entity.RailcraftDamageSource) Game(mods.railcraft.common.util.misc.Game) BlockPos(net.minecraft.util.math.BlockPos) RailcraftBlocks(mods.railcraft.common.blocks.RailcraftBlocks) Char2ObjectOpenHashMap(it.unimi.dsi.fastutil.chars.Char2ObjectOpenHashMap) WorldPlugin(mods.railcraft.common.plugins.forge.WorldPlugin) Char2ObjectMap(it.unimi.dsi.fastutil.chars.Char2ObjectMap) IBlockState(net.minecraft.block.state.IBlockState) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) TileLogic(mods.railcraft.common.blocks.TileLogic) MiscTools(mods.railcraft.common.util.misc.MiscTools) Optional(java.util.Optional) RCEntitySelectors(mods.railcraft.common.util.entity.RCEntitySelectors) TileCrafter(mods.railcraft.common.blocks.TileCrafter) IBlockState(net.minecraft.block.state.IBlockState) Char2ObjectOpenHashMap(it.unimi.dsi.fastutil.chars.Char2ObjectOpenHashMap) TileLogic(mods.railcraft.common.blocks.TileLogic)

Example 2 with TileLogic

use of mods.railcraft.common.blocks.TileLogic in project Railcraft by Railcraft.

the class StructurePattern method placeStructure.

public Optional<TileLogic> placeStructure(World world, BlockPos pos, Char2ObjectMap<IBlockState> blockMapping) {
    int xWidth = getPatternWidthX();
    int zWidth = getPatternWidthZ();
    int height = getPatternHeight();
    BlockPos offset = pos.subtract(getMasterOffset());
    Optional<TileLogic> master = Optional.empty();
    for (byte px = 0; px < xWidth; px++) {
        for (byte py = 0; py < height; py++) {
            for (byte pz = 0; pz < zWidth; pz++) {
                char marker = getPatternMarker(px, py, pz);
                IBlockState blockState = blockMapping.get(marker);
                if (blockState == null)
                    continue;
                BlockPos p = new BlockPos(px, py, pz).add(offset);
                world.setBlockState(p, blockState, 3);
                if (px == masterOffset.getX() && py == masterOffset.getY() && pz == masterOffset.getZ())
                    master = WorldPlugin.getTileEntity(world, pos, TileLogic.class);
            }
        }
    }
    return master;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos) TileLogic(mods.railcraft.common.blocks.TileLogic)

Example 3 with TileLogic

use of mods.railcraft.common.blocks.TileLogic in project Railcraft by Railcraft.

the class ItemMagnifyingGlass method onItemUseFirst.

@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
    if (Game.isClient(world))
        return EnumActionResult.PASS;
    TileEntity t = WorldPlugin.getBlockTile(world, pos);
    EnumActionResult returnValue = EnumActionResult.PASS;
    if (t instanceof IOwnable) {
        IOwnable ownable = (IOwnable) t;
        ChatPlugin.sendLocalizedChatFromServer(player, "gui.railcraft.mag.glass.placedby", ownable.getDisplayName(), ownable.getOwner());
        returnValue = EnumActionResult.SUCCESS;
    }
    if (t instanceof TileMultiBlock) {
        TileMultiBlock tile = (TileMultiBlock) t;
        if (tile.isStructureValid()) {
            ChatPlugin.sendLocalizedChatFromServer(player, "railcraft.multiblock.state.valid");
            ChatPlugin.sendLocalizedChatFromServer(player, "railcraft.multiblock.state.master." + (tile.isValidMaster() ? "true" : "false"));
        } else
            for (State returnState : EnumSet.complementOf(EnumSet.of(State.VALID))) {
                List<StructurePattern> pats = tile.patternStates.get(returnState);
                if (!pats.isEmpty()) {
                    List<Integer> indexList = pats.stream().map(map -> tile.getPatterns().indexOf(map)).collect(Collectors.toList());
                    ChatPlugin.sendLocalizedChatFromServer(player, returnState.message, indexList.toString());
                }
            }
        returnValue = EnumActionResult.SUCCESS;
    }
    if (t instanceof TileLogic) {
        TileLogic tile = (TileLogic) t;
        Optional<StructureLogic> optLogic = tile.getLogic(StructureLogic.class);
        if (optLogic.isPresent()) {
            StructureLogic logic = optLogic.get();
            if (logic.isStructureValid()) {
                ChatPlugin.sendLocalizedChatFromServer(player, "railcraft.multiblock.state.valid");
                ChatPlugin.sendLocalizedChatFromServer(player, "railcraft.multiblock.state.master." + (logic.isValidMaster() ? "true" : "false"));
            } else
                for (State returnState : EnumSet.complementOf(EnumSet.of(State.VALID))) {
                    List<StructurePattern> pats = logic.patternStates.get(returnState);
                    if (!pats.isEmpty()) {
                        List<Integer> indexList = pats.stream().map(map -> logic.getPatterns().indexOf(map)).collect(Collectors.toList());
                        ChatPlugin.sendLocalizedChatFromServer(player, returnState.message, indexList.toString());
                    }
                }
            returnValue = EnumActionResult.SUCCESS;
        }
    }
    if (t instanceof IDualHeadSignal) {
        IDualHeadSignal signal = (IDualHeadSignal) t;
        SignalAspect top = signal.getSignalAspect(DualLamp.TOP);
        SignalAspect bottom = signal.getSignalAspect(DualLamp.BOTTOM);
        ChatPlugin.sendLocalizedChatFromServer(player, "gui.railcraft.mag.glass.aspect.dual", top.getLocalizationTag(), bottom.getLocalizationTag());
        returnValue = EnumActionResult.SUCCESS;
    } else if (t instanceof TileSignalBase) {
        ChatPlugin.sendLocalizedChatFromServer(player, "gui.railcraft.mag.glass.aspect", ((TileSignalBase) t).getSignalAspect().getLocalizationTag());
        returnValue = EnumActionResult.SUCCESS;
    }
    if (t instanceof IMagnifiable) {
        ((IMagnifiable) t).onMagnify(player);
    }
    return returnValue;
}
Also used : SignalAspect(mods.railcraft.api.signals.SignalAspect) TileMultiBlock(mods.railcraft.common.blocks.structures.TileMultiBlock) IDualHeadSignal(mods.railcraft.common.blocks.machine.wayobjects.signals.IDualHeadSignal) TileSignalBase(mods.railcraft.common.blocks.machine.wayobjects.signals.TileSignalBase) TileEntity(net.minecraft.tileentity.TileEntity) EnumActionResult(net.minecraft.util.EnumActionResult) StructureLogic(mods.railcraft.common.blocks.logic.StructureLogic) State(mods.railcraft.common.blocks.structures.StructurePattern.State) IOwnable(mods.railcraft.api.core.IOwnable) List(java.util.List) TileLogic(mods.railcraft.common.blocks.TileLogic)

Aggregations

TileLogic (mods.railcraft.common.blocks.TileLogic)3 List (java.util.List)2 IBlockState (net.minecraft.block.state.IBlockState)2 BlockPos (net.minecraft.util.math.BlockPos)2 Char2ObjectMap (it.unimi.dsi.fastutil.chars.Char2ObjectMap)1 Char2ObjectOpenHashMap (it.unimi.dsi.fastutil.chars.Char2ObjectOpenHashMap)1 ArrayList (java.util.ArrayList)1 Optional (java.util.Optional)1 IOwnable (mods.railcraft.api.core.IOwnable)1 SignalAspect (mods.railcraft.api.signals.SignalAspect)1 ClientEffects (mods.railcraft.client.util.effects.ClientEffects)1 RailcraftBlocks (mods.railcraft.common.blocks.RailcraftBlocks)1 TileCrafter (mods.railcraft.common.blocks.TileCrafter)1 mods.railcraft.common.blocks.logic (mods.railcraft.common.blocks.logic)1 StructureLogic (mods.railcraft.common.blocks.logic.StructureLogic)1 IDualHeadSignal (mods.railcraft.common.blocks.machine.wayobjects.signals.IDualHeadSignal)1 TileSignalBase (mods.railcraft.common.blocks.machine.wayobjects.signals.TileSignalBase)1 ICON (mods.railcraft.common.blocks.structures.BlockRockCrusher.ICON)1 State (mods.railcraft.common.blocks.structures.StructurePattern.State)1 TileMultiBlock (mods.railcraft.common.blocks.structures.TileMultiBlock)1