Search in sources :

Example 16 with CoverBehavior

use of gregtech.api.cover.CoverBehavior in project GregTech by GregTechCE.

the class MetaTileEntity method removeCover.

public final boolean removeCover(EnumFacing side) {
    Preconditions.checkNotNull(side, "side");
    CoverBehavior coverBehavior = getCoverAtSide(side);
    if (coverBehavior == null) {
        return false;
    }
    List<ItemStack> drops = coverBehavior.getDrops();
    coverBehavior.onRemoved();
    this.coverBehaviors[side.getIndex()] = null;
    for (ItemStack dropStack : drops) {
        Block.spawnAsEntity(getWorld(), getPos(), dropStack);
    }
    writeCustomData(-6, buffer -> buffer.writeByte(side.getIndex()));
    if (getHolder() != null) {
        getHolder().notifyBlockUpdate();
        getHolder().markDirty();
    }
    onCoverPlacementUpdate();
    return true;
}
Also used : ItemStack(net.minecraft.item.ItemStack) CoverBehavior(gregtech.api.cover.CoverBehavior)

Example 17 with CoverBehavior

use of gregtech.api.cover.CoverBehavior in project GregTech by GregTechCE.

the class MetaTileEntity method updateInputRedstoneSignals.

public void updateInputRedstoneSignals() {
    for (EnumFacing side : EnumFacing.VALUES) {
        int redstoneValue = GTUtility.getRedstonePower(getWorld(), getPos(), side);
        int currentValue = sidedRedstoneInput[side.getIndex()];
        if (redstoneValue != currentValue) {
            this.sidedRedstoneInput[side.getIndex()] = redstoneValue;
            CoverBehavior coverBehavior = getCoverAtSide(side);
            if (coverBehavior != null) {
                coverBehavior.onRedstoneInputSignalChange(redstoneValue);
            }
        }
    }
}
Also used : CoverBehavior(gregtech.api.cover.CoverBehavior)

Example 18 with CoverBehavior

use of gregtech.api.cover.CoverBehavior in project GregTech by GregTechCE.

the class MetaTileEntity method onCoverRightClick.

public final boolean onCoverRightClick(EntityPlayer playerIn, EnumHand hand, CuboidRayTraceResult result) {
    CoverBehavior coverBehavior = getCoverAtSide(result.sideHit);
    EnumActionResult coverResult = coverBehavior == null ? EnumActionResult.PASS : coverBehavior.onRightClick(playerIn, hand, result);
    if (coverResult != EnumActionResult.PASS) {
        return coverResult == EnumActionResult.SUCCESS;
    }
    return onRightClick(playerIn, hand, result.sideHit, result);
}
Also used : CoverBehavior(gregtech.api.cover.CoverBehavior)

Example 19 with CoverBehavior

use of gregtech.api.cover.CoverBehavior in project GregTech by GregTechCE.

the class MetaTileEntity method readFromNBT.

public void readFromNBT(NBTTagCompound data) {
    this.frontFacing = EnumFacing.VALUES[data.getInteger("FrontFacing")];
    this.paintingColor = data.getInteger(TAG_KEY_PAINTING_COLOR);
    this.cachedLightValue = data.getInteger("CachedLightValue");
    if (shouldSerializeInventories()) {
        GTUtility.readItems(importItems, "ImportInventory", data);
        GTUtility.readItems(exportItems, "ExportInventory", data);
        importFluids.deserializeNBT(data.getCompoundTag("ImportFluidInventory"));
        exportFluids.deserializeNBT(data.getCompoundTag("ExportFluidInventory"));
    }
    for (MTETrait mteTrait : this.mteTraits) {
        NBTTagCompound traitCompound = data.getCompoundTag(mteTrait.getName());
        mteTrait.deserializeNBT(traitCompound);
    }
    NBTTagList coversList = data.getTagList("Covers", NBT.TAG_COMPOUND);
    for (int index = 0; index < coversList.tagCount(); index++) {
        NBTTagCompound tagCompound = coversList.getCompoundTagAt(index);
        if (tagCompound.hasKey("CoverId", NBT.TAG_STRING)) {
            EnumFacing coverSide = EnumFacing.VALUES[tagCompound.getByte("Side")];
            ResourceLocation coverId = new ResourceLocation(tagCompound.getString("CoverId"));
            CoverDefinition coverDefinition = CoverDefinition.getCoverById(coverId);
            CoverBehavior coverBehavior = coverDefinition.createCoverBehavior(this, coverSide);
            coverBehavior.readFromNBT(tagCompound);
            this.coverBehaviors[coverSide.getIndex()] = coverBehavior;
        }
    }
    this.isFragile = data.getBoolean(TAG_KEY_FRAGILE);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) CoverBehavior(gregtech.api.cover.CoverBehavior) CoverDefinition(gregtech.api.cover.CoverDefinition)

Example 20 with CoverBehavior

use of gregtech.api.cover.CoverBehavior in project GregTech by GregTechCE.

the class MetaTileEntity method getHighestOutputRedstoneSignal.

public final int getHighestOutputRedstoneSignal() {
    int highestSignal = 0;
    for (EnumFacing side : EnumFacing.VALUES) {
        CoverBehavior behavior = getCoverAtSide(side);
        int sidedOutput = sidedRedstoneOutput[side.getIndex()];
        int sideResult = behavior == null ? sidedOutput : behavior.getRedstoneSignalOutput();
        highestSignal = Math.max(highestSignal, sideResult);
    }
    return highestSignal;
}
Also used : CoverBehavior(gregtech.api.cover.CoverBehavior)

Aggregations

CoverBehavior (gregtech.api.cover.CoverBehavior)32 EnumFacing (net.minecraft.util.EnumFacing)10 ItemStack (net.minecraft.item.ItemStack)6 CoverDefinition (gregtech.api.cover.CoverDefinition)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 NBTTagList (net.minecraft.nbt.NBTTagList)4 CuboidRayTraceResult (codechicken.lib.raytracer.CuboidRayTraceResult)2 CoverSideData (gregtech.api.cover.ICoverable.CoverSideData)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 NBT (net.minecraftforge.common.util.Constants.NBT)2 IndexedCuboid6 (codechicken.lib.raytracer.IndexedCuboid6)1 IScrewdriverItem (gregtech.api.capability.tool.IScrewdriverItem)1 IWrenchItem (gregtech.api.capability.tool.IWrenchItem)1 Nullable (javax.annotation.Nullable)1 ITickable (net.minecraft.util.ITickable)1