-
Notifications
You must be signed in to change notification settings - Fork 25
/
ClientCache.java
153 lines (139 loc) · 8.12 KB
/
ClientCache.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package com.sinthoras.visualprospecting.database;
import com.sinthoras.visualprospecting.*;
import com.sinthoras.visualprospecting.hooks.ProspectingNotificationEvent;
import com.sinthoras.visualprospecting.network.ProspectingRequest;
import gregtech.common.blocks.GT_TileEntity_Ores;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class ClientCache extends WorldCache {
public static final ClientCache instance = new ClientCache();
protected File getStorageDirectory() {
final EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer;
return new File(Utils.getSubDirectory(Tags.CLIENT_DIR), player.getDisplayName() + "_" + player.getPersistentID().toString());
}
private void notifyNewOreVein(OreVeinPosition oreVeinPosition) {
final String location = "(" + (oreVeinPosition.getBlockX() + 8) + "," + (oreVeinPosition.getBlockZ() + 8) + ")";
final IChatComponent veinNotification = new ChatComponentTranslation("visualprospecting.vein.prospected", I18n.format(oreVeinPosition.veinType.name), location);
veinNotification.getChatStyle().setItalic(true);
veinNotification.getChatStyle().setColor(EnumChatFormatting.GRAY);
Minecraft.getMinecraft().thePlayer.addChatMessage(veinNotification);
final String oreNames = String.join(", ", oreVeinPosition.veinType.getOreMaterialNames());
final IChatComponent oresNotification = new ChatComponentTranslation("visualprospecting.vein.contents", oreNames);
oresNotification.getChatStyle().setItalic(true);
oresNotification.getChatStyle().setColor(EnumChatFormatting.GRAY);
Minecraft.getMinecraft().thePlayer.addChatMessage(oresNotification);
}
public void putOreVeins(List<OreVeinPosition> oreVeinPositions) {
if(oreVeinPositions.size() == 1) {
final OreVeinPosition oreVeinPosition = oreVeinPositions.get(0);
if(putOreVein(oreVeinPosition) != DimensionCache.UpdateResult.AlreadyKnown) {
MinecraftForge.EVENT_BUS.post(new ProspectingNotificationEvent.OreVein(oreVeinPosition));
notifyNewOreVein(oreVeinPosition);
}
}
else if(oreVeinPositions.size() > 1) {
int newOreVeins = 0;
for(OreVeinPosition oreVeinPosition : oreVeinPositions) {
if(putOreVein(oreVeinPosition) != DimensionCache.UpdateResult.AlreadyKnown) {
MinecraftForge.EVENT_BUS.post(new ProspectingNotificationEvent.OreVein(oreVeinPosition));
newOreVeins++;
}
}
if(newOreVeins > 0) {
final IChatComponent oreVeinNotification = new ChatComponentTranslation("visualprospecting.veins.prospected", newOreVeins);
oreVeinNotification.getChatStyle().setItalic(true);
oreVeinNotification.getChatStyle().setColor(EnumChatFormatting.GRAY);
Minecraft.getMinecraft().thePlayer.addChatMessage(oreVeinNotification);
}
}
}
public void toggleOreVein(int dimensionId, int chunkX, int chunkZ) {
super.toggleOreVein(dimensionId, chunkX, chunkZ);
}
public void putUndergroundFluids(List<UndergroundFluidPosition> undergroundFluids) {
int newUndergroundFluids = 0;
int updatedUndergroundFluids = 0;
for(UndergroundFluidPosition undergroundFluidPosition : undergroundFluids) {
DimensionCache.UpdateResult updateResult = putUndergroundFluids(undergroundFluidPosition);
if(updateResult == DimensionCache.UpdateResult.New) {
MinecraftForge.EVENT_BUS.post(new ProspectingNotificationEvent.UndergroundFluid(undergroundFluidPosition));
newUndergroundFluids++;
}
else if(updateResult == DimensionCache.UpdateResult.Updated) {
MinecraftForge.EVENT_BUS.post(new ProspectingNotificationEvent.UndergroundFluid(undergroundFluidPosition));
updatedUndergroundFluids++;
}
}
if(newUndergroundFluids > 0 && updatedUndergroundFluids > 0) {
final IChatComponent undergroundFluidsNotification = new ChatComponentTranslation("visualprospecting.undergroundfluid.prospected.newandupdated", newUndergroundFluids, updatedUndergroundFluids);
undergroundFluidsNotification.getChatStyle().setItalic(true);
undergroundFluidsNotification.getChatStyle().setColor(EnumChatFormatting.GRAY);
Minecraft.getMinecraft().thePlayer.addChatMessage(undergroundFluidsNotification);
}
else {
if(newUndergroundFluids > 0) {
final IChatComponent undergroundFluidsNotification = new ChatComponentTranslation("visualprospecting.undergroundfluid.prospected.onlynew", newUndergroundFluids);
undergroundFluidsNotification.getChatStyle().setItalic(true);
undergroundFluidsNotification.getChatStyle().setColor(EnumChatFormatting.GRAY);
Minecraft.getMinecraft().thePlayer.addChatMessage(undergroundFluidsNotification);
}
if(updatedUndergroundFluids > 0) {
final IChatComponent undergroundFluidsNotification = new ChatComponentTranslation("visualprospecting.undergroundfluid.prospected.onlyupdated", updatedUndergroundFluids);
undergroundFluidsNotification.getChatStyle().setItalic(true);
undergroundFluidsNotification.getChatStyle().setColor(EnumChatFormatting.GRAY);
Minecraft.getMinecraft().thePlayer.addChatMessage(undergroundFluidsNotification);
}
}
}
public void onOreInteracted(World world, int blockX, int blockY, int blockZ, EntityPlayer entityPlayer) {
if(world.isRemote && Config.enableProspecting
&& Minecraft.getMinecraft().thePlayer == entityPlayer) {
final TileEntity tTileEntity = world.getTileEntity(blockX, blockY, blockZ);
if (tTileEntity instanceof GT_TileEntity_Ores) {
final short oreMetaData = ((GT_TileEntity_Ores) tTileEntity).mMetaData;
if (Utils.isSmallOreId(oreMetaData) == false
&& oreMetaData != 0) {
final int chunkX = Utils.coordBlockToChunk(blockX);
final int chunkZ = Utils.coordBlockToChunk(blockZ);
final OreVeinPosition oreVeinPosition = getOreVein(entityPlayer.dimension, chunkX, chunkZ);
final short materialId = Utils.oreIdToMaterialId(oreMetaData);
if(oreVeinPosition.veinType.containsOre(materialId) == false && ProspectingRequest.canSendRequest()) {
VP.network.sendToServer(new ProspectingRequest(entityPlayer.dimension, blockX, blockY, blockZ, materialId));
}
}
}
}
}
public void resetPlayerProgression() {
Utils.deleteDirectoryRecursively(oreVeinCacheDirectory);
Utils.deleteDirectoryRecursively(undergroundFluidCacheDirectory);
oreVeinCacheDirectory.mkdirs();
undergroundFluidCacheDirectory.mkdirs();
reset();
}
public List<OreVeinPosition> getAllOreVeins() {
List<OreVeinPosition> allOreVeins = new ArrayList<>();
for(DimensionCache dimension : dimensions.values()) {
allOreVeins.addAll(dimension.getAllOreVeins());
}
return allOreVeins;
}
public List<UndergroundFluidPosition> getAllUndergroundFluids() {
List<UndergroundFluidPosition> allUndergroundFluids = new ArrayList<>();
for(DimensionCache dimension : dimensions.values()) {
allUndergroundFluids.addAll(dimension.getAllUndergroundFluids());
}
return allUndergroundFluids;
}
}