Skip to content

Commit

Permalink
Merge pull request #33 from GiantTreeLP/1.10.2-wip
Browse files Browse the repository at this point in the history
1.10.2 wip
  • Loading branch information
GiantTreeLP committed Aug 4, 2016
2 parents b28db78 + c5b97db commit 01dc46b
Show file tree
Hide file tree
Showing 15 changed files with 1,027 additions and 562 deletions.
17 changes: 9 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,33 @@ buildscript {
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT'
classpath "gradle.plugin.com.matthewprenger:CurseGradle:1.0.7"
classpath 'org.standardout:gradle-versioneye-plugin:1.5.0-SNAPSHOT'
}
}

plugins {
id 'com.matthewprenger.cursegradle' version "1.0.8"
id "org.standardout.versioneye" version "1.4.0"
}

repositories {
mavenCentral()
}

apply plugin: 'org.standardout.versioneye'
apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'maven'
apply plugin: 'java'
apply plugin: "com.matthewprenger.cursegradle"
compileJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}

version = "1.10.2-0.4.3"
version = "1.10.2-0.4.4"
group = "gtlp.prettyniceores" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
//noinspection GroovyUnusedAssignment
archivesBaseName = "prettyniceores"

minecraft {
version = "1.10.2-12.18.1.2018"
version = "1.10.2-12.18.1.2044"
runDir = "run"

// the mappings can be changed at any time, and must be in the following format.
Expand Down Expand Up @@ -73,7 +75,6 @@ dependencies {
// for more info...
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html
compile 'junit:junit:4.12'
}

processResources {
Expand Down Expand Up @@ -109,4 +110,4 @@ minecraft {
replaceIn "Constants.java"
replace "\${version}", project.version
replace "\${mcversion}", project.minecraft.version
}
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Jul 07 02:04:11 CEST 2016
#Tue Jul 26 20:41:48 CEST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.7-all.zip
396 changes: 0 additions & 396 deletions guard.pro

This file was deleted.

1 change: 1 addition & 0 deletions setup-idea.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gradlew setupdecompworkspace idea genintellijruns
93 changes: 41 additions & 52 deletions src/main/java/gtlp/prettyniceores/PrettyNiceOres.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gtlp.prettyniceores;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import gtlp.prettyniceores.blocks.modded.*;
import gtlp.prettyniceores.blocks.vanilla.*;
Expand All @@ -10,7 +11,6 @@
import gtlp.prettyniceores.interfaces.INamedBlock;
import gtlp.prettyniceores.interfaces.IOreDictCompatible;
import gtlp.prettyniceores.interfaces.ISmeltable;
import gtlp.prettyniceores.items.DebugAndTestingItem;
import gtlp.prettyniceores.recipes.ShapelessOreDictRecipe;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -39,8 +39,6 @@
import org.apache.logging.log4j.Logger;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;
Expand All @@ -59,7 +57,6 @@

public class PrettyNiceOres {
public static final Logger LOGGER = LogManager.getLogger(Constants.MOD_ID);

public static final CreativeTabs CREATIVE_TAB = new CreativeTabs(Constants.MOD_ID) {
@SuppressWarnings("ConstantConditions")
@SideOnly(Side.CLIENT)
Expand All @@ -70,20 +67,19 @@ public Item getTabIconItem() {
}
};

private static final Map<String, Block> blockList = new HashMap<>();
private static final Map<String, Item> itemList = new HashMap<>();
private static final Map<String, ItemBlock> itemBlockList = new HashMap<>();
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
private static final List<IRecipe> recipeList = new ArrayList<>();
private static final Map<String, Block> BLOCK_MAP = Maps.newHashMap();
private static final Map<String, Item> ITEM_MAP = Maps.newHashMap();
private static final Map<String, ItemBlock> ITEMBLOCK_MAP = Maps.newHashMap();
private static final List<IRecipe> recipeList = Lists.newArrayList();

@SidedProxy(clientSide = "gtlp.prettyniceores.client.ClientProxy", serverSide = "gtlp.prettyniceores.common.CommonProxy")
public static CommonProxy proxy;
@Mod.Instance
private static PrettyNiceOres instance;
private NiceConfig config;

public static Map<String, Block> getBlockList() {
return blockList;
public static Map<String, Block> getBlockMap() {
return BLOCK_MAP;
}

/**
Expand All @@ -92,8 +88,8 @@ public static Map<String, Block> getBlockList() {
* @param item to register the item renderer for
*/
@SideOnly(Side.CLIENT)
private static void registerItemRenderer(Item item, int meta) {
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, meta, new ModelResourceLocation(item.getRegistryName(), "inventory"));
private static void registerItemRenderer(Item item) {
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory"));
}

/**
Expand Down Expand Up @@ -124,55 +120,50 @@ private static void addSmeltingRecipe(Block block) {
}
}

private static void filterBlocksAndApplyConfig(final Map<String, Block> blockList, Configuration config) {
private static void filterBlocksAndApplyConfig(Configuration config) {
config.setCategoryComment(Constants.CATEGORY_ENABLED_BLOCKS, I18n.format(String.format(Constants.CONFIG_S_CATEGORY, Constants.CATEGORY_ENABLED_BLOCKS)));
ConcurrentMap<String, Block> newBlockList = Maps.newConcurrentMap();
blockList.entrySet().forEach(entry -> {
PrettyNiceOres.BLOCK_MAP.entrySet().forEach(entry -> {
Property prop = config.get(Constants.CATEGORY_ENABLED_BLOCKS, entry.getKey(), "true", I18n.format("config.enabled_blocks.block.comment", entry.getValue().getLocalizedName()), Property.Type.BOOLEAN);
if (prop.getBoolean()) {
newBlockList.put(entry.getKey(), entry.getValue());
}
}
);
blockList.clear();
blockList.putAll(newBlockList);
PrettyNiceOres.BLOCK_MAP.clear();
PrettyNiceOres.BLOCK_MAP.putAll(newBlockList);
}

/**
* Adds all replacements for the basic vanilla ores
*
* @param blockList list to add blocks to
*/
private static void addVanillaOres(final Map<String, Block> blockList) {
blockList.put(NiceIronOre.NAME, new NiceIronOre());
blockList.put(NiceGoldOre.NAME, new NiceGoldOre());
blockList.put(NiceCoalOre.NAME, new NiceCoalOre());
blockList.put(NiceRedstoneOre.NAME, new NiceRedstoneOre());
blockList.put(NiceLapisOre.NAME, new NiceLapisOre());
blockList.put(NiceDiamondOre.NAME, new NiceDiamondOre());
blockList.put(NiceEmeraldOre.NAME, new NiceEmeraldOre());
blockList.put(NiceNetherQuartzOre.NAME, new NiceNetherQuartzOre());
private static void addVanillaOres(Map<String, Block> blockMap) {
blockMap.put(NiceIronOre.NAME, new NiceIronOre());
blockMap.put(NiceGoldOre.NAME, new NiceGoldOre());
blockMap.put(NiceCoalOre.NAME, new NiceCoalOre());
blockMap.put(NiceRedstoneOre.NAME, new NiceRedstoneOre());
blockMap.put(NiceLapisOre.NAME, new NiceLapisOre());
blockMap.put(NiceDiamondOre.NAME, new NiceDiamondOre());
blockMap.put(NiceEmeraldOre.NAME, new NiceEmeraldOre());
blockMap.put(NiceNetherQuartzOre.NAME, new NiceNetherQuartzOre());
}

/**
* Adds all replacements for mod ores, if they have been created by any other mod.
*
* @param blockList list to add blocks to
* @param blockMap list to add blocks to
*/
private static void addModOres(final Map<String, Block> blockList) {
Block[] blockArray = {
new NiceCopperOre(),
private static void addModOres(Map<String, Block> blockMap) {

Stream.of(new NiceCopperOre(),
new NiceTinOre(),
new NiceSilverOre(),
new NiceLeadOre(),
new NiceNickelOre(),
new NicePlatinumOre(),
new NiceZincOre(),
new NiceMercuryOre(),
};

Stream.of(blockArray).filter(block -> block instanceof IOreDictCompatible && block instanceof INamedBlock)
.forEach(block -> blockList.put(((INamedBlock) block).getName(), block));
new NiceMercuryOre()).filter(block -> block instanceof IOreDictCompatible && block instanceof INamedBlock)
.forEach(block -> blockMap.put(block.getName(), block));
}

public static NiceConfig getConfig() {
Expand All @@ -191,27 +182,27 @@ public void preInit(FMLPreInitializationEvent event) {

RecipeSorter.register(Constants.MOD_ID + ":shapelessoredict", ShapelessOreDictRecipe.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless");

addVanillaOres(blockList);
addModOres(blockList);
addVanillaOres(BLOCK_MAP);
addModOres(BLOCK_MAP);

filterBlocksAndApplyConfig(blockList, config);
filterBlocksAndApplyConfig(config);
addItems();

blockList.forEach((name, block) -> {
BLOCK_MAP.forEach((name, block) -> {
ItemBlock itemBlock = new ItemBlock(block);
itemBlock.setRegistryName(block.getRegistryName());
itemBlockList.put(block instanceof INamedBlock ? ((INamedBlock) block).getName() : block.getRegistryName().getResourcePath(), itemBlock);
ITEMBLOCK_MAP.put(block instanceof INamedBlock ? ((INamedBlock) block).getName() : block.getRegistryName().getResourcePath(), itemBlock);
GameRegistry.register(block);
});
itemBlockList.forEach((name, item) -> {
ITEMBLOCK_MAP.forEach((name, item) -> {
GameRegistry.register(item);
Block block = item.getBlock();
if (block instanceof IOreDictCompatible) {
OreDictionary.registerOre(((IOreDictCompatible) block).getOreDictType(), item);
}
addSmeltingRecipe(block);
});
itemList.forEach((name, item) -> {
ITEM_MAP.forEach((name, item) -> {
GameRegistry.register(item);
if (item instanceof IOreDictCompatible) {
OreDictionary.registerOre(((IOreDictCompatible) item).getOreDictType(), item);
Expand All @@ -228,9 +219,7 @@ public void preInit(FMLPreInitializationEvent event) {
* Adds items.
*/
private void addItems() {
if (config.get(Constants.CATEGORY_DEBUG, "debug_item", "false", "", Property.Type.BOOLEAN).getBoolean()) {
itemList.put(DebugAndTestingItem.NAME, new DebugAndTestingItem());
}

}

/**
Expand All @@ -240,17 +229,17 @@ private void addItems() {
*/
@Mod.EventHandler
public void init(FMLInitializationEvent event) {
itemList.forEach((name, item) -> {
ITEM_MAP.forEach((name, item) -> {
if (event.getSide().isClient()) {
registerItemRenderer(item, 0);
registerItemRenderer(item);
}
});
itemBlockList.forEach((name, item) -> {
ITEMBLOCK_MAP.forEach((name, item) -> {
if (event.getSide().isClient()) {
registerItemRenderer(item, 0);
registerItemRenderer(item);
}
});
blockList.entrySet().stream().filter(entry -> entry.getValue() instanceof IOreDictCompatible).forEach(entry -> {
BLOCK_MAP.entrySet().stream().filter(entry -> entry.getValue() instanceof IOreDictCompatible).forEach(entry -> {
IOreDictCompatible block = (IOreDictCompatible) entry.getValue();
GameRegistry.addRecipe(new ShapelessOreDictRecipe(block.getOreDictType(), block.getOreDictType()));
});
Expand Down
67 changes: 43 additions & 24 deletions src/main/java/gtlp/prettyniceores/blocks/NiceOreBase.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package gtlp.prettyniceores.blocks;

import com.google.common.collect.Lists;
import gtlp.prettyniceores.Constants;
import gtlp.prettyniceores.PrettyNiceOres;
import gtlp.relocate.org.apache.commons.math3.distribution.EnumeratedDistribution;
import net.minecraft.block.Block;
import net.minecraft.block.BlockOre;
import net.minecraft.block.state.IBlockState;
Expand All @@ -11,9 +13,11 @@
import net.minecraft.init.Blocks;
import net.minecraft.init.Enchantments;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.World;
import net.minecraftforge.event.ForgeEventFactory;
import org.apache.commons.lang3.time.StopWatch;
import org.apache.logging.log4j.Level;

Expand All @@ -32,6 +36,10 @@ public abstract class NiceOreBase extends BlockOre {
new Vec3i(0, -1, 0), new Vec3i(0, -1, 1), new Vec3i(0, 0, -1), new Vec3i(0, 0, 1), new Vec3i(0, 1, -1), new Vec3i(0, 1, 0),
new Vec3i(0, 1, 1), new Vec3i(1, -1, -1), new Vec3i(1, -1, 0), new Vec3i(1, -1, 1), new Vec3i(1, 0, -1), new Vec3i(1, 0, 0),
new Vec3i(1, 0, 1), new Vec3i(1, 1, -1), new Vec3i(1, 1, 0), new Vec3i(1, 1, 1)};

//Weighted distribution of damage dealt to the tool. Seems fair.
@SuppressWarnings("unchecked")
private static final EnumeratedDistribution<Integer> damageDistribution = new EnumeratedDistribution<>(Lists.newArrayList(new EnumeratedDistribution.Pair<>(0, 0.1D), new EnumeratedDistribution.Pair<>(1, 0.3D), new EnumeratedDistribution.Pair<>(2, 0.4D), new EnumeratedDistribution.Pair<>(3, 0.2D)));
//Tested thread stack limit. Global constant, no matter what the actual set stack size is.
private static final int STACK_LIMIT = 1024;

Expand Down Expand Up @@ -83,7 +91,6 @@ public final boolean removedByPlayer(@Nonnull IBlockState state, World world, @N
getAdjacentBlocks(world, pos, world.getBlockState(pos).getBlock(), player, itemMainhand, blocks);
stopWatch.stop();
PrettyNiceOres.LOGGER.printf(Level.INFO, "Removed %d blocks in %d ms", blocks.get(), stopWatch.getTime());
itemMainhand.attemptDamageItem(itemMainhand.getItemDamage() % 2 == 0 ? 1 : 2, world.rand);
}
}
}
Expand All @@ -104,32 +111,44 @@ private void getAdjacentBlocks(World world, BlockPos pos, Block block, EntityPla
if (!world.getChunkFromBlockCoords(pos).isLoaded()) {
return;
}
if (itemMainhand != null && itemMainhand.canHarvestBlock(world.getBlockState(pos)) && itemMainhand.getItemDamage() <= itemMainhand.getMaxDamage()) {
int silktouchLvl = EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, itemMainhand);
if (silktouchLvl == 0) {
int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, itemMainhand);
world.getBlockState(pos).getBlock().dropBlockAsItem(world, player.getPosition(), world.getBlockState(pos), fortune);
if (block.getExpDrop(world.getBlockState(pos), world, pos, fortune) > 0) {
world.spawnEntityInWorld(new EntityXPOrb(world, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), block.getExpDrop(world.getBlockState(pos), world, pos, fortune)));
if (itemMainhand != null) {
if (itemMainhand.canHarvestBlock(world.getBlockState(pos))) {
int silktouchLvl = EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, itemMainhand);
if (silktouchLvl == 0) {
int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, itemMainhand);
world.getBlockState(pos).getBlock().dropBlockAsItem(world, player.getPosition(), world.getBlockState(pos), fortune);
if (block.getExpDrop(world.getBlockState(pos), world, pos, fortune) > 0) {
world.spawnEntityInWorld(new EntityXPOrb(world, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), block.getExpDrop(world.getBlockState(pos), world, pos, fortune)));
}
} else if (silktouchLvl >= 1) {
ItemStack itemStack = createStackedBlock(world.getBlockState(pos));
if (itemStack != null) {
Block.spawnAsEntity(world, player.getPosition(), itemStack);
}
}
} else if (silktouchLvl >= 1) {
ItemStack itemStack = createStackedBlock(world.getBlockState(pos));
if (itemStack != null) {
Block.spawnAsEntity(world, player.getPosition(), itemStack);

//Destroy the block without any effects (prevents crashes caused by too many sounds or particles)
world.setBlockState(pos, Blocks.AIR.getDefaultState(), world.isRemote ? 11 : 3);
//Increase amount of destroyed blocks
blocks.getAndAdd(1);

//Damage the item if possible, destroy if damaged more than possible or size of stack is 0
//Uses optimized comparisons to 0 (faster on CPU than arbitrary comparisons, useful for our bulk destruction)
itemMainhand.damageItem(damageDistribution.sample(), player);
if (itemMainhand.stackSize <= 0 || itemMainhand.getMaxDamage() - itemMainhand.getItemDamage() <= 0) {
ForgeEventFactory.onPlayerDestroyItem(player, itemMainhand, EnumHand.MAIN_HAND);
player.setHeldItem(EnumHand.MAIN_HAND, null);
return;
}
}

//Destroy the block without any effects (prevents crashes caused by too many sounds or particles)
world.setBlockState(pos, Blocks.AIR.getDefaultState(), world.isRemote ? 11 : 3);
//Increase amount of destroyed blocks
blocks.getAndAdd(1);
itemMainhand.attemptDamageItem(itemMainhand.getItemDamage() % 2 == 0 || itemMainhand.getMaxDamage() - itemMainhand.getItemDamage() == 1 ? 1 : 2, world.rand);
for (Vec3i vector : ADJACENT) {
if (Thread.currentThread().getStackTrace().length < STACK_LIMIT - 1) {
BlockPos posAdjacent = pos.add(vector);
IBlockState candidateBlockState = world.getBlockState(posAdjacent);
if (candidateBlockState.getBlock() == block) {
((NiceOreBase) candidateBlockState.getBlock()).getAdjacentBlocks(world, posAdjacent, block, player, itemMainhand, blocks);
//Recurse further over all adjacent blocks
for (Vec3i vector : ADJACENT) {
if (Thread.currentThread().getStackTrace().length < STACK_LIMIT - 1) {
BlockPos posAdjacent = pos.add(vector);
IBlockState candidateBlockState = world.getBlockState(posAdjacent);
if (candidateBlockState.getBlock() == block) {
((NiceOreBase) candidateBlockState.getBlock()).getAdjacentBlocks(world, posAdjacent, block, player, itemMainhand, blocks);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class NiceOresGenerator implements IWorldGenerator {
private final ConcurrentMap<ItemStackHolder, IBlockState> replacementMap = Maps.newConcurrentMap();

public NiceOresGenerator() {
PrettyNiceOres.getBlockList().entrySet().stream().filter(entry -> entry.getValue() instanceof INiceOre && entry.getValue() instanceof IOreDictCompatible).forEach(niceOre -> OreDictionary.getOres(((IOreDictCompatible) niceOre.getValue()).getOreDictType()).forEach(stack -> {
PrettyNiceOres.getBlockMap().entrySet().stream().filter(entry -> entry.getValue() instanceof INiceOre && entry.getValue() instanceof IOreDictCompatible).forEach(niceOre -> OreDictionary.getOres(((IOreDictCompatible) niceOre.getValue()).getOreDictType()).forEach(stack -> {
if (stack.getItem() instanceof ItemBlock && !(stack.getItem() instanceof INiceOre)) {
replacementMap.put(new ItemStackHolder(stack), niceOre.getValue().getDefaultState());
}
Expand Down
Loading

0 comments on commit 01dc46b

Please sign in to comment.