-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBucketHandler.java
More file actions
55 lines (41 loc) · 1.72 KB
/
BucketHandler.java
File metadata and controls
55 lines (41 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package practicalities;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.FillBucketEvent;
import practicalities.blocks.ModBlocks;
import practicalities.items.ModItems;
import cpw.mods.fml.common.eventhandler.Event.Result;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
public class BucketHandler {
public static BucketHandler INSTANCE = new BucketHandler();
public Map<Block, Item> buckets = new HashMap<Block, Item>();
public static void init() {
BucketHandler.INSTANCE.buckets.put(ModBlocks.blockPreChewedFood, ModItems.bucketPreChewedFood);
MinecraftForge.EVENT_BUS.register(BucketHandler.INSTANCE);
}
private BucketHandler() {
}
@SubscribeEvent
public void onBucketFill(FillBucketEvent event) {
ItemStack result = fillCustomBucket(event.world, event.target);
if (result == null)
return;
event.result = result;
event.setResult(Result.ALLOW);
}
private ItemStack fillCustomBucket(World world, MovingObjectPosition pos) {
Block block = world.getBlock(pos.blockX, pos.blockY, pos.blockZ);
Item bucket = buckets.get(block);
if (bucket != null && world.getBlockMetadata(pos.blockX, pos.blockY, pos.blockZ) == 0) {
world.setBlockToAir(pos.blockX, pos.blockY, pos.blockZ);
return new ItemStack(bucket);
} else
return null;
}
}