Search in sources :

Example 1 with StructurePattern

use of mods.railcraft.common.blocks.structures.StructurePattern in project Railcraft by Railcraft.

the class StructureLogic method readFromNBT.

@Override
@OverridingMethodsMustInvokeSuper
public void readFromNBT(NBTTagCompound data) {
    super.readFromNBT(data);
    functionalLogic.readFromNBT(data);
    isMaster = data.getBoolean("master");
    if (data.hasKey("marker"))
        marker = data.getString("marker").charAt(0);
    StructurePattern pat = null;
    try {
        byte index = data.getByte("pattern");
        pat = index < 0 ? null : patterns.get(index);
    } catch (Exception ex) {
    // NOOP
    }
    BlockPos pos = NBTPlugin.readBlockPos(data, "posInPattern");
    setPatternState(pat, pos);
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) StructurePattern(mods.railcraft.common.blocks.structures.StructurePattern) IOException(java.io.IOException) OverridingMethodsMustInvokeSuper(javax.annotation.OverridingMethodsMustInvokeSuper)

Example 2 with StructurePattern

use of mods.railcraft.common.blocks.structures.StructurePattern in project Railcraft by Railcraft.

the class StructureLogic method readPacketData.

@Override
@OverridingMethodsMustInvokeSuper
public void readPacketData(RailcraftInputStream data) throws IOException {
    requestPacket = false;
    state = data.readEnum(StructureState.VALUES);
    marker = data.readChar();
    if (state == StructureState.VALID) {
        int patternIndex = data.readByte();
        patternIndex = MathHelper.clamp(patternIndex, 0, patterns.size() - 1);
        StructurePattern pat = patterns.get(patternIndex);
        BlockPos posInPattern = data.readBlockPos();
        changePattern(pat, posInPattern);
        isMaster = pat.isMasterPosition(posInPattern);
        // TODO is this still necessary?
        if (!getMasterLogic().isPresent())
            requestPacket = true;
    } else {
        isMaster = false;
        changePattern(null, null);
    }
    super.readPacketData(data);
    functionalLogic.readPacketData(data);
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) StructurePattern(mods.railcraft.common.blocks.structures.StructurePattern) OverridingMethodsMustInvokeSuper(javax.annotation.OverridingMethodsMustInvokeSuper)

Example 3 with StructurePattern

use of mods.railcraft.common.blocks.structures.StructurePattern in project Railcraft by Railcraft.

the class StructureLogic method testIfMasterBlock.

protected void testIfMasterBlock() {
    // System.out.println("testing structure");
    testPatterns();
    List<TileRailcraft> old = new ArrayList<>(components);
    components.clear();
    components.add(tile);
    if (patternStates.containsKey(StructurePattern.State.VALID)) {
        state = StructureState.VALID;
        isMaster = true;
        // System.out.println("structure complete");
        StructurePattern pattern = patternStates.get(StructurePattern.State.VALID).get(0);
        int xWidth = pattern.getPatternWidthX();
        int zWidth = pattern.getPatternWidthZ();
        int height = pattern.getPatternHeight();
        BlockPos offset = getPos().subtract(pattern.getMasterOffset());
        Map<BlockPos, StructureLogic> newComponents = new HashMap<>();
        for (int px = 0; px < xWidth; px++) {
            for (int py = 0; py < height; py++) {
                for (int pz = 0; pz < zWidth; pz++) {
                    char marker = pattern.getPatternMarker(px, py, pz);
                    if (isMapPositionOtherBlock(marker))
                        continue;
                    BlockPos patternPos = new BlockPos(px, py, pz);
                    BlockPos pos = patternPos.add(offset);
                    WorldPlugin.getTileEntity(theWorldAsserted(), pos).flatMap(tileToLogic()).ifPresent(l -> {
                        components.add(l.tile);
                        newComponents.put(patternPos, l);
                    });
                }
            }
        }
        newComponents.forEach((pos, logic) -> logic.changePattern(pattern, pos));
        MinecraftForge.EVENT_BUS.post(new MultiBlockEvent.Form(tile));
    } else if (patternStates.containsKey(StructurePattern.State.NOT_LOADED)) {
        state = StructureState.UNKNOWN;
    } else {
        state = StructureState.INVALID;
        functionalLogic.getLogic(IDropsInv.class).ifPresent(i -> i.spewInventory(theWorldAsserted(), getPos()));
        if (isMaster) {
            isMaster = false;
            onMasterReset();
            sendUpdateToClient();
        }
    }
    old.removeAll(components);
    old.stream().filter(t -> !t.isInvalid()).map(tileToLogic()).flatMap(Streams.unwrap()).forEach(t -> t.changePattern(null, null));
}
Also used : java.util(java.util) ListMultimap(com.google.common.collect.ListMultimap) PacketTileRequest(mods.railcraft.common.util.network.PacketTileRequest) EnumHand(net.minecraft.util.EnumHand) IDropsInv(mods.railcraft.common.blocks.interfaces.IDropsInv) Streams(mods.railcraft.common.util.collections.Streams) Timer(mods.railcraft.common.util.misc.Timer) RailcraftInputStream(mods.railcraft.common.util.network.RailcraftInputStream) Function(java.util.function.Function) Multimaps(com.google.common.collect.Multimaps) EnumGui(mods.railcraft.common.gui.EnumGui) ItemStack(net.minecraft.item.ItemStack) Block(net.minecraft.block.Block) MultiBlockEvent(mods.railcraft.common.events.MultiBlockEvent) StructurePattern(mods.railcraft.common.blocks.structures.StructurePattern) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) OverridingMethodsMustInvokeSuper(javax.annotation.OverridingMethodsMustInvokeSuper) World(net.minecraft.world.World) Predicate(java.util.function.Predicate) EnumFacing(net.minecraft.util.EnumFacing) Game(mods.railcraft.common.util.misc.Game) BlockPos(net.minecraft.util.math.BlockPos) IOException(java.io.IOException) Optionals(mods.railcraft.common.util.misc.Optionals) WorldPlugin(mods.railcraft.common.plugins.forge.WorldPlugin) PacketDispatcher(mods.railcraft.common.util.network.PacketDispatcher) RailcraftOutputStream(mods.railcraft.common.util.network.RailcraftOutputStream) IBlockState(net.minecraft.block.state.IBlockState) Nullable(org.jetbrains.annotations.Nullable) MinecraftForge(net.minecraftforge.common.MinecraftForge) NBTPlugin(mods.railcraft.common.plugins.forge.NBTPlugin) TileRailcraft(mods.railcraft.common.blocks.TileRailcraft) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) MathHelper(net.minecraft.util.math.MathHelper) TileLogic(mods.railcraft.common.blocks.TileLogic) TileEntity(net.minecraft.tileentity.TileEntity) MultiBlockEvent(mods.railcraft.common.events.MultiBlockEvent) TileRailcraft(mods.railcraft.common.blocks.TileRailcraft) BlockPos(net.minecraft.util.math.BlockPos) StructurePattern(mods.railcraft.common.blocks.structures.StructurePattern)

Aggregations

OverridingMethodsMustInvokeSuper (javax.annotation.OverridingMethodsMustInvokeSuper)3 StructurePattern (mods.railcraft.common.blocks.structures.StructurePattern)3 BlockPos (net.minecraft.util.math.BlockPos)3 IOException (java.io.IOException)2 ListMultimap (com.google.common.collect.ListMultimap)1 Multimaps (com.google.common.collect.Multimaps)1 java.util (java.util)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 TileLogic (mods.railcraft.common.blocks.TileLogic)1 TileRailcraft (mods.railcraft.common.blocks.TileRailcraft)1 IDropsInv (mods.railcraft.common.blocks.interfaces.IDropsInv)1 MultiBlockEvent (mods.railcraft.common.events.MultiBlockEvent)1 EnumGui (mods.railcraft.common.gui.EnumGui)1 NBTPlugin (mods.railcraft.common.plugins.forge.NBTPlugin)1 WorldPlugin (mods.railcraft.common.plugins.forge.WorldPlugin)1 Streams (mods.railcraft.common.util.collections.Streams)1 Game (mods.railcraft.common.util.misc.Game)1 Optionals (mods.railcraft.common.util.misc.Optionals)1 Timer (mods.railcraft.common.util.misc.Timer)1