Skip to content

Commit 38840fb

Browse files
committed
Merge pr-40
2 parents 59749e3 + a127096 commit 38840fb

22 files changed

+362
-2
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.jaquadro.minecraft.storagedrawers.api.storage.attribute;
2+
3+
public interface IQuantifiable {
4+
5+
/**
6+
* Gets whether the drawer has the quantifiable attribute. The quantifiable attribute instructs the drawer to render
7+
* the quantity of the item contained in the drawer.
8+
*/
9+
boolean isQuantified();
10+
11+
boolean setIsQuantified(boolean state);
12+
}

src/main/java/com/jaquadro/minecraft/storagedrawers/block/BlockController.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer p
141141
te.toggleProtection(player.getGameProfile(), provider);
142142
}
143143

144+
return true;
145+
} else if (item.getItem() == ModItems.quantifyKey) {
146+
if (!world.isRemote) te.toggleQuantify(player.getGameProfile());
144147
return true;
145148
}
146149
}

src/main/java/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,9 @@ else if (item.getItem() == ModItems.upgrade || item.getItem() == ModItems.upgrad
392392
} else if (item.getItem() == ModItems.shroudKey) {
393393
tileDrawers.setIsShrouded(!tileDrawers.isShrouded());
394394
return true;
395+
} else if (item.getItem() == ModItems.quantifyKey) {
396+
tileDrawers.setIsQuantified(!tileDrawers.isQuantified());
397+
return true;
395398
} else if (item.getItem() instanceof ItemPersonalKey) {
396399
String securityKey = ((ItemPersonalKey) item.getItem())
397400
.getSecurityProviderKey(item.getItemDamage());

src/main/java/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.jaquadro.minecraft.storagedrawers.api.storage.ISmartGroup;
3737
import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.ILockable;
3838
import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.IProtectable;
39+
import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.IQuantifiable;
3940
import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.IShroudable;
4041
import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.IVoidable;
4142
import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.LockAttribute;
@@ -300,6 +301,34 @@ public void toggleShroud(GameProfile profile) {
300301
}
301302
}
302303

304+
public void toggleQuantify(GameProfile profile) {
305+
IQuantifiable template = null;
306+
boolean state = false;
307+
308+
for (StorageRecord record : storage.values()) {
309+
if (record.storage == null) continue;
310+
311+
if (record.storage instanceof IProtectable) {
312+
if (!SecurityManager.hasAccess(profile, (IProtectable) record.storage)) continue;
313+
}
314+
315+
for (int i = 0, n = record.storage.getDrawerCount(); i < n; i++) {
316+
if (!record.storage.isDrawerEnabled(i)) continue;
317+
318+
IDrawer drawer = record.storage.getDrawer(i);
319+
if (!(drawer instanceof IQuantifiable)) continue;
320+
321+
IQuantifiable quantifiableStorage = (IQuantifiable) drawer;
322+
if (template == null) {
323+
template = quantifiableStorage;
324+
state = !template.isQuantified();
325+
}
326+
327+
quantifiableStorage.setIsQuantified(state);
328+
}
329+
}
330+
}
331+
303332
public void toggleLock(EnumSet<LockAttribute> attributes, LockAttribute key, GameProfile profile) {
304333
ILockable template = null;
305334
boolean state = false;

src/main/java/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawers.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawe
4949
private int direction;
5050
private int drawerCapacity = 1;
5151
private boolean shrouded = false;
52+
private boolean quantified = false;
5253
private boolean taped = false;
5354
private boolean hideUpgrade = false;
5455
private boolean downgraded = false;
@@ -243,6 +244,23 @@ public void setIsShrouded(boolean shrouded) {
243244
}
244245
}
245246

247+
public boolean isQuantified() {
248+
if (!StorageDrawers.config.cache.enableQuantifyUpgrades) return false;
249+
250+
return quantified;
251+
}
252+
253+
public void setIsQuantified(boolean quantified) {
254+
if (this.quantified != quantified) {
255+
this.quantified = quantified;
256+
257+
if (worldObj != null && !worldObj.isRemote) {
258+
markDirty();
259+
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
260+
}
261+
}
262+
}
263+
246264
@Override
247265
public UUID getOwner() {
248266
if (!StorageDrawers.config.cache.enablePersonalUpgrades) return null;
@@ -651,6 +669,9 @@ public void readFromPortableNBT(NBTTagCompound tag) {
651669
shrouded = false;
652670
if (tag.hasKey("Shr")) shrouded = tag.getBoolean("Shr");
653671

672+
quantified = false;
673+
if (tag.hasKey("Qua")) quantified = tag.getBoolean("Qua");
674+
654675
owner = null;
655676
if (tag.hasKey("Own")) owner = UUID.fromString(tag.getString("Own"));
656677

@@ -703,6 +724,8 @@ public void writeToPortableNBT(NBTTagCompound tag) {
703724

704725
if (shrouded) tag.setBoolean("Shr", shrouded);
705726

727+
if (quantified) tag.setBoolean("Qua", quantified);
728+
706729
if (owner != null) tag.setString("Own", owner.toString());
707730

708731
if (securityKey != null) tag.setString("Sec", securityKey);

src/main/java/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawersComp.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,17 @@ public boolean setIsSlotShrouded(int slot, boolean state) {
649649
return true;
650650
}
651651

652+
@Override
653+
public boolean isQuantifiedSlot(int slot) {
654+
return isQuantified();
655+
}
656+
657+
@Override
658+
public boolean setIsSlotQuantifiable(int slot, boolean state) {
659+
setIsQuantified(state);
660+
return true;
661+
}
662+
652663
@Override
653664
public boolean isLocked(int slot, LockAttribute attr) {
654665
return TileEntityDrawersComp.this.isLocked(attr);

src/main/java/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawersStandard.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ public boolean setIsShrouded(int slot, boolean state) {
6868
return true;
6969
}
7070

71+
@Override
72+
public boolean isQuantified(int slot) {
73+
return TileEntityDrawersStandard.this.isQuantified();
74+
}
75+
76+
@Override
77+
public boolean setIsQuantified(int slot, boolean state) {
78+
TileEntityDrawersStandard.this.setIsQuantified(state);
79+
return true;
80+
}
81+
7182
@Override
7283
public boolean isStorageUnlimited(int slot) {
7384
return TileEntityDrawersStandard.this.isUnlimited();

src/main/java/com/jaquadro/minecraft/storagedrawers/client/renderer/TileEntityDrawersRenderer.java

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import net.minecraft.block.Block;
66
import net.minecraft.client.Minecraft;
7+
import net.minecraft.client.entity.EntityClientPlayerMP;
78
import net.minecraft.client.gui.FontRenderer;
89
import net.minecraft.client.renderer.OpenGlHelper;
910
import net.minecraft.client.renderer.RenderBlocks;
@@ -32,6 +33,7 @@
3233
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
3334
import com.jaquadro.minecraft.storagedrawers.block.BlockDrawers;
3435
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
36+
import com.jaquadro.minecraft.storagedrawers.util.CountFormatter;
3537

3638
import cpw.mods.fml.common.registry.GameData;
3739
import cpw.mods.fml.relauncher.Side;
@@ -267,6 +269,27 @@ public void renderTileEntityAt(TileEntity tile, double x, double y, double z, fl
267269
// Swallow exception
268270
}
269271

272+
if (StorageDrawers.config.cache.enableQuantifyUpgrades && tileDrawers.isQuantified()) {
273+
EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer;
274+
double dx = tile.xCoord + 0.5 - player.posX;
275+
double dy = tile.yCoord + 0.5 - player.posY;
276+
double dz = tile.zCoord + 0.5 - player.posZ;
277+
double distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
278+
279+
float alpha = 1.0f;
280+
if (distance > 4.0) {
281+
alpha = Math.max(1.0f - (float) ((distance - 4.0) / 6.0), 0.05f);
282+
}
283+
284+
if (distance < 10.0) {
285+
for (int i = 0; i < tileDrawers.getDrawerCount(); i++) {
286+
if (!tileDrawers.isDrawerEnabled(i)) continue;
287+
288+
drawDrawerTexts(tileDrawers, i, side, depth, alpha);
289+
}
290+
}
291+
}
292+
270293
mc.gameSettings.fancyGraphics = cache;
271294

272295
GL11.glPopMatrix();
@@ -349,6 +372,83 @@ private void renderFastItemSet(TileEntityDrawers tile, ForgeDirection side, floa
349372
}
350373
}
351374

375+
private void drawDrawerTexts(TileEntityDrawers tile, int slot, ForgeDirection side, float depth, float alpha) {
376+
BlockDrawers block = (BlockDrawers) tile.getBlockType();
377+
int drawerCount = tile.getDrawerCount();
378+
379+
float offsetX = 8;
380+
float offsetY = 14;
381+
382+
switch (drawerCount) {
383+
case 1:
384+
break;
385+
case 2:
386+
offsetY = (slot == 0) ? 6 : 14;
387+
break;
388+
case 3:
389+
switch (slot) {
390+
case 0:
391+
offsetY = 7;
392+
break;
393+
case 1:
394+
offsetX = 4;
395+
break;
396+
case 2:
397+
offsetX = 12;
398+
break;
399+
}
400+
break;
401+
case 4:
402+
switch (slot) {
403+
case 0:
404+
offsetX = 4;
405+
offsetY = 6;
406+
break;
407+
case 1:
408+
offsetX = 4;
409+
break;
410+
case 2:
411+
offsetX = 12;
412+
offsetY = 6;
413+
break;
414+
case 3:
415+
offsetX = 12;
416+
break;
417+
}
418+
break;
419+
}
420+
421+
renderText(
422+
CountFormatter.format(this.func_147498_b(), tile.getDrawer(slot)),
423+
side,
424+
offsetX,
425+
offsetY,
426+
1f - depth + block.getTrimDepth() - 0.005f,
427+
alpha);
428+
}
429+
430+
private void renderText(String renderString, ForgeDirection side, float offsetX, float offsetY, float offsetZ,
431+
float alpha) {
432+
int stringWidth = this.func_147498_b().getStringWidth(renderString);
433+
434+
GL11.glPushMatrix();
435+
436+
this.alignRendering(side);
437+
this.moveRendering(0.125f, offsetX, offsetY, offsetZ);
438+
439+
GL11.glDepthMask(false);
440+
GL11.glEnable(GL11.GL_BLEND);
441+
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
442+
443+
this.func_147498_b()
444+
.drawString(renderString, -stringWidth / 2, 0, (int) (255 * alpha) << 24 | 255 << 16 | 255 << 8 | 255);
445+
446+
GL11.glDepthMask(true);
447+
GL11.glDisable(GL11.GL_BLEND);
448+
449+
GL11.glPopMatrix();
450+
}
451+
352452
private void renderFancyItem(ItemStack itemStack, TileEntityDrawers tile, int slot, ForgeDirection side,
353453
float depth) {
354454
int drawerCount = tile.getDrawerCount();

src/main/java/com/jaquadro/minecraft/storagedrawers/config/ConfigManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public static class ConfigCache {
6262
public boolean enableVoidUpgrades;
6363
public boolean enableCreativeUpgrades;
6464
public boolean enableShroudUpgrades;
65+
public boolean enableQuantifyUpgrades;
6566
public boolean enablePersonalUpgrades;
6667
public boolean enableSortingUpgrades;
6768
public boolean enableRedstoneUpgrades;
@@ -341,6 +342,8 @@ public void syncConfig() {
341342
.setLanguageKey(LANG_PREFIX + "prop.enableCreativeUpgrades").setRequiresMcRestart(true).getBoolean();
342343
cache.enableShroudUpgrades = config.get(Configuration.CATEGORY_GENERAL, "enableShroudUpgrades", true)
343344
.setLanguageKey(LANG_PREFIX + "prop.enableShroudUpgrades").setRequiresMcRestart(true).getBoolean();
345+
cache.enableQuantifyUpgrades = config.get(Configuration.CATEGORY_GENERAL, "enableQuantifyUpgrades", true)
346+
.setLanguageKey(LANG_PREFIX + "prop.enableQuantifyUpgrades").setRequiresMcRestart(true).getBoolean();
344347
cache.enablePersonalUpgrades = config.get(Configuration.CATEGORY_GENERAL, "enablePersonalUpgrades", true)
345348
.setLanguageKey(LANG_PREFIX + "prop.enablePersonalUpgrades").setRequiresMcRestart(true).getBoolean();
346349
cache.enableSortingUpgrades = config.get(Configuration.CATEGORY_GENERAL, "enableSortingUpgrades", true)

src/main/java/com/jaquadro/minecraft/storagedrawers/core/ModItems.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
66
import com.jaquadro.minecraft.storagedrawers.item.ItemPersonalKey;
7+
import com.jaquadro.minecraft.storagedrawers.item.ItemQuantifyKey;
78
import com.jaquadro.minecraft.storagedrawers.item.ItemShroudKey;
89
import com.jaquadro.minecraft.storagedrawers.item.ItemTape;
910
import com.jaquadro.minecraft.storagedrawers.item.ItemUpgrade;
@@ -27,6 +28,7 @@ public class ModItems {
2728
public static ItemUpgradeRedstone upgradeRedstone;
2829
public static ItemShroudKey shroudKey;
2930
public static ItemPersonalKey personalKey;
31+
public static ItemQuantifyKey quantifyKey;
3032
public static ItemTape tape;
3133
public static ItemUpgradeDowngrade upgradeDowngrade;
3234

@@ -44,6 +46,7 @@ public void init() {
4446

4547
shroudKey = new ItemShroudKey(makeName("shroudKey"));
4648
personalKey = new ItemPersonalKey(makeName("personalKey"));
49+
quantifyKey = new ItemQuantifyKey(makeName("quantifyKey"));
4750
tape = new ItemTape(makeName("tape"));
4851

4952
GameRegistry.registerItem(upgradeTemplate, "upgradeTemplate");
@@ -58,6 +61,7 @@ public void init() {
5861
GameRegistry.registerItem(upgradeRedstone, "upgradeRedstone");
5962
if (StorageDrawers.config.cache.enableLockUpgrades) GameRegistry.registerItem(upgradeLock, "upgradeLock");
6063
if (StorageDrawers.config.cache.enableShroudUpgrades) GameRegistry.registerItem(shroudKey, "shroudKey");
64+
if (StorageDrawers.config.cache.enableQuantifyUpgrades) GameRegistry.registerItem(quantifyKey, "quantifyKey");
6165
if (StorageDrawers.config.cache.enablePersonalUpgrades) GameRegistry.registerItem(personalKey, "personalKey");
6266
if (StorageDrawers.config.cache.enableTape) GameRegistry.registerItem(tape, "tape");
6367
GameRegistry.registerItem(upgradeDowngrade, "upgradeDowngrade");

0 commit comments

Comments
 (0)