FANDOM


Bucket of a mystery liquid

Mysterious liquid to go!

In CS2, the bucket is a special item type that allows you to pick up custom fluids using a vanilla empty bucket. This makes things much simpler. For each fluid type block you add, you only need to one item file, following the same format as the example below.
This Article is up to date with Custom Stuff 2 CS2

Example Bucket (CS2 0.10.2 and above)

mod.js

config.addItemIdProperty("mysteryBucketID", 6400);
mod.addItem("mysteryBucket.js", "bucket");

mysteryBucket.js

id = config.getItemId("mysteryBucketID");
name = "mysteryFluidBucket";
displayName[0] = "Mysterious Fluid Bucket";

textureFile[0] = "mysteryBucket.png";
maxstack = 1;
full3d = true;
addToCreative[0] = true;
creativeTab = "tools";

leaveContainerItem = true;
containerItem = "325";      //an empty bucket
fluidId  = config.getBlockId("mysteryFluidMovingID");
fluidId2 = config.getBlockId("mysteryFluidStillID");


Important If you are using CS2 0.10.6 make these changes:

fluidId  = config.getBlockId("mysteryFluidID");

Remove fluidId2 as it is not needed anymore


The Liquid associated with this bucket is the example on the liquid page. Please refer there to learn more about the fluid block type if you have not already.

Bucket Item Attributes

Required Attributes

Optional Attributes

textureFile and textureIndex
In CS2 versions for 1.4.7 and below, CS2 0.9.9 or below, textureFile was used to specify the texture sheet and textureIndex was used for identifying the specific icon within the texture sheet. If using CS2 0.9.9 or lower, make sure to use both of these attributes.

CS1
Older Examples and Information for Custom Stuff 1.


In custom stuff 2.2.3_1, liquids currently do not behave properly with buckets. Any liquid that is picked up using a vanilla bucket will currently turn into water or lava depending on what the liquid's material attribute is set to. Until buckets are implemented for liquids, there needs to be a way to pick up and place custom liquids without them turning into water or lava. This is where this bucket page comes in.

Custom Buckets (CS1)

First, we need to make a custom bucket that will use scripts to pick up the liquid. I will start with files for the individual vanilla buckets (emptyBucket.js, waterBucket.js, lavaBucket.js) and save scripts for after the basics are done. First up is the empty bucket which calls the script to pick up liquids. The script will be described in a later section.

name = "emptyBucket";
displayName = "Empty Bucket";
id = 700;
addToCreative = true;
creativeTab = "misc";
textureIndex = 74;
textureFile = "textures.png"; // Copy of vanilla textures file
maxStack = 16;
maxDamage = 0;
full3d = true;
onUse = "mod.loadScript('bucketFill.js');";

After that is to make a custom version of a water bucket if you want to pick up regular water with the script without causing your bucket to turn into a vanilla bucket again.

name = "waterBucket";
displayName = "Water Bucket";
id = 702;
addToCreative = true;
creativeTab = "misc";
textureIndex = 75;
textureFile = "textures.png"; // Copy of vanilla textures file
maxStack = 1;
maxDamage = 0;
containerItem = "700";
full3d = true;
onUse = "player.placeBlock(position, side, 9, 0, false); player.setSlot(player.getCurrentSlot(), 700, 1, 0);";

As you can see, the water bucket uses the onUse event to place water against the selected block and gives you an item with the id of 700, your custom bucket from earlier. The same thing will be done with your custom lava bucket below.

name = "lavaBucket";
displayName = "Lava Bucket";
id = 703;
addToCreative = true;
creativeTab = "misc";
textureIndex = 76;
textureFile = "textures.png"; // Copy of vanilla textures file
maxStack = 1;
maxDamage = 0;
containerItem = "700";
full3d = true;
onUse = "player.placeBlock(position, side, 11, 0, false); player.setSlot(player.getCurrentSlot(), 700, 1, 0);";

A bucket for milk might be included in the future. To add milk for buckets would require the player to craft a vanilla milk bucket into a custom milk bucket, to pick up existing milk source blocks, or to punch any mob (yes, even a creeper) with a custom bucket that has a hitmob event.

You can add similar item files for any custom liquids you want to support.

Bucket Script

To make the script easy to add additional scripts, an array is used as a variable. All liquid block ids that you want the script to pay attention to should be listed in the variable at the top of the script. One other step is also necessary to make the liquids actually do something when the script is called, but that will be covered in depth later in the explaination.

var myLiquids = new Array(8,9,10,11,136,137);

switch(side)
{
case 0:
    position.y--;
    break;
case 1:
    position.y++;
    break;
case 2:
    position.z--;
    break;
case 3:
    position.z++;
    break;
case 4:
    position.x--;
    break;
case 5:
    position.x++;
    break;
default:
    player.sendMessage('An unknown side has been clicked.');
    break;
}

for(var liquidlist = 0; liquidlist < myLiquids.length; liquidlist++)
{
    if(world.getBlockMetadata(position) == 0 && world.getBlockId(position) == myLiquids[liquidlist])
    {
        switch(world.getBlockId(origin))
        {
            case 8:
            case 9:
                world.setBlockId(position, 0);
                player.removeFromSlot(player.getCurrentSlot(), 1);
                player.add(702, 1, 0);
                break;
            case 10:
            case 11:
                world.setBlockId(position, 0);
                player.removeFromSlot(player.getCurrentSlot(), 1);
                player.add(703, 1, 0);
                break;
            case 136:
            case 137:
                world.setBlockId(position, 0);
                world.createExplosion(position, 8);
                break;
        }
    }
}

I will now break the above script into slightly more manageable parts for explaination. Let us start with the variable that I stated would be an array.

var myLiquids = new Array(8,9,10,11,136,137);

This line of script will create a variable that contains as many variables as the amount listed. Each value can be accessed individually using myLiquids[number] with the current variable being the number inside the [ ] -1. This means that myLiquids[3] would equal 11, the 4th value in the list. Most that work with vanilla id's enough should notice that 8 and 9 are water and 10 and 11 are lava, but what are 136 and 137 you might ask? Good question. For the sake of demenstration of what this script could do, this liquid will be nitroglycerin, a very unstable liquid that explodes unless treated with extreme care.

switch(side)
{
case 0:
    position.y--;
    break;
case 1:
    position.y++;
    break;
case 2:
    position.z--;
    break;
case 3:
    position.z++;
    break;
case 4:
    position.x--;
    break;
case 5:
    position.x++;
    break;
default:
    player.sendMessage('An unknown side has been clicked.');
    break;
}

Now this chunk of code helps us target the liquid with the bucket since liquids cannot be directly affected by a right click. The side variable is a variable that is generated along with position to determine which side of a block a player has just interacted with. Based on what value side has, this bit of script will move the position 1 block along the x, y, or z axis. If for whatever reason, an impossible side is targeted or side glitches, a message will appear for the player to read.

for(var liquidlist = 0; liquidlist < myLiquids.length; liquidlist++)
{
    if(world.getBlockMetadata(position) == 0 && world.getBlockId(position) == myLiquids[liquidlist])
    {

This for loop uses a new variable, liquidlist, that is then increased by 1 each time that the loop ends. The loop is continued until liquidlist is no longer less than the number of values stored in the myLiquids array variable. The myLiquids.length is used to find the number of values stored in the myLiquids array, which at this moment is 6. This means that the for loop will activate for the values 0 to 5 then stop.

The if statement checks to make sure the block targeted has a 0 for its metadata. If this was not checked, then non-source blocks could be picked up as if they were full source blocks. This would allow a lava block to be harvested infinitely as long as the source is never taken away. The if statement also compares the id of the current position (moved in a previous step) is equal to the current value of the array. The liquidlist varable that is being incremented by the for loop will allow this single if statement to check every liquid id that the player has included in the array. If any are true, we now need to actually do something with the liquid.

switch(world.getBlockId(position))
{
case 8:
case 9:
    world.setBlockId(position, 0);
    player.removeFromSlot(player.getCurrentSlot(), 1);
    player.add(702, 1, 0);
    break;
case 10:
case 11:
    world.setBlockId(position, 0);
    player.removeFromSlot(player.getCurrentSlot(), 1);
    player.add(703, 1, 0);
    break;
case 136:
case 137:
    world.setBlockId(position, 0);
    world.createExplosion(position, 8);
    break;
}

Here is where we finally get to add the liquid to your custom bucket. Notice that there are cases that have no code in them, since there is no break command, they will continue excuting code until they either reach the end or find another break command. This means that even if you manage to find water that uses 8 as an id, it will still activate the code that the id 9 would activate, giving you a custom water bucket. The code for the first two sets of liquids will clear the liquid by changing it to air, remove one of the custom empty buckets from the current slot, and then add to inventory a custom water or lava bucket. But you have probably noticed that the code for 136 and 137 does not go into a bucket and instead causes an explosion. If you remember, I stated earlier that in this example 136 and 137 will be nitroglycerin. This liquid is so unstable that the mere act of trying to dip a bucket in the liquid will cause it to explode in your face! This last liquid shows that not everything can or even should be collected with a primative bucket.

If you want to add additional liquids to the script, there are two places that you need to add information. The first was the myLiquids variable at the start of the script. The second location is the cases found near the end of the script. As long as you remember to include a break command at the end of the last case in each pair, almost anything could be possible using the right scripting.

Current Problems

  • The method described above unfortunately requires the player to be able to right click on a block directly next to the liquid since liquids cannot be directly effected. A method to find the top liquid could be used to help fix this but would allow players to completely drain a column of water from the bottom.
  • In the current version of custom stuff (2.2.3_1), recipes that have a blank space in them cannot be removed from vanilla minecraft so any recipe for custom buckets will have to be a different pattern than the regular bucket pattern.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.