-
Notifications
You must be signed in to change notification settings - Fork 26
/
ItemEditableBookMixin.java
53 lines (49 loc) · 2.76 KB
/
ItemEditableBookMixin.java
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
package com.sinthoras.visualprospecting.mixins.minecraft;
import com.sinthoras.visualprospecting.VP;
import com.sinthoras.visualprospecting.Tags;
import com.sinthoras.visualprospecting.Utils;
import com.sinthoras.visualprospecting.database.ClientCache;
import com.sinthoras.visualprospecting.database.ServerCache;
import com.sinthoras.visualprospecting.database.UndergroundFluidPosition;
import com.sinthoras.visualprospecting.database.OreVeinPosition;
import com.sinthoras.visualprospecting.network.ProspectingNotification;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemEditableBook;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import java.util.List;
@Mixin(value = ItemEditableBook.class, remap = true)
public class ItemEditableBookMixin {
@Inject(method = "onItemRightClick",
at = @At("HEAD"),
remap = true,
require = 1,
locals = LocalCapture.CAPTURE_FAILEXCEPTION)
private void onItemRightClick(ItemStack itemStack, World world, EntityPlayer entityPlayer, CallbackInfoReturnable<ItemStack> callbackInfoReturnable) {
if(world.isRemote == false) {
final NBTTagCompound compound = itemStack.getTagCompound();
if(compound.hasKey(Tags.VISUALPROSPECTING_FLAG)) {
final int dimensionId = compound.getInteger(Tags.PROSPECTION_DIMENSION_ID);
final int blockX = compound.getInteger(Tags.PROSPECTION_BLOCK_X);
final int blockZ = compound.getInteger(Tags.PROSPECTION_BLOCK_Z);
final int blockRadius = compound.getInteger(Tags.PROSPECTION_ORE_RADIUS);
final List<OreVeinPosition> foundOreVeins = ServerCache.instance.prospectOreBlockRadius(dimensionId, blockX, blockZ, blockRadius);
final List<UndergroundFluidPosition> foundUndergroundFluids = ServerCache.instance.prospectUndergroundFluidBlockRadius(world, blockX, blockZ, VP.undergroundFluidChunkProspectingBlockRadius);
if(Utils.isLogicalClient()) {
ClientCache.instance.putOreVeins(foundOreVeins);
ClientCache.instance.putUndergroundFluids(foundUndergroundFluids);
}
else {
VP.network.sendTo(new ProspectingNotification(foundOreVeins, foundUndergroundFluids), (EntityPlayerMP) entityPlayer);
}
}
}
}
}