Search in sources :

Example 1 with TrackType

use of mods.railcraft.api.tracks.TrackType in project Railcraft by Railcraft.

the class ItemTrackOutfitted method initializeClient.

@SideOnly(Side.CLIENT)
@Override
public void initializeClient() {
    ArrayList<ModelResourceLocation> textures = new ArrayList<>();
    for (TrackType trackType : TrackRegistry.TRACK_TYPE) {
        for (TrackKit trackKit : TrackRegistry.TRACK_KIT) {
            textures.add(new ModelResourceLocation(new ResourceLocation(RailcraftConstants.RESOURCE_DOMAIN, MODEL_PREFIX + trackType.getName() + "." + trackKit.getName()), "inventory"));
        }
    }
    ModelManager.registerComplexItemModel(this, (stack -> new ModelResourceLocation(new ResourceLocation(RailcraftConstants.RESOURCE_DOMAIN, MODEL_PREFIX + getSuffix(stack)), "inventory")), textures.toArray(new ModelResourceLocation[textures.size()]));
}
Also used : HashMap(java.util.HashMap) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) Block(net.minecraft.block.Block) Side(net.minecraftforge.fml.relauncher.Side) Map(java.util.Map) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) TrackRegistry(mods.railcraft.api.tracks.TrackRegistry) World(net.minecraft.world.World) ITrackItem(mods.railcraft.api.core.items.ITrackItem) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) ItemTrack(mods.railcraft.common.blocks.tracks.ItemTrack) TrackKit(mods.railcraft.api.tracks.TrackKit) LocalizationPlugin(mods.railcraft.common.plugins.forge.LocalizationPlugin) IBlockState(net.minecraft.block.state.IBlockState) ILocalizedObject(mods.railcraft.api.core.ILocalizedObject) ModelManager(mods.railcraft.client.render.models.resource.ModelManager) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TrackType(mods.railcraft.api.tracks.TrackType) ResourceLocation(net.minecraft.util.ResourceLocation) TileEntity(net.minecraft.tileentity.TileEntity) CreativePlugin(mods.railcraft.common.plugins.forge.CreativePlugin) RailcraftConstants(mods.railcraft.common.core.RailcraftConstants) TrackType(mods.railcraft.api.tracks.TrackType) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ArrayList(java.util.ArrayList) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) TrackKit(mods.railcraft.api.tracks.TrackKit) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with TrackType

use of mods.railcraft.api.tracks.TrackType in project Railcraft by Railcraft.

the class OutfittedTrackModel method getDependencies.

@Override
public Collection<ResourceLocation> getDependencies() {
    if (trackTypeModelsLocations.isEmpty()) {
        for (TrackType trackType : TrackRegistry.TRACK_TYPE) {
            for (BlockRailBase.EnumRailDirection shape : BlockTrackOutfitted.SHAPE.getAllowedValues()) {
                trackTypeModelsLocations.add(getTrackTypeModelLocation(trackType, shape));
            }
        }
    }
    if (trackKitModelsLocations.isEmpty()) {
        TrackRegistry.TRACK_KIT.stream().filter(t -> t.getRenderer() == TrackKit.Renderer.COMPOSITE).forEach(t -> {
            EnumSet<BlockRailBase.EnumRailDirection> shapes = EnumSet.copyOf(BlockTrackOutfitted.SHAPE.getAllowedValues());
            if (!t.isAllowedOnSlopes()) {
                shapes.removeIf(s -> !TrackShapeHelper.isLevelStraight(s));
            }
            for (BlockRailBase.EnumRailDirection shape : shapes) {
                for (int state = 0; state < t.getRenderStates(); state++) trackKitModelsLocations.add(getTrackKitModelLocation(t, shape, state));
            }
        });
    }
    if (unifiedModelsLocations.isEmpty()) {
        TrackRegistry.TRACK_KIT.stream().filter(t -> t.getRenderer() == TrackKit.Renderer.UNIFIED).forEach(trackKit -> {
            EnumSet<BlockRailBase.EnumRailDirection> shapes = EnumSet.copyOf(BlockTrackOutfitted.SHAPE.getAllowedValues());
            if (!trackKit.isAllowedOnSlopes()) {
                shapes.removeIf(s -> !TrackShapeHelper.isLevelStraight(s));
            }
            for (TrackType trackType : TrackRegistry.TRACK_TYPE) for (BlockRailBase.EnumRailDirection shape : shapes) {
                for (int state = 0; state < trackKit.getRenderStates(); state++) unifiedModelsLocations.add(getUnifiedModelLocation(trackType, trackKit, shape, state));
            }
        });
    }
    if (models.isEmpty()) {
        models.addAll(trackTypeModelsLocations);
        models.addAll(trackKitModelsLocations);
        models.addAll(unifiedModelsLocations);
    }
    return models;
}
Also used : BlockTrackOutfitted(mods.railcraft.common.blocks.tracks.outfitted.BlockTrackOutfitted) java.util(java.util) Function(com.google.common.base.Function) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) IModelState(net.minecraftforge.common.model.IModelState) TrackShapeHelper(mods.railcraft.common.blocks.tracks.TrackShapeHelper) EnumFacing(net.minecraft.util.EnumFacing) IOException(java.io.IOException) IModel(net.minecraftforge.client.model.IModel) TrackKit(mods.railcraft.api.tracks.TrackKit) TrackTypes(mods.railcraft.common.blocks.tracks.behaivor.TrackTypes) IBlockState(net.minecraft.block.state.IBlockState) ICustomModelLoader(net.minecraftforge.client.model.ICustomModelLoader) BlockRailBase(net.minecraft.block.BlockRailBase) TrackType(mods.railcraft.api.tracks.TrackType) IResourceManager(net.minecraft.client.resources.IResourceManager) ResourceLocation(net.minecraft.util.ResourceLocation) TrackRegistry(mods.railcraft.api.tracks.TrackRegistry) VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat) Nullable(javax.annotation.Nullable) net.minecraft.client.renderer.block.model(net.minecraft.client.renderer.block.model) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) TrackType(mods.railcraft.api.tracks.TrackType) BlockRailBase(net.minecraft.block.BlockRailBase)

Example 3 with TrackType

use of mods.railcraft.api.tracks.TrackType in project Railcraft by Railcraft.

the class ItemTrackKit method onItemUse.

@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    playerIn.swingArm(hand);
    if (Game.isClient(worldIn))
        return EnumActionResult.PASS;
    IBlockState oldState = WorldPlugin.getBlockState(worldIn, pos);
    if (!TrackTools.isRailBlock(oldState)) {
        return EnumActionResult.PASS;
    }
    TrackType trackType = null;
    if (oldState.getBlock() instanceof BlockTrackFlex) {
        BlockTrackFlex track = (BlockTrackFlex) oldState.getBlock();
        trackType = track.getTrackType(worldIn, pos);
    } else if (oldState.getBlock() == Blocks.RAIL) {
        trackType = TrackTypes.IRON.getTrackType();
    }
    if (trackType != null) {
        BlockRailBase.EnumRailDirection shape = TrackTools.getTrackDirectionRaw(worldIn, pos);
        if (TrackShapeHelper.isStraight(shape)) {
            TrackKit trackKit = TrackRegistry.TRACK_KIT.get(stack);
            if (!shape.isAscending() || trackKit.isAllowedOnSlopes()) {
                if (!trackKit.isAllowedTrackType(trackType)) {
                    ChatPlugin.sendLocalizedChatFromServer(playerIn, "gui.railcraft.track_kit.item.invalid.track_type");
                    return EnumActionResult.PASS;
                }
                if (BlockTrackOutfitted.placeTrack(worldIn, pos, playerIn, shape, trackType, trackKit)) {
                    SoundHelper.playPlaceSoundForBlock(worldIn, pos);
                    stack.stackSize--;
                    return EnumActionResult.SUCCESS;
                }
            } else {
                ChatPlugin.sendLocalizedChatFromServer(playerIn, "gui.railcraft.track_kit.item.invalid.slope");
            }
        } else {
            ChatPlugin.sendLocalizedChatFromServer(playerIn, "gui.railcraft.track_kit.item.invalid.curve");
        }
    } else {
        ChatPlugin.sendLocalizedChatFromServer(playerIn, "gui.railcraft.track_kit.item.invalid.track");
    }
    return EnumActionResult.PASS;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) TrackType(mods.railcraft.api.tracks.TrackType) BlockTrackFlex(mods.railcraft.common.blocks.tracks.flex.BlockTrackFlex) BlockRailBase(net.minecraft.block.BlockRailBase) TrackKit(mods.railcraft.api.tracks.TrackKit)

Example 4 with TrackType

use of mods.railcraft.api.tracks.TrackType in project Railcraft by Railcraft.

the class TrackKitBooster method onMinecartPass.

@Override
public void onMinecartPass(EntityMinecart cart) {
    TrackType trackType = ((TileTrackOutfitted) getTile()).getTrackType();
    if (TrackTypes.REINFORCED.getTrackType() == trackType)
        onMinecartPassStandard(cart, BOOST_FACTOR_REINFORCED);
    else if (trackType.isHighSpeed())
        onMinecartPassHighSpeed(cart);
    else
        onMinecartPassStandard(cart, BOOST_FACTOR);
}
Also used : TrackType(mods.railcraft.api.tracks.TrackType) TileTrackOutfitted(mods.railcraft.common.blocks.tracks.outfitted.TileTrackOutfitted)

Example 5 with TrackType

use of mods.railcraft.api.tracks.TrackType in project Railcraft by Railcraft.

the class ItemSpikeMaul method onItemUse.

@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    playerIn.swingArm(hand);
    if (ISpikeMaulTarget.spikeMaulTargets.isEmpty())
        return EnumActionResult.PASS;
    IBlockState oldState = WorldPlugin.getBlockState(worldIn, pos);
    TileEntity oldTile = null;
    if (oldState.getBlock().hasTileEntity(oldState)) {
        oldTile = WorldPlugin.getBlockTile(worldIn, pos);
    }
    if (!TrackTools.isRailBlock(oldState))
        return EnumActionResult.PASS;
    TrackType trackType = TrackTools.getTrackTypeAt(worldIn, pos, oldState);
    BlockRailBase.EnumRailDirection shape = TrackTools.getTrackDirectionRaw(oldState);
    if (!TrackShapeHelper.isAscending(shape)) {
        Deque<ISpikeMaulTarget> targets = new LinkedList<>(ISpikeMaulTarget.spikeMaulTargets);
        Set<ISpikeMaulTarget> tried = new HashSet<>();
        boolean foundMatch = false;
        ISpikeMaulTarget target;
        while ((target = targets.poll()) != null && !tried.contains(target)) {
            if (target.matches(worldIn, pos, oldState)) {
                foundMatch = true;
                break;
            } else {
                tried.add(target);
                targets.addLast(target);
            }
        }
        if (foundMatch) {
            if (Game.isClient(worldIn))
                return EnumActionResult.SUCCESS;
            WorldPlugin.setBlockToAir(worldIn, pos);
            ChargeManager.getNetwork(worldIn).deregisterChargeNode(pos);
            while ((target = targets.poll()) != null) {
                if (target.setToTarget(worldIn, pos, oldState, playerIn, shape, trackType)) {
                    SoundHelper.playPlaceSoundForBlock(worldIn, pos);
                    stack.damageItem(1, playerIn);
                    return EnumActionResult.SUCCESS;
                }
            }
            WorldPlugin.setBlockState(worldIn, pos, oldState);
            if (oldTile != null) {
                oldTile.validate();
                worldIn.setTileEntity(pos, oldTile);
            }
            return EnumActionResult.FAIL;
        }
    }
    return EnumActionResult.PASS;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) ISpikeMaulTarget(mods.railcraft.api.core.items.ISpikeMaulTarget) TrackType(mods.railcraft.api.tracks.TrackType) BlockRailBase(net.minecraft.block.BlockRailBase)

Aggregations

TrackType (mods.railcraft.api.tracks.TrackType)5 IBlockState (net.minecraft.block.state.IBlockState)4 TrackKit (mods.railcraft.api.tracks.TrackKit)3 BlockRailBase (net.minecraft.block.BlockRailBase)3 TrackRegistry (mods.railcraft.api.tracks.TrackRegistry)2 TileEntity (net.minecraft.tileentity.TileEntity)2 EnumFacing (net.minecraft.util.EnumFacing)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 Function (com.google.common.base.Function)1 IOException (java.io.IOException)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Nullable (javax.annotation.Nullable)1 ILocalizedObject (mods.railcraft.api.core.ILocalizedObject)1 ISpikeMaulTarget (mods.railcraft.api.core.items.ISpikeMaulTarget)1 ITrackItem (mods.railcraft.api.core.items.ITrackItem)1 ModelManager (mods.railcraft.client.render.models.resource.ModelManager)1 ItemTrack (mods.railcraft.common.blocks.tracks.ItemTrack)1