Search in sources :

Example 1 with Settings

use of mcjty.rftoolsdim.config.Settings in project RFToolsDimensions by McJty.

the class GuiDimletWorkbench method updateList.

private void updateList() {
    if (!listDirty) {
        return;
    }
    listDirty = false;
    itemList.removeChildren();
    Map<DimletKey, Settings> dimlets = KnownDimletConfiguration.getKnownDimlets();
    String filter = searchBar.getText().toLowerCase();
    // First remove all dimlets with the same name and also apply the filter already
    Map<Pair<DimletType, String>, DimletKey> uniquelyNamedDimlets = new HashMap<>();
    for (DimletKey key : dimlets.keySet()) {
        String name = KnownDimletConfiguration.getDisplayName(key);
        if (dimletMatches(filter, key, name)) {
            Pair<DimletType, String> k = Pair.of(key.getType(), name);
            if (!uniquelyNamedDimlets.containsKey(k)) {
                uniquelyNamedDimlets.put(k, key);
            }
        }
    }
    List<DimletKey> keys = new ArrayList<>(uniquelyNamedDimlets.values());
    keys.sort((a, b) -> {
        int rc = a.getType().compareTo(b.getType());
        if (rc == 0) {
            return a.getId().compareTo(b.getId());
        } else {
            return rc;
        }
    });
    keys.stream().forEach(key -> addItemToList(key, itemList));
    if (itemList.getFirstSelected() >= itemList.getChildCount()) {
        itemList.setFirstSelected(0);
    }
}
Also used : HashMap(java.util.HashMap) DimletType(mcjty.rftoolsdim.dimensions.dimlets.types.DimletType) ArrayList(java.util.ArrayList) DimletKey(mcjty.rftoolsdim.dimensions.dimlets.DimletKey) Settings(mcjty.rftoolsdim.config.Settings) Pair(org.apache.commons.lang3.tuple.Pair)

Example 2 with Settings

use of mcjty.rftoolsdim.config.Settings in project RFToolsDimensions by McJty.

the class DimensionEditorTileEntity method update.

@Override
public void update() {
    if (getWorld().isRemote) {
        return;
    }
    ItemStack injectableItemStack = validateInjectableItemStack();
    if (injectableItemStack.isEmpty()) {
        return;
    }
    ItemStack dimensionItemStack = validateDimensionItemStack();
    if (dimensionItemStack.isEmpty()) {
        return;
    }
    if (ticksLeft == -1) {
        // We were not injecting. Start now.
        RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(getWorld());
        int id = dimensionItemStack.getTagCompound().getInteger("id");
        if (dimensionManager.getDimensionInformation(id).isCheater()) {
            ticksCost = 1;
            rfPerTick = 0;
        } else if (isMatterReceiver(injectableItemStack)) {
            ticksCost = DimletCosts.baseDimensionTickCost + 1000;
            rfPerTick = DimletCosts.baseDimensionCreationCost + 200;
        } else if (isTNT(injectableItemStack)) {
            ticksCost = 600;
            rfPerTick = 10;
        } else {
            DimletKey key = KnownDimletConfiguration.getDimletKey(injectableItemStack);
            Settings settings = KnownDimletConfiguration.getSettings(key);
            if (DimletObjectMapping.getSpecial(key) == SpecialType.SPECIAL_CHEATER) {
                ticksCost = 1;
                rfPerTick = 0;
            } else {
                ticksCost = DimletCosts.baseDimensionTickCost + settings.getTickCost();
                rfPerTick = DimletCosts.baseDimensionCreationCost + settings.getCreateCost();
            }
        }
        ticksLeft = ticksCost;
    } else {
        int rf = getEnergyStored();
        int rfpt = rfPerTick;
        rfpt = (int) (rfpt * (2.0f - getInfusedFactor()) / 2.0f);
        if (rf >= rfpt) {
            // Enough energy.
            consumeEnergy(rfpt);
            ticksLeft--;
            if (ticksLeft <= 0) {
                RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(getWorld());
                NBTTagCompound tagCompound = dimensionItemStack.getTagCompound();
                int id = tagCompound.getInteger("id");
                if (isMatterReceiver(injectableItemStack)) {
                    World dimWorld = RfToolsDimensionManager.getWorldForDimension(getWorld(), id);
                    int y = findGoodReceiverLocation(dimWorld);
                    if (y == -1) {
                        y = dimWorld.getHeight() / 2;
                    }
                    Item item = injectableItemStack.getItem();
                    if (item instanceof ItemBlock) {
                        ItemBlock itemBlock = (ItemBlock) item;
                        IBlockState state = itemBlock.getBlock().getStateFromMeta(itemBlock.getMetadata(injectableItemStack));
                        BlockPos pos = new BlockPos(8, y, 8);
                        dimWorld.setBlockState(pos, state, 2);
                        Block block = dimWorld.getBlockState(pos).getBlock();
                        // @todo @@@@@@@@@@@@@@ check if right?
                        block.onBlockActivated(dimWorld, pos, state, FakePlayerFactory.getMinecraft((WorldServer) dimWorld), EnumHand.MAIN_HAND, EnumFacing.DOWN, 0.0F, 0.0F, 0.0F);
                        // block.onBlockPlaced(dimWorld, pos, EnumFacing.DOWN, 0, 0, 0, 0, null);
                        block.onBlockPlacedBy(dimWorld, pos, state, null, injectableItemStack);
                        dimWorld.setBlockToAir(pos.up());
                        dimWorld.setBlockToAir(pos.up(2));
                    }
                } else if (isTNT(injectableItemStack)) {
                    safeDeleteDimension(id, dimensionItemStack);
                } else {
                    DimletKey key = KnownDimletConfiguration.getDimletKey(injectableItemStack);
                    DimensionInformation information = dimensionManager.getDimensionInformation(id);
                    information.injectDimlet(key);
                    dimensionManager.save(getWorld());
                }
                inventoryHelper.decrStackSize(DimensionEditorContainer.SLOT_INJECTINPUT, 1);
                stopInjecting();
            }
        }
    }
    markDirty();
    setState();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WorldServer(net.minecraft.world.WorldServer) DimletKey(mcjty.rftoolsdim.dimensions.dimlets.DimletKey) World(net.minecraft.world.World) ItemBlock(net.minecraft.item.ItemBlock) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager) Item(net.minecraft.item.Item) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) Settings(mcjty.rftoolsdim.config.Settings)

Example 3 with Settings

use of mcjty.rftoolsdim.config.Settings in project RFToolsDimensions by McJty.

the class EssencePainterTileEntity method convertToDimensionDescriptor.

/**
 * Convert the dimlets in the inventory to a dimension descriptor.
 */
private DimensionDescriptor convertToDimensionDescriptor() {
    List<DimletKey> descriptors = new ArrayList<>();
    long forcedSeed = 0;
    for (int i = 0; i < EssencePainterContainer.SIZE_DIMLETS; i++) {
        ItemStack stack = inventoryHelper.getStackInSlot(i + EssencePainterContainer.SLOT_DIMLETS);
        if (!stack.isEmpty()) {
            DimletKey key = KnownDimletConfiguration.getDimletKey(stack);
            Settings settings = KnownDimletConfiguration.getSettings(key);
            if (settings != null) {
                // Make sure the dimlet is not blacklisted.
                descriptors.add(key);
                NBTTagCompound tagCompound = stack.getTagCompound();
                if (tagCompound != null && tagCompound.getLong("forcedSeed") != 0) {
                    forcedSeed = tagCompound.getLong("forcedSeed");
                }
            }
        }
        inventoryHelper.setStackInSlot(i + EssencePainterContainer.SLOT_DIMLETS, ItemStack.EMPTY);
    }
    return new DimensionDescriptor(descriptors, forcedSeed);
}
Also used : DimensionDescriptor(mcjty.rftoolsdim.dimensions.description.DimensionDescriptor) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) DimletKey(mcjty.rftoolsdim.dimensions.dimlets.DimletKey) ItemStack(net.minecraft.item.ItemStack) Settings(mcjty.rftoolsdim.config.Settings)

Example 4 with Settings

use of mcjty.rftoolsdim.config.Settings in project RFToolsDimensions by McJty.

the class KnownDimletConfiguration method dumpMob.

private static void dumpMob(String id) {
    EntityEntry entry = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(id));
    Class<? extends Entity> entityClass = entry == null ? null : entry.getEntityClass();
    if (entry != null) {
        DimletKey key = new DimletKey(DimletType.DIMLET_MOB, id);
        String mod = entry.getRegistryName().getResourceDomain();
        Settings settings = DimletRules.getSettings(key, mod);
        String resourceName = EntityTools.findEntityIdByClass(entityClass);
        String readableName = EntityTools.findEntityLocNameByClass(entityClass);
        Logging.log(resourceName + " (" + resourceName + ", " + readableName + "): " + settings.toString());
    }
}
Also used : EntityEntry(net.minecraftforge.fml.common.registry.EntityEntry) ResourceLocation(net.minecraft.util.ResourceLocation) Settings(mcjty.rftoolsdim.config.Settings)

Example 5 with Settings

use of mcjty.rftoolsdim.config.Settings in project RFToolsDimensions by McJty.

the class DimletConfigurationManager method addRule.

@Override
public void addRule(IFilterBuilder filterBuilder, ISettingsBuilder settingsBuilder) {
    Filter filter = ((Filter.Builder) filterBuilder).build();
    Settings settings = ((Settings.Builder) settingsBuilder).build();
    rules.add(Pair.of(filter, settings));
}
Also used : Filter(mcjty.rftoolsdim.config.Filter) IFilterBuilder(mcjty.rftoolsdim.api.dimlet.IFilterBuilder) ISettingsBuilder(mcjty.rftoolsdim.api.dimlet.ISettingsBuilder) Settings(mcjty.rftoolsdim.config.Settings)

Aggregations

Settings (mcjty.rftoolsdim.config.Settings)32 DimletKey (mcjty.rftoolsdim.dimensions.dimlets.DimletKey)16 ItemStack (net.minecraft.item.ItemStack)8 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)6 Block (net.minecraft.block.Block)5 ArrayList (java.util.ArrayList)4 ResourceLocation (net.minecraft.util.ResourceLocation)4 Filter (mcjty.rftoolsdim.config.Filter)3 DimensionDescriptor (mcjty.rftoolsdim.dimensions.description.DimensionDescriptor)3 DimletType (mcjty.rftoolsdim.dimensions.dimlets.types.DimletType)2 IBlockState (net.minecraft.block.state.IBlockState)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 IFilterBuilder (mcjty.rftoolsdim.api.dimlet.IFilterBuilder)1 ISettingsBuilder (mcjty.rftoolsdim.api.dimlet.ISettingsBuilder)1 DimensionInformation (mcjty.rftoolsdim.dimensions.DimensionInformation)1 RfToolsDimensionManager (mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)1 BlockLiquid (net.minecraft.block.BlockLiquid)1