Added powerlevel command. Updated reach upgrade behaviour.
This commit is contained in:
@@ -6,6 +6,7 @@ import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.event.level.BlockEvent;
|
||||
@@ -18,6 +19,7 @@ import nl.requios.effortlessbuilding.network.ModifierSettingsPacket;
|
||||
import nl.requios.effortlessbuilding.network.PacketHandler;
|
||||
import nl.requios.effortlessbuilding.systems.PowerLevel;
|
||||
import nl.requios.effortlessbuilding.systems.ServerBuildState;
|
||||
import nl.requios.effortlessbuilding.utilities.PowerLevelCommand;
|
||||
|
||||
@EventBusSubscriber
|
||||
public class CommonEvents {
|
||||
@@ -29,6 +31,11 @@ public class CommonEvents {
|
||||
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerCommands(RegisterCommandsEvent event) {
|
||||
PowerLevelCommand.register(event.getDispatcher());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onTick(TickEvent.LevelTickEvent event) {
|
||||
if (event.phase != TickEvent.Phase.START) return;
|
||||
|
||||
@@ -3,6 +3,8 @@ package nl.requios.effortlessbuilding.item;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
@@ -35,11 +37,19 @@ public class PowerLevelItem extends Item {
|
||||
EffortlessBuildingClient.POWER_LEVEL.increasePowerLevel();
|
||||
EffortlessBuilding.log(player, "Upgraded power level to " + EffortlessBuildingClient.POWER_LEVEL.getPowerLevel());
|
||||
player.setItemInHand(hand, ItemStack.EMPTY);
|
||||
|
||||
SoundEvent soundEvent = new SoundEvent(new ResourceLocation("entity.player.levelup"));
|
||||
player.playSound(soundEvent, 1f, 1f);
|
||||
|
||||
return InteractionResultHolder.consume(player.getItemInHand(hand));
|
||||
|
||||
} else {
|
||||
|
||||
EffortlessBuilding.log(player, "Already reached maximum power level!");
|
||||
|
||||
SoundEvent soundEvent = new SoundEvent(new ResourceLocation("item.armor.equip_leather"));
|
||||
player.playSound(soundEvent, 1f, 1f);
|
||||
|
||||
return InteractionResultHolder.fail(player.getItemInHand(hand));
|
||||
}
|
||||
|
||||
|
||||
@@ -32,30 +32,31 @@ public class ReachUpgrade1Item extends Item {
|
||||
|
||||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
|
||||
if (player.isCreative()) {
|
||||
if (world.isClientSide) EffortlessBuilding.log(player, "Reach upgrades are not necessary in creative.");
|
||||
if (world.isClientSide) EffortlessBuilding.log(player, "Still want increased reach? Use the config.");
|
||||
return InteractionResultHolder.pass(player.getItemInHand(hand));
|
||||
}
|
||||
|
||||
if (!world.isClientSide) return InteractionResultHolder.consume(player.getItemInHand(hand));
|
||||
|
||||
int currentLevel = EffortlessBuildingClient.POWER_LEVEL.getPowerLevel();
|
||||
if (currentLevel == 0) {
|
||||
EffortlessBuildingClient.POWER_LEVEL.loadPowerLevel(1);
|
||||
|
||||
if (world.isClientSide) EffortlessBuilding.log(player, "Upgraded reach to " + EffortlessBuildingClient.POWER_LEVEL.getMaxReach(player));
|
||||
EffortlessBuildingClient.POWER_LEVEL.increasePowerLevel();
|
||||
EffortlessBuilding.log(player, "Upgraded power level to " + EffortlessBuildingClient.POWER_LEVEL.getPowerLevel());
|
||||
player.setItemInHand(hand, ItemStack.EMPTY);
|
||||
|
||||
SoundEvent soundEvent = new SoundEvent(new ResourceLocation("entity.player.levelup"));
|
||||
player.playSound(soundEvent, 1f, 1f);
|
||||
|
||||
return InteractionResultHolder.consume(player.getItemInHand(hand));
|
||||
|
||||
} else if (currentLevel > 0) {
|
||||
if (world.isClientSide)
|
||||
EffortlessBuilding.log(player, "Already used this upgrade! Current reach is " + EffortlessBuildingClient.POWER_LEVEL
|
||||
.getMaxReach(player) + ".");
|
||||
|
||||
EffortlessBuilding.log(player, "Already used this upgrade! Current power level is " + EffortlessBuildingClient.POWER_LEVEL.getPowerLevel() + ".");
|
||||
|
||||
SoundEvent soundEvent = new SoundEvent(new ResourceLocation("item.armor.equip_leather"));
|
||||
player.playSound(soundEvent, 1f, 1f);
|
||||
|
||||
}
|
||||
return InteractionResultHolder.consume(player.getItemInHand(hand));
|
||||
|
||||
return InteractionResultHolder.fail(player.getItemInHand(hand));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -33,35 +33,39 @@ public class ReachUpgrade2Item extends Item {
|
||||
|
||||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
|
||||
if (player.isCreative()) {
|
||||
if (world.isClientSide) EffortlessBuilding.log(player, "Reach upgrades are not necessary in creative.");
|
||||
if (world.isClientSide) EffortlessBuilding.log(player, "Still want increased reach? Use the config.");
|
||||
return new InteractionResultHolder<>(InteractionResult.PASS, player.getItemInHand(hand));
|
||||
}
|
||||
|
||||
if (!world.isClientSide) return InteractionResultHolder.consume(player.getItemInHand(hand));
|
||||
|
||||
int currentLevel = EffortlessBuildingClient.POWER_LEVEL.getPowerLevel();
|
||||
if (currentLevel == 1) {
|
||||
EffortlessBuildingClient.POWER_LEVEL.loadPowerLevel(2);
|
||||
|
||||
if (world.isClientSide) EffortlessBuilding.log(player, "Upgraded reach to " + EffortlessBuildingClient.POWER_LEVEL.getMaxReach(player));
|
||||
EffortlessBuildingClient.POWER_LEVEL.increasePowerLevel();
|
||||
EffortlessBuilding.log(player, "Upgraded power level to " + EffortlessBuildingClient.POWER_LEVEL.getPowerLevel());
|
||||
player.setItemInHand(hand, ItemStack.EMPTY);
|
||||
|
||||
SoundEvent soundEvent = new SoundEvent(new ResourceLocation("entity.player.levelup"));
|
||||
player.playSound(soundEvent, 1f, 1f);
|
||||
|
||||
return InteractionResultHolder.consume(player.getItemInHand(hand));
|
||||
|
||||
} else if (currentLevel < 1) {
|
||||
if (world.isClientSide) EffortlessBuilding.log(player, "Use Reach Upgrade 1 first.");
|
||||
|
||||
EffortlessBuilding.log(player, "Use Reach Upgrade 1 first.");
|
||||
|
||||
SoundEvent soundEvent = new SoundEvent(new ResourceLocation("item.armor.equip_leather"));
|
||||
player.playSound(soundEvent, 1f, 1f);
|
||||
|
||||
|
||||
} else if (currentLevel > 1) {
|
||||
if (world.isClientSide)
|
||||
EffortlessBuilding.log(player, "Already used this upgrade! Current reach is " + EffortlessBuildingClient.POWER_LEVEL
|
||||
.getMaxReach(player) + ".");
|
||||
|
||||
EffortlessBuilding.log(player, "Already used this upgrade! Current power level is " + EffortlessBuildingClient.POWER_LEVEL.getPowerLevel() + ".");
|
||||
|
||||
SoundEvent soundEvent = new SoundEvent(new ResourceLocation("item.armor.equip_leather"));
|
||||
player.playSound(soundEvent, 1f, 1f);
|
||||
|
||||
}
|
||||
return new InteractionResultHolder<>(InteractionResult.PASS, player.getItemInHand(hand));
|
||||
|
||||
return InteractionResultHolder.fail(player.getItemInHand(hand));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -33,38 +33,40 @@ public class ReachUpgrade3Item extends Item {
|
||||
|
||||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
|
||||
if (player.isCreative()) {
|
||||
if (world.isClientSide) EffortlessBuilding.log(player, "Reach upgrades are not necessary in creative.");
|
||||
if (world.isClientSide) EffortlessBuilding.log(player, "Still want increased reach? Use the config.");
|
||||
return new InteractionResultHolder<>(InteractionResult.PASS, player.getItemInHand(hand));
|
||||
}
|
||||
|
||||
if (!world.isClientSide) return InteractionResultHolder.consume(player.getItemInHand(hand));
|
||||
|
||||
int currentLevel = EffortlessBuildingClient.POWER_LEVEL.getPowerLevel();
|
||||
if (currentLevel == 2) {
|
||||
EffortlessBuildingClient.POWER_LEVEL.loadPowerLevel(3);
|
||||
|
||||
if (world.isClientSide) EffortlessBuilding.log(player, "Upgraded reach to " + EffortlessBuildingClient.POWER_LEVEL.getMaxReach(player));
|
||||
EffortlessBuildingClient.POWER_LEVEL.increasePowerLevel();
|
||||
EffortlessBuilding.log(player, "Upgraded power level to " + EffortlessBuildingClient.POWER_LEVEL.getPowerLevel());
|
||||
player.setItemInHand(hand, ItemStack.EMPTY);
|
||||
|
||||
SoundEvent soundEvent = new SoundEvent(new ResourceLocation("entity.player.levelup"));
|
||||
player.playSound(soundEvent, 1f, 1f);
|
||||
|
||||
return InteractionResultHolder.consume(player.getItemInHand(hand));
|
||||
|
||||
} else if (currentLevel < 2) {
|
||||
if (currentLevel == 0)
|
||||
if (world.isClientSide) EffortlessBuilding.log(player, "Use Reach Upgrade 1 and 2 first.");
|
||||
if (currentLevel == 1)
|
||||
if (world.isClientSide) EffortlessBuilding.log(player, "Use Reach Upgrade 2 first.");
|
||||
|
||||
if (currentLevel == 0) EffortlessBuilding.log(player, "Use Reach Upgrade 1 and 2 first.");
|
||||
if (currentLevel == 1) EffortlessBuilding.log(player, "Use Reach Upgrade 2 first.");
|
||||
|
||||
SoundEvent soundEvent = new SoundEvent(new ResourceLocation("item.armor.equip_leather"));
|
||||
player.playSound(soundEvent, 1f, 1f);
|
||||
|
||||
|
||||
} else if (currentLevel > 2) {
|
||||
if (world.isClientSide)
|
||||
EffortlessBuilding.log(player, "Already used this upgrade! Current reach is " + EffortlessBuildingClient.POWER_LEVEL
|
||||
.getMaxReach(player) + ".");
|
||||
|
||||
EffortlessBuilding.log(player, "Already used this upgrade! Current power level is " + EffortlessBuildingClient.POWER_LEVEL.getPowerLevel() + ".");
|
||||
|
||||
SoundEvent soundEvent = new SoundEvent(new ResourceLocation("item.armor.equip_leather"));
|
||||
player.playSound(soundEvent, 1f, 1f);
|
||||
|
||||
}
|
||||
return new InteractionResultHolder<>(InteractionResult.PASS, player.getItemInHand(hand));
|
||||
|
||||
return InteractionResultHolder.fail(player.getItemInHand(hand));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,7 +10,7 @@ import nl.requios.effortlessbuilding.network.PowerLevelPacket;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class PowerLevel {
|
||||
private static final int MAX_POWER_LEVEL = 3;
|
||||
|
||||
private int powerLevel;
|
||||
|
||||
public int getPowerLevel() {
|
||||
@@ -23,7 +23,7 @@ public class PowerLevel {
|
||||
}
|
||||
|
||||
public boolean canIncreasePowerLevel() {
|
||||
return getPowerLevel() < MAX_POWER_LEVEL;
|
||||
return getPowerLevel() < ServerPowerLevel.MAX_POWER_LEVEL;
|
||||
}
|
||||
|
||||
public void increasePowerLevel() {
|
||||
|
||||
@@ -8,6 +8,7 @@ import nl.requios.effortlessbuilding.network.PacketHandler;
|
||||
import nl.requios.effortlessbuilding.network.PowerLevelPacket;
|
||||
|
||||
public class ServerPowerLevel {
|
||||
public static final int MAX_POWER_LEVEL = 3; //Common access
|
||||
private static final String POWER_LEVEL_KEY = EffortlessBuilding.MODID + ":powerLevel";
|
||||
|
||||
public int getPowerLevel(Player player) {
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package nl.requios.effortlessbuilding.utilities;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.arguments.EntityArgument;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
import nl.requios.effortlessbuilding.systems.ServerPowerLevel;
|
||||
|
||||
public class PowerLevelCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||
dispatcher.register(Commands.literal("powerlevel")
|
||||
.requires(cs -> cs.hasPermission(2))
|
||||
.then(Commands.literal("query").executes(ctx -> {
|
||||
|
||||
//Get your own power level
|
||||
logPowerLevel(ctx.getSource(), ctx.getSource().getPlayerOrException());
|
||||
return 0;
|
||||
|
||||
}).then(Commands.argument("target", EntityArgument.player()).executes(ctx -> {
|
||||
|
||||
//Get power level of some player
|
||||
Player player = EntityArgument.getPlayer(ctx, "target");
|
||||
logPowerLevel(ctx.getSource(), player);
|
||||
return 0;
|
||||
|
||||
})))
|
||||
.then(Commands.literal("set")
|
||||
.then(Commands.argument("target", EntityArgument.player())
|
||||
.then(Commands.argument("value", IntegerArgumentType.integer(0, ServerPowerLevel.MAX_POWER_LEVEL)).executes(ctx -> {
|
||||
|
||||
//Set power level
|
||||
setPowerLevel(ctx.getSource(), EntityArgument.getPlayer(ctx, "target"), ctx.getArgument("value", Integer.class));
|
||||
return 0;
|
||||
|
||||
})))));
|
||||
}
|
||||
|
||||
private static void logPowerLevel(CommandSourceStack source, Player player) {
|
||||
int powerLevel = EffortlessBuilding.SERVER_POWER_LEVEL.getPowerLevel(player);
|
||||
source.sendSuccess(Component.translatable("effortlessbuilding.commands.powerlevel", player.getDisplayName(), powerLevel), false);
|
||||
}
|
||||
|
||||
private static void setPowerLevel(CommandSourceStack source, Player player, int powerLevel) throws CommandSyntaxException {
|
||||
EffortlessBuilding.SERVER_POWER_LEVEL.setPowerLevel(player, powerLevel);
|
||||
EffortlessBuilding.SERVER_POWER_LEVEL.sendToClient(player);
|
||||
source.sendSuccess(Component.translatable("effortlessbuilding.commands.powerlevel.success", player.getDisplayName(), powerLevel), true);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,9 @@
|
||||
"key.effortlessbuilding.altplacement.desc": "Alternative placement",
|
||||
"key.effortlessbuilding.previous_build_mode.desc": "Activate Previous Build Mode",
|
||||
"key.effortlessbuilding.disable_build_mode_toggle.desc": "Toggle Disabled <> Previous Build Mode",
|
||||
"key.effortlessbuilding.upgrade_power_level": "Use to permanently upgrade your Building Power Level by 1.",
|
||||
"key.effortlessbuilding.upgrade_power_level": "Right-click to permanently increase your Building Power Level by 1.",
|
||||
"key.effortlessbuilding.use_reach_upgrade": "Consume to increase your Building Power Level to %s.",
|
||||
"key.effortlessbuilding.require_previous_reach_upgrades": "Previous upgrades need to be consumed first.",
|
||||
|
||||
"item.effortlessbuilding.randomizer_bag": "Leather Randomizer Bag",
|
||||
"item.effortlessbuilding.golden_randomizer_bag": "Golden Randomizer Bag",
|
||||
@@ -106,5 +108,7 @@
|
||||
"effortlessbuilding.tooltip.keyShift": "Shift",
|
||||
"effortlessbuilding.tooltip.keyCtrl": "Ctrl",
|
||||
"effortlessbuilding.tooltip.keybind": "[%1$s]",
|
||||
"fdsaf": "key.effortlessbuilding.upgrade_power_level"
|
||||
|
||||
"effortlessbuilding.commands.powerlevel": "[Effortless Building] %s's Building Power Level is: %s",
|
||||
"effortlessbuilding.commands.powerlevel.success": "[Effortless Building] Set %s's Building Power Level to: %s"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user