Search in sources :

Example 1 with BlockBase

use of net.minecraft.block.BlockBase in project StationAPI by ModificationStation.

the class BlockStateHelper method toBlockState.

public static BlockState toBlockState(CompoundTag tag) {
    if (tag.containsKey("Name")) {
        @NotNull Optional<BlockBase> block = BlockRegistry.INSTANCE.get(Identifier.of(tag.getString("Name")));
        if (block.isPresent()) {
            BlockStateHolder stateHolder = (BlockStateHolder) block.get();
            BlockState blockState = stateHolder.getDefaultState();
            if (tag.containsKey("Properties")) {
                CompoundTag compoundTag = tag.getCompoundTag("Properties");
                StateManager<BlockBase, BlockState> stateManager = stateHolder.getStateManager();
                for (String string : ((CompoundTagAccessor) compoundTag).stationapi$getData().keySet()) {
                    Property<?> property = stateManager.getProperty(string);
                    if (property != null) {
                        blockState = withProperty(blockState, property, string, compoundTag, tag);
                    }
                }
            }
            return blockState;
        }
    }
    return States.AIR.get();
}
Also used : BlockState(net.modificationstation.stationapi.api.block.BlockState) BlockBase(net.minecraft.block.BlockBase) BlockStateHolder(net.modificationstation.stationapi.api.block.BlockStateHolder) NotNull(org.jetbrains.annotations.NotNull) CompoundTag(net.minecraft.util.io.CompoundTag)

Example 2 with BlockBase

use of net.minecraft.block.BlockBase in project StationAPI by ModificationStation.

the class BakedModelRendererImpl method renderWorld.

@Override
public boolean renderWorld(BlockState state, BakedModel model, BlockView blockView, int x, int y, int z, int textureOverride) {
    posAccessor.stationapi$setX(x);
    posAccessor.stationapi$setY(y);
    posAccessor.stationapi$setZ(z);
    long seed = state.getRenderingSeed(pos);
    if (!model.isVanillaAdapter()) {
        BlockRenderContext context = CONTEXTS.get();
        return context.render(blockView, model, state, pos, random, seed);
    }
    BlockBase block = state.getBlock();
    if (textureOverride >= 0)
        return true;
    Tessellator t = Tessellator.INSTANCE;
    StationTessellator fastT = StationTessellator.get(t);
    light.initialize(block, blockView, x, y, z, Minecraft.isSmoothLightingEnabled() && model.useAmbientOcclusion());
    boolean rendered = false;
    ImmutableList<BakedQuad> qs;
    BakedQuad q;
    float[] qlight = light.light;
    for (int quadSet = 0, size = DIRECTIONS.length; quadSet < size; quadSet++) {
        Direction face = DIRECTIONS[quadSet];
        random.setSeed(seed);
        qs = model.getQuads(state, face, random);
        if (!qs.isEmpty() && (face == null || block.isSideRendered(blockView, x + face.vector.x, y + face.vector.y, z + face.vector.z, quadSet))) {
            rendered = true;
            for (int j = 0, quadSize = qs.size(); j < quadSize; j++) {
                q = qs.get(j);
                light.calculateForQuad(q);
                if (q.hasColour()) {
                    int i = StationRenderAPI.getBlockColours().getColour(state, blockView, pos, q.getColorIndex());
                    float r = redI2F(i);
                    float g = greenI2F(i);
                    float b = blueI2F(i);
                    if (GameRenderer.anaglyph3d) {
                        float colourMultiplierGreenTmp = (r * 30F + g * 70F) / 100F, colourMultiplierBlueTmp = (r * 30F + b * 70F) / 100F;
                        r = (r * 30F + g * 59F + b * 11F) / 100F;
                        g = colourMultiplierGreenTmp;
                        b = colourMultiplierBlueTmp;
                    }
                    fastT.quad(q.getVertexData(), x, y, z, colourF2I(r * qlight[0], g * qlight[0], b * qlight[0]), colourF2I(r * qlight[1], g * qlight[1], b * qlight[1]), colourF2I(r * qlight[2], g * qlight[2], b * qlight[2]), colourF2I(r * qlight[3], g * qlight[3], b * qlight[3]));
                } else
                    fastT.quad(q.getVertexData(), x, y, z, colourF2I(qlight[0], qlight[0], qlight[0]), colourF2I(qlight[1], qlight[1], qlight[1]), colourF2I(qlight[2], qlight[2], qlight[2]), colourF2I(qlight[3], qlight[3], qlight[3]));
            }
        }
    }
    return rendered;
}
Also used : BakedQuad(net.modificationstation.stationapi.api.client.render.model.BakedQuad) Tessellator(net.minecraft.client.render.Tessellator) StationTessellator(net.modificationstation.stationapi.api.client.render.StationTessellator) BlockBase(net.minecraft.block.BlockBase) StationTessellator(net.modificationstation.stationapi.api.client.render.StationTessellator) Direction(net.modificationstation.stationapi.api.util.math.Direction)

Example 3 with BlockBase

use of net.minecraft.block.BlockBase in project StationAPI by ModificationStation.

the class TagBlockInit method addBlockIgnoreDamage.

private static void addBlockIgnoreDamage(String oreDictString, BlockBase itemBase) {
    ItemInstance itemInstanceToUse = new ItemInstance(itemBase);
    TagRegistry.INSTANCE.register(new TagEntry(new ItemInstance(itemBase), itemInstance -> itemInstanceToUse.itemId == itemInstance.itemId, Identifier.of(oreDictString)));
}
Also used : EventListener(net.mine_diver.unsafeevents.listener.EventListener) ListenerPriority(net.mine_diver.unsafeevents.listener.ListenerPriority) EventBusPolicy(net.modificationstation.stationapi.api.mod.entrypoint.EventBusPolicy) LOGGER(net.modificationstation.stationapi.api.StationAPI.LOGGER) TagRegistry(net.modificationstation.stationapi.api.tags.TagRegistry) Entrypoint(net.modificationstation.stationapi.api.mod.entrypoint.Entrypoint) Identifier(net.modificationstation.stationapi.api.registry.Identifier) ItemInstance(net.minecraft.item.ItemInstance) BlockBase(net.minecraft.block.BlockBase) TagRegisterEvent(net.modificationstation.stationapi.api.event.tags.TagRegisterEvent) TagEntry(net.modificationstation.stationapi.api.tags.TagEntry) TagEntry(net.modificationstation.stationapi.api.tags.TagEntry) ItemInstance(net.minecraft.item.ItemInstance)

Aggregations

BlockBase (net.minecraft.block.BlockBase)3 EventListener (net.mine_diver.unsafeevents.listener.EventListener)1 ListenerPriority (net.mine_diver.unsafeevents.listener.ListenerPriority)1 Tessellator (net.minecraft.client.render.Tessellator)1 ItemInstance (net.minecraft.item.ItemInstance)1 CompoundTag (net.minecraft.util.io.CompoundTag)1 LOGGER (net.modificationstation.stationapi.api.StationAPI.LOGGER)1 BlockState (net.modificationstation.stationapi.api.block.BlockState)1 BlockStateHolder (net.modificationstation.stationapi.api.block.BlockStateHolder)1 StationTessellator (net.modificationstation.stationapi.api.client.render.StationTessellator)1 BakedQuad (net.modificationstation.stationapi.api.client.render.model.BakedQuad)1 TagRegisterEvent (net.modificationstation.stationapi.api.event.tags.TagRegisterEvent)1 Entrypoint (net.modificationstation.stationapi.api.mod.entrypoint.Entrypoint)1 EventBusPolicy (net.modificationstation.stationapi.api.mod.entrypoint.EventBusPolicy)1 Identifier (net.modificationstation.stationapi.api.registry.Identifier)1 TagEntry (net.modificationstation.stationapi.api.tags.TagEntry)1 TagRegistry (net.modificationstation.stationapi.api.tags.TagRegistry)1 Direction (net.modificationstation.stationapi.api.util.math.Direction)1 NotNull (org.jetbrains.annotations.NotNull)1