diff --git a/README.md b/README.md index 6a1412f..409df82 100644 --- a/README.md +++ b/README.md @@ -3,15 +3,3 @@ □ minecraft mod 1.12.2 ve 1.20.1' e kadar ○ ./gradlew build komutu - -[CustomMenu] -#/menu create yeni gui menusu oluşturulur. -/menu create isim - -#/menu open oluşturduğunuz menuyu açar. -/menu open isim - -#/menu add oluşturduğunuz menuye item ekleyip komut ataya bilirsiniz. -/menu add isim item isim komut - -test \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..4ff92ca --- /dev/null +++ b/build.gradle @@ -0,0 +1,64 @@ +buildscript { + repositories { + mavenCentral() + maven { url 'https://maven.minecraftforge.net' } + } + dependencies { + classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true + } +} +apply plugin: 'net.minecraftforge.gradle' + +version = "2.0.1" +group = "com.buildwand" +archivesBaseName = "buildwand 1.15.2" + +sourceCompatibility = targetCompatibility = '1.8' +compileJava { + sourceCompatibility = targetCompatibility = '1.8' +} + +minecraft { + mappings channel: 'snapshot', version: '20200514-1.15.1' + + runs { + client { + workingDirectory project.file('run') + property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' + property 'forge.logging.console.level', 'debug' + mods { + buildwand { + source sourceSets.main + } + } + } + server { + workingDirectory project.file('run') + property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' + property 'forge.logging.console.level', 'debug' + mods { + buildwand { + source sourceSets.main + } + } + } + } +} + +dependencies { + minecraft 'net.minecraftforge:forge:1.15.2-31.2.0' +} + +processResources { + inputs.property "version", project.version + inputs.property "mcversion", "1.15" + + from(sourceSets.main.resources.srcDirs) { + include 'META-INF/mods.toml' + expand 'version':project.version + } + + from(sourceSets.main.resources.srcDirs) { + exclude 'META-INF/mods.toml' + } +} diff --git a/custommenu1.12.2.zip b/custommenu1.12.2.zip deleted file mode 100644 index 3841a4b..0000000 Binary files a/custommenu1.12.2.zip and /dev/null differ diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..61c57cf Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..4adcf64 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists \ No newline at end of file diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..2bc1dfc --- /dev/null +++ b/gradlew @@ -0,0 +1,223 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, not just bash. +# +# The "bash" shell, and others such as ksh, zsh, and dash, add many +# extensions to the POSIX shell specification. If code you add uses any +# of these extensions, such as zsh's «${1:q}» or bash's «${var//a/b}», +# then your changes will break when run in a less-capable shell. +# +# (3) Most script changes belong in the "generated_gradle_run_script_body", +# not here. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" \ No newline at end of file diff --git a/src/main/java/com/buildwand/BuildWandPlugin.java b/src/main/java/com/buildwand/BuildWandPlugin.java new file mode 100644 index 0000000..9f3d538 --- /dev/null +++ b/src/main/java/com/buildwand/BuildWandPlugin.java @@ -0,0 +1,75 @@ + +package com.buildwand; + +import com.buildwand.commands.WandCommand; +import com.buildwand.listeners.SelectionListener; +import com.buildwand.utils.AreaSelection; +import com.buildwand.utils.BuildManager; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; +import net.minecraftforge.fml.event.server.FMLServerStartingEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +@Mod("buildwand") +public class BuildWandPlugin { + + public static final String MODID = "buildwand"; + private static final Logger logger = LogManager.getLogger(MODID); + + private static BuildWandPlugin instance; + private Map playerSelections; + private BuildManager buildManager; + + public BuildWandPlugin() { + instance = this; + + FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); + MinecraftForge.EVENT_BUS.register(this); + } + + private void setup(final FMLCommonSetupEvent event) { + playerSelections = new HashMap<>(); + buildManager = new BuildManager(); + + // Register event listeners + MinecraftForge.EVENT_BUS.register(new SelectionListener()); + + logger.info("Build Wand mod initialized!"); + } + + @SubscribeEvent + public void onServerStarting(FMLServerStartingEvent event) { + // Register commands + WandCommand.register(event.getCommandDispatcher()); + + logger.info("Build Wand mod started!"); + } + + public static BuildWandPlugin getInstance() { + return instance; + } + + public static Logger getLogger() { + return logger; + } + + public Map getPlayerSelections() { + return playerSelections; + } + + public AreaSelection getOrCreatePlayerSelection(UUID playerUUID) { + return playerSelections.computeIfAbsent(playerUUID, k -> new AreaSelection()); + } + + public BuildManager getBuildManager() { + return buildManager; + } +} diff --git a/src/main/java/com/buildwand/commands/WandCommand.java b/src/main/java/com/buildwand/commands/WandCommand.java new file mode 100644 index 0000000..4779942 --- /dev/null +++ b/src/main/java/com/buildwand/commands/WandCommand.java @@ -0,0 +1,183 @@ +package com.buildwand.commands; + +import com.buildwand.BuildWandPlugin; +import com.buildwand.utils.AreaSelection; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.minecraft.command.CommandSource; +import net.minecraft.command.Commands; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.item.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.ListNBT; +import net.minecraft.nbt.StringNBT; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.Hand; +import net.minecraft.util.text.StringTextComponent; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.util.math.BlockPos; + +import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.UUID; + +public class WandCommand { + + public static void register(CommandDispatcher dispatcher) { + dispatcher.register(Commands.literal("wand") + .executes(WandCommand::executeWandCommand) + .then(Commands.literal("undo").executes(WandCommand::executeUndo)) + .then(Commands.literal("clear").executes(WandCommand::executeClearSelection)) + .then(Commands.literal("copy").executes(WandCommand::executeCopy)) + .then(Commands.literal("paste").executes(WandCommand::executePaste)) + .then(Commands.literal("help").executes(WandCommand::showHelp)) + ); + } + + private static int executeWandCommand(CommandContext context) throws CommandSyntaxException { + CommandSource source = context.getSource(); + PlayerEntity player = source.asPlayer(); + + // Create a wooden axe + ItemStack wandItem = new ItemStack(Items.WOODEN_AXE, 1); + CompoundNBT nbt = wandItem.getOrCreateTag(); + + // Set display name (JSON format required in 1.14) + CompoundNBT display = new CompoundNBT(); + display.putString("Name", "{\"text\":\"Seçim Baltası\",\"color\":\"gold\"}"); + + // Set lore + ListNBT lore = new ListNBT(); + lore.add(StringNBT.valueOf("{\"text\":\"İlk köşeyi seçmek için sol tıklayın\",\"color\":\"gray\"}")); + lore.add(StringNBT.valueOf("{\"text\":\"İkinci köşeyi seçmek için sağ tıklayın\",\"color\":\"gray\"}")); + lore.add(StringNBT.valueOf("{\"text\":\"Seçimden sonra malzemeyi ve miktarı belirtin\",\"color\":\"yellow\"}")); + display.put("Lore", lore); + + nbt.put("display", display); + + // Try to give player the wand or place in hand + if (!player.getHeldItem(Hand.MAIN_HAND).isEmpty()) { + // Try to add it to inventory + if (!player.inventory.addItemStackToInventory(wandItem)) { + player.sendMessage(new StringTextComponent(TextFormatting.RED + "Seçim Baltası size veremedim. Envanteriniz dolu.")); + return 0; + } else { + player.sendMessage(new StringTextComponent(TextFormatting.GREEN + "Seçim Baltası envanterinize eklendi.")); + } + } else { + // Place in main hand + player.setHeldItem(Hand.MAIN_HAND, wandItem); + player.sendMessage(new StringTextComponent(TextFormatting.GREEN + "Elinize seçim baltası verildi.")); + } + + // Check if player already has an area selected + AreaSelection selection = BuildWandPlugin.getInstance().getOrCreatePlayerSelection(player.getUniqueID()); + if (selection != null && selection.isComplete()) { + player.sendMessage(new StringTextComponent(TextFormatting.GREEN + "Zaten bir seçeneğiniz var " + + TextFormatting.YELLOW + selection.getBlockCount() + + TextFormatting.GREEN + " blocks.")); + + player.sendMessage(new StringTextComponent( + TextFormatting.GREEN + "Yapı malzemesini belirtmek için sohbete bir malzeme ve miktar yazın " + + TextFormatting.YELLOW + "(e.g., 'cobblestone 100 veya planks:2 100')")); + BuildWandPlugin.getInstance().getBuildManager().setAwaitingMaterialInput(player.getUniqueID(), true); + } else { + player.sendMessage(new StringTextComponent(TextFormatting.YELLOW + + "İlk köşeyi seçmek için sol tıklayın, ikinci köşeyi seçmek için sağ tıklayın.")); + } + return 1; + } + + + private static int executeUndo(CommandContext context) throws CommandSyntaxException { + PlayerEntity player = context.getSource().asPlayer(); + + // Try to undo the last build first + if (BuildWandPlugin.getInstance().getBuildManager().undoLastBuild(player)) { + return 1; + } + // If no recent build, try to clear selection + else { + UUID playerUUID = player.getUniqueID(); + AreaSelection selection = BuildWandPlugin.getInstance().getPlayerSelections().get(playerUUID); + + if (selection != null && (selection.getFirstPosition() != null || selection.getSecondPosition() != null)) { + // Clear the selection + BuildWandPlugin.getInstance().getPlayerSelections().remove(playerUUID); + player.sendMessage(new StringTextComponent(TextFormatting.YELLOW + "Alan seçiminiz temizlendi.")); + } else { + player.sendMessage(new StringTextComponent(TextFormatting.RED + "Geri alınacak yeni bir yapı veya temizlenecek bir seçim yok.")); + } + } + return 0; + } + + private static int executeClearSelection(CommandContext context) throws CommandSyntaxException { + PlayerEntity player = context.getSource().asPlayer(); + UUID playerUUID = player.getUniqueID(); + AreaSelection selection = BuildWandPlugin.getInstance().getPlayerSelections().get(playerUUID); + + if (selection != null && (selection.getFirstPosition() != null || selection.getSecondPosition() != null)) { + // Clear the selection + BuildWandPlugin.getInstance().getPlayerSelections().remove(playerUUID); + player.sendMessage(new StringTextComponent(TextFormatting.YELLOW + "Your area selection has been cleared.")); + } else { + player.sendMessage(new StringTextComponent(TextFormatting.RED + "You don't have an active selection to clear.")); + } + return 1; + } + + private static int executeCopy(CommandContext context) throws CommandSyntaxException { + PlayerEntity player = context.getSource().asPlayer(); + BuildWandPlugin.getInstance().getBuildManager().copyStructure(player); + return 1; + } + + private static int executePaste(CommandContext context) throws CommandSyntaxException { + PlayerEntity player = context.getSource().asPlayer(); + BuildWandPlugin.getInstance().getBuildManager().pasteStructure(player, true); + return 1; + } + + private static int showHelp(CommandContext context) throws CommandSyntaxException { + PlayerEntity player = context.getSource().asPlayer(); + player.sendMessage(new StringTextComponent(TextFormatting.GOLD + "=== BuildWand Commands ===")); + player.sendMessage(new StringTextComponent( + TextFormatting.YELLOW + "/wand" + TextFormatting.WHITE + " - Bir seçim baltayı al" + )); + player.sendMessage(new StringTextComponent( + TextFormatting.YELLOW + "/wand help" + TextFormatting.WHITE + " - Show this help message" + )); + player.sendMessage(new StringTextComponent( + TextFormatting.YELLOW + "/wand undo" + TextFormatting.WHITE + " - Son bina işleminizi geri alın veya seçiminizi temizleyin" + )); + player.sendMessage(new StringTextComponent( + TextFormatting.YELLOW + "/wand clear" + TextFormatting.WHITE + " - Mevcut seçiminizi temizleyin" + )); + player.sendMessage(new StringTextComponent( + TextFormatting.YELLOW + "/wand copy" + TextFormatting.WHITE + " - Seçili yapıyı kopyala (malzeme gereksinimlerini gösterir)" + )); + player.sendMessage(new StringTextComponent( + TextFormatting.YELLOW + "/wand paste" + TextFormatting.WHITE + " - Kopyalanan yapıyı bulunduğunuz yere yapıştırın (envanterdeki malzemeleri kullanır)" + )); + return 1; + } + + // The following methods are kept for compatibility or if specific tab completion logic is still needed. + // For 1.13+, Brigadier handles tab completion more dynamically. + + public List getTabCompletions(MinecraftServer server, CommandSource source, String[] args, @Nullable BlockPos targetPos) { + // This method is part of the old CommandBase system and might not be directly used with Brigadier. + // Brigadier's tab completion is handled within the CommandDispatcher registration. + if (args.length == 1) { + return Arrays.asList("undo", "clear", "copy", "paste", "help"); + } + return Collections.emptyList(); + } +} \ No newline at end of file diff --git a/src/main/java/com/buildwand/listeners/SelectionListener.java b/src/main/java/com/buildwand/listeners/SelectionListener.java new file mode 100644 index 0000000..77b40b2 --- /dev/null +++ b/src/main/java/com/buildwand/listeners/SelectionListener.java @@ -0,0 +1,96 @@ +package com.buildwand.listeners; + +import com.buildwand.BuildWandPlugin; +import com.buildwand.utils.AreaSelection; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.text.StringTextComponent; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.world.World; +import net.minecraftforge.event.entity.player.PlayerInteractEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; + +public class SelectionListener { + + @SubscribeEvent + public void onLeftClick(PlayerInteractEvent.LeftClickBlock event) { + // Only run on server side + if (event.getWorld().isRemote) return; + + PlayerEntity player = event.getPlayer(); + if (!isHoldingWand(player) || event.getPos() == null) { + return; + } + + // Get player's selection + AreaSelection selection = BuildWandPlugin.getInstance().getOrCreatePlayerSelection(player.getUniqueID()); + BlockPos pos = event.getPos(); + World world = event.getWorld(); + + // Set first position + selection.setFirstPosition(new net.minecraft.util.math.BlockPos(pos.getX(), pos.getY(), pos.getZ()), world); + player.sendMessage(new StringTextComponent(TextFormatting.GREEN + "Pozisyon 1 ayarlandı " + + TextFormatting.YELLOW + pos.getX() + ", " + + pos.getY() + ", " + pos.getZ())); + + // Check if both positions are set + checkBothPositionsSet(player, selection); + + // Cancel the event to prevent breaking blocks + event.setCanceled(true); + } + + @SubscribeEvent + public void onRightClick(PlayerInteractEvent.RightClickBlock event) { + // Only run on server side + if (event.getWorld().isRemote) return; + + PlayerEntity player = event.getPlayer(); + if (!isHoldingWand(player) || event.getPos() == null) { + return; + } + + // Get player's selection + AreaSelection selection = BuildWandPlugin.getInstance().getOrCreatePlayerSelection(player.getUniqueID()); + BlockPos pos = event.getPos(); + World world = event.getWorld(); + + // Set second position + selection.setSecondPosition(new net.minecraft.util.math.BlockPos(pos.getX(), pos.getY(), pos.getZ()), world); + player.sendMessage(new StringTextComponent(TextFormatting.GREEN + "Pozisyon 2 ayarlandı " + + TextFormatting.YELLOW + pos.getX() + ", " + + pos.getY() + ", " + pos.getZ())); + + // Check if both positions are set + checkBothPositionsSet(player, selection); + + // Cancel the event to prevent interacting with blocks + event.setCanceled(true); + } + + private boolean isHoldingWand(PlayerEntity player) { + ItemStack itemInHand = player.getHeldItemMainhand(); + return !itemInHand.isEmpty() && itemInHand.getItem() == Items.WOODEN_AXE; + } + + private void checkBothPositionsSet(PlayerEntity player, AreaSelection selection) { + if (selection.isComplete()) { + int blockCount = selection.getBlockCount(); + + player.sendMessage(new StringTextComponent( + TextFormatting.GREEN + "Seçim tamamlandı! Alan şunları içerir: " + + TextFormatting.YELLOW + blockCount + + TextFormatting.GREEN + " bloklar." + )); + + player.sendMessage(new StringTextComponent( + TextFormatting.GREEN + "Yapı malzemesini belirtmek için sohbete bir malzeme ve miktar yazın " + + TextFormatting.YELLOW + "(e.g., 'cobblestone 100' or 'planks:1 100')" + )); + + BuildWandPlugin.getInstance().getBuildManager().setAwaitingMaterialInput(player.getUniqueID(), true); + } + } +} diff --git a/src/main/java/com/buildwand/utils/AreaSelection.java b/src/main/java/com/buildwand/utils/AreaSelection.java new file mode 100644 index 0000000..7a55c27 --- /dev/null +++ b/src/main/java/com/buildwand/utils/AreaSelection.java @@ -0,0 +1,84 @@ +package com.buildwand.utils; + +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class AreaSelection { + private BlockPos firstPosition; + private BlockPos secondPosition; + private World world; + + public BlockPos getFirstPosition() { + return firstPosition; + } + + public void setFirstPosition(BlockPos firstPosition, World world) { + this.firstPosition = firstPosition; + if (this.world == null) { + this.world = world; + } + } + + public BlockPos getSecondPosition() { + return secondPosition; + } + + public void setSecondPosition(BlockPos secondPosition, World world) { + this.secondPosition = secondPosition; + if (this.world == null) { + this.world = world; + } + } + + public boolean isComplete() { + return firstPosition != null && secondPosition != null && world != null; + } + + public int getBlockCount() { + if (!isComplete()) { + return 0; + } + + int xMin = Math.min(firstPosition.getX(), secondPosition.getX()); + int yMin = Math.min(firstPosition.getY(), secondPosition.getY()); + int zMin = Math.min(firstPosition.getZ(), secondPosition.getZ()); + + int xMax = Math.max(firstPosition.getX(), secondPosition.getX()); + int yMax = Math.max(firstPosition.getY(), secondPosition.getY()); + int zMax = Math.max(firstPosition.getZ(), secondPosition.getZ()); + + int width = xMax - xMin + 1; + int height = yMax - yMin + 1; + int depth = zMax - zMin + 1; + + return width * height * depth; + } + + public int getMinX() { + return Math.min(firstPosition.getX(), secondPosition.getX()); + } + + public int getMinY() { + return Math.min(firstPosition.getY(), secondPosition.getY()); + } + + public int getMinZ() { + return Math.min(firstPosition.getZ(), secondPosition.getZ()); + } + + public int getMaxX() { + return Math.max(firstPosition.getX(), secondPosition.getX()); + } + + public int getMaxY() { + return Math.max(firstPosition.getY(), secondPosition.getY()); + } + + public int getMaxZ() { + return Math.max(firstPosition.getZ(), secondPosition.getZ()); + } + + public World getWorld() { + return world; + } +} diff --git a/src/main/java/com/buildwand/utils/BuildManager.java b/src/main/java/com/buildwand/utils/BuildManager.java new file mode 100644 index 0000000..68a0669 --- /dev/null +++ b/src/main/java/com/buildwand/utils/BuildManager.java @@ -0,0 +1,671 @@ + +package com.buildwand.utils; + +import com.buildwand.BuildWandPlugin; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.block.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3i; +import net.minecraft.util.text.StringTextComponent; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.world.World; +import net.minecraftforge.event.ServerChatEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.registries.ForgeRegistries; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class BuildManager { + private final Map awaitingMaterialInput = new HashMap<>(); + private static final Pattern MATERIAL_PATTERN = Pattern.compile("([a-zA-Z_:]+)\\s+(\\d+)"); + + // Structure to store block changes for undo functionality + private static class BlockChange { + BlockPos location; + World world; + BlockState originalState; + + BlockChange(BlockPos location, World world, BlockState originalState) { + this.location = location; + this.world = world; + this.originalState = originalState; + } + } + + // Structure to store build information for undo functionality + private static class BuildInfo { + List changes; + Item materialType; + int blocksPlaced; + Map usedMaterials; + List usedItemStacks; + + BuildInfo(List changes, Item materialType, int blocksPlaced) { + this.changes = changes; + this.materialType = materialType; + this.blocksPlaced = blocksPlaced; + this.usedMaterials = new HashMap<>(); + this.usedItemStacks = new ArrayList<>(); + } + } + + // Structure to store copied blocks for copy/paste functionality + private static class CopiedStructure { + Map blocks = new HashMap<>(); + Vec3i dimensions; + Vec3i origin; + + CopiedStructure(Map blocks, Vec3i dimensions, Vec3i origin) { + this.blocks = blocks; + this.dimensions = dimensions; + this.origin = origin; + } + + // Get a list of materials needed for this structure + Map getMaterialList() { + Map materials = new HashMap<>(); + + for (BlockState state : blocks.values()) { + Block block = state.getBlock(); + + if (block != Blocks.AIR) { + Item item = block.asItem(); + if (item != null) { + materials.put(item, materials.getOrDefault(item, 0) + 1); + } + } + } + + return materials; + } + + // Get a list of ItemStacks for this structure + List getMaterialStacks() { + Map consolidatedStacks = new HashMap<>(); + + for (BlockState state : blocks.values()) { + Block block = state.getBlock(); + + if (block != Blocks.AIR) { + Item item = block.asItem(); + if (item != null) { + String key = item.getRegistryName().toString(); + + if (consolidatedStacks.containsKey(key)) { + consolidatedStacks.get(key).grow(1); + } else { + consolidatedStacks.put(key, new ItemStack(item, 1)); + } + } + } + } + + return new ArrayList<>(consolidatedStacks.values()); + } + + // Get total number of blocks (excluding air) + int getTotalBlocks() { + int count = 0; + for (BlockState state : blocks.values()) { + if (state.getBlock() != Blocks.AIR) { + count++; + } + } + return count; + } + } + + // Store the last set of changes for each player + private final Map lastBuilds = new HashMap<>(); + + // Store copied structures for players + private final Map playerCopies = new HashMap<>(); + + public BuildManager() { + MinecraftForge.EVENT_BUS.register(this); + } + + public void setAwaitingMaterialInput(UUID playerUUID, boolean awaiting) { + awaitingMaterialInput.put(playerUUID, awaiting); + } + + /** + * Copies a structure from an area selection + * @param player The player requesting the copy + * @return true if copy was successful, false if selection is incomplete + */ + public boolean copyStructure(PlayerEntity player) { + UUID playerUUID = player.getUniqueID(); + AreaSelection selection = BuildWandPlugin.getInstance().getPlayerSelections().get(playerUUID); + + if (selection == null || !selection.isComplete()) { + player.sendMessage(new StringTextComponent(TextFormatting.RED + "Öncelikle tam bir seçim yapmanız gerekiyor!")); + return false; + } + + World world = selection.getWorld(); + Map blocks = new HashMap<>(); + + // Calculate dimensions + int minX = selection.getMinX(); + int minY = selection.getMinY(); + int minZ = selection.getMinZ(); + int maxX = selection.getMaxX(); + int maxY = selection.getMaxY(); + int maxZ = selection.getMaxZ(); + + Vec3i dimensions = new Vec3i(maxX - minX + 1, maxY - minY + 1, maxZ - minZ + 1); + Vec3i origin = new Vec3i(minX, minY, minZ); + + // Copy all blocks in the selection + for (int x = minX; x <= maxX; x++) { + for (int y = minY; y <= maxY; y++) { + for (int z = minZ; z <= maxZ; z++) { + BlockPos pos = new BlockPos(x, y, z); + BlockState state = world.getBlockState(pos); + + // Store relative position from minimum coordinates + Vec3i relativePos = new Vec3i(x - minX, y - minY, z - minZ); + blocks.put(relativePos, state); + } + } + } + + // Create and store the copied structure + CopiedStructure copiedStructure = new CopiedStructure(blocks, dimensions, origin); + playerCopies.put(playerUUID, copiedStructure); + + // Generate a material list summary + Map materials = copiedStructure.getMaterialList(); + int totalBlocks = copiedStructure.getTotalBlocks(); + + // Send confirmation message to player + player.sendMessage(new StringTextComponent( + TextFormatting.GREEN + "Boyutları olan bir yapı başarıyla kopyalandı " + + TextFormatting.YELLOW + dimensions.getX() + "x" + dimensions.getY() + "x" + dimensions.getZ() + + TextFormatting.GREEN + " içeren " + + TextFormatting.YELLOW + totalBlocks + + TextFormatting.GREEN + " bloklar. " + )); + + // Show material list if not empty + if (!materials.isEmpty()) { + player.sendMessage(new StringTextComponent(TextFormatting.GREEN + "Gerekli malzemeler:")); + + for (Map.Entry entry : materials.entrySet()) { + String itemName = entry.getKey().getRegistryName() != null ? entry.getKey().getRegistryName().toString() : "unknown"; + player.sendMessage(new StringTextComponent( + TextFormatting.YELLOW + "• " + + TextFormatting.GOLD + entry.getValue() + "x " + + TextFormatting.WHITE + itemName + )); + } + + player.sendMessage(new StringTextComponent( + TextFormatting.GREEN + "Kullanmak " + + TextFormatting.YELLOW + "/wand paste" + + TextFormatting.GREEN + " Bu yapıyı yerleştirmek için." + )); + } + + return true; + } + + /** + * Undoes the last building operation for a player and returns materials + * @param player The player requesting the undo + * @return true if undo was successful, false if there was nothing to undo + */ + public boolean undoLastBuild(PlayerEntity player) { + UUID playerUUID = player.getUniqueID(); + BuildInfo buildInfo = lastBuilds.get(playerUUID); + + if (buildInfo == null || buildInfo.changes.isEmpty()) { + return false; + } + + int blocksReverted = 0; + + // Restore each block back to its original state + for (BlockChange change : buildInfo.changes) { + change.world.setBlockState(change.location, change.originalState, 3); + blocksReverted++; + } + + // Return materials to player's inventory + int returnedBlocks = 0; + + // Check if this was a copy-paste operation (multiple materials) + if (buildInfo.usedItemStacks != null && !buildInfo.usedItemStacks.isEmpty()) { + // Return each ItemStack + for (ItemStack stack : buildInfo.usedItemStacks) { + Item type = stack.getItem(); + int count = stack.getCount(); + + if (count > 0) { + returnMaterialsToInventory(player, type, count); + returnedBlocks += count; + } + } + + player.sendMessage(new StringTextComponent( + TextFormatting.GREEN + "Başarıyla geri alındı " + + TextFormatting.YELLOW + blocksReverted + + TextFormatting.GREEN + " blokları orijinal hallerine geri döndürür. " + + TextFormatting.GOLD + returnedBlocks + + TextFormatting.GREEN + " Çeşitli türdeki malzemeler envanterinize geri döndü. " + )); + } + // Fallback to old usedMaterials map (for backward compatibility) + else if (buildInfo.usedMaterials != null && !buildInfo.usedMaterials.isEmpty()) { + // Return each type of material + Map materials = buildInfo.usedMaterials; + + for (Map.Entry entry : materials.entrySet()) { + Item type = entry.getKey(); + int count = entry.getValue(); + + if (count > 0) { + returnMaterialsToInventory(player, type, count); + returnedBlocks += count; + } + } + + player.sendMessage(new StringTextComponent( + TextFormatting.GREEN + "Başarıyla geri alındı " + + TextFormatting.YELLOW + blocksReverted + + TextFormatting.GREEN + " blokları orijinal hallerine geri döndürür. " + + TextFormatting.GOLD + returnedBlocks + + TextFormatting.GREEN + " Çeşitli türdeki malzemeler envanterinize geri döndü." + )); + } + // Regular build (single material) + else if (buildInfo.materialType != null && buildInfo.blocksPlaced > 0) { + returnMaterialsToInventory(player, buildInfo.materialType, buildInfo.blocksPlaced); + + String itemName = buildInfo.materialType.getRegistryName() != null ? buildInfo.materialType.getRegistryName().toString() : "unknown"; + player.sendMessage(new StringTextComponent( + TextFormatting.GREEN + "Başarıyla geri alındı " + + TextFormatting.YELLOW + blocksReverted + + TextFormatting.GREEN + " bloklar orijinal durumlarına geri döner. " + + TextFormatting.GOLD + buildInfo.blocksPlaced + + TextFormatting.GREEN + " malzemeleri " + + TextFormatting.YELLOW + itemName + + TextFormatting.GREEN + " envanterinize iade edildi." + )); + } + // No materials to return + else { + player.sendMessage(new StringTextComponent( + TextFormatting.GREEN + "Başarıyla geri alındı " + + TextFormatting.YELLOW + blocksReverted + + TextFormatting.GREEN + " bloklar orijinal durumlarına geri döner." + )); + } + + // Clear the build info after undoing + lastBuilds.remove(playerUUID); + + return true; + } + + /** + * Pastes previously copied structure at player's location + * @param player The player requesting the paste + * @param checkMaterials Whether to check if player has required materials + * @return true if paste was successful, false if no structure was copied + */ + public boolean pasteStructure(PlayerEntity player, boolean checkMaterials) { + UUID playerUUID = player.getUniqueID(); + CopiedStructure copiedStructure = playerCopies.get(playerUUID); + + if (copiedStructure == null) { + player.sendMessage(new StringTextComponent(TextFormatting.RED + "Önce bir yapıyı kopyalamanız gerekiyor!")); + return false; + } + + // Get the player's location to use as the paste origin + BlockPos playerPos = player.getPosition(); + World world = player.world; + + // We'll use the block the player is standing on + int originX = playerPos.getX(); + int originY = playerPos.getY() - 1; // One below the player + int originZ = playerPos.getZ(); + + // Track actually removed ItemStacks for accurate undo + List actuallyRemoved = new ArrayList<>(); + + // Check materials if required + if (checkMaterials) { + List requiredStacks = copiedStructure.getMaterialStacks(); + List missingStacks = new ArrayList<>(); + + // Check each material + for (ItemStack requiredStack : requiredStacks) { + Item itemType = requiredStack.getItem(); + int required = requiredStack.getCount(); + int available = countPlayerItems(player, itemType); + + if (available < required) { + missingStacks.add(new ItemStack(itemType, required - available)); + } + } + + // If anything is missing, tell the player + if (!missingStacks.isEmpty()) { + player.sendMessage(new StringTextComponent(TextFormatting.RED + "Yeterli materyaliniz yok:")); + + for (ItemStack missingStack : missingStacks) { + Item item = missingStack.getItem(); + String itemName = item.getRegistryName() != null ? item.getRegistryName().toString() : "bilinmeyen"; + player.sendMessage(new StringTextComponent( + TextFormatting.YELLOW + "• İhtiyaç " + + TextFormatting.GOLD + missingStack.getCount() + + TextFormatting.YELLOW + " Daha " + + TextFormatting.WHITE + itemName + )); + } + + return false; + } + + // Remove materials from player inventory + for (ItemStack requiredStack : requiredStacks) { + Item itemType = requiredStack.getItem(); + int count = requiredStack.getCount(); + + // Remove and track what was actually removed + removeItemTypeFromInventory(player, itemType, count); + actuallyRemoved.add(new ItemStack(itemType, count)); + } + } + + int blocksPlaced = 0; + List changes = new ArrayList<>(); + + // Paste each block + for (Map.Entry entry : copiedStructure.blocks.entrySet()) { + Vec3i relPos = entry.getKey(); + BlockState state = entry.getValue(); + + // Skip air blocks + if (state.getBlock() == Blocks.AIR) { + continue; + } + + // Calculate world position + int x = originX + relPos.getX(); + int y = originY + relPos.getY(); + int z = originZ + relPos.getZ(); + + BlockPos pos = new BlockPos(x, y, z); + + // Record original state for undo + BlockState originalState = world.getBlockState(pos); + changes.add(new BlockChange(pos, world, originalState)); + + // Place the block + world.setBlockState(pos, state, 3); + blocksPlaced++; + } + + // Save changes for undo + if (blocksPlaced > 0) { + if (checkMaterials) { + // Store actually removed materials for undo to return them + BuildInfo buildInfo = new BuildInfo(changes, null, 0); + buildInfo.usedItemStacks = actuallyRemoved; + lastBuilds.put(playerUUID, buildInfo); + } else { + // Free mode - no materials to return on undo + lastBuilds.put(playerUUID, new BuildInfo(changes, null, 0)); + } + + player.sendMessage(new StringTextComponent( + TextFormatting.GREEN + "Yapı başarıyla yapıştırıldı " + + TextFormatting.YELLOW + blocksPlaced + + TextFormatting.GREEN + " bloklar." + )); + + player.sendMessage(new StringTextComponent( + TextFormatting.GRAY + "Tip " + + TextFormatting.YELLOW + "/wand undo" + + TextFormatting.GRAY + " bu yapıştırmayı geri almak için." + )); + } else { + player.sendMessage(new StringTextComponent(TextFormatting.YELLOW + "Hiçbir blok yerleştirilmedi (yapı yalnızca hava blokları içerebilir).")); + } + + return true; + } + + /** + * Removes a specific item type from player's inventory + */ + private void removeItemTypeFromInventory(PlayerEntity player, Item itemType, int amount) { + int remaining = amount; + PlayerInventory inventory = player.inventory; + + // Remove items from inventory + for (int i = 0; i < inventory.getSizeInventory() && remaining > 0; i++) { + ItemStack stack = inventory.getStackInSlot(i); + + if (!stack.isEmpty() && stack.getItem() == itemType) { + int toRemove = Math.min(remaining, stack.getCount()); + + if (toRemove == stack.getCount()) { + inventory.setInventorySlotContents(i, ItemStack.EMPTY); + } else { + stack.shrink(toRemove); + } + + remaining -= toRemove; + } + } + } + + /** + * Returns materials to the player's inventory + * @param player The player to give items to + * @param itemType The type of item to give + * @param amount The amount of items to give + */ + private void returnMaterialsToInventory(PlayerEntity player, Item itemType, int amount) { + PlayerInventory inventory = player.inventory; + + // Calculate full stacks and remaining items + int maxStackSize = new ItemStack(itemType).getMaxStackSize(); + int fullStacks = amount / maxStackSize; + int remainingItems = amount % maxStackSize; + + // Add full stacks + for (int i = 0; i < fullStacks; i++) { + ItemStack stack = new ItemStack(itemType, maxStackSize); + + if (!inventory.addItemStackToInventory(stack)) { + // Drop the item if inventory is full + player.dropItem(stack, false); + } + } + + // Add remaining items if any + if (remainingItems > 0) { + ItemStack stack = new ItemStack(itemType, remainingItems); + + if (!inventory.addItemStackToInventory(stack)) { + // Drop the item if inventory is full + player.dropItem(stack, false); + } + } + } + + @SubscribeEvent + public void onChat(ServerChatEvent event) { + PlayerEntity player = event.getPlayer(); + UUID playerUUID = player.getUniqueID(); + + // Check if the player is expected to input a material + if (awaitingMaterialInput.getOrDefault(playerUUID, false)) { + String message = event.getMessage(); + + // Parse the message for material and quantity + Matcher matcher = MATERIAL_PATTERN.matcher(message); + if (matcher.matches()) { + event.setCanceled(true); // Cancel the chat message + awaitingMaterialInput.put(playerUUID, false); // Reset awaiting state + + String materialName = matcher.group(1); + int quantity = Integer.parseInt(matcher.group(2)); + + handleMaterialSpecification(player, materialName, quantity); + } + } + } + + private void handleMaterialSpecification(PlayerEntity player, String materialName, int quantity) { + // Normalize material name to lowercase and add minecraft: prefix if not present + materialName = materialName.toLowerCase(); + if (!materialName.contains(":")) { + materialName = "minecraft:" + materialName; + } + + // Try to find the block from the registry + Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(materialName)); + + if (block == null) { + player.sendMessage(new StringTextComponent(TextFormatting.RED + "Bilinmeyen malzeme: " + materialName)); + BuildWandPlugin.getInstance().getLogger().warn("Bilinmeyen blok türü: " + materialName); + return; + } + + // Get the default block state + BlockState blockState = block.getDefaultState(); + + // Get the corresponding item + Item item = block.asItem(); + + if (item == null) { + player.sendMessage(new StringTextComponent(TextFormatting.RED + "Blok için karşılık gelen öğe bulunamadı: " + materialName)); + BuildWandPlugin.getInstance().getLogger().warn("Blok için öğe türü bulunamadı: " + materialName); + return; + } + + // Check if player has enough of the material + int playerHasAmount = countPlayerItems(player, item); + + if (playerHasAmount < quantity) { + String blockName = block.getRegistryName() != null ? block.getRegistryName().toString() : "bilinmeyen"; + player.sendMessage(new StringTextComponent(TextFormatting.RED + "Yeterince sahip değilsin " + + TextFormatting.GOLD + blockName + + TextFormatting.RED + ". İhtiyaç " + + TextFormatting.YELLOW + quantity + + TextFormatting.RED + " ama sadece sahip olduğun " + + TextFormatting.YELLOW + playerHasAmount + + TextFormatting.RED + ".")); + return; + } + + // Get the player's selection + AreaSelection selection = BuildWandPlugin.getInstance().getPlayerSelections().get(player.getUniqueID()); + + if (selection == null || !selection.isComplete()) { + player.sendMessage(new StringTextComponent(TextFormatting.RED + "Tam bir seçiminiz yok.")); + return; + } + + // Check if specified quantity is enough for the area + int blocksInArea = selection.getBlockCount(); + + if (quantity < blocksInArea) { + player.sendMessage(new StringTextComponent(TextFormatting.YELLOW + "Uyarı: Belirttiğiniz " + + TextFormatting.GOLD + quantity + + TextFormatting.YELLOW + " bloklar ancak alan içerir " + + TextFormatting.GOLD + blocksInArea + + TextFormatting.YELLOW + " bloklar. Bazı bloklar doldurulamayabilir.")); + } + + // Perform the build operation + buildArea(player, selection, blockState, item, quantity); + } + + private int countPlayerItems(PlayerEntity player, Item itemType) { + int count = 0; + PlayerInventory inventory = player.inventory; + + // Iterate through the player's inventory to count items + for (int i = 0; i < inventory.getSizeInventory(); i++) { + ItemStack stack = inventory.getStackInSlot(i); + if (!stack.isEmpty() && stack.getItem() == itemType) { + count += stack.getCount(); + } + } + + return count; + } + + private void buildArea(PlayerEntity player, AreaSelection selection, BlockState blockState, Item item, int maxBlocks) { + World world = selection.getWorld(); + + int blocksPlaced = 0; + List changes = new ArrayList<>(); + + // Iterate over the selected area + for (int x = selection.getMinX(); x <= selection.getMaxX() && blocksPlaced < maxBlocks; x++) { + for (int y = selection.getMinY(); y <= selection.getMaxY() && blocksPlaced < maxBlocks; y++) { + for (int z = selection.getMinZ(); z <= selection.getMaxZ() && blocksPlaced < maxBlocks; z++) { + BlockPos pos = new BlockPos(x, y, z); + + // Skip non-air blocks (only replace air) + if (world.getBlockState(pos).getBlock() != Blocks.AIR) { + continue; + } + + // Store the original state for undo functionality + BlockState originalState = world.getBlockState(pos); + changes.add(new BlockChange(pos, world, originalState)); + + // Place the block + world.setBlockState(pos, blockState, 3); + blocksPlaced++; + } + } + } + + // Store the build information for this player (for undo) + lastBuilds.put(player.getUniqueID(), new BuildInfo(changes, item, blocksPlaced)); + + // Remove the used items from player's inventory + removeItemTypeFromInventory(player, item, blocksPlaced); + + Block blockType = blockState.getBlock(); + String blockName = blockType.getRegistryName() != null ? blockType.getRegistryName().toString() : "bilinmeyen"; + + player.sendMessage(new StringTextComponent(TextFormatting.GREEN + "Başarıyla yerleştirildi " + + TextFormatting.YELLOW + blocksPlaced + + TextFormatting.GREEN + " blokları " + + TextFormatting.GOLD + blockName + + TextFormatting.GREEN + ".")); + + if (blocksPlaced > 0) { + player.sendMessage(new StringTextComponent( + TextFormatting.GRAY + "Tip " + + TextFormatting.YELLOW + "/wand undo" + + TextFormatting.GRAY + " Bu yapıyı geri almak için." + )); + } + } +} diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml new file mode 100644 index 0000000..605c5eb --- /dev/null +++ b/src/main/resources/META-INF/mods.toml @@ -0,0 +1,25 @@ +modLoader="javafml" +loaderVersion="[29,)" +license="All Rights Reserved" + +[[mods]] +modId="buildwand" +version="${version}" +displayName="Build Wand" +description=''' +A build wand mod for Minecraft 1.15 +''' + +[[dependencies.buildwand]] + modId="forge" + mandatory=true + versionRange="[29,32,)" + ordering="NONE" + side="BOTH" + +[[dependencies.buildwand]] + modId="minecraft" + mandatory=true + versionRange="[1.15,1.15.3)" + ordering="NONE" + side="BOTH" \ No newline at end of file diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info new file mode 100644 index 0000000..762da07 --- /dev/null +++ b/src/main/resources/mcmod.info @@ -0,0 +1,16 @@ +[ + { + "modid": "buildwand", + "name": "Build Wand", + "description": "Oyuncuların bir alanı seçip, otomatik olarak belirtilen malzemelerle doldurmasına olanak tanıyan bir mod", + "version": "2.0.0", + "mcversion": "1.15.x", + "url": "", + "updateUrl": "", + "authorList": ["LorNople"], + "credits": "Replit-AI", + "logoFile": "", + "screenshots": [], + "dependencies": [] + } +] diff --git a/wand1.12-1.12.2.zip b/wand1.12-1.12.2.zip deleted file mode 100644 index bad58bd..0000000 Binary files a/wand1.12-1.12.2.zip and /dev/null differ diff --git a/wand1.13.2.zip b/wand1.13.2.zip deleted file mode 100644 index aa3876c..0000000 Binary files a/wand1.13.2.zip and /dev/null differ diff --git a/wand1.14.2-1.14.4.zip b/wand1.14.2-1.14.4.zip deleted file mode 100644 index 8d0a3ac..0000000 Binary files a/wand1.14.2-1.14.4.zip and /dev/null differ diff --git a/wand1.15-1.15.2.zip b/wand1.15-1.15.2.zip deleted file mode 100644 index 2c479fa..0000000 Binary files a/wand1.15-1.15.2.zip and /dev/null differ diff --git a/wand1.16.1-1.16.5.zip b/wand1.16.1-1.16.5.zip deleted file mode 100644 index eb4b93b..0000000 Binary files a/wand1.16.1-1.16.5.zip and /dev/null differ diff --git a/wand1.17.1.zip b/wand1.17.1.zip deleted file mode 100644 index 883f0dc..0000000 Binary files a/wand1.17.1.zip and /dev/null differ