-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
319 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
Treasure2-1.12.2/src/com/someguyssoftware/treasure2/enums/Pearls.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** | ||
* | ||
*/ | ||
package com.someguyssoftware.treasure2.enums; | ||
|
||
import java.util.EnumSet; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* | ||
* @author Mark Gottschling on Aug 18, 2019 | ||
* | ||
*/ | ||
public enum Pearls implements IEnum { | ||
WHITE(0, "White PearlItem"), | ||
BLACK(1, "Black PearlItem"); | ||
|
||
private static final Map<Integer, IEnum> codes = new HashMap<Integer, IEnum>(); | ||
private static final Map<String, IEnum> values = new HashMap<String, IEnum>(); | ||
private Integer code; | ||
private String value; | ||
|
||
// setup reverse lookup | ||
static { | ||
for (Pearls p : EnumSet.allOf(Pearls.class)) { | ||
codes.put(p.getCode(), p); | ||
values.put(p.getValue(), p); | ||
} | ||
} | ||
|
||
/** | ||
* Full constructor | ||
* @param code | ||
* @param value | ||
*/ | ||
Pearls(Integer code, String value) { | ||
this.code = code; | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name(); | ||
} | ||
|
||
@Override | ||
public Integer getCode() { | ||
return code; | ||
} | ||
|
||
@Override | ||
public void setCode(Integer code) { | ||
this.code = code; | ||
} | ||
|
||
@Override | ||
public String getValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public void setValue(String value) { | ||
this.value = value; | ||
} | ||
|
||
/** | ||
* | ||
* @param code | ||
* @return | ||
*/ | ||
public static Pearls getByCode(Integer code) { | ||
return (Pearls) codes.get(code); | ||
} | ||
/** | ||
* | ||
* @param value | ||
* @return | ||
*/ | ||
public static Pearls getByValue(String value) { | ||
return (Pearls) values.get(value); | ||
} | ||
|
||
@Override | ||
public Map<Integer, IEnum> getCodes() { | ||
return codes; | ||
} | ||
@Override | ||
public Map<String, IEnum> getValues() { | ||
return values; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
Treasure2-1.12.2/src/com/someguyssoftware/treasure2/item/PearlItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
/** | ||
* | ||
*/ | ||
package com.someguyssoftware.treasure2.item; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Random; | ||
import java.util.Map.Entry; | ||
|
||
import com.someguyssoftware.gottschcore.cube.Cube; | ||
import com.someguyssoftware.gottschcore.item.ModItem; | ||
import com.someguyssoftware.gottschcore.loot.LootTable; | ||
import com.someguyssoftware.gottschcore.positional.Coords; | ||
import com.someguyssoftware.gottschcore.positional.ICoords; | ||
import com.someguyssoftware.gottschcore.random.RandomHelper; | ||
import com.someguyssoftware.gottschcore.world.WorldInfo; | ||
import com.someguyssoftware.treasure2.Treasure; | ||
import com.someguyssoftware.treasure2.block.TreasureBlocks; | ||
import com.someguyssoftware.treasure2.enums.Coins; | ||
import com.someguyssoftware.treasure2.enums.Pearls; | ||
import com.someguyssoftware.treasure2.enums.Rarity; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraft.client.util.ITooltipFlag; | ||
import net.minecraft.entity.item.EntityItem; | ||
import net.minecraft.init.Blocks; | ||
import net.minecraft.init.Items; | ||
import net.minecraft.inventory.InventoryHelper; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.text.TextFormatting; | ||
import net.minecraft.util.text.translation.I18n; | ||
import net.minecraft.world.World; | ||
|
||
/** | ||
* TODO implement Lombok and remove getter/setters | ||
* @author Mark Gottschling on Aug 18, 2019 | ||
* | ||
*/ | ||
public class PearlItem extends ModItem { | ||
|
||
public static final int MAX_STACK_SIZE = 8; | ||
private Pearls pearl; | ||
|
||
/** | ||
* | ||
*/ | ||
public PearlItem (String modID, String name) { | ||
super(); | ||
this.setItemName(modID, name); | ||
this.setMaxStackSize(MAX_STACK_SIZE); | ||
this.setCreativeTab(Treasure.TREASURE_TAB); | ||
this.pearl = Pearls.WHITE; | ||
} | ||
|
||
/** | ||
* | ||
* @param pearl | ||
*/ | ||
public PearlItem(String modID, String name, Pearls pearl) { | ||
this(modID, name); | ||
this.setPearl(pearl); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
@SuppressWarnings("deprecation") | ||
@Override | ||
public void addInformation(ItemStack stack, World worldIn, List<String> tooltip, ITooltipFlag flagIn) { | ||
super.addInformation(stack, worldIn, tooltip, flagIn); | ||
tooltip.add(TextFormatting.GOLD + I18n.translateToLocal("tooltip.label.coin")); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
@Override | ||
public boolean onEntityItemUpdate(EntityItem entityItem) { | ||
World world = entityItem.getEntityWorld(); | ||
if (WorldInfo.isClientSide(world)) { | ||
return super.onEntityItemUpdate(entityItem); | ||
} | ||
|
||
// get the position | ||
ICoords coords = new Coords(entityItem.getPosition()); | ||
Cube cube = new Cube(world, coords); | ||
Block block = cube.toBlock(); | ||
int numWishingWellBlocks = 0; | ||
// check if in water | ||
if (cube.equalsBlock(Blocks.WATER)) { | ||
// check if the water block is adjacent to 2 wishing well blocks | ||
ICoords checkCoords = coords.add(-1, 0, -1); | ||
for (int z = 0; z < 3; z++) { | ||
for (int x = 0; x < 3; x++) { | ||
Cube checkCube = new Cube(world, checkCoords); | ||
if (checkCube.equalsBlock(TreasureBlocks.WISHING_WELL_BLOCK)) { | ||
numWishingWellBlocks++; | ||
} | ||
if (numWishingWellBlocks >= 2) { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
List<LootTable> lootTables = new ArrayList<>(); | ||
if (numWishingWellBlocks >=2) { | ||
Random random = new Random(); | ||
|
||
// determine pearl type | ||
if (getPearl() == Pearls.WHITE) { | ||
lootTables.addAll(Treasure.LOOT_TABLES.getLootTableByRarity(Rarity.RARE)); | ||
} | ||
else if (getPearl() == Pearls.BLACK) { | ||
lootTables.addAll(Treasure.LOOT_TABLES.getLootTableByRarity(Rarity.EPIC)); | ||
} | ||
|
||
ItemStack stack = null; | ||
// handle if loot tables is null or size = 0. return an item (apple) to ensure continuing functionality | ||
if (lootTables == null || lootTables.size() == 0) { | ||
stack = new ItemStack(Items.DIAMOND); | ||
} | ||
else { | ||
// select a table | ||
LootTable table = lootTables.get(RandomHelper.randomInt(random, 0, lootTables.size()-1)); | ||
|
||
// generate a list of itemStacks from the table pools | ||
List<ItemStack> list =table.generateLootFromPools(random, Treasure.LOOT_TABLES.getContext()); | ||
|
||
// select one item randomly | ||
stack = list.get(list.size()-1); | ||
} | ||
|
||
// spawn the item | ||
if (stack != null) { | ||
InventoryHelper.spawnItemStack(world, (double)coords.getX(), (double)coords.getY()+1, (double)coords.getZ(), stack); | ||
} | ||
|
||
// remove the item entity | ||
entityItem.setDead(); | ||
return true; | ||
} | ||
} | ||
|
||
return super.onEntityItemUpdate(entityItem); | ||
} | ||
|
||
/** | ||
* @return the pearl | ||
*/ | ||
public Pearls getPearl() { | ||
return pearl; | ||
} | ||
/** | ||
* @param pearl the pearl to set | ||
*/ | ||
public PearlItem setPearl(Pearls pearl) { | ||
this.pearl = pearl; | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
Treasure2-1.12.2/src/resources/assets/treasure2/models/item/black_pearl.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"parent": "builtin/generated", | ||
"textures": { | ||
"layer0": "treasure2:items/pearls/black_pearl" | ||
}, | ||
"display": { | ||
"thirdperson_righthand": { | ||
"translation": [ 0, 1, 0], | ||
"scale":[ 0.25, 0.25, 0.25] | ||
}, | ||
"firstperson_righthand": { | ||
"translation": [ 0, 2, 0], | ||
"scale": [ 0.5, 0.5, 0.5 ] | ||
}, | ||
"ground": { | ||
"rotation": [ 0, 0, 0 ], | ||
"translation": [ 0, 1, 0], | ||
"scale":[ 0.25, 0.25, 0.25] | ||
} | ||
} | ||
} |
Oops, something went wrong.