Added tuning driver tool

Added recipes sorting support
This commit is contained in:
LemADEC 2017-02-23 14:00:04 +01:00
parent cfbd6567bc
commit e37a0a3afd
11 changed files with 210 additions and 56 deletions

View file

@ -10,6 +10,8 @@ import cr0s.warpdrive.block.atomic.*;
import cr0s.warpdrive.block.detection.*;
import cr0s.warpdrive.block.forcefield.*;
import cr0s.warpdrive.block.hull.BlockHullStairs;
import cr0s.warpdrive.config.RecipeParticleShapedOre;
import cr0s.warpdrive.config.RecipeTuningDriver;
import cr0s.warpdrive.damage.*;
import cr0s.warpdrive.item.*;
import net.minecraft.block.Block;
@ -36,6 +38,7 @@ import net.minecraftforge.common.ForgeChunkManager.Type;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.oredict.RecipeSorter;
import org.apache.logging.log4j.Logger;
import cpw.mods.fml.client.registry.RenderingRegistry;
@ -172,7 +175,7 @@ public class WarpDrive implements LoadingCallback {
public static ItemComponent itemComponent;
public static ItemCrystalToken itemCrystalToken;
public static ItemUpgrade itemUpgrade;
public static ItemTuningFork itemTuningRod;
public static ItemTuningFork itemTuningFork;
public static ItemTuningDriver itemTuningDriver;
public static ItemForceFieldShape itemForceFieldShape;
public static ItemForceFieldUpgrade itemForceFieldUpgrade;
@ -222,6 +225,9 @@ public class WarpDrive implements LoadingCallback {
WarpDriveConfig.onFMLpreInitialization(event.getModConfigurationDirectory().getAbsolutePath());
RecipeSorter.register("warpdrive:particleShaped", RecipeParticleShapedOre.class, RecipeSorter.Category.SHAPED, "before:minecraft:shaped");
RecipeSorter.register("warpdrive:tuningDriver", RecipeTuningDriver.class, RecipeSorter.Category.SHAPELESS, "before:minecraft:shapeless");
if (FMLCommonHandler.instance().getSide().isClient()) {
MinecraftForge.EVENT_BUS.register(new RenderOverlayCamera(Minecraft.getMinecraft()));
@ -528,12 +534,12 @@ public class WarpDrive implements LoadingCallback {
}
// TOOL ITEMS
itemTuningRod = new ItemTuningFork();
GameRegistry.registerItem(itemTuningRod, "itemTuningRod");
/*
itemTuningFork = new ItemTuningFork();
GameRegistry.registerItem(itemTuningFork, "itemTuningFork");
itemTuningDriver = new ItemTuningDriver();
GameRegistry.registerItem(itemTuningDriver, "itemTuningDriver");
/**/
// FORCE FIELD UPGRADES
itemForceFieldShape = new ItemForceFieldShape();
GameRegistry.registerItem(itemForceFieldShape, "itemForceFieldShape");
@ -802,7 +808,11 @@ public class WarpDrive implements LoadingCallback {
case "WarpDrive:warpCore":
mapping.remap(Item.getItemFromBlock(blockShipCore));
break;
case "WarpDrive:itemTuningRod":
mapping.remap(itemTuningFork);
break;
}
} else if (mapping.type == GameRegistry.Type.BLOCK) {
switch (mapping.name) {
case "WarpDrive:airBlock":

View file

@ -14,8 +14,4 @@ public interface IParticleContainerItem {
// called during recipe match to set amount to consume in next call to getContainerItem
void setAmountToConsume(ItemStack container, int amount);
// called during recipe creation to display 'fake' items in NEI, so our handler takes priority
// NBT changes aren't supported by default, so you need to change item or damage.
ItemStack getFakeVariant(ItemStack container);
}

View file

@ -112,18 +112,8 @@ public class RecipeParticleShapedOre implements IRecipe {
itemStackIngredients[indexSlot++] = mapInputs.get(chr);
}
// add vanilla Shaped recipe for NEI support with an impossible tag so our handler still pass through
Object[] recipeDummy = recipe.clone();
for (int indexDummy = 0; indexDummy < recipeDummy.length; indexDummy++) {
Object objectDummy = recipeDummy[indexDummy];
if (objectDummy instanceof ItemStack && ((ItemStack) objectDummy).hasTagCompound()) {
ItemStack itemStackDummy = ((ItemStack) objectDummy).copy();
if (itemStackDummy.getItem() instanceof IParticleContainerItem) {
recipeDummy[indexDummy] = ((IParticleContainerItem) itemStackDummy.getItem()).getFakeVariant(itemStackDummy);
}
}
}
GameRegistry.addRecipe(new ShapedOreRecipe(result, recipeDummy));
// add lower priority vanilla Shaped recipe for NEI support
GameRegistry.addRecipe(new ShapedOreRecipe(result, recipe));
}
// add ore dictionary support to an existing (vanilla) recipe

View file

@ -0,0 +1,124 @@
package cr0s.warpdrive.config;
import cpw.mods.fml.common.registry.GameRegistry;
import cr0s.warpdrive.item.ItemTuningDriver;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.ShapelessOreRecipe;
import java.util.ArrayList;
// Used to change tuning driver values
public class RecipeTuningDriver implements IRecipe {
private ItemStack itemStackTool;
private ItemStack itemStackConsumable;
private int countDyesExpected;
private ItemStack itemStackResult = new ItemStack(Blocks.fire);
public RecipeTuningDriver(final ItemStack itemStackTool, final ItemStack itemStackConsumable, final int countDyes) {
this.itemStackTool = itemStackTool.copy();
this.itemStackConsumable = itemStackConsumable.copy();
this.countDyesExpected = countDyes;
// add lower priority vanilla Shaped recipe for NEI support
Object[] recipe = new Object[getRecipeSize()];
recipe[0] = itemStackTool;
recipe[1] = itemStackConsumable;
for (int index = 0; index < countDyes; index++) {
recipe[2 + index] = "dye";
}
GameRegistry.addRecipe(new ShapelessOreRecipe(itemStackResult, recipe));
}
// Returns an Item that is the result of this recipe
@Override
public ItemStack getCraftingResult(InventoryCrafting inventoryCrafting) {
return itemStackResult.copy();
}
// Returns the size of the recipe area
@Override
public int getRecipeSize() {
return 1 + (itemStackConsumable != null ? 1 : 0) + countDyesExpected;
}
@Override
public ItemStack getRecipeOutput() {
return itemStackResult;
}
// check if a recipe matches current crafting inventory
@Override
public boolean matches(InventoryCrafting inventoryCrafting, World world) {
ItemStack itemStackInput = null;
boolean isConsumableFound = false;
int dye = 0;
int countDyesFound = 0;
for (int indexSlot = 0; indexSlot <= inventoryCrafting.getSizeInventory(); indexSlot++) {
ItemStack itemStackSlot = inventoryCrafting.getStackInSlot(indexSlot);
//noinspection StatementWithEmptyBody
if (itemStackSlot == null) {
// continue
} else if (OreDictionary.itemMatches(itemStackSlot, itemStackTool, false)) {
// too many inputs?
if (itemStackInput != null) {
return false;
}
itemStackInput = itemStackSlot;
} else if (OreDictionary.itemMatches(itemStackSlot, itemStackConsumable, false)) {
// too many consumables?
if (isConsumableFound) {
return false;
}
isConsumableFound = true;
} else {
// find a matching dye from ore dictionary
boolean matched = false;
for (int indexDye = 0; indexDye < Recipes.oreDyes.length; indexDye++) {
ArrayList<ItemStack> itemStackDyes = OreDictionary.getOres(Recipes.oreDyes[indexDye]);
for (ItemStack itemStackDye : itemStackDyes) {
if (OreDictionary.itemMatches(itemStackSlot, itemStackDye, true)) {
// match found, update dye combination
matched = true;
countDyesFound++;
dye = dye * 16 + indexDye;
}
}
}
if (!matched) {
return false;
}
}
}
// missing input
if (itemStackInput == null) {
return false;
}
// missing or too many dyes
if (countDyesFound != countDyesExpected) {
return false;
}
// consumable missing or not required
if ( (itemStackConsumable != null && !isConsumableFound)
|| (itemStackConsumable == null && isConsumableFound) ) {
return false;
}
// build result
itemStackResult = itemStackInput.copy();
ItemTuningDriver.setValue(itemStackResult, dye);
return true;
}
}

View file

@ -12,6 +12,7 @@ import cr0s.warpdrive.item.ItemComponent;
import cr0s.warpdrive.item.ItemElectromagneticCell;
import cr0s.warpdrive.item.ItemForceFieldShape;
import cr0s.warpdrive.item.ItemForceFieldUpgrade;
import cr0s.warpdrive.item.ItemTuningDriver;
import cr0s.warpdrive.item.ItemUpgrade;
import net.minecraft.block.BlockColored;
import net.minecraft.init.Blocks;
@ -25,7 +26,7 @@ import net.minecraftforge.oredict.ShapelessOreRecipe;
* Hold the different recipe sets
*/
public class Recipes {
private static final String[] oreDyes = {
public static final String[] oreDyes = {
"dyeBlack",
"dyeRed",
"dyeGreen",
@ -1415,26 +1416,41 @@ public class Recipes {
'w', Blocks.wool,
'r', rubberOrLeather));
// Tuning rod ore dictionary
// Tuning fork ore dictionary
for (int dyeColor = 0; dyeColor < 16; dyeColor++) {
OreDictionary.registerOre("itemTuningRod", new ItemStack(WarpDrive.itemTuningRod, 1, dyeColor));
OreDictionary.registerOre("itemTuningFork", new ItemStack(WarpDrive.itemTuningFork, 1, dyeColor));
}
// Tuning rod variations
// Tuning fork variations
for (int dyeColor = 0; dyeColor < 16; dyeColor++) {
// crafting tuning rod
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(WarpDrive.itemTuningRod, 1, dyeColor), false, " q", "iX ", " i ",
'q', Items.quartz, // "gemQuartz", // Items.quartz,
'i', Items.iron_ingot, // "ingotIron",
// crafting tuning fork
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(WarpDrive.itemTuningFork, 1, dyeColor), false, " q", "iX ", " i ",
'q', "gemQuartz",
'i', "ingotIron",
'X', oreDyes[dyeColor] ));
// changing colors
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(WarpDrive.itemTuningRod, 1, dyeColor),
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(WarpDrive.itemTuningFork, 1, dyeColor),
oreDyes[dyeColor],
"itemTuningRod"));
"itemTuningFork"));
}
// Tuning driver crafting
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(WarpDrive.itemTuningDriver, 1, ItemTuningDriver.MODE_VIDEO_CHANNEL), false, " q", "pm ", "d ",
'q', "gemQuartz",
'p', Blocks.heavy_weighted_pressure_plate,
'd', ItemComponent.getItemStack(EnumComponentType.DIAMOND_CRYSTAL),
'm', ItemComponent.getItemStack(EnumComponentType.MEMORY_CRYSTAL) ));
// Tuning driver configuration
GameRegistry.addRecipe(new RecipeTuningDriver(new ItemStack(WarpDrive.itemTuningDriver, 1, ItemTuningDriver.MODE_VIDEO_CHANNEL),
new ItemStack(Items.redstone), 7));
GameRegistry.addRecipe(new RecipeTuningDriver(new ItemStack(WarpDrive.itemTuningDriver, 1, ItemTuningDriver.MODE_BEAM_FREQUENCY),
new ItemStack(Items.redstone), 4));
GameRegistry.addRecipe(new RecipeTuningDriver(new ItemStack(WarpDrive.itemTuningDriver, 1, ItemTuningDriver.MODE_CONTROL_CHANNEL),
new ItemStack(Items.redstone), 7));
// HULL blocks and variations
initDynamicHull();

View file

@ -21,7 +21,6 @@ import java.util.List;
public class ItemElectromagneticCell extends Item implements IParticleContainerItem {
private static final String AMOUNT_TO_CONSUME_TAG = "amountToConsume";
private static final int FAKE_DAMAGE = 1000;
@SideOnly(Side.CLIENT)
private IIcon[] icons = new IIcon[31];
@ -74,11 +73,7 @@ public class ItemElectromagneticCell extends Item implements IParticleContainerI
@Override
@SideOnly(Side.CLIENT)
public IIcon getIconFromDamage(int damage) {
if (damage > FAKE_DAMAGE) {
return icons[(damage - FAKE_DAMAGE) % icons.length];
} else {
return icons[damage % icons.length];
}
return icons[damage % icons.length];
}
public static ItemStack getItemStackNoCache(final Particle particle, final int amount) {
@ -148,13 +143,6 @@ public class ItemElectromagneticCell extends Item implements IParticleContainerI
return 0;
}
@Override
public ItemStack getFakeVariant(ItemStack itemStack) {
ItemStack itemStackFake = itemStack.copy();
itemStackFake.setItemDamage(FAKE_DAMAGE + itemStack.getItemDamage());
return itemStackFake;
}
private static int getDamageLevel(ItemStack itemStack, final ParticleStack particleStack) {
if (!(itemStack.getItem() instanceof ItemElectromagneticCell)) {
WarpDrive.logger.error("Invalid ItemStack passed, expecting ItemElectromagneticCell: " + itemStack);

View file

@ -14,16 +14,19 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
import net.minecraft.util.StatCollector;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.api.IBeamFrequency;
import cr0s.warpdrive.api.IVideoChannel;
public class ItemTuningDriver extends Item implements IWarpTool {
static final int MODE_VIDEO_CHANNEL = 0;
static final int MODE_BEAM_FREQUENCY = 1;
static final int MODE_CONTROL_CHANNEL = 2;
public static final int MODE_VIDEO_CHANNEL = 0;
public static final int MODE_BEAM_FREQUENCY = 1;
public static final int MODE_CONTROL_CHANNEL = 2;
private IIcon icons[];
@ -145,29 +148,56 @@ public class ItemTuningDriver extends Item implements IWarpTool {
return itemStack;
}
public static ItemStack setValue(ItemStack itemStack, final int dye) {
switch (itemStack.getItemDamage()) {
case MODE_VIDEO_CHANNEL : return setVideoChannel(itemStack, dye);
case MODE_BEAM_FREQUENCY : return setBeamFrequency(itemStack, dye);
case MODE_CONTROL_CHANNEL: return setControlChannel(itemStack, dye);
default : return itemStack;
}
}
// server side version of EntityLivingBase.rayTrace
private static final double BLOCK_REACH_DISTANCE = 5.0D; // this is a client side hardcoded value, applicable to creative players
private static MovingObjectPosition getInteractingBlock(World world, EntityPlayer entityPlayer, final double distance) {
Vec3 vec3Position = Vec3.createVectorHelper(entityPlayer.posX, entityPlayer.posY + entityPlayer.eyeHeight, entityPlayer.posZ);
Vec3 vec3Look = entityPlayer.getLook(1.0F);
Vec3 vec3Target = vec3Position.addVector(vec3Look.xCoord * distance, vec3Look.yCoord * distance, vec3Look.zCoord * distance);
return world.func_147447_a(vec3Position, vec3Target, false, false, true);
}
@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer entityPlayer) {
if (world.isRemote || !(itemStack.getItem() instanceof ItemTuningDriver)) {
return itemStack;
}
if (entityPlayer.isSneaking()) {
// check if a block is in players reach
MovingObjectPosition movingObjectPosition = getInteractingBlock(world, entityPlayer, BLOCK_REACH_DISTANCE);
if (movingObjectPosition.typeOfHit != MovingObjectType.MISS) {
return itemStack;
}
if (entityPlayer.isSneaking() && entityPlayer.capabilities.isCreativeMode) {
switch (itemStack.getItemDamage()) {
case MODE_VIDEO_CHANNEL:
setVideoChannel(itemStack, world.rand.nextInt(IVideoChannel.VIDEO_CHANNEL_MAX));
WarpDrive.addChatMessage(entityPlayer, StatCollector.translateToLocalFormatted("warpdrive.video_channel.get",
getVideoChannel(itemStack)));
entityPlayer.getCommandSenderName(),
getVideoChannel(itemStack)));
return itemStack;
case MODE_BEAM_FREQUENCY:
setBeamFrequency(itemStack, world.rand.nextInt(IBeamFrequency.BEAM_FREQUENCY_MAX));
WarpDrive.addChatMessage(entityPlayer, StatCollector.translateToLocalFormatted("warpdrive.beam_frequency.get",
getBeamFrequency(itemStack)));
entityPlayer.getCommandSenderName(),
getBeamFrequency(itemStack)));
return itemStack;
case MODE_CONTROL_CHANNEL:
setControlChannel(itemStack, world.rand.nextInt(IControlChannel.CONTROL_CHANNEL_MAX));
WarpDrive.addChatMessage(entityPlayer, StatCollector.translateToLocalFormatted("warpdrive.control_channel.get",
getControlChannel(itemStack)));
entityPlayer.getCommandSenderName(),
getControlChannel(itemStack)));
return itemStack;
default:
@ -180,7 +210,7 @@ public class ItemTuningDriver extends Item implements IWarpTool {
itemStack.setItemDamage(MODE_BEAM_FREQUENCY);
entityPlayer.setCurrentItemOrArmor(0, itemStack);
break;
case MODE_BEAM_FREQUENCY:
itemStack.setItemDamage(MODE_CONTROL_CHANNEL);
entityPlayer.setCurrentItemOrArmor(0, itemStack);

View file

@ -130,7 +130,7 @@ item.warpdrive.tool.tuning_driver.video_channel.name=Video Channel Tuning Driver
item.warpdrive.tool.tuning_driver.beam_frequency.name=Beam Frequency Tuning Driver !!!
item.warpdrive.tool.tuning_driver.control_channel.name=Control Channel Tuning Driver !!!
item.warpdrive.tool.tuning_driver.tooltip.usage=§bRight click a block§7 to tune its crystals\n§bSneak§7 to change mode !!!
item.warpdrive.tool.tuning_driver.tooltip.usage=§bRight click a block§7 to tune its crystals\n§bSneak§7 to retrieve its value\n§bRight click air§7 to change mode !!!
item.warpdrive.tool.tuning_fork.name=Stimmgabel

View file

@ -130,7 +130,7 @@ item.warpdrive.tool.tuning_driver.video_channel.name=Video Channel Tuning Driver
item.warpdrive.tool.tuning_driver.beam_frequency.name=Beam Frequency Tuning Driver
item.warpdrive.tool.tuning_driver.control_channel.name=Control Channel Tuning Driver
item.warpdrive.tool.tuning_driver.tooltip.usage=§bRight click a block§7 to tune its crystals\n§bSneak§7 to change mode
item.warpdrive.tool.tuning_driver.tooltip.usage=§bRight click a block§7 to tune its crystals\n§bSneak§7 to retrieve its value\n§bRight click air§7 to change mode
item.warpdrive.tool.tuning_fork.name=Tuning Fork

View file

@ -130,7 +130,7 @@ item.warpdrive.tool.tuning_driver.video_channel.name=Ajusteur de canal vidéo
item.warpdrive.tool.tuning_driver.beam_frequency.name=Ajusteur de fréquence de faisceau
item.warpdrive.tool.tuning_driver.control_channel.name=Ajusteur de canal de contrôle
item.warpdrive.tool.tuning_driver.tooltip.usage=§bCliques droit sur un block§r pour ajuster ses cristaux\n§bAccroupi§r pour changer de mode
item.warpdrive.tool.tuning_driver.tooltip.usage=§bCliques droit sur un block§r pour ajuster ses cristaux\n§bAccroupi§r pour récupérer sa valeur\n§bCliques droit en l'air§r pour lire pour changer de mode
item.warpdrive.tool.tuning_fork.name=Diapason

View file

@ -130,7 +130,7 @@ item.warpdrive.tool.tuning_driver.video_channel.name=Video Channel Tuning Driver
item.warpdrive.tool.tuning_driver.beam_frequency.name=Beam Frequency Tuning Driver
item.warpdrive.tool.tuning_driver.control_channel.name=Control Channel Tuning Driver
item.warpdrive.tool.tuning_driver.tooltip.usage=§bRight click a block§7 to tune its crystals\n§bSneak§7 to change mode
item.warpdrive.tool.tuning_driver.tooltip.usage=§bRight click a block§7 to tune its crystals\n§bSneak§7 to retrieve its value\n§bRight click air§7 to change mode
item.warpdrive.tool.tuning_fork.name=Камертон