Skip to content

Commit

Permalink
- fixed: some buckets of other mods did not appear in creative tab
Browse files Browse the repository at this point in the history
- fixed: dublicated milk buckets in creative tab
  • Loading branch information
cech12 committed Aug 10, 2020
1 parent 449d2d3 commit cd9beb3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,19 @@ public boolean tryPlaceContainedLiquid(@Nullable PlayerEntity player, @Nonnull W
}

public boolean tryPlaceContainedLiquid(@Nullable PlayerEntity player, World worldIn, BlockPos posIn, @Nullable BlockRayTraceResult raytrace, ItemStack stack) {
if (!(this.getFluid(stack) instanceof FlowingFluid)) {
Fluid fluid = this.getFluid(stack);
FluidAttributes fluidAttributes = fluid.getAttributes();
if (!(fluid instanceof FlowingFluid)) {
return false;
} else if (!fluidAttributes.canBePlacedInWorld(worldIn, posIn, fluid.getDefaultState())) {
return false;
} else {
BlockState blockstate = worldIn.getBlockState(posIn);
Material material = blockstate.getMaterial();
boolean flag = !material.isSolid();
boolean flag1 = material.isReplaceable();
if (worldIn.isAirBlock(posIn) || flag || flag1 || blockstate.getBlock() instanceof ILiquidContainer && ((ILiquidContainer) blockstate.getBlock()).canContainFluid(worldIn, posIn, blockstate, this.getFluid())) {
if (worldIn.dimension.doesWaterVaporize() && this.getFluid(stack).isIn(FluidTags.WATER)) {
if (worldIn.dimension.doesWaterVaporize() && fluid.isIn(FluidTags.WATER)) {
int i = posIn.getX();
int j = posIn.getY();
int k = posIn.getZ();
Expand All @@ -162,8 +166,8 @@ public boolean tryPlaceContainedLiquid(@Nullable PlayerEntity player, World worl
for (int l = 0; l < 8; ++l) {
worldIn.addParticle(ParticleTypes.LARGE_SMOKE, (double) i + Math.random(), (double) j + Math.random(), (double) k + Math.random(), 0.0D, 0.0D, 0.0D);
}
} else if (blockstate.getBlock() instanceof ILiquidContainer && this.getFluid(stack) == Fluids.WATER) {
if (((ILiquidContainer) blockstate.getBlock()).receiveFluid(worldIn, posIn, blockstate, ((FlowingFluid) this.getFluid(stack)).getStillFluidState(false))) {
} else if (blockstate.getBlock() instanceof ILiquidContainer && fluid == Fluids.WATER) {
if (((ILiquidContainer) blockstate.getBlock()).receiveFluid(worldIn, posIn, blockstate, ((FlowingFluid) fluid).getStillFluidState(false))) {
this.playEmptySound(player, worldIn, posIn);
}
} else {
Expand All @@ -172,7 +176,7 @@ public boolean tryPlaceContainedLiquid(@Nullable PlayerEntity player, World worl
}

this.playEmptySound(player, worldIn, posIn);
worldIn.setBlockState(posIn, this.getFluid(stack).getDefaultState().getBlockState(), 11);
worldIn.setBlockState(posIn, fluid.getDefaultState().getBlockState(), 11);
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import cech12.ceramicbucket.util.CeramicBucketUtils;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.BucketItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
Expand All @@ -19,6 +21,7 @@
import net.minecraftforge.registries.ForgeRegistries;

import javax.annotation.Nonnull;
import java.util.ArrayList;

public class FilledCeramicBucketItem extends AbstractCeramicBucketItem {

Expand Down Expand Up @@ -48,15 +51,21 @@ public ItemStack getDefaultInstance() {
@Override
public void fillItemGroup(@Nonnull ItemGroup group, @Nonnull NonNullList<ItemStack> items) {
if (this.isInGroup(group)) {
ArrayList<Fluid> addedFluids = new ArrayList<>();
for (Fluid fluid : ForgeRegistries.FLUIDS) {
//only add non milk source fluids with a bucket item
if (fluid.getDefaultState().isSource() && !CeramicBucketUtils.isMilkFluid(fluid) && fluid.getFilledBucket() != null) {
items.add(getFilledInstance(fluid));
//add a property per fluid
this.addPropertyOverride(fluid.getRegistryName(),
(stack, world, livingEntity) ->
((FilledCeramicBucketItem) stack.getItem()).getFluid(stack).getRegistryName().equals(fluid.getRegistryName()) ? 1.0F : 0.0F
);
Item bucket = fluid.getFilledBucket();
if (!CeramicBucketUtils.isMilkFluid(fluid) && bucket != null && bucket instanceof BucketItem) {
Fluid bucketFluid = ((BucketItem) bucket).getFluid();
if (!addedFluids.contains(bucketFluid)) {
items.add(getFilledInstance(bucketFluid));
//add a property per fluid
this.addPropertyOverride(bucketFluid.getRegistryName(),
(stack, world, livingEntity) ->
((FilledCeramicBucketItem) stack.getItem()).getFluid(stack).getRegistryName().equals(bucketFluid.getRegistryName()) ? 1.0F : 0.0F
);
addedFluids.add(bucketFluid);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import cech12.ceramicbucket.item.FilledCeramicBucketItem;
import net.minecraft.fluid.Fluid;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.tags.FluidTags;
import net.minecraft.tags.Tag;
import net.minecraft.util.ResourceLocation;
Expand All @@ -29,6 +30,10 @@ public static boolean isMilkFluid(@Nonnull Fluid fluid) {
if (fluid.isIn(MILK_TAG)) {
return true;
}
ResourceLocation location = fluid.getFilledBucket().getRegistryName();
if (location != null && location.equals(Items.MILK_BUCKET.getRegistryName())) {
return true;
}
for (ResourceLocation name : MILK_FLUIDS) {
if (name.equals(fluid.getRegistryName())) {
return true;
Expand Down
8 changes: 7 additions & 1 deletion src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ issueTrackerURL="https://github.com/cech12/CeramicBucket/issues"
mandatory=true
versionRange="[1.14.4,)"
ordering="NONE"
side="BOTH"
side="BOTH"
[[dependencies.ceramicbucket]]
modId="jei"
mandatory=false
versionRange="[6.0.0.27,)"
ordering="NONE"
side="BOTH"

0 comments on commit cd9beb3

Please sign in to comment.