Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
zlainsama committed Feb 16, 2017
1 parent 9624607 commit cff1b32
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 23 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
}
apply plugin: 'net.minecraftforge.gradle.forge'

version = "1.10.2-v1-test"
version = "1.10.2-v1"
group= "lain.mods.cleanview"
archivesBaseName = "CleanView"

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/lain/mods/cleanview/CleanView.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package lain.mods.cleanview;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;

@Mod(modid = "CleanView", useMetadata = true)
@Mod(modid = "cleanview", useMetadata = true, acceptedMinecraftVersions = "[1.10,)")
public class CleanView
{

Expand Down
51 changes: 34 additions & 17 deletions src/main/java/lain/mods/cleanview/Proxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
import java.lang.ref.WeakReference;
import java.util.Collection;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.potion.PotionHelper;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import net.minecraft.potion.PotionEffect;
import net.minecraft.potion.PotionUtils;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;

public class Proxy
{
Expand All @@ -24,22 +26,35 @@ public static void setup()
private static final String TAG = "0256d9da-9c1b-46ea-a83c-01ae6981a2c8";
private static final Proxy INSTANCE = new Proxy();

WeakReference<EntityLivingBase> ref;
WeakReference<EntityLivingBase> ref = new WeakReference<EntityLivingBase>(null);
boolean enabled = true;
KeyBinding keyToggle;

private Proxy()
{
FMLCommonHandler.instance().bus().register(this);
MinecraftForge.EVENT_BUS.register(this);

keyToggle = new KeyBinding("key.toggleCleanView", 0, "key.categories.misc");
ClientRegistry.registerKeyBinding(keyToggle);
}

@SuppressWarnings("unchecked")
private <T extends Entity> T getRenderViewEntity()
{
try
{
return (T) FMLClientHandler.instance().getClient().getRenderViewEntity();
}
catch (Error ignored)
{
return null;
}
}

@SubscribeEvent
public void handleEvent(InputEvent.KeyInputEvent event)
{
if (keyToggle.getIsKeyPressed())
if (keyToggle.isPressed())
enabled = !enabled;
}

Expand All @@ -48,25 +63,27 @@ public void handleEvent(TickEvent.ClientTickEvent event)
{
if (event.phase == TickEvent.Phase.START)
{
EntityLivingBase ent = enabled ? FMLClientHandler.instance().getClient().renderViewEntity : null;
EntityLivingBase ent = getRenderViewEntity();
EntityLivingBase prevEnt = ref.get();

if (!enabled)
ent = null;

EntityLivingBase prevEnt = (ref != null) ? ref.get() : null;
if (prevEnt != ent)
{
if (prevEnt != null && prevEnt.getEntityData().getBoolean(TAG))
{
@SuppressWarnings("rawtypes")
Collection effects = prevEnt.getActivePotionEffects();
Collection<PotionEffect> effects = prevEnt.getActivePotionEffects();
if (!effects.isEmpty())
prevEnt.getDataWatcher().updateObject(7, PotionHelper.calcPotionLiquidColor(effects));
prevEnt.getDataManager().set(EntityLivingBase.POTION_EFFECTS, PotionUtils.getPotionColorFromEffectList(effects));
prevEnt.getEntityData().removeTag(TAG);
}
ref = (ent != null) ? new WeakReference<EntityLivingBase>(ent) : null;
ref = new WeakReference<EntityLivingBase>(ent);
}

if (ent != null)
{
ent.getDataWatcher().updateObject(7, 0);
ent.getDataManager().set(EntityLivingBase.POTION_EFFECTS, 0);
if (!ent.getEntityData().getBoolean(TAG))
ent.getEntityData().setBoolean(TAG, true);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/mcmod.info
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
"version": "${version}",
"mcversion": "${mcversion}",
"url": "https://github.com/zlainsama/cleanview",
"updateUrl": "https://github.com/zlainsama/cleanview/releases",
"updateUrl": "",
"authorList": ["zlainsama"],
"credits": "",
"logoFile": "",
"screenshots": [],
"parent": "",
"requiredMods": ["forge"],
"requiredMods": [],
"dependencies": [],
"dependants": [],
"useDependencyInformation": true
Expand Down

0 comments on commit cff1b32

Please sign in to comment.