Search in sources :

Example 1 with TileRailcraft

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

the class MultiBlockFormedTrigger method onMultiBlockForm.

@SubscribeEvent
public void onMultiBlockForm(MultiBlockEvent.Form event) {
    TileRailcraft tile = event.getMaster();
    GameProfile owner = tile.getOwner();
    MinecraftServer server = requireNonNull(Game.getServer());
    EntityPlayerMP player = server.getPlayerList().getPlayerByUUID(owner.getId());
    if (player == null) {
        // Offline
        return;
    }
    PlayerAdvancements advancements = player.getAdvancements();
    Collection<Listener<Instance>> done = manager.get(advancements).stream().filter(listener -> listener.getCriterionInstance().matches(tile)).collect(Collectors.toList());
    for (Listener<Instance> listener : done) {
        listener.grantCriterion(advancements);
    }
}
Also used : JsonObject(com.google.gson.JsonObject) GameProfile(com.mojang.authlib.GameProfile) Conditions(mods.railcraft.common.util.misc.Conditions) JsonDeserializationContext(com.google.gson.JsonDeserializationContext) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) RailcraftConstantsAPI(mods.railcraft.api.core.RailcraftConstantsAPI) MinecraftServer(net.minecraft.server.MinecraftServer) MultiBlockEvent(mods.railcraft.common.events.MultiBlockEvent) Objects.requireNonNull(java.util.Objects.requireNonNull) ICriterionInstance(net.minecraft.advancements.ICriterionInstance) PlayerAdvancements(net.minecraft.advancements.PlayerAdvancements) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Collection(java.util.Collection) Game(mods.railcraft.common.util.misc.Game) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) MinecraftForge(net.minecraftforge.common.MinecraftForge) Instance(mods.railcraft.common.advancements.criterion.MultiBlockFormedTrigger.Instance) JsonTools(mods.railcraft.common.util.json.JsonTools) TileRailcraft(mods.railcraft.common.blocks.TileRailcraft) JsonUtils(net.minecraft.util.JsonUtils) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) TileEntity(net.minecraft.tileentity.TileEntity) NBTPredicate(net.minecraft.advancements.critereon.NBTPredicate) PlayerAdvancements(net.minecraft.advancements.PlayerAdvancements) GameProfile(com.mojang.authlib.GameProfile) ICriterionInstance(net.minecraft.advancements.ICriterionInstance) Instance(mods.railcraft.common.advancements.criterion.MultiBlockFormedTrigger.Instance) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) TileRailcraft(mods.railcraft.common.blocks.TileRailcraft) MinecraftServer(net.minecraft.server.MinecraftServer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with TileRailcraft

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

the class PacketTileRequest method readData.

@Override
public void readData(RailcraftInputStream data) throws IOException {
    World world = DimensionManager.getWorld(data.readInt());
    if (world == null)
        return;
    int x = data.readInt();
    int y = data.readInt();
    int z = data.readInt();
    tile = world.getTileEntity(new BlockPos(x, y, z));
    if (tile instanceof TileRailcraft && player != null)
        PacketBuilder.instance().sendTileEntityPacket(tile, player);
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) TileRailcraft(mods.railcraft.common.blocks.TileRailcraft)

Example 3 with TileRailcraft

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

the class CommandDebug method executeSubCommand.

@Override
public void executeSubCommand(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (args.length != 0)
        CommandHelpers.throwWrongUsage(sender, this);
    RayTraceResult rayTraceResult = MiscTools.rayTracePlayerLook((EntityPlayer) sender);
    if (rayTraceResult == null)
        CommandHelpers.throwWrongUsage(sender, this);
    List<String> debug = Collections.emptyList();
    switch(rayTraceResult.typeOfHit) {
        case ENTITY:
            Entity entity = rayTraceResult.entityHit;
            if (entity instanceof EntityMinecart) {
                debug = CartTools.getDebugOutput((EntityMinecart) entity);
            } else {
                throw new EntityInvalidException(entity);
            }
            break;
        case BLOCK:
            World world = CommandHelpers.getWorld(sender);
            TileEntity tile = WorldPlugin.getBlockTile(world, rayTraceResult.getBlockPos());
            if (tile instanceof TileRailcraft) {
                debug = ((TileRailcraft) tile).getDebugOutput();
            } else {
                throw new BlockNotFoundException();
            }
            break;
    }
    for (String s : debug) {
        printLine(sender, s);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) RayTraceResult(net.minecraft.util.math.RayTraceResult) World(net.minecraft.world.World) EntityMinecart(net.minecraft.entity.item.EntityMinecart) TileRailcraft(mods.railcraft.common.blocks.TileRailcraft)

Example 4 with TileRailcraft

use of mods.railcraft.common.blocks.TileRailcraft 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

TileRailcraft (mods.railcraft.common.blocks.TileRailcraft)4 TileEntity (net.minecraft.tileentity.TileEntity)3 World (net.minecraft.world.World)3 MultiBlockEvent (mods.railcraft.common.events.MultiBlockEvent)2 Game (mods.railcraft.common.util.misc.Game)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 BlockPos (net.minecraft.util.math.BlockPos)2 MinecraftForge (net.minecraftforge.common.MinecraftForge)2 Nullable (org.jetbrains.annotations.Nullable)2 ListMultimap (com.google.common.collect.ListMultimap)1 Multimaps (com.google.common.collect.Multimaps)1 JsonDeserializationContext (com.google.gson.JsonDeserializationContext)1 JsonObject (com.google.gson.JsonObject)1 GameProfile (com.mojang.authlib.GameProfile)1 IOException (java.io.IOException)1 java.util (java.util)1 Collection (java.util.Collection)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1