-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from MoreThanHidden/master
- Loading branch information
Showing
10 changed files
with
178 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
# | ||
#Sat Dec 15 23:44:18 GMT 2018 | ||
version=1.2 | ||
#Wed Jan 09 18:10:16 AWST 2019 | ||
mod_name=Morph-o-Tool | ||
forge_version=14.23.2.2613 | ||
dir_repo=./ | ||
mc_mappings=snapshot_20171003 | ||
arl_version=1.3-27.10 | ||
version=1.2 | ||
dir_output=../Build Output/Morphtool/ | ||
build_number=21 | ||
mc_version=1.12.2 | ||
forge_version=14.23.2.2613 | ||
dir_repo=./ | ||
build_number=19 | ||
mod_name=Morph-o-Tool |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package vazkii.morphtool; | ||
|
||
import net.minecraft.block.state.IBlockState; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.entity.EntityPlayerSP; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.nbt.NBTTagCompound; | ||
import net.minecraft.util.EnumHand; | ||
import net.minecraft.util.math.RayTraceResult; | ||
import net.minecraftforge.client.event.MouseEvent; | ||
import net.minecraftforge.fml.common.eventhandler.EventPriority; | ||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | ||
import net.minecraftforge.fml.relauncher.Side; | ||
import net.minecraftforge.fml.relauncher.SideOnly; | ||
import vazkii.arl.network.NetworkHandler; | ||
import vazkii.morphtool.network.MessageMorphTool; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
@SideOnly(Side.CLIENT) | ||
public class ClientHandler { | ||
|
||
public static final ClientHandler INSTANCE = new ClientHandler(); | ||
protected static boolean autoMode = true; | ||
|
||
//Priority Highest so that it happens before the other mods | ||
@SubscribeEvent(priority = EventPriority.HIGHEST) | ||
public void onMouseEvent(MouseEvent event) { | ||
EntityPlayerSP player = Minecraft.getMinecraft().player; | ||
ItemStack mainHandItem = player.getHeldItem(ConfigHandler.invertHandShift ? EnumHand.OFF_HAND : EnumHand.MAIN_HAND); | ||
if(MorphingHandler.isMorphTool(mainHandItem)) { | ||
ItemStack newStack = mainHandItem; | ||
RayTraceResult res = MorphingHandler.raycast(player, 4.5); | ||
String mod = MorphingHandler.getModFromStack(mainHandItem); | ||
String modlook = ""; | ||
|
||
//Get looked at Mod | ||
if (res != null) { | ||
IBlockState state = player.world.getBlockState(res.getBlockPos()); | ||
modlook = MorphingHandler.getModFromState(state); | ||
//Morph tool to looked at Mod | ||
if(autoMode && event.getDwheel() == 0){ | ||
newStack = MorphingHandler.getShiftStackForMod(mainHandItem, modlook); | ||
} | ||
} | ||
//Manual Scroll for Morph (exluding looked at a mod block incase it also needs scrolling) | ||
if (event.getDwheel() != 0 && player.isSneaking() && !modlook.equals(mod)) { | ||
if(mainHandItem.getTagCompound() != null){ | ||
NBTTagCompound morphData = mainHandItem.getTagCompound().getCompoundTag(MorphingHandler.TAG_MORPH_TOOL_DATA); | ||
mod = event.getDwheel() < 0 ? nextMod(morphData, mod) : previousMod(morphData, mod); | ||
newStack = MorphingHandler.getShiftStackForMod(mainHandItem, mod); | ||
autoMode = mod.equals("morphtool"); | ||
event.setCanceled(true); | ||
} | ||
} | ||
|
||
if(newStack != mainHandItem && !ItemStack.areItemsEqual(newStack, mainHandItem)) { | ||
player.inventory.setInventorySlotContents(ConfigHandler.invertHandShift ? player.inventory.getSizeInventory() - 1 : player.inventory.currentItem, newStack); | ||
NetworkHandler.INSTANCE.sendToServer(new MessageMorphTool(newStack, player.inventory.currentItem)); | ||
MorphTool.proxy.updateEquippedItem(); | ||
} | ||
} | ||
} | ||
|
||
public static String nextMod(NBTTagCompound morphData, String mod) { | ||
List<String> mods = new ArrayList<>(morphData.getKeySet()); | ||
mods.add("morphtool"); | ||
if (!mod.equals("morphtool")){ | ||
mods.add(mod); | ||
} | ||
Collections.sort(mods); | ||
int id = mods.indexOf(mod); | ||
int retid = 0; | ||
//Move up the Array | ||
if(mods.size() > (id + 1)){ | ||
retid = id + 1; | ||
} | ||
return mods.get(retid); | ||
} | ||
|
||
public static String previousMod(NBTTagCompound morphData, String mod) { | ||
List<String> mods = new ArrayList<>(morphData.getKeySet()); | ||
mods.add("morphtool"); | ||
if (!mod.equals("morphtool")){ | ||
mods.add(mod); | ||
} | ||
Collections.sort(mods); | ||
int id = mods.indexOf(mod); | ||
int retid = mods.size() - 1; | ||
//Move down the Array | ||
if(0 <= (id - 1)){ | ||
retid = (id - 1); | ||
} | ||
return mods.get(retid); | ||
} | ||
|
||
} |
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
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
35 changes: 35 additions & 0 deletions
35
src/main/java/vazkii/morphtool/network/MessageMorphTool.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,35 @@ | ||
package vazkii.morphtool.network; | ||
|
||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.EnumHand; | ||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage; | ||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; | ||
import vazkii.arl.network.NetworkMessage; | ||
import vazkii.morphtool.ConfigHandler; | ||
import vazkii.morphtool.MorphingHandler; | ||
|
||
public class MessageMorphTool extends NetworkMessage{ | ||
|
||
public ItemStack stack; | ||
public int slot; | ||
|
||
public MessageMorphTool() {} | ||
|
||
public MessageMorphTool(ItemStack stack, int slot) { | ||
this.stack = stack; | ||
this.slot = slot; | ||
} | ||
|
||
@Override | ||
public IMessage handleMessage(MessageContext context) { | ||
EntityPlayer player = context.getServerHandler().player; | ||
ItemStack mainHandItem = player.getHeldItem(ConfigHandler.invertHandShift ? EnumHand.OFF_HAND : EnumHand.MAIN_HAND); | ||
if(MorphingHandler.isMorphTool(mainHandItem) && stack != mainHandItem && !ItemStack.areItemsEqual(stack, mainHandItem) ) { | ||
player.inventory.setInventorySlotContents(ConfigHandler.invertHandShift ? player.inventory.getSizeInventory() - 1 : slot, stack); | ||
} | ||
return null; | ||
} | ||
|
||
|
||
} |
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