Search in sources :

Example 1 with DimletKey

use of mcjty.rftoolsdim.dimensions.dimlets.DimletKey in project RFToolsDimensions by McJty.

the class DimensionEditorTileEntity method update.

@Override
public void update() {
    if (getWorld().isRemote) {
        return;
    }
    ItemStack injectableItemStack = validateInjectableItemStack();
    if (ItemStackTools.isEmpty(injectableItemStack)) {
        return;
    }
    ItemStack dimensionItemStack = validateDimensionItemStack();
    if (ItemStackTools.isEmpty(dimensionItemStack)) {
        return;
    }
    if (ticksLeft == -1) {
        // We were not injecting. Start now.
        if (isMatterReceiver(injectableItemStack)) {
            ticksCost = DimletCosts.baseDimensionTickCost + 1000;
            ticksLeft = ticksCost;
            rfPerTick = DimletCosts.baseDimensionCreationCost + 200;
        } else if (isTNT(injectableItemStack)) {
            ticksCost = 600;
            ticksLeft = ticksCost;
            rfPerTick = 10;
        } else {
            DimletKey key = KnownDimletConfiguration.getDimletKey(injectableItemStack);
            Settings settings = KnownDimletConfiguration.getSettings(key);
            ticksCost = DimletCosts.baseDimensionTickCost + settings.getTickCost();
            ticksLeft = ticksCost;
            rfPerTick = DimletCosts.baseDimensionCreationCost + settings.getCreateCost();
        }
    } else {
        int rf = getEnergyStored(EnumFacing.DOWN);
        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());
                ItemStack dimensionTab = validateDimensionItemStack();
                NBTTagCompound tagCompound = dimensionTab.getTagCompound();
                int id = tagCompound.getInteger("id");
                injectableItemStack = validateInjectableItemStack();
                if (isMatterReceiver(injectableItemStack)) {
                    World dimWorld = dimensionManager.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?
                        CompatBlock.activateBlock(block, dimWorld, pos, state, FakePlayerFactory.getMinecraft((WorldServer) dimWorld), EnumHand.MAIN_HAND, EnumFacing.DOWN, 0, 0, 0);
                        //                            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, dimensionTab);
                } 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) CompatBlock(mcjty.lib.compat.CompatBlock) 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 2 with DimletKey

use of mcjty.rftoolsdim.dimensions.dimlets.DimletKey in project RFToolsDimensions by McJty.

the class EssencePainterTileEntity method extractDimlets.

private void extractDimlets() {
    ItemStack realizedTab = inventoryHelper.getStackInSlot(EssencePainterContainer.SLOT_TAB);
    NBTTagCompound tagCompound = realizedTab.getTagCompound();
    if (tagCompound != null) {
        int idx = EssencePainterContainer.SLOT_DIMLETS;
        String descriptionString = tagCompound.getString("descriptionString");
        for (DimletKey descriptor : DimensionDescriptor.parseDescriptionString(descriptionString)) {
            int id = tagCompound.getInteger("id");
            if (GeneralConfiguration.ownerDimletsNeeded && id != 0) {
                // If we need owner dimlets and the dimension is created we don't extract the owern dimlet.
                if (descriptor.getType() == DimletType.DIMLET_SPECIAL && DimletObjectMapping.getSpecial(descriptor) == SpecialType.SPECIAL_OWNER) {
                    continue;
                }
            }
            inventoryHelper.setStackInSlot(idx++, KnownDimletConfiguration.getDimletStack(descriptor));
        }
    }
    inventoryHelper.setStackInSlot(EssencePainterContainer.SLOT_TAB, new ItemStack(ModItems.emptyDimensionTabItem));
    markDirty();
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) DimletKey(mcjty.rftoolsdim.dimensions.dimlets.DimletKey)

Example 3 with DimletKey

use of mcjty.rftoolsdim.dimensions.dimlets.DimletKey in project RFToolsDimensions by McJty.

the class GuiEssencePainter method validateDimlets.

private void validateDimlets() {
    List<String> tooltips = new ArrayList<String>();
    TerrainType terrainType = null;
    int cntTerrain = 0;
    int cntBiomes = 0;
    int cntController = 0;
    int cntOwner = 0;
    for (int i = EssencePainterContainer.SLOT_DIMLETS; i < EssencePainterContainer.SLOT_TAB; i++) {
        Slot slot = inventorySlots.getSlot(i);
        if (slot != null && ItemStackTools.isValid(slot.getStack())) {
            ItemStack stack = slot.getStack();
            DimletKey key = KnownDimletConfiguration.getDimletKey(stack);
            if (key.getType() == DimletType.DIMLET_TERRAIN) {
                cntTerrain++;
                terrainType = DimletObjectMapping.getTerrain(key);
            } else if (key.getType() == DimletType.DIMLET_BIOME) {
                cntBiomes++;
            } else if (key.getType() == DimletType.DIMLET_CONTROLLER) {
                cntController++;
            } else if (key.getType() == DimletType.DIMLET_SPECIAL && DimletObjectMapping.getSpecial(key) == SpecialType.SPECIAL_OWNER) {
                cntOwner++;
            }
        }
    }
    if (cntOwner > 1) {
        tooltips.add("Using more then one owner dimlet is not useful!");
    }
    if (GeneralConfiguration.ownerDimletsNeeded && cntOwner != 1) {
        tooltips.add("You cannot make a dimension without an owner dimlet!");
        storeButton.setEnabled(false);
    }
    if (cntTerrain > 1) {
        tooltips.add("Using more then one TERRAIN is not useful!");
        terrainType = null;
    }
    if (cntController > 1) {
        tooltips.add("Using more then one CONTROLLER is not useful!");
    }
    List<DimletKey> modifiers = new ArrayList<DimletKey>();
    for (int i = EssencePainterContainer.SLOT_DIMLETS; i < EssencePainterContainer.SLOT_TAB; i++) {
        Slot slot = inventorySlots.getSlot(i);
        if (slot != null && ItemStackTools.isValid(slot.getStack())) {
            ItemStack stack = slot.getStack();
            DimletKey key = KnownDimletConfiguration.getDimletKey(stack);
            DimletType type = key.getType();
            if (type.dimletType.isModifier()) {
                modifiers.add(key);
            } else {
                List<DimletKey> modifiersForType = extractModifiersForType(modifiers, type);
                if (type == DimletType.DIMLET_TERRAIN) {
                    if (DimletObjectMapping.getTerrain(key) == TerrainType.TERRAIN_VOID && !modifiersForType.isEmpty()) {
                        tooltips.add("VOID terrain cannot use modifiers");
                    }
                } else if (type == DimletType.DIMLET_FEATURE) {
                    FeatureType featureType = DimletObjectMapping.getFeature(key);
                    Counter<DimletType> modifierAmountUsed = new Counter<DimletType>();
                    for (DimletKey modifier : modifiersForType) {
                        modifierAmountUsed.increment(modifier.getType());
                    }
                    for (Map.Entry<DimletType, Integer> entry : modifierAmountUsed.entrySet()) {
                        Integer amountSupported = featureType.getSupportedModifierAmount(entry.getKey());
                        if (amountSupported == null) {
                            tooltips.add(shortenName(featureType.name()) + " does not use " + shortenName(entry.getKey().name()) + " modifiers!");
                        } else if (amountSupported == 1 && entry.getValue() > 1) {
                            tooltips.add(shortenName(featureType.name()) + " only needs one " + shortenName(entry.getKey().name()) + " modifier!");
                        }
                    }
                    if (terrainType == null && !featureType.supportsAllTerrains()) {
                        tooltips.add(shortenName(featureType.name()) + " is possibly useless as it does not work on all terrains!");
                    }
                    if (terrainType != null && !featureType.isTerrainSupported(terrainType)) {
                        tooltips.add(shortenName(featureType.name()) + " does not work for terrain " + shortenName(terrainType.name()) + "!");
                    }
                } else if (type == DimletType.DIMLET_CONTROLLER) {
                    ControllerType controllerType = DimletObjectMapping.getController(key);
                    int neededBiomes = controllerType.getNeededBiomes();
                    if (neededBiomes != -1) {
                        if (cntBiomes > neededBiomes) {
                            tooltips.add("Too many biomes specified for " + shortenName(controllerType.name()) + "!");
                        } else if (cntBiomes < neededBiomes) {
                            tooltips.add("Too few biomes specified for " + shortenName(controllerType.name()) + "!");
                        }
                    }
                }
            }
        }
    }
    if (!modifiers.isEmpty()) {
        tooltips.add("There are dangling modifiers in this descriptor");
    }
    boolean error = true;
    if (tooltips.isEmpty()) {
        tooltips.add("Everything appears to be alright");
        error = false;
    }
    validateField.setTooltips(tooltips.toArray(new String[tooltips.size()]));
    validateField.setColor(error ? 0xFF0000 : 0x008800);
    validateField.setText(error ? "Warn" : "Ok");
}
Also used : FeatureType(mcjty.rftoolsdim.dimensions.types.FeatureType) ArrayList(java.util.ArrayList) TerrainType(mcjty.rftoolsdim.dimensions.types.TerrainType) DimletKey(mcjty.rftoolsdim.dimensions.dimlets.DimletKey) ControllerType(mcjty.rftoolsdim.dimensions.types.ControllerType) Counter(mcjty.lib.varia.Counter) DimletType(mcjty.rftoolsdim.dimensions.dimlets.types.DimletType) Slot(net.minecraft.inventory.Slot) ItemStack(net.minecraft.item.ItemStack)

Example 4 with DimletKey

use of mcjty.rftoolsdim.dimensions.dimlets.DimletKey in project RFToolsDimensions by McJty.

the class GuiDimensionEnscriber method validateDimlets.

private void validateDimlets() {
    List<String> tooltips = new ArrayList<String>();
    TerrainType terrainType = null;
    int cntTerrain = 0;
    int cntBiomes = 0;
    int cntController = 0;
    int cntOwner = 0;
    for (int i = DimensionEnscriberContainer.SLOT_DIMLETS; i < DimensionEnscriberContainer.SLOT_TAB; i++) {
        Slot slot = inventorySlots.getSlot(i);
        if (slot != null && ItemStackTools.isValid(slot.getStack())) {
            ItemStack stack = slot.getStack();
            DimletKey key = KnownDimletConfiguration.getDimletKey(stack);
            if (key.getType() == DimletType.DIMLET_TERRAIN) {
                cntTerrain++;
                terrainType = DimletObjectMapping.getTerrain(key);
            } else if (key.getType() == DimletType.DIMLET_BIOME) {
                cntBiomes++;
            } else if (key.getType() == DimletType.DIMLET_CONTROLLER) {
                cntController++;
            } else if (key.getType() == DimletType.DIMLET_SPECIAL && DimletObjectMapping.getSpecial(key) == SpecialType.SPECIAL_OWNER) {
                cntOwner++;
            }
        }
    }
    if (cntOwner > 1) {
        tooltips.add("Using more then one owner dimlet is not useful!");
    }
    if (GeneralConfiguration.ownerDimletsNeeded && cntOwner != 1) {
        tooltips.add("You cannot make a dimension without an owner dimlet!");
        storeButton.setEnabled(false);
    }
    if (cntTerrain > 1) {
        tooltips.add("Using more then one TERRAIN is not useful!");
        terrainType = null;
    }
    if (cntController > 1) {
        tooltips.add("Using more then one CONTROLLER is not useful!");
    }
    List<DimletKey> modifiers = new ArrayList<DimletKey>();
    for (int i = DimensionEnscriberContainer.SLOT_DIMLETS; i < DimensionEnscriberContainer.SLOT_TAB; i++) {
        Slot slot = inventorySlots.getSlot(i);
        if (slot != null && ItemStackTools.isValid(slot.getStack())) {
            ItemStack stack = slot.getStack();
            DimletKey key = KnownDimletConfiguration.getDimletKey(stack);
            DimletType type = key.getType();
            if (type.dimletType.isModifier()) {
                modifiers.add(key);
            } else {
                List<DimletKey> modifiersForType = extractModifiersForType(modifiers, type);
                if (type == DimletType.DIMLET_TERRAIN) {
                    if (DimletObjectMapping.getTerrain(key) == TerrainType.TERRAIN_VOID && !modifiersForType.isEmpty()) {
                        tooltips.add("VOID terrain cannot use modifiers");
                    }
                } else if (type == DimletType.DIMLET_FEATURE) {
                    FeatureType featureType = DimletObjectMapping.getFeature(key);
                    Counter<DimletType> modifierAmountUsed = new Counter<DimletType>();
                    for (DimletKey modifier : modifiersForType) {
                        modifierAmountUsed.increment(modifier.getType());
                    }
                    for (Map.Entry<DimletType, Integer> entry : modifierAmountUsed.entrySet()) {
                        Integer amountSupported = featureType.getSupportedModifierAmount(entry.getKey());
                        if (amountSupported == null) {
                            tooltips.add(shortenName(featureType.name()) + " does not use " + shortenName(entry.getKey().name()) + " modifiers!");
                        } else if (amountSupported == 1 && entry.getValue() > 1) {
                            tooltips.add(shortenName(featureType.name()) + " only needs one " + shortenName(entry.getKey().name()) + " modifier!");
                        }
                    }
                    if (terrainType == null && !featureType.supportsAllTerrains()) {
                        tooltips.add(shortenName(featureType.name()) + " is possibly useless as it does not work on all terrains!");
                    }
                    if (terrainType != null && !featureType.isTerrainSupported(terrainType)) {
                        tooltips.add(shortenName(featureType.name()) + " does not work for terrain " + shortenName(terrainType.name()) + "!");
                    }
                } else if (type == DimletType.DIMLET_CONTROLLER) {
                    ControllerType controllerType = DimletObjectMapping.getController(key);
                    int neededBiomes = controllerType.getNeededBiomes();
                    if (neededBiomes != -1) {
                        if (cntBiomes > neededBiomes) {
                            tooltips.add("Too many biomes specified for " + shortenName(controllerType.name()) + "!");
                        } else if (cntBiomes < neededBiomes) {
                            tooltips.add("Too few biomes specified for " + shortenName(controllerType.name()) + "!");
                        }
                    }
                }
            }
        }
    }
    if (!modifiers.isEmpty()) {
        tooltips.add("There are dangling modifiers in this descriptor");
    }
    boolean error = true;
    if (tooltips.isEmpty()) {
        tooltips.add("Everything appears to be alright");
        error = false;
    }
    validateField.setTooltips(tooltips.toArray(new String[tooltips.size()]));
    validateField.setColor(error ? 0xFF0000 : 0x008800);
    validateField.setText(error ? "Warn" : "Ok");
}
Also used : FeatureType(mcjty.rftoolsdim.dimensions.types.FeatureType) ArrayList(java.util.ArrayList) TerrainType(mcjty.rftoolsdim.dimensions.types.TerrainType) DimletKey(mcjty.rftoolsdim.dimensions.dimlets.DimletKey) ControllerType(mcjty.rftoolsdim.dimensions.types.ControllerType) Counter(mcjty.lib.varia.Counter) DimletType(mcjty.rftoolsdim.dimensions.dimlets.types.DimletType) Slot(net.minecraft.inventory.Slot) ItemStack(net.minecraft.item.ItemStack)

Example 5 with DimletKey

use of mcjty.rftoolsdim.dimensions.dimlets.DimletKey in project RFToolsDimensions by McJty.

the class GuiDimensionEnscriber method extractModifiersForType.

private List<DimletKey> extractModifiersForType(List<DimletKey> modifiers, DimletType type) {
    List<DimletKey> modifiersForType = new ArrayList<DimletKey>();
    int i = 0;
    while (i < modifiers.size()) {
        DimletKey modifier = modifiers.get(i);
        if (type.dimletType.isModifiedBy(modifier.getType())) {
            modifiersForType.add(modifier);
            modifiers.remove(i);
        } else {
            i++;
        }
    }
    return modifiersForType;
}
Also used : ArrayList(java.util.ArrayList) DimletKey(mcjty.rftoolsdim.dimensions.dimlets.DimletKey)

Aggregations

DimletKey (mcjty.rftoolsdim.dimensions.dimlets.DimletKey)61 ArrayList (java.util.ArrayList)19 List (java.util.List)15 Settings (mcjty.rftoolsdim.config.Settings)14 ItemStack (net.minecraft.item.ItemStack)14 DimletType (mcjty.rftoolsdim.dimensions.dimlets.types.DimletType)13 Block (net.minecraft.block.Block)10 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)7 IBlockState (net.minecraft.block.state.IBlockState)6 TerrainType (mcjty.rftoolsdim.dimensions.types.TerrainType)5 DimensionDescriptor (mcjty.rftoolsdim.dimensions.description.DimensionDescriptor)3 IDimletType (mcjty.rftoolsdim.dimensions.dimlets.types.IDimletType)3 ControllerType (mcjty.rftoolsdim.dimensions.types.ControllerType)3 FeatureType (mcjty.rftoolsdim.dimensions.types.FeatureType)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)3 Pair (org.apache.commons.lang3.tuple.Pair)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Argument (mcjty.lib.network.Argument)2