Deprecate the poss ball, replace with mob capture ball
This commit is contained in:
parent
845a3b920b
commit
74ec5fcbc5
7 changed files with 97 additions and 30 deletions
|
@ -1,23 +1,35 @@
|
|||
package dev.zontreck.otemod.commands.dims;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import dev.zontreck.libzontreck.exceptions.InvalidDeserialization;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import dev.zontreck.libzontreck.vectors.Vector3;
|
||||
import dev.zontreck.libzontreck.vectors.WorldPosition;
|
||||
import dev.zontreck.otemod.configs.OTEServerConfig;
|
||||
import dev.zontreck.otemod.implementation.Messages;
|
||||
import dev.zontreck.otemod.registry.ModDimensions;
|
||||
import dev.zontreck.otemod.registry.PerPlayerDataRegistry;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.server.commands.ExperienceCommand;
|
||||
import net.minecraftforge.server.command.EnumArgument;
|
||||
|
||||
public class BuildCommand
|
||||
{
|
||||
private enum Options {
|
||||
enter,
|
||||
leave
|
||||
}
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("builder").executes(c->run(c.getSource())));
|
||||
var cmd = Commands.literal("builder");
|
||||
cmd.then(Commands.literal("enter").executes(c->run(c.getSource(), Options.enter)));
|
||||
cmd.then(Commands.literal("leave").executes(c->run(c.getSource(), Options.leave)));
|
||||
dispatcher.register(cmd);
|
||||
}
|
||||
|
||||
public static int run(CommandSourceStack stack)
|
||||
public static int run(CommandSourceStack stack, Options direction)
|
||||
{
|
||||
if(stack.isPlayer())
|
||||
{
|
||||
|
@ -26,11 +38,32 @@ public class BuildCommand
|
|||
if(playerIsOp || OTEServerConfig.ALLOW_BUILDER_DIM.get())
|
||||
{
|
||||
|
||||
WorldPosition pos = new WorldPosition(new Vector3(0, -55, 0), ModDimensions.BUILDER_DIM());
|
||||
if(direction == Options.enter)
|
||||
{
|
||||
WorldPosition save = new WorldPosition(stack.getPlayer());
|
||||
PerPlayerDataRegistry.put(stack.getPlayer().getUUID(), "builder_entered_from", save.serialize());
|
||||
|
||||
stack.getPlayer().teleportTo(pos.getActualDimension(), pos.Position.x, pos.Position.y, pos.Position.z, 0, 0);
|
||||
WorldPosition pos = new WorldPosition(new Vector3(0, -55, 0), ModDimensions.BUILDER_DIM());
|
||||
|
||||
return 0;
|
||||
stack.getPlayer().teleportTo(pos.getActualDimension(), pos.Position.x, pos.Position.y, pos.Position.z, 0, 0);
|
||||
|
||||
return 0;
|
||||
} else {
|
||||
|
||||
CompoundTag tag = (CompoundTag) PerPlayerDataRegistry.get(stack.getPlayer().getUUID(), "builder_entereed_from");
|
||||
if(tag != null)
|
||||
{
|
||||
try {
|
||||
WorldPosition pos = new WorldPosition(tag, false);
|
||||
|
||||
stack.getPlayer().teleportTo(pos.getActualDimension(), pos.Position.x, pos.Position.y, pos.Position.z, 0,0);
|
||||
} catch (InvalidDeserialization e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}else {
|
||||
ChatHelpers.broadcastTo(stack.getPlayer(), ChatHelpers.macro(Messages.BUILDER_DIMENSION_DISALLOWED), stack.getServer());
|
||||
|
||||
|
|
|
@ -6,18 +6,15 @@ import net.minecraft.sounds.SoundSource;
|
|||
import net.minecraft.stats.Stats;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.entity.monster.Guardian;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.projectile.Arrow;
|
||||
import net.minecraft.world.item.EggItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
public class PossBallItem extends Item
|
||||
public class MobCaptureBall extends Item
|
||||
{
|
||||
public PossBallItem(Properties pProperties) {
|
||||
super(pProperties);
|
||||
public MobCaptureBall() {
|
||||
super(new Properties());
|
||||
}
|
||||
@Override
|
||||
public boolean isFoil(ItemStack pStack) {
|
||||
|
@ -42,7 +39,7 @@ public class PossBallItem extends Item
|
|||
|
||||
stack.shrink(1);
|
||||
|
||||
ThrownPossBall TPB = new ThrownPossBall(pLevel, pPlayer, single);
|
||||
ThrownMobCaptureBall TPB = new ThrownMobCaptureBall(pLevel, pPlayer, single);
|
||||
|
||||
|
||||
TPB.shootFromRotation(pPlayer, pPlayer.getXRot(), pPlayer.getYRot(), 0.0F, 1.5F, 1.0F);
|
|
@ -1,11 +1,8 @@
|
|||
package dev.zontreck.otemod.items;
|
||||
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.blocks.FoiledBlockItem;
|
||||
import dev.zontreck.otemod.entities.ModEntityTypes;
|
||||
import dev.zontreck.otemod.implementation.CreativeModeTabs;
|
||||
import net.minecraft.world.item.*;
|
||||
import net.minecraftforge.common.ForgeSpawnEggItem;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
@ -55,7 +52,10 @@ public class ModItems {
|
|||
|
||||
public static final RegistryObject<Item> VAULT_RAW_ORE = CreativeModeTabs.addToOTEModTab(ITEMS.register("raw_vault_steel_ore", () -> new Item(new Item.Properties().stacksTo(64))));
|
||||
|
||||
public static final RegistryObject<Item> POSS_BALL = CreativeModeTabs.addToOTEModTab(ITEMS.register("poss_ball", () -> new PossBallItem(new Item.Properties())));
|
||||
@Deprecated
|
||||
public static final RegistryObject<Item> POSS_BALL = CreativeModeTabs.addToOTEModTab(ITEMS.register("poss_ball", () -> new DeprecatedItem()));
|
||||
|
||||
public static final RegistryObject<Item> MIAB = CreativeModeTabs.addToOTEModTab(ITEMS.register("mob_capture_ball", ()->new MobCaptureBall()));
|
||||
|
||||
|
||||
public static final RegistryObject<Item> EMPTY_SPAWN_EGG = CreativeModeTabs.addToOTEModTab(ITEMS.register("empty_spawn_egg", () -> new Item(new Item.Properties())));
|
||||
|
|
|
@ -1,17 +1,12 @@
|
|||
package dev.zontreck.otemod.items;
|
||||
|
||||
import dev.zontreck.libzontreck.chat.ChatColor;
|
||||
import dev.zontreck.libzontreck.lore.ExtraLore;
|
||||
import dev.zontreck.libzontreck.lore.LoreContainer;
|
||||
import dev.zontreck.libzontreck.lore.LoreEntry;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import dev.zontreck.libzontreck.util.ServerUtilities;
|
||||
import net.minecraft.core.particles.ItemParticleOption;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
|
@ -21,24 +16,23 @@ import net.minecraft.world.entity.projectile.ThrowableItemProjectile;
|
|||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.DropperBlock;
|
||||
import net.minecraft.world.phys.EntityHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ThrownPossBall extends ThrowableItemProjectile
|
||||
public class ThrownMobCaptureBall extends ThrowableItemProjectile
|
||||
{
|
||||
boolean captured = false;
|
||||
LivingEntity shooter;
|
||||
ItemStack self;
|
||||
|
||||
public ThrownPossBall(EntityType<? extends ThrownPossBall> entity, Level level)
|
||||
public ThrownMobCaptureBall(EntityType<? extends ThrownMobCaptureBall> entity, Level level)
|
||||
{
|
||||
super(entity, level);
|
||||
}
|
||||
public ThrownPossBall(Level level, LivingEntity shooter, ItemStack item)
|
||||
public ThrownMobCaptureBall(Level level, LivingEntity shooter, ItemStack item)
|
||||
{
|
||||
super(EntityType.SNOWBALL, shooter, level);
|
||||
|
|
@ -1,6 +1,52 @@
|
|||
package dev.zontreck.otemod.registry;
|
||||
|
||||
import dev.zontreck.libzontreck.events.ProfileUnloadedEvent;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PerPlayerDataRegistry {
|
||||
// The idea here is to make a registry unique to a player for mod data
|
||||
// This will allow separating handling of functions, like cooldowns
|
||||
private static Map<UUID, CompoundTag> cache = new HashMap<>();
|
||||
|
||||
public static void put(UUID ID, String nick, Tag tag)
|
||||
{
|
||||
if(cache.containsKey(ID))
|
||||
{
|
||||
CompoundTag xTag = cache.get(ID);
|
||||
xTag.put(nick, tag);
|
||||
}else {
|
||||
CompoundTag xTag = new CompoundTag();
|
||||
xTag.put(nick,tag);
|
||||
|
||||
cache.put(ID, xTag);
|
||||
}
|
||||
}
|
||||
|
||||
public static Tag get(UUID ID, String nick)
|
||||
{
|
||||
if(cache.containsKey(ID))
|
||||
{
|
||||
CompoundTag tag = cache.get(ID);
|
||||
if(tag.contains(nick)) return tag.get(nick);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onProfileUnload(ProfileUnloadedEvent ev)
|
||||
{
|
||||
if(cache.containsKey(UUID.fromString(ev.user_id)))
|
||||
{
|
||||
cache.remove(UUID.fromString(ev.user_id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,10 +33,7 @@
|
|||
"item.otemod.vault_fragment_right": "Vault Fragment",
|
||||
"item.otemod.vault_fragment_center": "Vault Fragment",
|
||||
"item.otemod.raw_vault_steel_ore": "Raw Vault Steel",
|
||||
"item.otemod.poss_ball": "Physics Operated Storage System (POSS)",
|
||||
"item.otemod.ilusium_ingot": "Ilusium Ingot",
|
||||
"item.otemod.ilusium_rod": "Ilusium Rod",
|
||||
"item.otemod.ilusium_ore": "Raw Ilusium Ore",
|
||||
"item.otemod.mob_capture_ball": "Mob Capture Ball",
|
||||
"item.otemod.empty_spawn_egg": "Empty Spawn Egg",
|
||||
"item.otemod.compressed_obsidian_sheet": "Sheet of Compressed Obsidian",
|
||||
"item.otemod.layered_compressed_obsidian_sheet": "Layered Sheet of Compressed Obsidian",
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "otemod:poss_ball",
|
||||
"item": "otemod:mob_capture_ball",
|
||||
"count": 1
|
||||
}
|
||||
}
|
Reference in a new issue