Skip to content

Commit

Permalink
1.8.3 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
JackyyTV committed Jul 4, 2018
1 parent 7b6ce48 commit 60e714e
Show file tree
Hide file tree
Showing 39 changed files with 156 additions and 99 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Submit any bug reports / suggestions via [issue tracker](https://github.com/Jack
## Contact Me

- Twitter - [@JackyyTV](https://twitter.com/JackyyTV)
- Discord - Jacky#3044
- Discord - Jacky#1234
- Twitch - [Jackyy](https://www.twitch.tv/jackyy)
- Reddit - [Jacky1356400](https://www.reddit.com/message/compose/?to=Jacky1356400)

Expand Down
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.10.2
forge_version=1.10.2-12.18.3.2511
mod_version=1.8.2
mod_version=1.8.3
mappings_version=snapshot_20161111
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 @@ -19,7 +19,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.10.2-1.8.2";
public static final String VERSION = "1.10.2-1.8.3";
public static final String MCVERSION = "[1.10,1.11)";
public static final String MODID = "exchangers";
public static final String MODNAME = "Exchangers";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTUtil;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
Expand Down Expand Up @@ -132,11 +133,10 @@ public void renderWorldLastEvent(RenderWorldLastEvent event) {
IBlockState state = world.getBlockState(mouseOver.getBlockPos());
Block block = state.getBlock();
if (block.getMaterial(state) != Material.AIR) {
int meta = block.getMetaFromState(state);
ItemStack stack = player.getHeldItemMainhand();
float partialTicks = event.getPartialTicks();
if (stack != null && stack.getItem() instanceof ItemExchangerBase && stack.getTagCompound() != null && mouseOver.sideHit != null) {
Set<BlockPos> coordinates = ExchangerHandler.findSuitableBlocks(stack, player.getEntityWorld(), mouseOver.sideHit, mouseOver.getBlockPos(), block, meta);
Set<BlockPos> coordinates = ExchangerHandler.findSuitableBlocks(stack, player.getEntityWorld(), mouseOver.sideHit, mouseOver.getBlockPos(), block, block.getMetaFromState(state));
double offsetX = player.prevPosX + (player.posX - player.prevPosX) * (double) partialTicks;
double offsetY = player.prevPosY + (player.posY - player.prevPosY) * (double) partialTicks;
double offsetZ = player.prevPosZ + (player.posZ - player.prevPosZ) * (double) partialTicks;
Expand All @@ -153,10 +153,10 @@ public void renderWorldLastEvent(RenderWorldLastEvent event) {

for (BlockPos coordinate : coordinates) {
String exId = ExchangerHandler.getTagCompound(stack).getString("block");
IBlockState exState = NBTUtil.readBlockState(ExchangerHandler.getTagCompound(stack).getCompoundTag("blockstate"));
Block exBlock = Block.getBlockFromName(exId);
int exMeta = ExchangerHandler.getTagCompound(stack).getInteger("meta");
float blockHardness = block.getBlockHardness(state, world, coordinate);
if (world.isAirBlock(coordinate) || (exBlock == block && exMeta == meta)) {
if (world.isAirBlock(coordinate) || (exBlock == block && exState == state)) {
continue;
}
double renderX = coordinate.getX() - offsetX;
Expand Down
88 changes: 30 additions & 58 deletions src/main/java/jackyy/exchangers/handler/ExchangerHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import jackyy.exchangers.helper.StringHelper;
import jackyy.exchangers.registry.ModConfig;
import jackyy.exchangers.util.IExchanger;
import net.minecraft.block.*;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.item.EntityItem;
Expand All @@ -18,6 +18,7 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTUtil;
import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
Expand All @@ -33,20 +34,6 @@

public class ExchangerHandler extends Item implements IExchanger {

public static final int MODE_1X1 = 0;
public static final int MODE_3X3 = 1;
public static final int MODE_5X5 = 2;
public static final int MODE_7X7 = 3;
public static final int MODE_9X9 = 4;
public static final int MODE_11X11 = 5;
public static final int MODE_13X13 = 6;
public static final int MODE_15X15 = 7;
public static final int MODE_17X17 = 8;
public static final int MODE_19X19 = 9;
public static final int MODE_21X21 = 10;
public static final int MODE_23X23 = 11;
public static final int MODE_25X25 = 12;

public static final String[] modeSwitchList = new String[] {
"1x1", "3x3", "5x5", "7x7", "9x9",
"11x11", "13x13", "15x15", "17x17",
Expand All @@ -56,19 +43,21 @@ public static void setDefaultTagCompound(ItemStack stack) {
if (stack.getTagCompound() == null) {
NBTTagCompound compound = new NBTTagCompound();
compound.setString("block", "minecraft:air");
compound.setInteger("meta", 0);
compound.setTag("blockstate", new NBTTagCompound());
compound.setInteger("mode", 0);
compound.setBoolean("forceDropItems", false);
stack.setTagCompound(compound);
} else {
if (!stack.getTagCompound().hasKey("block")) {
stack.getTagCompound().setString("block", "minecraft:air");
} else if (!stack.getTagCompound().hasKey("meta")) {
stack.getTagCompound().setInteger("meta", 0);
} else if (!stack.getTagCompound().hasKey("blockstate")) {
stack.getTagCompound().setTag("blockstate", new NBTTagCompound());
} else if (!stack.getTagCompound().hasKey("mode")) {
stack.getTagCompound().setInteger("mode", 0);
} else if (!stack.getTagCompound().hasKey("forceDropItems")) {
stack.getTagCompound().setBoolean("forceDropItems", false);
} else if (stack.getTagCompound().hasKey("meta")) {
stack.getTagCompound().removeTag("meta");
}
}
}
Expand All @@ -84,14 +73,14 @@ public void addInformation(ItemStack stack, EntityPlayer player, List<String> to

NBTTagCompound compound = stack.getTagCompound();
String id = compound.getString("block");
IBlockState state = NBTUtil.readBlockState(compound.getCompoundTag("blockstate"));

if (StringHelper.isShiftKeyDown()) {
if (id.equals("minecraft:air")) {
tooltip.add(StringHelper.localize("tooltip.no_selected_block"));
} else {
Block block = Block.getBlockFromName(id);
int meta = compound.getInteger("meta");
tooltip.add(StringHelper.localize("tooltip.selected_block") + " " + getBlockName(block, meta));
tooltip.add(StringHelper.localize("tooltip.selected_block") + " " + getBlockName(block, state.getBlock().getMetaFromState(state)));
}
tooltip.add(StringHelper.localize("tooltip.current_range") + " " + modeSwitchList[compound.getInteger("mode")]);
tooltip.add(StringHelper.localize("tooltip.max_range") + " " + modeSwitchList[getMaxRange()]);
Expand Down Expand Up @@ -134,8 +123,8 @@ public void switchMode(EntityPlayer player, ItemStack stack) {
ItemStack heldItem = player.getHeldItemMainhand();
if (heldItem != null) {
if (modeSwitch > getMaxRange()) {
modeSwitch = MODE_1X1;
} else if (modeSwitch < MODE_1X1) {
modeSwitch = 0;
} else if (modeSwitch < 0) {
modeSwitch = getMaxRange();
}
}
Expand Down Expand Up @@ -171,7 +160,7 @@ public static boolean isWhitelisted(World world, BlockPos pos) {
return true;
}
}
return world.getBlockState(pos).getBlock().getRegistryName().getResourceDomain().equals("tconstruct");
return world.getBlockState(pos).getBlock().getRegistryName().equals("tconstruct:seared");
}

public static boolean isBlacklisted(World world, BlockPos pos) {
Expand All @@ -183,34 +172,20 @@ public static boolean isBlacklisted(World world, BlockPos pos) {
return false;
}

private boolean isSpecial(Block block) {
return block instanceof BlockLog
|| block instanceof BlockTrapDoor
|| block instanceof BlockDoor
|| block instanceof BlockFenceGate;
}

private boolean isMoreSpecial(Block block) {
return block instanceof BlockTorch;
}

@SuppressWarnings("deprecation")
private void placeBlock(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side) {
NBTTagCompound tagCompound = stack.getTagCompound();
Block block;
int meta;
String id = tagCompound.getString("block");
block = Block.getBlockFromName(id);
meta = tagCompound.getInteger("meta");

Block block = Block.getBlockFromName(id);
IBlockState state = NBTUtil.readBlockState(tagCompound.getCompoundTag("blockstate"));
IBlockState oldState = world.getBlockState(pos);
Block oldblock = oldState.getBlock();

int oldmeta = oldblock.getMetaFromState(oldState);
float blockHardness = oldblock.getBlockHardness(oldState, world, pos);

if (id.equals("minecraft:air")) {
return;
} else if ((block == oldblock) && (meta == oldmeta)) {
} else if ((block == oldblock) && (state == oldState)) {
return;
} else if (world.getTileEntity(pos) != null && !isWhitelisted(world, pos)) {
ChatHelper.msgPlayer(player, "error.invalid_block.te");
Expand All @@ -228,14 +203,16 @@ private void placeBlock(ItemStack stack, EntityPlayer player, World world, Block
ChatHelper.msgPlayer(player, "error.low_harvest_level");
return;
}

Set<BlockPos> coordinates = findSuitableBlocks(stack, world, side, pos, oldblock, oldmeta);
boolean notEnough = false;
world.captureBlockSnapshots = false;

for (BlockPos coordinate : coordinates) {
BlockEvent.PlaceEvent event = new BlockEvent.PlaceEvent(BlockSnapshot.getBlockSnapshot(world, coordinate, 3), Blocks.AIR.getDefaultState(), player, player.getActiveHand());
world.setBlockState(coordinate, block.getStateFromMeta(meta), 3);
world.setBlockState(coordinate, state, 3);
if (!MinecraftForge.EVENT_BUS.post(event)) {
if (consumeItemInInventory(Item.getItemFromBlock(block), meta, player.inventory, player)) {
if (consumeItemInInventory(Item.getItemFromBlock(block), state.getBlock().getItem(world, pos, state).getMetadata(), player.inventory, player)) {
if (!player.capabilities.isCreativeMode && !isCreative()) {
if (ModConfig.misc.doExchangersSilkTouch || EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0) {
ItemStack oldblockItem = oldblock.getItem(world, pos, oldState);
Expand Down Expand Up @@ -280,21 +257,9 @@ private void selectBlock(ItemStack stack, EntityPlayer player, World world, Bloc
setDefaultTagCompound(stack);
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
int meta;
if (isSpecial(block)) {
meta = block.getDefaultState().getBlock().getMetaFromState(block.getDefaultState());
} else if (isMoreSpecial(block)) {
meta = 0;
} else {
meta = block.getMetaFromState(state);
}
NBTTagCompound tagCompound = getTagCompound(stack);
String name = getBlockName(block, meta);
float blockHardness = block.getBlockHardness(state, world, pos);
if (name == null) {
ChatHelper.msgPlayer(player, "error.invalid_block.null");
return;
} else if (world.getTileEntity(pos) != null && !isWhitelisted(world, pos)) {
if (world.getTileEntity(pos) != null && !isWhitelisted(world, pos)) {
ChatHelper.msgPlayer(player, "error.invalid_block.te");
return;
} else if (isBlacklisted(world, pos)) {
Expand All @@ -306,7 +271,7 @@ private void selectBlock(ItemStack stack, EntityPlayer player, World world, Bloc
}
String id = Block.REGISTRY.getNameForObject(block).toString();
tagCompound.setString("block", id);
tagCompound.setInteger("meta", meta);
NBTUtil.writeBlockState(tagCompound.getCompoundTag("blockstate"), state);
}

protected static Set<BlockPos> findSuitableBlocks(ItemStack stack, World world, EnumFacing sideHit, BlockPos pos, Block centerBlock, int centerMeta) {
Expand Down Expand Up @@ -473,7 +438,14 @@ protected static NBTTagCompound getTagCompound(ItemStack stack) {

private static String getBlockName(Block block, int meta) {
ItemStack stack = new ItemStack(block, 1, meta);
return stack.getDisplayName();
String name;
try {
name = stack.getDisplayName();
return name;
} catch (NullPointerException e) {
e.printStackTrace();
}
return "Unable to fetch block name.";
}

}
15 changes: 15 additions & 0 deletions src/main/java/jackyy/exchangers/helper/NBTHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;

import java.io.*;

public class NBTHelper {

public static NBTTagCompound getTag(ItemStack stack) {
Expand Down Expand Up @@ -47,4 +49,17 @@ public static int getEnergyStored(ItemStack container) {
return getInt(container, "Energy");
}

public static byte[] serializeToBytes(Object obj) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
ObjectOutputStream objOutput = new ObjectOutputStream(output);
objOutput.writeObject(obj);
return output.toByteArray();
}

public static Object deserializeToObject(byte[] data) throws IOException, ClassNotFoundException {
ByteArrayInputStream input = new ByteArrayInputStream(data);
ObjectInputStream objInput = new ObjectInputStream(input);
return objInput.readObject();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public int getHarvestLevel() {

@Override
public int getMaxRange() {
return MODE_3X3;
return ModConfig.enderIOTweaks.conductiveMaxRange;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public int getHarvestLevel() {

@Override
public int getMaxRange() {
return MODE_13X13;
return ModConfig.enderIOTweaks.darkSteelMaxRange;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public int getHarvestLevel() {

@Override
public int getMaxRange() {
return MODE_9X9;
return ModConfig.enderIOTweaks.electricalSteelMaxRange;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public int getHarvestLevel() {

@Override
public int getMaxRange() {
return MODE_11X11;
return ModConfig.enderIOTweaks.energeticMaxRange;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public int getHarvestLevel() {

@Override
public int getMaxRange() {
return MODE_5X5;
return ModConfig.enderIOTweaks.pulsatingMaxRange;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public int getHarvestLevel() {

@Override
public int getMaxRange() {
return MODE_15X15;
return ModConfig.enderIOTweaks.vibrantMaxRange;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public int getHarvestLevel() {

@Override
public int getMaxRange() {
return MODE_15X15;
return ModConfig.immersiveEngineeringTweaks.hvMaxRange;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public int getHarvestLevel() {

@Override
public int getMaxRange() {
return MODE_5X5;
return ModConfig.immersiveEngineeringTweaks.lvMaxRange;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public int getHarvestLevel() {

@Override
public int getMaxRange() {
return MODE_11X11;
return ModConfig.immersiveEngineeringTweaks.mvMaxRange;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public int getHarvestLevel() {

@Override
public int getMaxRange() {
return MODE_11X11;
return ModConfig.mekanismTweaks.advancedMaxRange;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public int getHarvestLevel() {

@Override
public int getMaxRange() {
return MODE_7X7;
return ModConfig.mekanismTweaks.basicMaxRange;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public int getHarvestLevel() {

@Override
public int getMaxRange() {
return MODE_13X13;
return ModConfig.mekanismTweaks.eliteMaxRange;
}

@Override
Expand Down
Loading

0 comments on commit 60e714e

Please sign in to comment.