Java Code Examples for net.minecraftforge.common.property.IExtendedBlockState#getValue()

The following examples show how to use net.minecraftforge.common.property.IExtendedBlockState#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RenderCrop.java    From AgriCraft with MIT License 6 votes vote down vote up
@Override
public void renderWorldBlockStatic(ITessellator tessellator, IBlockState state, BlockCrop block, EnumFacing side) {
    TextureAtlasSprite sprite = RenderCrop.getIcon(TEXTURE);
    this.renderBaseQuads(tessellator, side, sprite);
    if (state instanceof IExtendedBlockState) {
        IExtendedBlockState extendedState = (IExtendedBlockState) state;
        IAgriPlant plant = extendedState.getValue(AgriProperties.CROP_PLANT);
        int growthstage = extendedState.getValue(AgriProperties.GROWTH_STAGE);
        if (extendedState.getValue(AgriProperties.CROSS_CROP)) {
            tessellator.drawScaledPrism(0, 10, 2, 16, 11, 3, sprite);
            tessellator.drawScaledPrism(0, 10, 13, 16, 11, 14, sprite);
            tessellator.drawScaledPrism(2, 10, 0, 3, 11, 16, sprite);
            tessellator.drawScaledPrism(13, 10, 0, 14, 11, 16, sprite);
        }
        if (plant != null) {
            tessellator.addQuads(plant.getPlantQuads(extendedState, growthstage, side, tessellator));
        }
    }
}
 
Example 2
Source File: BlockEnderUtilitiesTileEntity.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos)
{
    if (this.isCamoBlock())
    {
        IExtendedBlockState extendedState = (IExtendedBlockState) this.getExtendedState(state.getActualState(world, pos), world, pos);
        IBlockState stateCamo = extendedState.getValue(CAMOBLOCKSTATE);

        if (stateCamo != null)
        {
            // Can't call this same world sensitive method here, because it might/will recurse back here!
            return stateCamo.getLightValue();
        }
    }

    return super.getLightValue(state, world, pos);
}
 
Example 3
Source File: BakedSmallVesselModel.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand) 
{
	List<PropertyItem.PItem> items = Collections.emptyList();

	if(state instanceof IExtendedBlockState) {
		IExtendedBlockState extendedState = (IExtendedBlockState) state;

		if(extendedState.getUnlistedNames().contains(BlockSmallVessel.INVENTORY)) {
			if(extendedState.getValue(BlockSmallVessel.INVENTORY) != null) {
				items = extendedState.getValue(BlockSmallVessel.INVENTORY).items;
			}
		}

		// remove all world specific data
		// This is so that the next call to getQuads from the transformed TRSRModel doesn't do this again
		// otherwise table models inside table model items recursively calls this with the state of the original table
		state = extendedState.withProperty(BlockSmallVessel.INVENTORY, PropertyItem.PropItems.EMPTY);
	}

	// models are symmetric, no need to rotate if there's nothing on it where rotation matters, so we just use default
	if(items == null) {
		return standard.getQuads(state, side, rand);
	}

	// the model returned by getActualModel should be a simple model with no special handling
	return getActualModel(state, items).getQuads(state, side, rand);
}
 
Example 4
Source File: BakedPitKilnModel.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand) 
{
	List<PropertyItem.PItem> items = Collections.emptyList();

	if(state instanceof IExtendedBlockState) {
		IExtendedBlockState extendedState = (IExtendedBlockState) state;

		if(extendedState.getUnlistedNames().contains(BlockPitKiln.INVENTORY)) {
			if(extendedState.getValue(BlockPitKiln.INVENTORY) != null) {
				items = extendedState.getValue(BlockPitKiln.INVENTORY).items;
			}
		}

		// remove all world specific data
		// This is so that the next call to getQuads from the transformed TRSRModel doesn't do this again
		// otherwise table models inside table model items recursively calls this with the state of the original table
		state = extendedState.withProperty(BlockPitKiln.INVENTORY, PropertyItem.PropItems.EMPTY);
	}

	// models are symmetric, no need to rotate if there's nothing on it where rotation matters, so we just use default
	if(items == null) {
		return standard.getQuads(state, side, rand);
	}

	// the model returned by getActualModel should be a simple model with no special handling
	return getActualModel(state, items).getQuads(state, side, rand);
}
 
Example 5
Source File: BakedAnvilModel.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand) 
{
	List<PropertyItem.PItem> items = Collections.emptyList();
	EnumFacing face = EnumFacing.SOUTH;

	if(state instanceof IExtendedBlockState) {
		IExtendedBlockState extendedState = (IExtendedBlockState) state;

		if(/*Config.renderTableItems &&*/ extendedState.getUnlistedNames().contains(BlockAnvil.INVENTORY)) {
			if(extendedState.getValue(BlockAnvil.INVENTORY) != null) {
				items = extendedState.getValue(BlockAnvil.INVENTORY).items;
			}
		}

		// remove all world specific data
		// This is so that the next call to getQuads from the transformed TRSRModel doesn't do this again
		// otherwise table models inside table model items recursively calls this with the state of the original table
		state = extendedState.withProperty(BlockAnvil.INVENTORY, PropertyItem.PropItems.EMPTY);
	}

	// models are symmetric, no need to rotate if there's nothing on it where rotation matters, so we just use default
	if(items == null) {
		return standard.getQuads(state, side, rand);
	}

	// the model returned by getActualModel should be a simple model with no special handling
	return getActualModel(state, items, face).getQuads(state, side, rand);
}
 
Example 6
Source File: BakedModelBarrel.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
synchronized public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand)
{
    // Item model
    if (state == null)
    {
        return this.itemQuads;
    }

    IExtendedBlockState extendedState = (IExtendedBlockState) state;
    IBlockState actualState = extendedState.getClean();
    IBlockState camoState = extendedState.getValue(BlockEnderUtilitiesTileEntity.CAMOBLOCKSTATE);
    boolean validCamo = camoState != null && camoState.getBlock() != Blocks.AIR;

    Optional<IBlockState> key = Optional.of(actualState);
    Map<Optional<IBlockState>, ImmutableMap<Optional<EnumFacing>, ImmutableList<BakedQuad>>> cache = validCamo ? QUAD_CACHE_CAMO : QUAD_CACHE_NORMAL;
    ImmutableMap<Optional<EnumFacing>, ImmutableList<BakedQuad>> map = cache.get(key);

    if (map == null)
    {
        IBakedModel bakedModel = validCamo ? this.getBakedOverlayModel(actualState) : this.getBakedBaseModel(actualState);
        map = this.getQuadsForState(bakedModel, extendedState, rand, validCamo);
        cache.put(key, map);
    }

    return map.get(Optional.ofNullable(side));
}
 
Example 7
Source File: VariantModel.java    From OpenModsLib with MIT License 5 votes vote down vote up
private static VariantModelState getModelSelectors(IBlockState state) {
	if (state instanceof IExtendedBlockState) {
		final IExtendedBlockState extendedState = (IExtendedBlockState)state;
		if (extendedState.getUnlistedNames().contains(VariantModelState.PROPERTY)) {
			final VariantModelState result = extendedState.getValue(VariantModelState.PROPERTY);
			if (result != null)
				return result;
		}
	}

	return VariantModelState.EMPTY;
}
 
Example 8
Source File: BakedEvalModel.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Override
public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand) {

	if (state instanceof IExtendedBlockState) {
		final IExtendedBlockState extState = (IExtendedBlockState)state;

		final EvalModelState args = extState.getValue(EvalModelState.PROPERTY);
		if (args != null) { return (args.isShortLived()? shortTermCache : longTermCache).getUnchecked(args.getArgs()).getQuads(state, side, rand); }
	}

	return super.getQuads(state, side, rand);
}
 
Example 9
Source File: VanillaModelWrapper.java    From VanillaFix with MIT License 4 votes vote down vote up
private IBakedModel bakeNormal(ModelBlock model, IModelState perState, final IModelState modelState, List<TRSRTransformation> newTransforms, final VertexFormat format, final Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter, boolean uvLocked) {
    final TRSRTransformation baseState = modelState.apply(Optional.empty()).orElse(TRSRTransformation.identity());
    TextureAtlasSprite particle = bakedTextureGetter.apply(new ResourceLocation(model.resolveTextureName("particle")));
    SimpleBakedModel.Builder builder = new SimpleBakedModel.Builder(model, model.createOverrides()).setTexture(particle);
    for (int i = 0; i < model.getElements().size(); i++) {
        if (modelState.apply(Optional.of(Models.getHiddenModelPart(ImmutableList.of(Integer.toString(i))))).isPresent()) {
            continue;
        }
        BlockPart part = model.getElements().get(i);
        TRSRTransformation transformation = baseState;
        if (newTransforms.get(i) != null) {
            transformation = transformation.compose(newTransforms.get(i));
            BlockPartRotation rot = part.partRotation;
            if (rot == null) rot = new BlockPartRotation(new org.lwjgl.util.vector.Vector3f(), EnumFacing.Axis.Y, 0, false);
            part = new BlockPart(part.positionFrom, part.positionTo, part.mapFaces, rot, part.shade);
        }
        for (Map.Entry<EnumFacing, BlockPartFace> e : part.mapFaces.entrySet()) {
            TextureAtlasSprite textureatlassprite1 = bakedTextureGetter.apply(new ResourceLocation(model.resolveTextureName(e.getValue().texture)));

            if (e.getValue().cullFace == null || !TRSRTransformation.isInteger(transformation.getMatrix())) {
                builder.addGeneralQuad(makeBakedQuad(part, e.getValue(), textureatlassprite1, e.getKey(), transformation, uvLocked));
            } else {
                builder.addFaceQuad(baseState.rotate(e.getValue().cullFace), makeBakedQuad(part, e.getValue(), textureatlassprite1, e.getKey(), transformation, uvLocked));
            }
        }
    }

    return new PerspectiveMapWrapper(builder.makeBakedModel(), perState) {
        private final ItemOverrideList overrides = new AnimationItemOverrideList(VanillaModelWrapper.this, modelState, format, bakedTextureGetter, super.getOverrides());

        @Override
        public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
            List<BakedQuad> quads = null;

            if (state instanceof IExtendedBlockState) {
                IExtendedBlockState exState = (IExtendedBlockState) state;
                if (exState.getUnlistedNames().contains(Properties.AnimationProperty)) {
                    IModelState newState = exState.getValue(Properties.AnimationProperty);
                    IExtendedBlockState newExState = exState.withProperty(Properties.AnimationProperty, null);
                    if (newState != null) {
                        quads = bake(new ModelStateComposition(modelState, newState), format, bakedTextureGetter).getQuads(newExState, side, rand);
                    }
                }
            }

            if (quads == null) {
                quads = super.getQuads(state, side, rand);
            }

            return quads;
        }

        @Override
        public ItemOverrideList getOverrides() {
            return overrides;
        }
    };
}