Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Manual Morph #28 and Fix #29 #30 #33

Merged
merged 8 commits into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ version = "${config.version}-${config.build_number}"
group = "vazkii.morphtool" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = config.mod_name

repositories {
maven {
// for AutoRegLib
name "blamejared"
url "http://maven.blamejared.com/"
}
}

dependencies {
compile "vazkii.autoreglib:AutoRegLib:${config.arl_version}"
}

minecraft {
version = "${config.mc_version}-${config.forge_version}"
runDir = "eclipse/assets"
Expand Down
13 changes: 7 additions & 6 deletions build.properties
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
9 changes: 5 additions & 4 deletions src/main/java/vazkii/morphtool/AttachementRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public ItemStack getCraftingResult(InventoryCrafting var1) {
return copy;
}

@Override
public boolean canFit(int width, int height) {
return false;
}

public boolean isTarget(ItemStack stack) {
if(stack.isEmpty() || MorphingHandler.isMorphTool(stack))
return false;
Expand Down Expand Up @@ -111,9 +116,5 @@ public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) {
return NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY);
}

@Override
public boolean canFit(int p_194133_1_, int p_194133_2_) {
return false;
}

}
99 changes: 99 additions & 0 deletions src/main/java/vazkii/morphtool/ClientHandler.java
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);
}

}
2 changes: 1 addition & 1 deletion src/main/java/vazkii/morphtool/ConfigHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void load() {
"immersiveengineering:tool",
"buildersguides:mallet",
"environmentaltech:tool_multiblock_assembler",
"bloodmagic:itemritualreader",
"bloodmagic:ritual_reader",
"draconicevolution:crystal_binder",
"crossroads:omnimeter");

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/vazkii/morphtool/ItemMorphTool.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package vazkii.morphtool;

import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.creativetab.CreativeTabs;
Expand All @@ -15,6 +13,8 @@
import net.minecraft.world.World;
import vazkii.arl.item.ItemMod;

import java.util.List;

public class ItemMorphTool extends ItemMod {

public ItemMorphTool() {
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/vazkii/morphtool/MorphTool.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package vazkii.morphtool;

import net.minecraft.init.Items;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import vazkii.arl.network.NetworkHandler;
import vazkii.morphtool.network.MessageMorphTool;
import vazkii.morphtool.proxy.CommonProxy;

@Mod(modid = MorphTool.MOD_ID, name = MorphTool.MOD_NAME, version = MorphTool.VERSION, dependencies = MorphTool.DEPENDENCIES, guiFactory = MorphTool.GUI_FACTORY)
Expand All @@ -28,7 +25,7 @@ public class MorphTool {
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
ConfigHandler.init(event.getSuggestedConfigurationFile());

NetworkHandler.register(MessageMorphTool.class, Side.SERVER);
proxy.preInit();
}

Expand Down
34 changes: 5 additions & 29 deletions src/main/java/vazkii/morphtool/MorphingHandler.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
package vazkii.morphtool;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.function.Consumer;

import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.translation.I18n;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.item.ItemTossEvent;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.function.Consumer;

public final class MorphingHandler {

public static final MorphingHandler INSTANCE = new MorphingHandler();
Expand All @@ -34,28 +32,6 @@ public final class MorphingHandler {
public static final String TAG_MORPH_TOOL_DATA = "morphtool:data";
public static final String TAG_MORPH_TOOL_DISPLAY_NAME = "morphtool:displayName";

@SubscribeEvent
public void onPlayerTick(LivingUpdateEvent event) {
if(event.getEntity() instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) event.getEntity();
ItemStack mainHandItem = player.getHeldItem(ConfigHandler.invertHandShift ? EnumHand.OFF_HAND : EnumHand.MAIN_HAND);

if(isMorphTool(mainHandItem)) {
RayTraceResult res = raycast(player, 4.5);
if(res != null) {
IBlockState state = player.getEntityWorld().getBlockState(res.getBlockPos());
String mod = getModFromState(state);

ItemStack newStack = getShiftStackForMod(mainHandItem, mod);
if(newStack != mainHandItem && !ItemStack.areItemsEqual(newStack, mainHandItem)) {
player.inventory.setInventorySlotContents(ConfigHandler.invertHandShift ? player.inventory.getSizeInventory() - 1 : player.inventory.currentItem, newStack);
MorphTool.proxy.updateEquippedItem();
}
}
}
}
}

@SubscribeEvent
public void onItemDropped(ItemTossEvent event) {
if(!event.getPlayer().isSneaking())
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/vazkii/morphtool/network/MessageMorphTool.java
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;
}


}
11 changes: 8 additions & 3 deletions src/main/java/vazkii/morphtool/proxy/ClientProxy.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package vazkii.morphtool.proxy;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.util.EnumHand;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.MinecraftForge;
import vazkii.morphtool.ClientHandler;
import vazkii.morphtool.ConfigHandler;
import vazkii.morphtool.MorphTool;

public class ClientProxy extends CommonProxy {

@Override
public void preInit() {
super.preInit();
MinecraftForge.EVENT_BUS.register(ClientHandler.INSTANCE);
}

@Override
public void updateEquippedItem() {
Minecraft.getMinecraft().entityRenderer.itemRenderer.resetEquippedProgress(ConfigHandler.invertHandShift ? EnumHand.OFF_HAND : EnumHand.MAIN_HAND);
Expand Down