use of net.minecraftforge.fluids.FluidStack 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.FluidStack in project MinecraftForge by MinecraftForge.
the class FluidHandlerConcatenate method drain.
@Override
public FluidStack drain(int maxDrain, boolean doDrain) {
if (maxDrain == 0)
return null;
FluidStack totalDrained = null;
for (IFluidHandler handler : subHandlers) {
if (totalDrained == null) {
totalDrained = handler.drain(maxDrain, doDrain);
if (totalDrained != null) {
maxDrain -= totalDrained.amount;
}
} else {
FluidStack copy = totalDrained.copy();
copy.amount = maxDrain;
FluidStack drain = handler.drain(copy, doDrain);
if (drain != null) {
totalDrained.amount += drain.amount;
maxDrain -= drain.amount;
}
}
if (maxDrain <= 0)
break;
}
return totalDrained;
}
use of net.minecraftforge.fluids.FluidStack in project MinecraftForge by MinecraftForge.
the class BlockLiquidWrapper method getTankProperties.
@Override
public IFluidTankProperties[] getTankProperties() {
FluidStack containedStack = null;
IBlockState blockState = world.getBlockState(blockPos);
if (blockState.getBlock() == blockLiquid) {
containedStack = getStack(blockState);
}
return new FluidTankProperties[] { new FluidTankProperties(containedStack, Fluid.BUCKET_VOLUME, false, true) };
}
use of net.minecraftforge.fluids.FluidStack in project MinecraftForge by MinecraftForge.
the class FluidBlockWrapper method getTankProperties.
@Override
public IFluidTankProperties[] getTankProperties() {
float percentFilled = fluidBlock.getFilledPercentage(world, blockPos);
if (percentFilled < 0) {
percentFilled *= -1;
}
int amountFilled = Math.round(Fluid.BUCKET_VOLUME * percentFilled);
FluidStack fluid = amountFilled > 0 ? new FluidStack(fluidBlock.getFluid(), amountFilled) : null;
return new FluidTankProperties[] { new FluidTankProperties(fluid, Fluid.BUCKET_VOLUME, false, true) };
}
use of net.minecraftforge.fluids.FluidStack 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);
}
}
}
}
}
Aggregations