Skip to content

Commit

Permalink
Fix client sync and other issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmess1221 committed May 30, 2016
1 parent dd6e3b6 commit 7a9e429
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 53 deletions.
5 changes: 1 addition & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ buildscript {
apply plugin: 'net.minecraftforge.gradle.liteloader'
apply plugin: 'org.spongepowered.mixin'
apply plugin: 'mnm.gradle.ap-ide'

group = "mnm.mods"
version = "1.1"

Expand All @@ -35,7 +36,6 @@ minecraft {
mappings = "snapshot_20160517"
replace "@VERSION@", project.version
runDir = 'run'
clientJvmArgs += '-Dmixin.env.compatLevel=JAVA_8'
}
sourceSets.main {
refMap = 'mixins.itemdash.refmap.json'
Expand All @@ -62,7 +62,4 @@ litemod.json {
jar {
from litemod
exclude '*.xcf'
manifest {
attributes 'MixinCompatibilityLevel': 'JAVA_8'
}
}
4 changes: 2 additions & 2 deletions build.number
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
#Tue May 24 00:51:42 EDT 2016
build.number=29
#Sun May 29 23:26:24 EDT 2016
build.number=38
27 changes: 11 additions & 16 deletions src/main/java/mnm/mods/itemdash/ItemDash.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
import com.google.common.collect.ObjectArrays;

import mnm.mods.itemdash.ducks.IGuiContainer;
import mnm.mods.itemdash.ducks.IGuiCreativeContainer;
import mnm.mods.itemdash.easing.EasingType;
import mnm.mods.itemdash.easing.EasingsFactory;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.gui.inventory.GuiContainerCreative;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.InventoryEffectRenderer;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -150,7 +149,7 @@ public void arrangeItems(GuiContainer cont) {
scroll(0);
}

private void checkForGuiChanges(GuiContainer cont, int mousex, int mousey) {
private void checkForGuiChanges(InventoryEffectRenderer cont) {
int yPos = 0;
int width = (int) ((cont.width - ((IGuiContainer) cont).getXSize()) / (3f / 2f));
width = (width / DASH_ICON_W) * DASH_ICON_W;
Expand Down Expand Up @@ -210,19 +209,20 @@ private void checkForGuiChanges(GuiContainer cont, int mousex, int mousey) {
}
}

public void preRender(GuiContainer cont, int mousex, int mousey) {
public void updateDash(InventoryEffectRenderer screen) {

checkForGuiChanges(cont, mousex, mousey);
int guiWidth = ((IGuiContainer) cont).getXSize();
checkForGuiChanges(screen);
int guiWidth = ((IGuiContainer) screen).getXSize();
int newLeft = xPos / 2 - guiWidth / 2;
if (!mc.thePlayer.getActivePotionEffects().isEmpty()) {
newLeft += 50;
}
((IGuiContainer) cont).setGuiLeft(newLeft);
if (cont instanceof GuiContainerCreative) {
// changing guiLeft breaks the creative search box
fixCreativeInv((GuiContainerCreative) cont);
}
((IGuiContainer) screen).setGuiLeft(newLeft);

}

public void preRender(GuiContainer cont, int mousex, int mousey) {

GlStateManager.enableAlpha();
drawBackground();
if (!this.settings.isVisible()) {
Expand All @@ -231,11 +231,6 @@ public void preRender(GuiContainer cont, int mousex, int mousey) {
}
}

private void fixCreativeInv(GuiContainerCreative inv) {
GuiTextField search = ((IGuiCreativeContainer) inv).getSearchField();
search.xPosition = ((IGuiContainer) inv).getGuiLeft() + 82;
}

public void postRender(GuiContainer cont, int mousex, int mousey) {

if (this.settings.isVisible())
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/mnm/mods/itemdash/LiteModItemDash.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ public class LiteModItemDash implements Tickable, InitCompleteListener, PacketHa
public ItemSorter sort = ItemSorter.DEFAULT;
@Expose
public String[] ignored = {
"minecraft:farmland", "minecraft:lit_furnace", "minecraft:map", "minecraft:enchanted_book"
"minecraft:farmland", "minecraft:lit_furnace", "minecraft:map", "minecraft:enchanted_book", "minecraft:end_crystal"
};
@Expose
public String[] favorites = {};

@Override
public String getName() {
Expand Down Expand Up @@ -121,7 +123,9 @@ public void giveItem(ItemStack stack) {
if (mc.isSingleplayer()) {
UUID uuid = mc.thePlayer.getGameProfile().getId();
EntityPlayer player = mc.getIntegratedServer().getPlayerList().getPlayerByUUID(uuid);
player.inventory.addItemStackToInventory(stack);
boolean added = player.inventory.addItemStackToInventory(stack);
if (added)
player.inventoryContainer.detectAndSendChanges();
} else {
String message = formatGiveCommand(stack);
mc.thePlayer.sendChatMessage(message);
Expand Down Expand Up @@ -202,4 +206,9 @@ public static LiteModItemDash getInstance() {
return instance;
}

public static void onUpdateScreen(InventoryEffectRenderer screen) {
instance.itemdash.updateDash(screen);

}

}
2 changes: 0 additions & 2 deletions src/main/java/mnm/mods/itemdash/ducks/IGuiContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ public interface IGuiContainer {

int getXSize();

int getGuiLeft();

void setGuiLeft(int i);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,40 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import mnm.mods.itemdash.LiteModItemDash;
import mnm.mods.itemdash.ducks.IGuiCreativeContainer;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.inventory.GuiContainerCreative;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.InventoryEffectRenderer;

@Mixin(GuiContainerCreative.class)
public abstract class MixinGuiContainerCreative extends InventoryEffectRenderer implements IGuiCreativeContainer {
public abstract class MixinGuiContainerCreative extends InventoryEffectRenderer {

@Shadow
private GuiTextField searchField;

@Inject(method = "drawGuiContainerBackgroundLayer(FII)V", at = @At("RETURN"))
@Inject(method = "drawGuiContainerBackgroundLayer(FII)V", at = @At("HEAD"))
protected void onDrawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY, CallbackInfo ci) {
LiteModItemDash.onPreRenderScreen(this, mouseX, mouseY, partialTicks);
}

@Inject(method = "drawGuiContainerForegroundLayer(II)V", at = @At("HEAD"))
@Inject(method = "drawGuiContainerForegroundLayer(II)V", at = @At("RETURN"))
protected void onDrawGuiContainerForegroundLayer(int mouseX, int mouseY, CallbackInfo ci) {
GlStateManager.pushMatrix();
GlStateManager.translate(-guiLeft, -this.guiTop, 0);
LiteModItemDash.onPostRenderScreen(this, mouseX, mouseY);
GlStateManager.popMatrix();
}

@Inject(method = "updateScreen()V", at = @At("HEAD"))
private void onUpdateScreen(CallbackInfo ci) {
LiteModItemDash.onUpdateScreen(this);
fixCreativeInv();
}

private void fixCreativeInv() {
this.searchField.xPosition = this.guiLeft + 82;
}

@Inject(method = "handleMouseInput()V", cancellable = true, at = @At("HEAD"))
private void onHandleMouse(CallbackInfo ci) {
int x = Mouse.getEventX() * this.width / this.mc.displayWidth;
Expand All @@ -53,9 +62,4 @@ private void onKeyTyped(char typedChar, int keyCode, CallbackInfo ci) {
public MixinGuiContainerCreative() {
super(null);
}

@Override
public GuiTextField getSearchField() {
return this.searchField;
}
}
13 changes: 9 additions & 4 deletions src/main/java/mnm/mods/itemdash/mixin/MixinGuiInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,24 @@ public MixinGuiInventory(Container inventorySlotsIn) {
super(inventorySlotsIn);
}

@Inject(method = "drawGuiContainerBackgroundLayer(FII)V", at = @At("RETURN"))
protected void onDrawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY, CallbackInfo ci) {
@Inject(method = "drawGuiContainerBackgroundLayer(FII)V", at = @At("HEAD"))
private void onDrawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY, CallbackInfo ci) {
LiteModItemDash.onPreRenderScreen(this, mouseX, mouseY, partialTicks);
}

@Inject(method = "drawGuiContainerForegroundLayer(II)V", at = @At("HEAD"))
protected void onDrawGuiContainerForegroundLayer(int mouseX, int mouseY, CallbackInfo ci) {
@Inject(method = "drawGuiContainerForegroundLayer(II)V", at = @At("RETURN"))
private void onDrawGuiContainerForegroundLayer(int mouseX, int mouseY, CallbackInfo ci) {
GlStateManager.pushMatrix();
GlStateManager.translate(-guiLeft, -this.guiTop, 0);
LiteModItemDash.onPostRenderScreen(this, mouseX, mouseY);
GlStateManager.popMatrix();
}

@Inject(method = "updateScreen()V", at = @At("HEAD"))
private void onUpdateScreen(CallbackInfo ci) {
LiteModItemDash.onUpdateScreen(this);
}

@Override
public void handleMouseInput() throws IOException {
int x = Mouse.getEventX() * this.width / this.mc.displayWidth;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public MixinInventoryEffectRenderer(Container inventorySlotsIn) {
super(inventorySlotsIn);
}

@Override
public void initGui() {
super.initGui();
LiteModItemDash.onUpdateScreen((InventoryEffectRenderer) (Object) this);
}

@Override
protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
LiteModItemDash.onMouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
Expand All @@ -40,11 +46,6 @@ public int getXSize() {
return this.xSize;
}

@Override
public int getGuiLeft() {
return guiLeft;
}

@Override
public void setGuiLeft(int i) {
this.guiLeft = i;
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/litemod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "ItemDash",
"version": "$version",
"mcversion": "$mcversion",
"revision": "$revision",
"author": "JoyJoy",
"description": "Get items easilly",
"mixinConfigs": ["mixins.itemdash.json"]
}
3 changes: 2 additions & 1 deletion src/main/resources/mixins.itemdash.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"required": true,
"minVersion": "0.5.5",
"minVersion": "0.5.6",
"compatibilityLevel": "JAVA_8",
"package": "mnm.mods.itemdash.mixin",
"refmap": "mixins.itemdash.refmap.json",
"mixins": [
Expand Down

0 comments on commit 7a9e429

Please sign in to comment.