Skip to content
This repository has been archived by the owner on Jun 23, 2024. It is now read-only.

Commit

Permalink
first working version
Browse files Browse the repository at this point in the history
  • Loading branch information
gbl committed Jul 28, 2017
1 parent 5a71b15 commit 4938208
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ apply plugin: 'net.minecraftforge.gradle.forge'
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.


version = "1.0"
version = "1.12-forge14.21.1.2387-1.0"
group = "de.guntram.mcmod.antighost" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "antighost"

Expand Down
69 changes: 68 additions & 1 deletion src/main/java/de/guntram/mcmod/antighost/AntiGhost.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
package de.guntram.mcmod.antighost;

import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.network.play.client.CPacketPlayerDigging;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
Expand All @@ -13,14 +25,15 @@
acceptedMinecraftVersions = "[1.12]"
)

public class AntiGhost
public class AntiGhost implements ICommand
{
static final String MODID="antighost";
static final String VERSION="1.0";
@EventHandler
public void init(FMLInitializationEvent event)
{
MinecraftForge.EVENT_BUS.register(this);
ClientCommandHandler.instance.registerCommand(this);
}

@EventHandler
Expand All @@ -29,4 +42,58 @@ public void preInit(final FMLPreInitializationEvent event) {
confHandler.load(event.getSuggestedConfigurationFile());
MinecraftForge.EVENT_BUS.register(confHandler);
}

@Override
public String getName() {
return "ghost";
}

@Override
public String getUsage(ICommandSender sender) {
return "/ghost";
}

@Override
public List<String> getAliases() {
return new ArrayList<>();
}

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
Minecraft mc=Minecraft.getMinecraft();
NetHandlerPlayClient conn = mc.getConnection();
if (conn==null)
return;
BlockPos pos=sender.getPosition();
for (int dx=-4; dx<=4; dx++)
for (int dy=-4; dy<=4; dy++)
for (int dz=-4; dz<=4; dz++) {
CPacketPlayerDigging packet=new CPacketPlayerDigging(
CPacketPlayerDigging.Action.ABORT_DESTROY_BLOCK,
new BlockPos(pos.getX()+dx, pos.getY()+dy, pos.getZ()+dz),
EnumFacing.UP // with ABORT_DESTROY_BLOCK, this value is unused
);
conn.sendPacket(packet);
}
}

@Override
public boolean checkPermission(MinecraftServer server, ICommandSender sender) {
return true;
}

@Override
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos targetPos) {
return new ArrayList<>();
}

@Override
public boolean isUsernameIndex(String[] args, int index) {
return false;
}

@Override
public int compareTo(ICommand o) {
return getName().compareTo(o.getName());
}
}

0 comments on commit 4938208

Please sign in to comment.