Skip to content

Commit

Permalink
2.6.1 Update
Browse files Browse the repository at this point in the history
- Added a Silk Touch mode config option, if Silk Touch mode is disabled, players may enchant the Exchangers with Silk Touch to achieve Silk Touching on Exchangers or Fortune to get additional drops

- Added a PlaceEvent for when Exchangers tries to replace blocks, allows other mods to cancel the event, which also fixes an issue with Faction Mod, closes #41

- Migrated over to use string block IDs instead of integers

- Rewritten lots of translation stuff

- Changed all the camelCase translation keys to be lowercase with underscores

- Added a special blocks list for internal use

- Fixed a major problem with Exchangers not being able to replace blocks with metadata, closes #42

Internal code optimizations to greatly reduce redundancy

- Added a config option to allow Unbreaking enchant reducing chance of using power for Powered Exchangers, currently tested and works on all MC versions, enabled by default (Part of #37)

- Added a way to decrease range for Exchangers (by holding sneak and pressing the mode key)
  • Loading branch information
JackyyTV committed Jan 6, 2018
1 parent 6a164b3 commit 1b74e16
Show file tree
Hide file tree
Showing 65 changed files with 507 additions and 885 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
org.gradle.jvmargs=-Xmx4G
mc_version=1.12.2
forge_version=1.12.2-14.23.1.2575
mod_version=2.6
mod_version=2.6.1
mappings_version=snapshot_20170917
6 changes: 6 additions & 0 deletions src/main/java/jackyy/exchangers/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ public class Config {
//Misc
public static String[] blocksWhitelist;
public static boolean holdingEnchantment;
public static boolean unbreakingPoweredExchangers;
public static boolean useOreDictCircuits;
public static boolean doExchangersSilkTouch;

public static void readConfig() {
Configuration cfg = CommonProxy.config;
Expand Down Expand Up @@ -286,8 +288,12 @@ private static void initConfig(Configuration cfg) {
holdingEnchantment = cfg.getBoolean("Holding Enchantment", CATEGORY_MISC, true,
"If true, allows the Holding Enchantment from CoFHCore to be used in Powered Exchangers\n"
+ "Calculation formula: Base Energy + (Base Energy * Enchantment Level / 2)\n");
unbreakingPoweredExchangers = cfg.getBoolean("Unbreaking Enchantment Affects Powered Exchangers", CATEGORY_MISC, true,
"If true, allows Unbreaking Enchantment to affect Powered Exchangers");
useOreDictCircuits = cfg.getBoolean("Use OreDict Circuits", CATEGORY_MISC, false,
"If true, allows Circuits in Mekanism Exchanger recipes to use OreDict");
doExchangersSilkTouch = cfg.getBoolean("Exchangers Silk Touch", CATEGORY_MISC, true,
"If true, enables Silk Touch (gets the blocks itself rather than drops) in all Exchangers");

}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/jackyy/exchangers/Exchangers.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@Mod(modid = Exchangers.MODID, version = Exchangers.VERSION, name = Exchangers.MODNAME, dependencies = Exchangers.DEPENDS, guiFactory = Exchangers.GUIFACTORY, certificateFingerprint = "@FINGERPRINT@", acceptedMinecraftVersions = Exchangers.MCVERSION, useMetadata = true)
public class Exchangers {

public static final String VERSION = "1.12.2-2.6";
public static final String VERSION = "1.12.2-2.6.1";
public static final String MCVERSION = "[1.12,1.13)";
public static final String MODID = "exchangers";
public static final String MODNAME = "Exchangers";
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/jackyy/exchangers/client/Keys.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package jackyy.exchangers.client;

import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.client.settings.IKeyConflictContext;
import net.minecraftforge.client.settings.KeyConflictContext;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
Expand All @@ -9,7 +11,16 @@
@SideOnly(Side.CLIENT)
public class Keys {

public static final KeyBinding MODE_KEY = new KeyBinding("key.exchangermode", Keyboard.KEY_COMMA, "key.categories.exchangers");
public static final KeyBinding MODE_KEY = new KeyBinding("key.exchanger_mode", new IKeyConflictContext() {
@Override
public boolean isActive() {
return KeyConflictContext.IN_GAME.isActive();
}
@Override
public boolean conflicts(IKeyConflictContext other) {
return other == this || KeyConflictContext.IN_GAME.isActive();
}
}, Keyboard.KEY_COMMA, "key.categories.exchangers");

public static void init() {
ClientRegistry.registerKeyBinding(MODE_KEY);
Expand Down
254 changes: 142 additions & 112 deletions src/main/java/jackyy/exchangers/handler/ExchangerHandler.java

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main/java/jackyy/exchangers/handler/GUIHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void onGameOverlayRender(RenderGameOverlayEvent event) {
EntityPlayer player = (EntityPlayer) mc.getRenderViewEntity();

if (player == null || !mc.inGameHasFocus || !Minecraft.isGuiEnabled()) return;
if (player.getHeldItemMainhand() == null || !(player.getHeldItemMainhand().getItem() instanceof ItemExchangerBase)) return;
if (player.getHeldItemMainhand() == ItemStack.EMPTY || !(player.getHeldItemMainhand().getItem() instanceof ItemExchangerBase)) return;

ItemStack stack = player.getHeldItemMainhand();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package jackyy.exchangers.handler;

import jackyy.exchangers.item.ItemExchangerBase;
import jackyy.exchangers.util.StackUtil;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
Expand All @@ -13,7 +12,6 @@
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraftforge.client.event.RenderWorldLastEvent;
Expand All @@ -30,8 +28,8 @@ public class RenderOverlayHandler {
public void renderWorldLastEvent(RenderWorldLastEvent event) {
Minecraft mc = Minecraft.getMinecraft();
EntityPlayerSP player = mc.player;
ItemStack stack = player.getHeldItem(EnumHand.MAIN_HAND);
if (StackUtil.isEmpty(stack)) {
ItemStack stack = player.getHeldItemMainhand();
if (stack == ItemStack.EMPTY) {
return;
}
if ((stack.getItem() instanceof ItemExchangerBase)) {
Expand Down Expand Up @@ -118,9 +116,8 @@ public void renderOverlay(RenderWorldLastEvent evt, EntityPlayerSP player, ItemS
Block block = state.getBlock();
if ((block != null) && (block.getMaterial(state) != Material.AIR)) {
int meta = block.getMetaFromState(state);

int exId = ExchangerHandler.getTagCompound(stack).getInteger("block");
Block exBlock = Block.REGISTRY.getObjectById(exId);
String exId = ExchangerHandler.getTagCompound(stack).getString("block");
Block exBlock = Block.getBlockFromName(exId);
int exMeta = ExchangerHandler.getTagCompound(stack).getInteger("meta");
if ((exBlock == block) && (exMeta == meta)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ public static int nextID() {

public static void registerMessages(String channelName) {
INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(channelName);

// Server side
INSTANCE.registerMessage(PacketToggleMode.class, PacketToggleMode.class, nextID(), Side.SERVER);

// Client side
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public PacketToggleMode() { }
public IMessage onMessage(PacketToggleMode message, MessageContext context) {
EntityPlayerMP playerMP = context.getServerHandler().player;
ItemStack heldItem = playerMP.getHeldItemMainhand();
if (heldItem != null && heldItem.getItem() instanceof ExchangerHandler) {
if (heldItem != ItemStack.EMPTY && heldItem.getItem() instanceof ExchangerHandler) {
ExchangerHandler exchanger = (ExchangerHandler) (heldItem.getItem());
exchanger.switchMode(playerMP, heldItem);
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/jackyy/exchangers/helper/ChatHelper.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package jackyy.exchangers.helper;

import jackyy.exchangers.Exchangers;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextComponentTranslation;

public class ChatHelper {

public static void msgPlayer(EntityPlayer player, String msg) {
player.sendStatusMessage(new TextComponentString(msg), true);
player.sendStatusMessage(new TextComponentTranslation(Exchangers.MODID + "." + msg), true);
}

}
11 changes: 5 additions & 6 deletions src/main/java/jackyy/exchangers/helper/NBTHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,25 @@ public static int getInt(ItemStack stack, String key) {
public static int receiveEnergy(ItemStack container, int energy, int maxEnergy, boolean simulate) {
int stored = getEnergyStored(container);
int accepted = Math.min(energy, maxEnergy-stored);
if(!simulate)
{
if (!simulate) {
stored += accepted;
NBTHelper.setInt(container, "Energy", stored);
setInt(container, "Energy", stored);
}
return accepted;
}

public static int extractEnergy(ItemStack container, int energy, boolean simulate) {
int stored = getEnergyStored(container);
int extracted = Math.min(energy, stored);
if(!simulate)
{
if (!simulate) {
stored -= extracted;
NBTHelper.setInt(container, "Energy", stored);
setInt(container, "Energy", stored);
}
return extracted;
}

public static int getEnergyStored(ItemStack container) {
return getInt(container, "Energy");
}

}
2 changes: 1 addition & 1 deletion src/main/java/jackyy/exchangers/helper/StringHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static String getTierText(int tier) {
}

public static String getShiftText() {
return TextFormatting.GRAY + localize("tooltip.holdShift", TextFormatting.YELLOW.toString() + TextFormatting.ITALIC + localize("tooltip.holdShift.shift") + TextFormatting.RESET + TextFormatting.GRAY);
return TextFormatting.GRAY + localize("tooltip.hold_shift", TextFormatting.YELLOW.toString() + TextFormatting.ITALIC + localize("tooltip.hold_shift.shift") + TextFormatting.RESET + TextFormatting.GRAY);
}

public static boolean isShiftKeyDown() {
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/jackyy/exchangers/item/ItemCoreBase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package jackyy.exchangers.item;

import jackyy.exchangers.Exchangers;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;

public class ItemCoreBase extends Item {

public ItemCoreBase(){
setMaxStackSize(16);
setCreativeTab(Exchangers.TAB);
}

@Override
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> list) {
if (isInCreativeTab(tab)) {
if (checkLoaded()) {
list.add(new ItemStack(this));
}
}
}

public boolean checkLoaded() {
return true;
}

}
35 changes: 31 additions & 4 deletions src/main/java/jackyy/exchangers/item/ItemExchangerBase.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package jackyy.exchangers.item;

import jackyy.exchangers.Exchangers;
import jackyy.exchangers.handler.ExchangerHandler;
import jackyy.exchangers.helper.StringHelper;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
Expand All @@ -12,6 +15,12 @@

public class ItemExchangerBase extends ExchangerHandler {

public ItemExchangerBase(){
setMaxStackSize(1);
setCreativeTab(Exchangers.TAB);
}

@Override
public boolean showDurabilityBar(ItemStack stack) {
return stack.isItemDamaged();
}
Expand All @@ -21,15 +30,33 @@ public boolean isPowered() {
return false;
}

@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, World world, List<String> tooltip, ITooltipFlag bool) {
super.addInformation(stack, world, tooltip, bool);
@Override
public void addInformation(ItemStack stack, World world, List<String> tooltip, ITooltipFlag bool) {
super.addInformation(stack, world, tooltip, bool);
if (StringHelper.isShiftKeyDown()) {
if (!isPowered()) {
tooltip.add(StringHelper.formatNumber(stack.getMaxDamage() - stack.getItemDamage()) + " / " + StringHelper.formatNumber(stack.getMaxDamage()) + " " + StringHelper.localize("tooltip.durability"));
}
}
}

@Override
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> list) {
if (isInCreativeTab(tab)) {
if (checkLoaded()) {
list.add(new ItemStack(this));
}
}
}

@Override @SideOnly(Side.CLIENT)
public boolean hasEffect(ItemStack stack) {
return false;
}

@Override
public int getItemEnchantability() {
return 20;
}

}
31 changes: 25 additions & 6 deletions src/main/java/jackyy/exchangers/item/ItemExchangerBasePowered.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
import cofh.core.item.IEnchantableItem;
import cofh.redstoneflux.api.IEnergyContainerItem;
import jackyy.exchangers.Config;
import jackyy.exchangers.handler.ExchangerHandler;
import jackyy.exchangers.helper.EnergyHelper;
import jackyy.exchangers.helper.NBTHelper;
import jackyy.exchangers.helper.StringHelper;
import jackyy.exchangers.util.EnergyContainerItemWrapper;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.Optional;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import java.util.List;

Expand All @@ -26,6 +27,10 @@ public class ItemExchangerBasePowered extends ItemExchangerBase implements IEner

private Enchantment holding = Enchantment.getEnchantmentByLocation("cofhcore:holding");

public ItemExchangerBasePowered(){
setNoRepair();
}

@Override
public int receiveEnergy(ItemStack container, int energy, boolean simulate) {
return NBTHelper.receiveEnergy(container, energy, getMaxEnergyStored(container), simulate);
Expand Down Expand Up @@ -63,15 +68,29 @@ public double getDurabilityForDisplay(ItemStack stack) {
return 1D - ((double) stack.getTagCompound().getInteger("Energy") / (double) getMaxEnergyStored(stack));
}

@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, World world, List<String> tooltip, ITooltipFlag bool) {
super.addInformation(stack, world, tooltip, bool);
@Override
public void addInformation(ItemStack stack, World world, List<String> tooltip, ITooltipFlag bool) {
super.addInformation(stack, world, tooltip, bool);
if (StringHelper.isShiftKeyDown()) {
tooltip.add(StringHelper.formatNumber(getEnergyStored(stack)) + " / " + StringHelper.formatNumber(getMaxEnergyStored(stack)) + " RF");
}
}

@Override
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> list) {
if (isInCreativeTab(tab)) {
if (checkLoaded()) {
ItemStack empty = new ItemStack(this);
ExchangerHandler.setDefaultTagCompound(empty);
list.add(empty);
ItemStack full = new ItemStack(this);
ExchangerHandler.setDefaultTagCompound(full);
EnergyHelper.setDefaultEnergyTag(full, getMaxEnergyStored(full));
list.add(full);
}
}
}

@Override
public boolean isDamaged(ItemStack stack) {
return true;
Expand Down
Loading

0 comments on commit 1b74e16

Please sign in to comment.