Skip to content

Commit 56e9ce4

Browse files
committed
Introduce long awaited WorldEdit like commands to FoxLoader
1 parent a74f0c1 commit 56e9ce4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1491
-15
lines changed

client/src/main/java/com/fox2code/foxloader/client/ClientCommandWrapper.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fox2code.foxloader.network.NetworkPlayer;
44
import com.fox2code.foxloader.registry.CommandCompat;
55
import net.minecraft.mitask.command.Command;
6+
import net.minecraft.src.client.gui.StringTranslate;
67
import net.minecraft.src.client.player.EntityPlayerSP;
78

89
public final class ClientCommandWrapper extends Command {
@@ -15,7 +16,13 @@ public ClientCommandWrapper(CommandCompat commandCompat) {
1516

1617
@Override
1718
public void onExecute(String[] args, EntityPlayerSP commandExecutor) {
18-
this.commandCompat.onExecute(args, (NetworkPlayer) commandExecutor);
19+
try {
20+
this.commandCompat.onExecute(args, (NetworkPlayer) commandExecutor);
21+
} catch (Throwable t) {
22+
t.printStackTrace();
23+
((NetworkPlayer) commandExecutor).displayChatMessage(
24+
StringTranslate.getInstance().translateKey("command.error.internal-error"));
25+
}
1926
}
2027

2128
@Override
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.fox2code.foxloader.client.mixins;
2+
3+
import com.fox2code.foxloader.registry.RegisteredEntity;
4+
import com.fox2code.foxloader.registry.RegisteredWorld;
5+
import net.minecraft.src.game.entity.Entity;
6+
import net.minecraft.src.game.level.World;
7+
import org.spongepowered.asm.mixin.Mixin;
8+
import org.spongepowered.asm.mixin.Shadow;
9+
10+
@Mixin(Entity.class)
11+
public class MixinEntity implements RegisteredEntity {
12+
@Shadow public double posX;
13+
@Shadow public double posY;
14+
@Shadow public double posZ;
15+
@Shadow public World worldObj;
16+
17+
@Override
18+
public RegisteredWorld getCurrentRegisteredWorld() {
19+
return (RegisteredWorld) this.worldObj;
20+
}
21+
22+
@Override
23+
public double getRegisteredX() {
24+
return this.posX;
25+
}
26+
27+
@Override
28+
public double getRegisteredY() {
29+
return this.posY;
30+
}
31+
32+
@Override
33+
public double getRegisteredZ() {
34+
return this.posZ;
35+
}
36+
}

client/src/main/java/com/fox2code/foxloader/client/mixins/MixinEntityPlayerSP.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,9 @@ public boolean isOperator() {
4343
public void kick(String message) {
4444
throw new IllegalStateException("kick cannot be used client-side");
4545
}
46+
47+
@Override
48+
public NetworkPlayerController getNetworkPlayerController() {
49+
return (NetworkPlayerController) Minecraft.getInstance().playerController;
50+
}
4651
}

client/src/main/java/com/fox2code/foxloader/client/mixins/MixinGameSettings.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public void onOptionInit(CallbackInfo ci) {
3333

3434
@Inject(method = "getKeyBinding", at = @At("HEAD"))
3535
public void hotfix_onGetKeyBinding(EnumOptions option, CallbackInfoReturnable<String> cir) {
36-
if (option == EnumOptions.FRAMERATE_LIMIT && this.limitFramerate > 2) {
36+
if (option == EnumOptions.FRAMERATE_LIMIT && this.limitFramerate > 2 &&
37+
!EnumOptions.FRAMERATE_LIMIT.getEnumFloat()) {
3738
this.limitFramerate = 0;
3839
}
3940
}

client/src/main/java/com/fox2code/foxloader/client/mixins/MixinItemStack.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
public abstract class MixinItemStack implements RegisteredItemStack, NetworkItemStack {
1515
@Shadow public int itemID;
1616
@Shadow public int stackSize;
17-
@Shadow int itemDamage;
17+
@Shadow public int itemDamage;
1818
@Unique private int networkId;
1919

2020
@Shadow public abstract Item getItem();
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.fox2code.foxloader.client.mixins;
2+
3+
import com.fox2code.foxloader.network.NetworkPlayer;
4+
import net.minecraft.src.client.player.PlayerController;
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.Shadow;
7+
8+
@Mixin(PlayerController.class)
9+
public abstract class MixinPlayerController implements NetworkPlayer.NetworkPlayerController {
10+
@Shadow public abstract boolean isInCreativeMode();
11+
12+
@Override
13+
public boolean hasCreativeModeRegistered() {
14+
return this.isInCreativeMode();
15+
}
16+
17+
@Override
18+
public boolean hasSelection() {
19+
return false;
20+
}
21+
22+
public int getMinX() {
23+
return 0;
24+
}
25+
26+
public int getMaxX() {
27+
return 0;
28+
}
29+
30+
public int getMinY() {
31+
return 0;
32+
}
33+
34+
public int getMaxY() {
35+
return 0;
36+
}
37+
38+
public int getMinZ() {
39+
return 0;
40+
}
41+
42+
public int getMaxZ() {
43+
return 0;
44+
}
45+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.fox2code.foxloader.client.mixins;
2+
3+
import com.fox2code.foxloader.loader.ClientMod;
4+
import com.fox2code.foxloader.loader.ModLoader;
5+
import com.fox2code.foxloader.network.NetworkPlayer;
6+
import net.minecraft.client.Minecraft;
7+
import net.minecraft.src.client.player.PlayerController;
8+
import net.minecraft.src.client.player.PlayerControllerMP;
9+
import net.minecraft.src.client.renderer.Vec3D;
10+
import net.minecraft.src.game.entity.player.EntityPlayer;
11+
import net.minecraft.src.game.item.ItemStack;
12+
import net.minecraft.src.game.level.World;
13+
import org.spongepowered.asm.mixin.Mixin;
14+
import org.spongepowered.asm.mixin.injection.At;
15+
import org.spongepowered.asm.mixin.injection.Inject;
16+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
17+
18+
@Mixin(PlayerControllerMP.class)
19+
public class MixinPlayerControllerMP extends PlayerController {
20+
public MixinPlayerControllerMP(Minecraft minecraft) {
21+
super(minecraft);
22+
}
23+
24+
@Inject(method = "sendUseItem", at = @At("HEAD"), cancellable = true)
25+
public void onSendUseItem(EntityPlayer player, World world,
26+
ItemStack itemstack, CallbackInfoReturnable<Boolean> cir) {
27+
if (ModLoader.Internal.notifyPlayerUseItem((NetworkPlayer) player,
28+
ClientMod.toRegisteredItemStack(itemstack))) {
29+
cir.setReturnValue(Boolean.FALSE);
30+
}
31+
}
32+
33+
@Inject(method = "sendPlaceBlock", at = @At("HEAD"), cancellable = true)
34+
public void onSendPlaceBlock(EntityPlayer player, World world, ItemStack itemstack,
35+
int x, int y, int z, int facing, Vec3D vec3d, CallbackInfoReturnable<Boolean> cir) {
36+
if (ModLoader.Internal.notifyPlayerUseItemOnBlock((NetworkPlayer) player,
37+
ClientMod.toRegisteredItemStack(itemstack), x, y, z, facing,
38+
(float) vec3d.xCoord,(float) vec3d.yCoord,(float) vec3d.zCoord)) {
39+
cir.setReturnValue(Boolean.FALSE);
40+
}
41+
}
42+
43+
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
package com.fox2code.foxloader.client.mixins;
2+
3+
import com.fox2code.foxloader.client.network.ImplNetworkPlayerControllerExt;
4+
import com.fox2code.foxloader.loader.ClientMod;
5+
import com.fox2code.foxloader.loader.ModLoader;
6+
import com.fox2code.foxloader.network.NetworkPlayer;
7+
import net.minecraft.client.Minecraft;
8+
import net.minecraft.src.client.player.PlayerController;
9+
import net.minecraft.src.client.player.PlayerControllerMP;
10+
import net.minecraft.src.client.player.PlayerControllerSP;
11+
import net.minecraft.src.game.entity.player.EntityPlayer;
12+
import net.minecraft.src.game.item.Item;
13+
import net.minecraft.src.game.item.ItemStack;
14+
import org.spongepowered.asm.mixin.Mixin;
15+
import org.spongepowered.asm.mixin.Unique;
16+
import org.spongepowered.asm.mixin.injection.At;
17+
import org.spongepowered.asm.mixin.injection.Inject;
18+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
19+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
20+
21+
@Mixin(value = {PlayerControllerMP.class, PlayerControllerSP.class})
22+
public class MixinPlayerControllerMix extends PlayerController implements
23+
NetworkPlayer.NetworkPlayerController, ImplNetworkPlayerControllerExt {
24+
@Unique int x1, x2, y1, y2, z1, z2;
25+
@Unique boolean hasPrimary, hasSecondary;
26+
27+
public MixinPlayerControllerMix(Minecraft minecraft) {
28+
super(minecraft);
29+
}
30+
31+
@Inject(method = "clickBlock", at = @At("HEAD"), cancellable = true)
32+
public void onBlockClicked(int x, int y, int z, int facing, CallbackInfo ci) {
33+
ItemStack item = this.mc.thePlayer.getCurrentEquippedItem();
34+
NetworkPlayer networkPlayer = (NetworkPlayer) this.mc.thePlayer;
35+
if (ModLoader.Internal.notifyPlayerStartBreakBlock(networkPlayer,
36+
ClientMod.toRegisteredItemStack(item), x, y, z, facing)) {
37+
ci.cancel();
38+
return;
39+
}
40+
if ((!this.mc.theWorld.multiplayerWorld) && item != null &&
41+
item.itemID == Item.axeWood.itemID && this.isInCreativeMode() &&
42+
networkPlayer.isOperator()) {
43+
x1 = x;
44+
y1 = y;
45+
z1 = z;
46+
hasPrimary = true;
47+
NetworkPlayer.NetworkPlayerController controller = networkPlayer.getNetworkPlayerController();
48+
if (controller != this && controller instanceof ImplNetworkPlayerControllerExt) {
49+
((ImplNetworkPlayerControllerExt) controller).notifyRegisteredSetPrimary(x, y, z);
50+
}
51+
networkPlayer.displayChatMessage(
52+
"Pos1: [" + x + ", " + y + ", " + z + "]");
53+
ci.cancel();
54+
}
55+
}
56+
57+
@Inject(method = "sendBlockRemoved", at = @At("HEAD"), cancellable = true)
58+
public void onBlockRemoving(int x, int y, int z, int facing, CallbackInfoReturnable<Boolean> cir) {
59+
ItemStack item = this.mc.thePlayer.getCurrentEquippedItem();
60+
if (ModLoader.Internal.notifyPlayerBreakBlock(ClientMod.getLocalNetworkPlayer(),
61+
ClientMod.toRegisteredItemStack(item), x, y, z, facing)) {
62+
cir.setReturnValue(Boolean.FALSE);
63+
}
64+
}
65+
66+
@Override
67+
public boolean notifyRegisteredItemUsedImpl(EntityPlayer player, ItemStack itemstack, int x, int y, int z) {
68+
NetworkPlayer networkPlayer = (NetworkPlayer) this.mc.thePlayer;
69+
if ((!this.mc.theWorld.multiplayerWorld) && itemstack != null &&
70+
itemstack.itemID == Item.axeWood.itemID && this.isInCreativeMode() &&
71+
networkPlayer.isOperator()) {
72+
x2 = x;
73+
y2 = y;
74+
z2 = z;
75+
hasSecondary = true;
76+
NetworkPlayer.NetworkPlayerController controller = networkPlayer.getNetworkPlayerController();
77+
if (controller != this && controller instanceof ImplNetworkPlayerControllerExt) {
78+
((ImplNetworkPlayerControllerExt) controller).notifyRegisteredSetSecondary(x, y, z);
79+
}
80+
networkPlayer.displayChatMessage(
81+
"Pos2: [" + x + ", " + y + ", " + z + "]");
82+
return true;
83+
}
84+
return false;
85+
}
86+
87+
@Override
88+
public void notifyRegisteredSetPrimary(int x, int y, int z) {
89+
this.x1 = x; this.y1 = y; this.z1 = z; this.hasPrimary = true;
90+
}
91+
92+
@Override
93+
public void notifyRegisteredSetSecondary(int x, int y, int z) {
94+
this.x2 = x; this.y2 = y; this.z2 = z; this.hasSecondary = true;
95+
}
96+
97+
@Override
98+
public boolean hasSelection() {
99+
return hasPrimary && hasSecondary;
100+
}
101+
102+
@Override
103+
public int getMinX() {
104+
return Math.min(x1, x2);
105+
}
106+
107+
@Override
108+
public int getMaxX() {
109+
return Math.max(x1, x2);
110+
}
111+
112+
@Override
113+
public int getMinY() {
114+
return Math.min(y1, y2);
115+
}
116+
117+
@Override
118+
public int getMaxY() {
119+
return Math.max(y1, y2);
120+
}
121+
122+
@Override
123+
public int getMinZ() {
124+
return Math.min(z1, z2);
125+
}
126+
127+
@Override
128+
public int getMaxZ() {
129+
return Math.max(z1, z2);
130+
}
131+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.fox2code.foxloader.client.mixins;
2+
3+
import com.fox2code.foxloader.client.network.ImplNetworkPlayerControllerExt;
4+
import com.fox2code.foxloader.loader.ClientMod;
5+
import com.fox2code.foxloader.loader.ModLoader;
6+
import com.fox2code.foxloader.network.NetworkPlayer;
7+
import net.minecraft.client.Minecraft;
8+
import net.minecraft.src.client.player.PlayerController;
9+
import net.minecraft.src.client.player.PlayerControllerSP;
10+
import net.minecraft.src.client.renderer.Vec3D;
11+
import net.minecraft.src.game.entity.player.EntityPlayer;
12+
import net.minecraft.src.game.item.ItemStack;
13+
import net.minecraft.src.game.level.World;
14+
import org.spongepowered.asm.mixin.Mixin;
15+
16+
@Mixin(PlayerControllerSP.class)
17+
public class MixinPlayerControllerSP extends PlayerController implements ImplNetworkPlayerControllerExt {
18+
public MixinPlayerControllerSP(Minecraft minecraft) {
19+
super(minecraft);
20+
}
21+
22+
@Override
23+
public boolean sendUseItem(EntityPlayer player, World var2, ItemStack var3) {
24+
if (ModLoader.Internal.notifyPlayerUseItem((NetworkPlayer) player,
25+
ClientMod.toRegisteredItemStack(var3))) {
26+
return false;
27+
}
28+
return super.sendUseItem(player, var2, var3);
29+
}
30+
31+
@Override
32+
public boolean sendPlaceBlock(EntityPlayer player, World world, ItemStack itemstack, int x, int y, int z, int facing, Vec3D vec3d) {
33+
if (ModLoader.Internal.notifyPlayerUseItemOnBlock((NetworkPlayer) player,
34+
ClientMod.toRegisteredItemStack(itemstack), x, y, z, facing,
35+
(float) vec3d.xCoord,(float) vec3d.yCoord,(float) vec3d.zCoord)) {
36+
return false;
37+
}
38+
if (this.notifyRegisteredItemUsedImpl(player, itemstack, x, y, z)) {
39+
return false;
40+
}
41+
return super.sendPlaceBlock(player, world, itemstack, x, y, z, facing, vec3d);
42+
}
43+
}

0 commit comments

Comments
 (0)