use of net.minecraftforge.fluids.Fluid in project MinecraftForge by MinecraftForge.
the class ModelLoader method loadItemModels.
@Override
protected void loadItemModels() {
// register model for the universal bucket, if it exists
if (FluidRegistry.isUniversalBucketEnabled()) {
setBucketModelDefinition(ForgeModContainer.getInstance().universalBucket);
}
registerVariantNames();
List<Item> items = Lists.newArrayList(Iterables.filter(Item.REGISTRY, new Predicate<Item>() {
public boolean apply(Item item) {
return item.getRegistryName() != null;
}
}));
Collections.sort(items, new Comparator<Item>() {
public int compare(Item i1, Item i2) {
return i1.getRegistryName().toString().compareTo(i2.getRegistryName().toString());
}
});
ProgressBar itemBar = ProgressManager.push("ModelLoader: items", items.size());
for (Item item : items) {
itemBar.step(item.getRegistryName().toString());
for (String s : getVariantNames(item)) {
ResourceLocation file = getItemLocation(s);
ModelResourceLocation memory = getInventoryVariant(s);
IModel model = ModelLoaderRegistry.getMissingModel();
Exception exception = null;
try {
model = ModelLoaderRegistry.getModel(file);
} catch (Exception normalException) {
// try blockstate json if the item model is missing
FMLLog.fine("Item json isn't found for '" + memory + "', trying to load the variant from the blockstate json");
try {
model = ModelLoaderRegistry.getModel(memory);
} catch (Exception blockstateException) {
exception = new ItemLoadingException("Could not load item model either from the normal location " + file + " or from the blockstate", normalException, blockstateException);
}
}
if (exception != null) {
storeException(memory, exception);
model = ModelLoaderRegistry.getMissingModel(memory, exception);
}
stateModels.put(memory, model);
}
}
ProgressManager.pop(itemBar);
// replace vanilla bucket models if desired. done afterwards for performance reasons
if (ForgeModContainer.replaceVanillaBucketModel) {
// ensure the bucket model is loaded
if (!stateModels.containsKey(ModelDynBucket.LOCATION)) {
// load forges blockstate json for it
try {
registerVariant(getModelBlockDefinition(ModelDynBucket.LOCATION), ModelDynBucket.LOCATION);
} catch (Exception exception) {
FMLLog.getLogger().error("Could not load the forge bucket model from the blockstate", exception);
return;
}
}
// empty bucket
for (String s : getVariantNames(Items.BUCKET)) {
ModelResourceLocation memory = getInventoryVariant(s);
IModel model = ModelLoaderRegistry.getModelOrMissing(new ResourceLocation(ForgeVersion.MOD_ID, "item/bucket"));
// only on successful load, otherwise continue using the old model
if (model != getMissingModel()) {
stateModels.put(memory, model);
}
}
setBucketModel(Items.WATER_BUCKET);
setBucketModel(Items.LAVA_BUCKET);
// milk bucket only replaced if some mod adds milk
if (FluidRegistry.isFluidRegistered("milk")) {
// can the milk be put into a bucket?
Fluid milk = FluidRegistry.getFluid("milk");
FluidStack milkStack = new FluidStack(milk, Fluid.BUCKET_VOLUME);
IFluidHandler bucketHandler = FluidUtil.getFluidHandler(new ItemStack(Items.BUCKET));
if (bucketHandler != null && bucketHandler.fill(milkStack, false) == Fluid.BUCKET_VOLUME) {
setBucketModel(Items.MILK_BUCKET);
}
} else {
// milk bucket if no milk fluid is present
for (String s : getVariantNames(Items.MILK_BUCKET)) {
ModelResourceLocation memory = getInventoryVariant(s);
IModel model = ModelLoaderRegistry.getModelOrMissing(new ResourceLocation(ForgeVersion.MOD_ID, "item/bucket_milk"));
// only on successful load, otherwise continue using the old model
if (model != getMissingModel()) {
stateModels.put(memory, model);
}
}
}
}
}
use of net.minecraftforge.fluids.Fluid in project MinecraftForge by MinecraftForge.
the class ModelDynBucket method process.
/**
* Sets the liquid in the model.
* fluid - Name of the fluid in the FluidRegistry
* flipGas - If "true" the model will be flipped upside down if the liquid is a gas. If "false" it wont
* <p/>
* If the fluid can't be found, water is used
*/
@Override
public ModelDynBucket process(ImmutableMap<String, String> customData) {
String fluidName = customData.get("fluid");
Fluid fluid = FluidRegistry.getFluid(fluidName);
if (fluid == null)
fluid = this.fluid;
boolean flip = flipGas;
if (customData.containsKey("flipGas")) {
String flipStr = customData.get("flipGas");
if (flipStr.equals("true"))
flip = true;
else if (flipStr.equals("false"))
flip = false;
else
throw new IllegalArgumentException(String.format("DynBucket custom data \"flipGas\" must have value \'true\' or \'false\' (was \'%s\')", flipStr));
}
// create new model with correct liquid
return new ModelDynBucket(baseLocation, liquidLocation, coverLocation, fluid, flip);
}
use of net.minecraftforge.fluids.Fluid in project MinecraftForge by MinecraftForge.
the class DynBucketTest method onBucketFill.
@SubscribeEvent
public void onBucketFill(FillBucketEvent event) {
RayTraceResult target = event.getTarget();
if (target != null) {
IBlockState state = event.getWorld().getBlockState(target.getBlockPos());
if (state.getBlock() instanceof IFluidBlock) {
Fluid fluid = ((IFluidBlock) state.getBlock()).getFluid();
FluidStack fs = new FluidStack(fluid, Fluid.BUCKET_VOLUME);
ItemStack bucket = event.getEmptyBucket();
IFluidHandlerItem fluidHandler = FluidUtil.getFluidHandler(bucket);
if (fluidHandler != null) {
int fillAmount = fluidHandler.fill(fs, true);
if (fillAmount > 0) {
ItemStack filledBucket = fluidHandler.getContainer();
event.setFilledBucket(filledBucket);
event.setResult(Result.ALLOW);
}
}
}
}
}
use of net.minecraftforge.fluids.Fluid in project LogisticsPipes by RS485.
the class FluidRenderer method getFluidDisplayLists.
public static int[] getFluidDisplayLists(FluidStack fluidStack, World world, boolean flowing) {
if (fluidStack == null) {
return null;
}
Fluid fluid = fluidStack.getFluid();
if (fluid == null) {
return null;
}
Map<Fluid, int[]> cache = flowing ? FluidRenderer.flowingRenderCache : FluidRenderer.stillRenderCache;
int[] diplayLists = cache.get(fluid);
if (diplayLists != null) {
return diplayLists;
}
diplayLists = new int[FluidRenderer.DISPLAY_STAGES];
if (fluid.getBlock() != null) {
FluidRenderer.liquidBlock.baseBlock = fluid.getBlock();
FluidRenderer.liquidBlock.texture = FluidRenderer.getFluidTexture(fluidStack, flowing);
} else {
FluidRenderer.liquidBlock.baseBlock = Blocks.water;
FluidRenderer.liquidBlock.texture = FluidRenderer.getFluidTexture(fluidStack, flowing);
}
cache.put(fluid, diplayLists);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_CULL_FACE);
for (int s = 0; s < FluidRenderer.DISPLAY_STAGES; ++s) {
diplayLists[s] = GLAllocation.generateDisplayLists(1);
GL11.glNewList(diplayLists[s], 4864);
FluidRenderer.liquidBlock.minX = 0.01f;
FluidRenderer.liquidBlock.minY = 0;
FluidRenderer.liquidBlock.minZ = 0.01f;
FluidRenderer.liquidBlock.maxX = 0.99f;
FluidRenderer.liquidBlock.maxY = (float) s / (float) FluidRenderer.DISPLAY_STAGES;
FluidRenderer.liquidBlock.maxZ = 0.99f;
CustomBlockRenderer.INSTANCE.renderBlock(FluidRenderer.liquidBlock, world, 0, 0, 0, false, true);
GL11.glEndList();
}
GL11.glColor4f(1, 1, 1, 1);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_LIGHTING);
return diplayLists;
}
use of net.minecraftforge.fluids.Fluid in project Witchworks by Um-Mitternacht.
the class TileKettle method onLiquidChange.
@SuppressWarnings("ConstantConditions")
@Override
public void onLiquidChange() {
ingredients = ItemNullHelper.asArray(64);
mode = Mode.NORMAL;
ritual = null;
Fluid fluid = inv.getInnerFluid();
if (fluid != null) {
int color = (fluid == FluidRegistry.WATER || fluid.getColor() == 0xFFFFFFFF) ? 0x12193b : fluid.getColor();
setColorRGB(color);
}
if (!world.isRemote)
PacketHandler.updateToNearbyPlayers(world, pos);
}
Aggregations