Search in sources :

Example 6 with IExplosiveData

use of icbm.classic.api.reg.IExplosiveData in project ICBM-Classic by BuiltBrokenModding.

the class BlockExplosive method getStateForPlacement.

@Override
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
    ItemStack stack = placer.getHeldItem(hand);
    IBlockState state = getDefaultState().withProperty(ROTATION_PROP, facing);
    IExplosiveData prop = ICBMClassicAPI.EXPLOSIVE_REGISTRY.getExplosiveData(stack.getItemDamage());
    if (prop != null) {
        return state.withProperty(EX_PROP, prop);
    } else {
        // if the explosives id doesnt exist, then fallback to the one with the id 0
        prop = ICBMClassicAPI.EXPLOSIVE_REGISTRY.getExplosiveData(0);
        ICBMClassic.logger().log(Level.ERROR, "Unable to get explosives kind, choosing " + prop.getRegistryName().toString() + " as a fallback.");
        stack.setItemDamage(0);
        return state.withProperty(EX_PROP, prop);
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ItemStack(net.minecraft.item.ItemStack) IExplosiveData(icbm.classic.api.reg.IExplosiveData)

Example 7 with IExplosiveData

use of icbm.classic.api.reg.IExplosiveData in project ICBM-Classic by BuiltBrokenModding.

the class ClientReg method registerCartRenders.

protected static void registerCartRenders() {
    for (// TODO run loop once for all 4 content types
    IExplosiveData data : // TODO run loop once for all 4 content types
    ICBMClassicAPI.EX_MINECART_REGISTRY.getExplosives()) {
        final String resourcePath = data.getRegistryName().getNamespace() + ":bombcarts/" + data.getRegistryName().getPath();
        cartModelMap.put(data, new ModelResourceLocation(resourcePath, "inventory"));
    }
    ModelLoader.registerItemVariants(ItemReg.itemBombCart, cartModelMap.values().stream().map(model -> new ResourceLocation(model.getNamespace() + ":" + model.getPath())).toArray(ResourceLocation[]::new));
    ModelLoader.setCustomMeshDefinition(ItemReg.itemBombCart, new ItemModelMapperExplosive(cartModelMap, cartModelMap.get(ICBMExplosives.CONDENSED)));
}
Also used : ItemModelMapperExplosive(icbm.classic.client.mapper.ItemModelMapperExplosive) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) IExplosiveData(icbm.classic.api.reg.IExplosiveData)

Example 8 with IExplosiveData

use of icbm.classic.api.reg.IExplosiveData in project ICBM-Classic by BuiltBrokenModding.

the class ClientReg method registerExBlockRenders.

protected static void registerExBlockRenders() {
    for (// TODO run loop once for all 4 content types
    IExplosiveData data : // TODO run loop once for all 4 content types
    ICBMClassicAPI.EX_BLOCK_REGISTRY.getExplosives()) {
        // Add block state
        final HashMap<EnumFacing, ModelResourceLocation> facingModelMap = new HashMap<>();
        final String resourcePath = data.getRegistryName().getNamespace() + ":explosives/" + data.getRegistryName().getPath();
        for (EnumFacing facing : EnumFacing.VALUES) {
            facingModelMap.put(facing, new ModelResourceLocation(resourcePath, "explosive=" + data.getRegistryName().toString().replace(":", "_") + ",rotation=" + facing));
        }
        blockModelMap.put(data, facingModelMap);
        // Add item state
        // IBlockState state = BlockReg.blockExplosive.getDefaultState().withProperty(BlockICBM.ROTATION_PROP, EnumFacing.UP);
        // String properties_string = getPropertyString(state.getProperties());
        itemBlockModelMap.put(data, new ModelResourceLocation(resourcePath, "inventory"));
    }
    // Block state mapper
    ModelLoader.setCustomStateMapper(BlockReg.blockExplosive, new BlockModelMapperExplosive(blockModelMap, blockModelMap.get(ICBMExplosives.CONDENSED).get(EnumFacing.UP)));
    // Item state mapper
    ModelLoader.setCustomMeshDefinition(Item.getItemFromBlock(BlockReg.blockExplosive), new ItemModelMapperExplosive(itemBlockModelMap, itemBlockModelMap.get(ICBMExplosives.CONDENSED)));
    ModelBakery.registerItemVariants(Item.getItemFromBlock(BlockReg.blockExplosive), itemBlockModelMap.values().stream().map(mrl -> new ResourceLocation(mrl.getNamespace(), mrl.getPath())).collect(Collectors.toList()).toArray(new ResourceLocation[itemBlockModelMap.values().size()]));
}
Also used : TileEMPTower(icbm.classic.content.blocks.emptower.TileEMPTower) Item(net.minecraft.item.Item) TileLauncherFrame(icbm.classic.content.blocks.launcher.frame.TileLauncherFrame) ModelRegistryEvent(net.minecraftforge.client.event.ModelRegistryEvent) TESRRadarStation(icbm.classic.content.blocks.radarstation.TESRRadarStation) TileLauncherScreen(icbm.classic.content.blocks.launcher.screen.TileLauncherScreen) ItemCrafting(icbm.classic.content.items.ItemCrafting) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) icbm.classic.content.entity(icbm.classic.content.entity) OBJLoader(net.minecraftforge.client.model.obj.OBJLoader) IProperty(net.minecraft.block.properties.IProperty) Block(net.minecraft.block.Block) Side(net.minecraftforge.fml.relauncher.Side) ICBMExplosives(icbm.classic.api.refs.ICBMExplosives) TileRadarStation(icbm.classic.content.blocks.radarstation.TileRadarStation) Map(java.util.Map) ItemModelMapperExplosive(icbm.classic.client.mapper.ItemModelMapperExplosive) BlockICBM(icbm.classic.prefab.tile.BlockICBM) TESRCruiseLauncher(icbm.classic.content.blocks.launcher.cruise.TESRCruiseLauncher) Collectors(java.util.stream.Collectors) icbm.classic.content.entity.mobs(icbm.classic.content.entity.mobs) icbm.classic.client.render.entity(icbm.classic.client.render.entity) BlockReg(icbm.classic.content.reg.BlockReg) HashMap(java.util.HashMap) BlockModelMapperExplosive(icbm.classic.client.mapper.BlockModelMapperExplosive) EntityMissile(icbm.classic.content.entity.missile.EntityMissile) ModelBakery(net.minecraft.client.renderer.block.model.ModelBakery) ClientRegistry(net.minecraftforge.fml.client.registry.ClientRegistry) IExplosiveData(icbm.classic.api.reg.IExplosiveData) EnumTier(icbm.classic.api.EnumTier) RenderingRegistry(net.minecraftforge.fml.client.registry.RenderingRegistry) Mod(net.minecraftforge.fml.common.Mod) ModelLoader(net.minecraftforge.client.model.ModelLoader) ItemReg(icbm.classic.content.reg.ItemReg) DefaultStateMapper(net.minecraft.client.renderer.block.statemap.DefaultStateMapper) ICBMConstants(icbm.classic.ICBMConstants) TESRLauncherBase(icbm.classic.content.blocks.launcher.base.TESRLauncherBase) TileLauncherBase(icbm.classic.content.blocks.launcher.base.TileLauncherBase) EnumFacing(net.minecraft.util.EnumFacing) ConfigItems(icbm.classic.config.ConfigItems) TESRLauncherFrame(icbm.classic.content.blocks.launcher.frame.TESRLauncherFrame) ICBMClassicAPI(icbm.classic.api.ICBMClassicAPI) IBlockState(net.minecraft.block.state.IBlockState) TESREMPTower(icbm.classic.content.blocks.emptower.TESREMPTower) TESRLauncherScreen(icbm.classic.content.blocks.launcher.screen.TESRLauncherScreen) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) TileCruiseLauncher(icbm.classic.content.blocks.launcher.cruise.TileCruiseLauncher) Collections(java.util.Collections) ItemModelMapperExplosive(icbm.classic.client.mapper.ItemModelMapperExplosive) HashMap(java.util.HashMap) EnumFacing(net.minecraft.util.EnumFacing) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) BlockModelMapperExplosive(icbm.classic.client.mapper.BlockModelMapperExplosive) IExplosiveData(icbm.classic.api.reg.IExplosiveData)

Example 9 with IExplosiveData

use of icbm.classic.api.reg.IExplosiveData in project ICBM-Classic by BuiltBrokenModding.

the class CommandBlastSpread method doCommand.

private void doCommand(@Nonnull ICommandSender sender, @Nonnull String[] args) throws CommandException {
    final int count = CommandBase.parseInt(args[0], 1);
    final int distance = CommandBase.parseInt(args[1], 1);
    // Get explosive data from user
    final IExplosiveData explosiveData = CommandBlastTrigger.getExplosive(args[2]);
    // Get world position
    final World world = CommandUtils.getWorld(sender, args[3], sender.getEntityWorld());
    final double xInput = CommandUtils.getNumber(sender, args[4], sender.getPosition().getX() + 0.5);
    final double yInput = CommandUtils.getNumber(sender, args[5], sender.getPosition().getY() + 0.5);
    final double zInput = CommandUtils.getNumber(sender, args[6], sender.getPosition().getZ() + 0.5);
    // Get scale from user
    // TODO turn into helper method
    final float scale = Float.parseFloat(args[7]);
    if (scale <= 0) {
        throw new SyntaxErrorException(CommandBlastTrigger.TRANSLATION_ERROR_SCALE_ZERO);
    }
    final int expectedSpawnCount = (int) Math.floor(Math.pow((count * 2) + 1, 2));
    sender.sendMessage(new TextComponentTranslation(TRANSLATION_SPREAD_START, explosiveData.getRegistryName(), scale, world.provider.getDimension(), world.getWorldType().getName(), xInput, yInput, zInput, count, distance, expectedSpawnCount));
    // Generate blasts in a grid
    for (int xi = -count; xi <= count; xi++) {
        for (int zi = -count; zi <= count; zi++) {
            // calc position
            final double x = xInput + xi * distance;
            final double z = zInput + zi * distance;
            // Trigger blast
            final BlastState result = ExplosiveHandler.createExplosion(null, world, x, yInput, z, explosiveData.getRegistryID(), scale, null);
            if (result != BlastState.TRIGGERED && result != BlastState.THREADING) {
                // Send translated message to user
                sender.sendMessage(new TextComponentTranslation(CommandBlastTrigger.getTranslationKey(result), explosiveData.getRegistryName(), scale, world.provider.getDimension(), world.getWorldType().getName(), x, yInput, z));
            }
        }
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) SyntaxErrorException(net.minecraft.command.SyntaxErrorException) World(net.minecraft.world.World) IExplosiveData(icbm.classic.api.reg.IExplosiveData) BlastState(icbm.classic.api.explosion.BlastState)

Example 10 with IExplosiveData

use of icbm.classic.api.reg.IExplosiveData in project ICBM-Classic by BuiltBrokenModding.

the class ExplosiveContentRegistry method lockRegistry.

@Override
public void lockRegistry() {
    if (!locked) {
        locked = true;
        // Turn into immutable
        nameCache = ImmutableSet.copyOf(nameCache);
        // Generate reference map
        final HashMap<ResourceLocation, IExplosiveData> map = new HashMap();
        for (ResourceLocation name : nameCache) {
            final IExplosiveData data = ICBMClassicAPI.EXPLOSIVE_REGISTRY.getExplosiveData(name);
            if (data != null) {
                map.put(name, data);
            } else {
                throw new RuntimeException(this + ": Failed to locate explosive by name " + name);
            }
        }
        mapCache = ImmutableMap.copyOf(map);
        // Map ids to cache
        idCache = map.values().stream().map(entry -> entry.getRegistryID()).collect(ImmutableSet.toImmutableSet());
        dataCache = map.values().stream().collect(ImmutableSet.toImmutableSet());
    } else
        throw new RuntimeException(this + ": Registry was locked twice!");
}
Also used : HashMap(java.util.HashMap) ResourceLocation(net.minecraft.util.ResourceLocation) IExplosiveData(icbm.classic.api.reg.IExplosiveData)

Aggregations

IExplosiveData (icbm.classic.api.reg.IExplosiveData)17 ResourceLocation (net.minecraft.util.ResourceLocation)6 ItemModelMapperExplosive (icbm.classic.client.mapper.ItemModelMapperExplosive)4 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)4 EntityMissile (icbm.classic.content.entity.missile.EntityMissile)3 ItemStack (net.minecraft.item.ItemStack)3 EnumTier (icbm.classic.api.EnumTier)2 HashMap (java.util.HashMap)2 IBlockState (net.minecraft.block.state.IBlockState)2 TileEntity (net.minecraft.tileentity.TileEntity)2 ICBMConstants (icbm.classic.ICBMConstants)1 ICBMClassicAPI (icbm.classic.api.ICBMClassicAPI)1 LauncherEvent (icbm.classic.api.events.LauncherEvent)1 BlastState (icbm.classic.api.explosion.BlastState)1 ICBMExplosives (icbm.classic.api.refs.ICBMExplosives)1 BlockModelMapperExplosive (icbm.classic.client.mapper.BlockModelMapperExplosive)1 icbm.classic.client.render.entity (icbm.classic.client.render.entity)1 ConfigItems (icbm.classic.config.ConfigItems)1 TESREMPTower (icbm.classic.content.blocks.emptower.TESREMPTower)1 TileEMPTower (icbm.classic.content.blocks.emptower.TileEMPTower)1