Update to 1.13.2
This commit is contained in:
186
src/main/java/exopandora/worldhandler/helper/ActionHelper.java
Normal file
186
src/main/java/exopandora/worldhandler/helper/ActionHelper.java
Normal file
@@ -0,0 +1,186 @@
|
||||
package exopandora.worldhandler.helper;
|
||||
|
||||
import com.mojang.realmsclient.gui.ChatFormatting;
|
||||
|
||||
import exopandora.worldhandler.Main;
|
||||
import exopandora.worldhandler.builder.impl.BuilderDifficulty;
|
||||
import exopandora.worldhandler.builder.impl.BuilderDifficulty.EnumDifficulty;
|
||||
import exopandora.worldhandler.builder.impl.BuilderGamemode;
|
||||
import exopandora.worldhandler.builder.impl.BuilderGamemode.EnumGamemode;
|
||||
import exopandora.worldhandler.builder.impl.BuilderTime;
|
||||
import exopandora.worldhandler.builder.impl.BuilderTime.EnumMode;
|
||||
import exopandora.worldhandler.builder.impl.BuilderWeather;
|
||||
import exopandora.worldhandler.builder.impl.BuilderWeather.EnumWeather;
|
||||
import exopandora.worldhandler.config.Config;
|
||||
import exopandora.worldhandler.gui.container.impl.GuiWorldHandler;
|
||||
import exopandora.worldhandler.gui.content.Content;
|
||||
import exopandora.worldhandler.gui.content.Contents;
|
||||
import exopandora.worldhandler.util.ActionHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.text.ChatType;
|
||||
import net.minecraft.util.text.Style;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.util.text.event.ClickEvent;
|
||||
import net.minecraft.util.text.event.ClickEvent.Action;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class ActionHelper
|
||||
{
|
||||
public static void backToGame()
|
||||
{
|
||||
Minecraft.getInstance().displayGuiScreen(null);
|
||||
Minecraft.getInstance().mouseHelper.grabMouse();
|
||||
}
|
||||
|
||||
public static void back(Content content) throws Exception
|
||||
{
|
||||
if(content.getBackContent() != null)
|
||||
{
|
||||
Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(content.getBackContent()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void changeTab(Content content, int index)
|
||||
{
|
||||
try
|
||||
{
|
||||
Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(content.getCategory().getContent(index)));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void timeDawn()
|
||||
{
|
||||
CommandHelper.sendCommand(new BuilderTime(EnumMode.SET, Config.getSettings().getDawn()));
|
||||
}
|
||||
|
||||
public static void timeNoon()
|
||||
{
|
||||
CommandHelper.sendCommand(new BuilderTime(EnumMode.SET, Config.getSettings().getNoon()));
|
||||
}
|
||||
|
||||
public static void timeSunset()
|
||||
{
|
||||
CommandHelper.sendCommand(new BuilderTime(EnumMode.SET, Config.getSettings().getSunset()));
|
||||
}
|
||||
|
||||
public static void timeMidnight()
|
||||
{
|
||||
CommandHelper.sendCommand(new BuilderTime(EnumMode.SET, Config.getSettings().getMidnight()));
|
||||
}
|
||||
|
||||
public static void weatherClear()
|
||||
{
|
||||
CommandHelper.sendCommand(new BuilderWeather(EnumWeather.CLEAR));
|
||||
}
|
||||
|
||||
public static void weatherRain()
|
||||
{
|
||||
CommandHelper.sendCommand(new BuilderWeather(EnumWeather.RAIN));
|
||||
}
|
||||
|
||||
public static void weatherThunder()
|
||||
{
|
||||
CommandHelper.sendCommand(new BuilderWeather(EnumWeather.THUNDER));
|
||||
}
|
||||
|
||||
public static void difficultyPeaceful()
|
||||
{
|
||||
CommandHelper.sendCommand(new BuilderDifficulty(EnumDifficulty.PEACEFUL));
|
||||
}
|
||||
|
||||
public static void difficultyEasy()
|
||||
{
|
||||
CommandHelper.sendCommand(new BuilderDifficulty(EnumDifficulty.EASY));
|
||||
}
|
||||
|
||||
public static void difficultyNormal()
|
||||
{
|
||||
CommandHelper.sendCommand(new BuilderDifficulty(EnumDifficulty.NORMAL));
|
||||
}
|
||||
|
||||
public static void difficultyHard()
|
||||
{
|
||||
CommandHelper.sendCommand(new BuilderDifficulty(EnumDifficulty.HARD));
|
||||
}
|
||||
|
||||
public static void gamemodeSurvival()
|
||||
{
|
||||
CommandHelper.sendCommand(new BuilderGamemode(EnumGamemode.SURVIVAL));
|
||||
}
|
||||
|
||||
public static void gamemodeCreative()
|
||||
{
|
||||
CommandHelper.sendCommand(new BuilderGamemode(EnumGamemode.CREATIVE));
|
||||
}
|
||||
|
||||
public static void gamemodeAdventure()
|
||||
{
|
||||
CommandHelper.sendCommand(new BuilderGamemode(EnumGamemode.ADVENTURE));
|
||||
}
|
||||
|
||||
public static void gamemodeSpectator()
|
||||
{
|
||||
CommandHelper.sendCommand(new BuilderGamemode(EnumGamemode.SPECTATOR));
|
||||
}
|
||||
|
||||
public static void tryRun(ActionHandler action)
|
||||
{
|
||||
try
|
||||
{
|
||||
action.run();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
if(!Minecraft.getInstance().isGameFocused())
|
||||
{
|
||||
Minecraft.getInstance().displayGuiScreen(null);
|
||||
Minecraft.getInstance().mouseHelper.grabMouse();
|
||||
}
|
||||
|
||||
TextComponentString name = new TextComponentString(Main.NAME);
|
||||
name.setStyle(new Style().setUnderlined(true).setClickEvent(new ClickEvent(Action.OPEN_URL, Main.URL)));
|
||||
|
||||
TextComponentTranslation message = new TextComponentTranslation("worldhandler.error.gui", name);
|
||||
message.setStyle(new Style().setColor(net.minecraft.util.text.TextFormatting.RED));
|
||||
|
||||
Minecraft.getInstance().ingameGUI.addChatMessage(ChatType.SYSTEM, message);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void displayGui()
|
||||
{
|
||||
if(!CommandHelper.canPlayerIssueCommand() && Config.getSettings().permissionQuery())
|
||||
{
|
||||
Minecraft.getInstance().ingameGUI.addChatMessage(ChatType.SYSTEM, new TextComponentString(ChatFormatting.RED + I18n.format("worldhandler.permission.refused")));
|
||||
Minecraft.getInstance().ingameGUI.addChatMessage(ChatType.SYSTEM, new TextComponentString(ChatFormatting.RED + I18n.format("worldhandler.permission.refused.change", I18n.format("gui.worldhandler.config.key.settings.permission_query"))));
|
||||
}
|
||||
else
|
||||
{
|
||||
ActionHelper.tryRun(() ->
|
||||
{
|
||||
if(BlockHelper.isFocusedBlockEqualTo(Blocks.SIGN) || BlockHelper.isFocusedBlockEqualTo(Blocks.WALL_SIGN))
|
||||
{
|
||||
Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.SIGN_EDITOR));
|
||||
}
|
||||
else if(BlockHelper.isFocusedBlockEqualTo(Blocks.NOTE_BLOCK))
|
||||
{
|
||||
Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.NOTE_EDITOR));
|
||||
}
|
||||
else
|
||||
{
|
||||
Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.MAIN));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package exopandora.worldhandler.helper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import exopandora.worldhandler.builder.impl.BuilderAdvancement.EnumMode;
|
||||
import net.minecraft.advancements.AdvancementManager;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class AdvancementHelper
|
||||
{
|
||||
public static final AdvancementManager ADVANCEMENT_MANAGER = new AdvancementManager(null);
|
||||
private final Node modes = new Node();
|
||||
|
||||
public AdvancementHelper()
|
||||
{
|
||||
this.init();
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
for(EnumMode mode : EnumMode.values())
|
||||
{
|
||||
this.modes.addNode(mode.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public List<Node> getModes()
|
||||
{
|
||||
if(this.modes != null)
|
||||
{
|
||||
return this.modes.getEntries();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -3,29 +3,36 @@ package exopandora.worldhandler.helper;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import exopandora.worldhandler.WorldHandler;
|
||||
import exopandora.worldhandler.builder.impl.BuilderSetblock;
|
||||
import exopandora.worldhandler.builder.types.Coordinate;
|
||||
import exopandora.worldhandler.config.ConfigSettings;
|
||||
import exopandora.worldhandler.util.UtilPlayer;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import exopandora.worldhandler.builder.impl.BuilderFill;
|
||||
import exopandora.worldhandler.builder.impl.BuilderSetBlock;
|
||||
import exopandora.worldhandler.builder.impl.BuilderSummon;
|
||||
import exopandora.worldhandler.builder.types.BlockResourceLocation;
|
||||
import exopandora.worldhandler.builder.types.Coordinate.CoordinateType;
|
||||
import exopandora.worldhandler.builder.types.CoordinateDouble;
|
||||
import exopandora.worldhandler.builder.types.CoordinateInt;
|
||||
import exopandora.worldhandler.config.Config;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.network.play.client.CPacketCustomPayload;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.network.play.client.CPacketUpdateCommandBlock;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.tileentity.TileEntityCommandBlock;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class BlockHelper
|
||||
{
|
||||
private static BlockPos POS_1 = BlockPos.ORIGIN;
|
||||
@@ -36,32 +43,29 @@ public class BlockHelper
|
||||
|
||||
public static BlockPos getFocusedBlockPos()
|
||||
{
|
||||
RayTraceResult rayTrace = Minecraft.getMinecraft().objectMouseOver;
|
||||
RayTraceResult rayTrace = Minecraft.getInstance().objectMouseOver;
|
||||
|
||||
if(rayTrace != null)
|
||||
if(rayTrace != null && rayTrace.type.equals(RayTraceResult.Type.BLOCK))
|
||||
{
|
||||
if(rayTrace.typeOfHit.equals(RayTraceResult.Type.BLOCK))
|
||||
BlockPos position = rayTrace.getBlockPos();
|
||||
|
||||
if(!ArrayUtils.contains(BLACKLIST, Minecraft.getInstance().world.getBlockState(position).getBlock()))
|
||||
{
|
||||
BlockPos position = rayTrace.getBlockPos();
|
||||
|
||||
if(!ArrayUtils.contains(BLACKLIST, Minecraft.getMinecraft().world.getBlockState(position).getBlock()))
|
||||
{
|
||||
return position;
|
||||
}
|
||||
return position;
|
||||
}
|
||||
}
|
||||
|
||||
return Minecraft.getMinecraft().player.getPosition();
|
||||
return Minecraft.getInstance().player.getPosition();
|
||||
}
|
||||
|
||||
public static boolean isFocusedBlockEqualTo(Block block)
|
||||
{
|
||||
return Block.isEqualTo(getFocusedBlock(), block);
|
||||
return getBlock(getFocusedBlockPos()) == block;
|
||||
}
|
||||
|
||||
public static Block getFocusedBlock()
|
||||
public static Block getBlock(BlockPos pos)
|
||||
{
|
||||
return Minecraft.getMinecraft().world.getBlockState(getFocusedBlockPos()).getBlock();
|
||||
return Minecraft.getInstance().world.getBlockState(pos).getBlock();
|
||||
}
|
||||
|
||||
public static BlockPos setX(BlockPos pos, double x)
|
||||
@@ -117,6 +121,13 @@ public class BlockHelper
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T addPositionObservers(T observer, Function<T, Consumer<BlockPos>> pos1generator, Function<T, Consumer<BlockPos>> pos2generator)
|
||||
{
|
||||
BlockHelper.addPos1Observer(pos1generator.apply(observer));
|
||||
BlockHelper.addPos2Observer(pos2generator.apply(observer));
|
||||
return observer;
|
||||
}
|
||||
|
||||
public static void addPos1Observer(Consumer<BlockPos> observer)
|
||||
{
|
||||
POS_1_OBSERVERS.add(observer);
|
||||
@@ -137,90 +148,83 @@ public class BlockHelper
|
||||
POS_2_OBSERVERS.add(observer);
|
||||
}
|
||||
|
||||
private static NBTTagCompound newCommandBlock(String command)
|
||||
{
|
||||
NBTTagCompound blockState = new NBTTagCompound();
|
||||
blockState.setString("Name", Blocks.COMMAND_BLOCK.getRegistryName().toString());
|
||||
|
||||
NBTTagCompound tileEntityData = new NBTTagCompound();
|
||||
tileEntityData.setString("Command", command);
|
||||
tileEntityData.setBoolean("auto", true);
|
||||
|
||||
NBTTagCompound commandBlock = new NBTTagCompound();
|
||||
commandBlock.setInt("Time", 1);
|
||||
commandBlock.setTag("BlockState", blockState);
|
||||
commandBlock.setTag("TileEntityData", tileEntityData);
|
||||
|
||||
return commandBlock;
|
||||
}
|
||||
|
||||
public static boolean setCommandBlockNearPlayer(String command)
|
||||
{
|
||||
if(UtilPlayer.canIssueCommand())
|
||||
if(CommandHelper.canPlayerIssueCommand() && Minecraft.getInstance().getConnection() != null)
|
||||
{
|
||||
BlockPos player = new BlockPos(Minecraft.getMinecraft().player.posX, Minecraft.getMinecraft().player.posY, Minecraft.getMinecraft().player.posZ);
|
||||
BlockPos block = player;
|
||||
BlockPos button = player;
|
||||
BuilderFill fill = new BuilderFill();
|
||||
fill.setX1(new CoordinateInt(0, CoordinateType.GLOBAL));
|
||||
fill.setY1(new CoordinateInt(-2, CoordinateType.GLOBAL));
|
||||
fill.setZ1(new CoordinateInt(0, CoordinateType.GLOBAL));
|
||||
fill.setX2(new CoordinateInt(0, CoordinateType.GLOBAL));
|
||||
fill.setY2(new CoordinateInt(0, CoordinateType.GLOBAL));
|
||||
fill.setZ2(new CoordinateInt(0, CoordinateType.GLOBAL));
|
||||
fill.setBlock1(new BlockResourceLocation(Blocks.AIR.getRegistryName()));
|
||||
|
||||
int meta = 0;
|
||||
NBTTagCompound block = newCommandBlock(fill.toActualCommand());
|
||||
block.setString("id", "falling_block");
|
||||
|
||||
switch(UtilPlayer.getPlayerDirection())
|
||||
{
|
||||
case 0:
|
||||
block = block.add(0, 0, 2);
|
||||
button = button.add(0, 0, 1);
|
||||
meta = 4;
|
||||
break;
|
||||
case 1:
|
||||
block = block.add(-2, 0, 0);
|
||||
button = button.add(-1, 0, 0);
|
||||
meta = 1;
|
||||
break;
|
||||
case 2:
|
||||
block = block.add(0, 0, -2);
|
||||
button = button.add(0, 0, -1);
|
||||
meta = 3;
|
||||
break;
|
||||
case 3:
|
||||
block = block.add(2, 0, 0);
|
||||
button = button.add(1, 0, 0);
|
||||
meta = 2;
|
||||
break;
|
||||
}
|
||||
NBTTagList passengers = new NBTTagList();
|
||||
passengers.add(block);
|
||||
|
||||
boolean flag = false;
|
||||
NBTTagCompound nbt = newCommandBlock(command);
|
||||
nbt.setTag("Passengers", passengers);
|
||||
|
||||
if(Minecraft.getMinecraft().world.isAirBlock(block))
|
||||
{
|
||||
Minecraft.getMinecraft().player.sendChatMessage(new BuilderSetblock(block, Blocks.COMMAND_BLOCK.getRegistryName(), 0, ConfigSettings.getMode()).toActualCommand());
|
||||
Minecraft.getMinecraft().player.sendChatMessage(new BuilderSetblock(button, Blocks.WOODEN_BUTTON.getRegistryName(), meta, ConfigSettings.getMode()).toActualCommand());
|
||||
flag = true;
|
||||
}
|
||||
Minecraft.getInstance().displayGuiScreen(null);
|
||||
Minecraft.getInstance().mouseHelper.grabMouse();
|
||||
|
||||
if(Minecraft.getMinecraft().world.getBlockState(block).getBlock().equals(Blocks.COMMAND_BLOCK) || flag)
|
||||
{
|
||||
if(Minecraft.getMinecraft().getConnection() != null)
|
||||
{
|
||||
PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer());
|
||||
packetbuffer.writeInt(block.getX());
|
||||
packetbuffer.writeInt(block.getY());
|
||||
packetbuffer.writeInt(block.getZ());
|
||||
packetbuffer.writeString(command);
|
||||
packetbuffer.writeBoolean(true);
|
||||
packetbuffer.writeString(TileEntityCommandBlock.Mode.REDSTONE.name());
|
||||
packetbuffer.writeBoolean(false);
|
||||
packetbuffer.writeBoolean(false);
|
||||
|
||||
Minecraft.getMinecraft().getConnection().sendPacket(new CPacketCustomPayload("MC|AutoCmd", packetbuffer));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
BuilderSummon summon = new BuilderSummon();
|
||||
summon.setEntity(EntityType.FALLING_BLOCK.getRegistryName().toString());
|
||||
summon.setX(new CoordinateDouble(0.0, CoordinateType.LOCAL));
|
||||
summon.setY(new CoordinateDouble(0.54, CoordinateType.LOCAL));
|
||||
summon.setZ(new CoordinateDouble(0.0, CoordinateType.LOCAL));
|
||||
summon.setNBT(nbt);
|
||||
|
||||
BlockPos pos = Minecraft.getInstance().player.getPosition().add(0, 3, 0);
|
||||
Minecraft.getInstance().player.sendChatMessage(new BuilderSetBlock(pos, Blocks.COMMAND_BLOCK.getRegistryName(), Config.CLIENT.getSettings().getBlockPlacingMode()).toActualCommand());
|
||||
Minecraft.getInstance().getConnection().sendPacket(new CPacketUpdateCommandBlock(pos, summon.toActualCommand(false), TileEntityCommandBlock.Mode.REDSTONE, true, false, true));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void setBlockNearPlayer(Block block, byte southMeta, byte westMeta, byte northMeta, byte eastMeta)
|
||||
public static void setBlockNearPlayer(Block block)
|
||||
{
|
||||
int direction = UtilPlayer.getPlayerDirection();
|
||||
|
||||
switch(direction)
|
||||
System.out.println(Minecraft.getInstance().player.getHorizontalFacing());
|
||||
switch(Minecraft.getInstance().player.getHorizontalFacing())
|
||||
{
|
||||
case 0:
|
||||
WorldHandler.sendCommand(new BuilderSetblock(new Coordinate(), new Coordinate(), new Coordinate(2, true), block.getRegistryName(), southMeta, ConfigSettings.getMode()));
|
||||
case NORTH:
|
||||
CommandHelper.sendCommand(new BuilderSetBlock(new CoordinateInt(CoordinateType.LOCAL), new CoordinateInt(CoordinateType.LOCAL), new CoordinateInt(2, CoordinateType.LOCAL), block.getRegistryName(), Config.getSettings().getBlockPlacingMode()).withState(BlockStateProperties.HORIZONTAL_FACING, EnumFacing.SOUTH));
|
||||
break;
|
||||
case 1:
|
||||
WorldHandler.sendCommand(new BuilderSetblock(new Coordinate(-2, true), new Coordinate(), new Coordinate(), block.getRegistryName(), westMeta, ConfigSettings.getMode()));
|
||||
case EAST:
|
||||
CommandHelper.sendCommand(new BuilderSetBlock(new CoordinateInt(CoordinateType.LOCAL), new CoordinateInt(CoordinateType.LOCAL), new CoordinateInt(2, CoordinateType.LOCAL), block.getRegistryName(), Config.getSettings().getBlockPlacingMode()).withState(BlockStateProperties.HORIZONTAL_FACING, EnumFacing.WEST));
|
||||
break;
|
||||
case 2:
|
||||
WorldHandler.sendCommand(new BuilderSetblock(new Coordinate(), new Coordinate(), new Coordinate(-2, true), block.getRegistryName(), northMeta, ConfigSettings.getMode()));
|
||||
case SOUTH:
|
||||
CommandHelper.sendCommand(new BuilderSetBlock(new CoordinateInt(CoordinateType.LOCAL), new CoordinateInt(CoordinateType.LOCAL), new CoordinateInt(2, CoordinateType.LOCAL), block.getRegistryName(), Config.getSettings().getBlockPlacingMode()).withState(BlockStateProperties.HORIZONTAL_FACING, EnumFacing.NORTH));
|
||||
break;
|
||||
case 3:
|
||||
WorldHandler.sendCommand(new BuilderSetblock(new Coordinate(2, true), new Coordinate(), new Coordinate(), block.getRegistryName(), eastMeta, ConfigSettings.getMode()));
|
||||
case WEST:
|
||||
CommandHelper.sendCommand(new BuilderSetBlock(new CoordinateInt(CoordinateType.LOCAL), new CoordinateInt(CoordinateType.LOCAL), new CoordinateInt(2, CoordinateType.LOCAL), block.getRegistryName(), Config.getSettings().getBlockPlacingMode()).withState(BlockStateProperties.HORIZONTAL_FACING, EnumFacing.EAST));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package exopandora.worldhandler.helper;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
|
||||
import exopandora.worldhandler.WorldHandler;
|
||||
import exopandora.worldhandler.builder.ICommandBuilder;
|
||||
import exopandora.worldhandler.builder.ICommandBuilderSyntax;
|
||||
import exopandora.worldhandler.command.CommandWH;
|
||||
import exopandora.worldhandler.command.CommandWorldHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class CommandHelper
|
||||
{
|
||||
public static void sendFeedback(CommandSource source, String message)
|
||||
{
|
||||
source.sendFeedback(new TextComponentString(message), false);
|
||||
}
|
||||
|
||||
public static boolean canPlayerIssueCommand()
|
||||
{
|
||||
return Minecraft.getInstance().player.hasPermissionLevel(1);
|
||||
}
|
||||
|
||||
public static void registerCommands(CommandDispatcher<CommandSource> dispatcher)
|
||||
{
|
||||
CommandWorldHandler.register(dispatcher);
|
||||
CommandWH.register(dispatcher);
|
||||
}
|
||||
|
||||
public static void sendCommand(ICommandBuilder builder)
|
||||
{
|
||||
CommandHelper.sendCommand(builder, false);
|
||||
}
|
||||
|
||||
public static void sendCommand(ICommandBuilder builder, boolean special)
|
||||
{
|
||||
if(builder != null)
|
||||
{
|
||||
String command;
|
||||
|
||||
if(builder instanceof ICommandBuilderSyntax)
|
||||
{
|
||||
command = ((ICommandBuilderSyntax) builder).toActualCommand();
|
||||
}
|
||||
else
|
||||
{
|
||||
command = builder.toCommand();
|
||||
}
|
||||
|
||||
WorldHandler.LOGGER.info("Command: " + command);
|
||||
|
||||
if(builder.needsCommandBlock() || special)
|
||||
{
|
||||
BlockHelper.setCommandBlockNearPlayer(command);
|
||||
}
|
||||
else
|
||||
{
|
||||
Minecraft.getInstance().player.sendChatMessage(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
package exopandora.worldhandler.helper;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.common.registry.EntityEntry;
|
||||
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class EntityHelper
|
||||
{
|
||||
private static final Map<ResourceLocation, String> RESOURCELOCATION_TO_NAME = new HashMap<ResourceLocation, String>();
|
||||
private static final Map<Class<? extends Entity>, ResourceLocation> CLASS_TO_RESOURCELOCATION = new HashMap<Class<? extends Entity>, ResourceLocation>();
|
||||
|
||||
static
|
||||
{
|
||||
if(ForgeRegistries.ENTITIES.getEntries().isEmpty())
|
||||
{
|
||||
throw new RuntimeException("Accessed Entities before register!");
|
||||
}
|
||||
|
||||
for(Entry<ResourceLocation, EntityEntry> entity : ForgeRegistries.ENTITIES.getEntries())
|
||||
{
|
||||
RESOURCELOCATION_TO_NAME.put(entity.getKey(), entity.getValue().getName());
|
||||
CLASS_TO_RESOURCELOCATION.put(entity.getValue().getEntityClass(), entity.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getUnifiedEntityName(String name)
|
||||
{
|
||||
for(ResourceLocation location : RESOURCELOCATION_TO_NAME.keySet())
|
||||
{
|
||||
if(RESOURCELOCATION_TO_NAME.get(location).equals(name))
|
||||
{
|
||||
return location.getResourcePath();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getEntityName(ResourceLocation location)
|
||||
{
|
||||
return RESOURCELOCATION_TO_NAME.get(location);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getEntityName(String name)
|
||||
{
|
||||
for(ResourceLocation location : RESOURCELOCATION_TO_NAME.keySet())
|
||||
{
|
||||
if(location.getResourcePath().equals(name))
|
||||
{
|
||||
return RESOURCELOCATION_TO_NAME.get(location);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean doesExist(ResourceLocation key)
|
||||
{
|
||||
return RESOURCELOCATION_TO_NAME.containsKey(key);
|
||||
}
|
||||
|
||||
public static boolean doesExist(String value)
|
||||
{
|
||||
return RESOURCELOCATION_TO_NAME.containsValue(value);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ResourceLocation getResourceLocation(Class<? extends Entity> entity)
|
||||
{
|
||||
return CLASS_TO_RESOURCELOCATION.get(entity);
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,14 @@ package exopandora.worldhandler.helper;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class EnumHelper
|
||||
{
|
||||
@Nullable
|
||||
public static <T extends Enum<T>> T valueOf(Class<T> klass, String name)
|
||||
public static <T extends Enum<T>> T valueOf(String name, Class<T> klass)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -6,16 +6,14 @@ import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class Node
|
||||
{
|
||||
private final String key;
|
||||
@@ -157,10 +155,15 @@ public class Node
|
||||
|
||||
public void mergeItems()
|
||||
{
|
||||
this.mergeItems(null, this);
|
||||
this.mergeItems(null, this, null);
|
||||
}
|
||||
|
||||
private void mergeItems(Node root, Node child)
|
||||
public void mergeItems(BiPredicate<String, String> predicate)
|
||||
{
|
||||
this.mergeItems(null, this, predicate);
|
||||
}
|
||||
|
||||
private void mergeItems(Node root, Node child, BiPredicate<String, String> predicate)
|
||||
{
|
||||
if(child != null && child.getEntries() != null)
|
||||
{
|
||||
@@ -168,7 +171,7 @@ public class Node
|
||||
{
|
||||
for(Node node : child.getEntries())
|
||||
{
|
||||
this.mergeItems(child, node);
|
||||
this.mergeItems(child, node, predicate);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -181,14 +184,13 @@ public class Node
|
||||
{
|
||||
if(node.getEntries() != null && !node.getEntries().isEmpty())
|
||||
{
|
||||
this.mergeItems(child, node);
|
||||
this.mergeItems(child, node, predicate);
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
else
|
||||
else if(predicate != null)
|
||||
{
|
||||
ResourceLocation location = new ResourceLocation(child.getKey(), node.getKey());
|
||||
flag = flag && (Item.REGISTRY.containsKey(location) || Block.REGISTRY.containsKey(location));
|
||||
flag = flag && predicate.test(child.getKey(), node.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,4 +279,10 @@ public class Node
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return this.getKey();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package exopandora.worldhandler.helper;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.registry.IRegistry;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class RegistryTranslator
|
||||
{
|
||||
private static final Map<IForgeRegistry<?>, Function<?, String>> FORGE = new HashMap<IForgeRegistry<?>, Function<?, String>>();
|
||||
private static final Map<IRegistry<?>, Function<?, String>> VANILLA = new HashMap<IRegistry<?>, Function<?, String>>();
|
||||
|
||||
static
|
||||
{
|
||||
register(ForgeRegistries.BLOCKS, Block::getTranslationKey);
|
||||
register(ForgeRegistries.ITEMS, Item::getTranslationKey);
|
||||
register(ForgeRegistries.POTIONS, Potion::getName);
|
||||
register(ForgeRegistries.BIOMES, Biome::getTranslationKey);
|
||||
register(ForgeRegistries.ENCHANTMENTS, Enchantment::getName);
|
||||
register(ForgeRegistries.ENTITIES, EntityType::getTranslationKey);
|
||||
register(IRegistry.field_212623_l, stat -> "stat." + stat.toString().replace(':', '.'));
|
||||
}
|
||||
|
||||
private static <T extends ForgeRegistryEntry<T>> void register(IForgeRegistry<T> registry, Function<T, String> mapper)
|
||||
{
|
||||
FORGE.put(registry, mapper);
|
||||
}
|
||||
|
||||
private static <T> void register(IRegistry<T> registry, Function<T, String> mapper)
|
||||
{
|
||||
VANILLA.put(registry, mapper);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> String translate(ResourceLocation resource)
|
||||
{
|
||||
for(IForgeRegistry<?> registry : FORGE.keySet())
|
||||
{
|
||||
if(registry.containsKey(resource))
|
||||
{
|
||||
return ((Function<T, String>) FORGE.get(registry)).apply((T) registry.getValue(resource));
|
||||
}
|
||||
}
|
||||
|
||||
for(IRegistry<?> registry : VANILLA.keySet())
|
||||
{
|
||||
if(registry.func_212607_c(resource))
|
||||
{
|
||||
return ((Function<T, String>) VANILLA.get(registry)).apply((T) registry.func_212608_b(resource));
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,17 @@
|
||||
package exopandora.worldhandler.helper;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import exopandora.worldhandler.Main;
|
||||
import exopandora.worldhandler.config.ConfigSkin;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.item.Item;
|
||||
import exopandora.worldhandler.builder.types.BlockResourceLocation;
|
||||
import exopandora.worldhandler.builder.types.ItemResourceLocation;
|
||||
import exopandora.worldhandler.config.Config;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class ResourceHelper
|
||||
{
|
||||
private static final ResourceLocation BACKGROUND = new ResourceLocation("textures/gui/demo_background.png");
|
||||
@@ -24,38 +22,57 @@ public class ResourceHelper
|
||||
{
|
||||
if(resource != null)
|
||||
{
|
||||
return new ResourceLocation(resource.replaceAll(" ", "_"));
|
||||
return new ResourceLocation(stripToResourceLocation(resource));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isRegisteredItem(String item)
|
||||
@Nullable
|
||||
public static String stripToResourceLocation(String resource)
|
||||
{
|
||||
return Item.REGISTRY.getKeys().contains(stringToResourceLocation(item));
|
||||
}
|
||||
|
||||
public static boolean isRegisteredBlock(String block)
|
||||
{
|
||||
return Block.REGISTRY.getKeys().contains(stringToResourceLocation(block));
|
||||
}
|
||||
|
||||
public static boolean isRegisteredMob(String mob)
|
||||
{
|
||||
return EntityList.isRegistered(stringToResourceLocation(mob));
|
||||
}
|
||||
|
||||
public static boolean isRegisteredAdvancement(String advancement)
|
||||
{
|
||||
return AdvancementHelper.ADVANCEMENT_MANAGER.getAdvancement(stringToResourceLocation(advancement)) != null;
|
||||
if(resource != null)
|
||||
{
|
||||
return resource.toLowerCase().replaceAll("[^a-z0-9/._\\-:]", "_");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ResourceLocation stringToResourceLocationNullable(String resource, Predicate<String> predicate)
|
||||
public static boolean isRegistered(ResourceLocation resource, IForgeRegistry<?> registry)
|
||||
{
|
||||
if(predicate.test(resource))
|
||||
return resource != null && registry != null && registry.containsKey(resource);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static boolean isRegistered(BlockResourceLocation resource, IForgeRegistry<?> registry)
|
||||
{
|
||||
if(resource != null)
|
||||
{
|
||||
return stringToResourceLocation(resource);
|
||||
return isRegistered(resource.getResourceLocation(), registry);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static boolean isRegistered(ItemResourceLocation resource, IForgeRegistry<?> registry)
|
||||
{
|
||||
if(resource != null)
|
||||
{
|
||||
return isRegistered(resource.getResourceLocation(), registry);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ResourceLocation assertRegistered(ResourceLocation resource, IForgeRegistry<?> registry)
|
||||
{
|
||||
if(ResourceHelper.isRegistered(resource, registry))
|
||||
{
|
||||
return resource;
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -63,7 +80,7 @@ public class ResourceHelper
|
||||
|
||||
public static ResourceLocation getBackgroundTexture()
|
||||
{
|
||||
if(ConfigSkin.getTextureType().equals("resourcepack"))
|
||||
if(Config.getSkin().getTextureType().equals("resourcepack"))
|
||||
{
|
||||
return BACKGROUND;
|
||||
}
|
||||
@@ -73,16 +90,16 @@ public class ResourceHelper
|
||||
|
||||
public static ResourceLocation getIconTexture()
|
||||
{
|
||||
return new ResourceLocation(Main.MODID, "textures/icons/icons" + ConfigSkin.getIconSize() + ".png");
|
||||
return new ResourceLocation(Main.MODID, "textures/icons/icons" + Config.getSkin().getIconSize() + ".png");
|
||||
}
|
||||
|
||||
public static ResourceLocation getButtonTexture()
|
||||
{
|
||||
if(ConfigSkin.getTextureType().equals("resourcepack"))
|
||||
if(Config.getSkin().getTextureType().equals("resourcepack"))
|
||||
{
|
||||
return BUTTON;
|
||||
}
|
||||
|
||||
return new ResourceLocation(Main.MODID, "textures/skins/" + ConfigSkin.getTextureType() + "/" + ConfigSkin.getTextureType() + "_buttons.png");
|
||||
return new ResourceLocation(Main.MODID, "textures/skins/" + Config.getSkin().getTextureType() + "/" + Config.getSkin().getTextureType() + "_buttons.png");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,13 +8,17 @@ import java.util.function.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.mojang.realmsclient.gui.ChatFormatting;
|
||||
|
||||
import net.minecraft.scoreboard.IScoreCriteria;
|
||||
import net.minecraft.scoreboard.ScoreCriteria;
|
||||
import net.minecraft.scoreboard.Team.CollisionRule;
|
||||
import net.minecraft.scoreboard.Team.EnumVisible;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.stats.StatType;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.registry.IRegistry;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class ScoreboardHelper
|
||||
{
|
||||
private final Node objectives = new Node();
|
||||
@@ -37,13 +41,28 @@ public class ScoreboardHelper
|
||||
|
||||
//Objectives
|
||||
|
||||
for(String criteria : IScoreCriteria.INSTANCES.keySet())
|
||||
for(String scoreCriteria : ScoreCriteria.INSTANCES.keySet())
|
||||
{
|
||||
this.objectives.insertNode(criteria.split("[.]"));
|
||||
this.objectives.insertNode(scoreCriteria.split("[.:]"));
|
||||
}
|
||||
|
||||
this.objectives.merge("minecraft", (parent, child) -> parent + "." + child);
|
||||
|
||||
for(StatType<?> type : IRegistry.field_212634_w)
|
||||
{
|
||||
if(!type.equals(StatList.CUSTOM))
|
||||
{
|
||||
List<Node> entries = new ArrayList<Node>();
|
||||
|
||||
for(ResourceLocation key : type.getRegistry().getKeys())
|
||||
{
|
||||
entries.add(new Node(this.buildKey(key)));
|
||||
}
|
||||
|
||||
this.objectives.addNode(this.buildKey(IRegistry.field_212634_w.getKey(type)), entries);
|
||||
}
|
||||
}
|
||||
|
||||
this.objectives.merge("stat", (parent, child) -> parent + "." + child);
|
||||
this.objectives.mergeItems();
|
||||
this.objectives.sort();
|
||||
|
||||
//Slots
|
||||
@@ -59,12 +78,18 @@ public class ScoreboardHelper
|
||||
this.options.addNode("color", colors);
|
||||
this.options.addNode("nametagVisibility", visibility);
|
||||
this.options.addNode("deathMessageVisibility", visibility);
|
||||
this.options.addNode("friendlyfire", bool);
|
||||
this.options.addNode("friendlyFire", bool);
|
||||
this.options.addNode("seeFriendlyInvisibles", bool);
|
||||
this.options.addNode("collisionRule", collision);
|
||||
|
||||
this.options.sort();
|
||||
}
|
||||
|
||||
private String buildKey(ResourceLocation key)
|
||||
{
|
||||
return key.toString().replace(":", ".");
|
||||
}
|
||||
|
||||
private <T> List<Node> createList(T[] array, Function<T, String> mapper)
|
||||
{
|
||||
return this.createList(array, mapper, Predicates.<T>alwaysTrue());
|
||||
|
||||
Reference in New Issue
Block a user