Search in sources :

Example 1 with TrackKit

use of mods.railcraft.api.tracks.TrackKit 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 TrackKit

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

the class ItemTrackOutfitted method placeBlockAt.

@Override
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState newState) {
    TrackKit trackKit = TrackRegistry.TRACK_KIT.get(stack);
    newState = newState.withProperty(BlockTrackOutfitted.TICKING, trackKit.requiresTicks());
    return super.placeBlockAt(stack, player, world, pos, side, hitX, hitY, hitZ, newState);
}
Also used : TrackKit(mods.railcraft.api.tracks.TrackKit)

Example 3 with TrackKit

use of mods.railcraft.api.tracks.TrackKit 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 4 with TrackKit

use of mods.railcraft.api.tracks.TrackKit 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)

Aggregations

TrackKit (mods.railcraft.api.tracks.TrackKit)4 TrackType (mods.railcraft.api.tracks.TrackType)3 IBlockState (net.minecraft.block.state.IBlockState)3 TrackRegistry (mods.railcraft.api.tracks.TrackRegistry)2 BlockRailBase (net.minecraft.block.BlockRailBase)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 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 TrackShapeHelper (mods.railcraft.common.blocks.tracks.TrackShapeHelper)1 TrackTypes (mods.railcraft.common.blocks.tracks.behaivor.TrackTypes)1