Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2d64426496 | |||
| ec31e090b9 | |||
| 935b2225c9 | |||
| cdd0a594f3 | |||
| a9d0b7fd94 | |||
| 1931848068 | |||
| a2a189a0c1 | |||
| d2d96b3f67 | |||
| 08e7952e34 | |||
| cc69b22aba | |||
| c7ff6de42b | |||
| d3b25b595a | |||
| 8007778c39 | |||
| fc70b2fe5a | |||
| 2f35493580 | |||
| 6526f92a67 | |||
| d6a324a93f | |||
| 1dd6914454 | |||
| c497884884 | |||
| a236abdd5c | |||
| b4d8df9e8e | |||
| 2ee3d946ec | |||
| ea5411450c | |||
| f533ae8515 | |||
| d84190ee3c | |||
| ac4f58b9a2 |
+37
-4
@@ -1,15 +1,23 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'fabric-loom' version '1.5-SNAPSHOT'
|
id 'fabric-loom' version '1.10-SNAPSHOT'
|
||||||
id 'maven-publish'
|
id 'maven-publish'
|
||||||
}
|
}
|
||||||
|
|
||||||
version = project.mod_version
|
version = project.mod_version
|
||||||
group = project.maven_group
|
group = project.maven_group
|
||||||
|
|
||||||
|
loom {
|
||||||
|
accessWidenerPath = file("src/main/resources/minions.accesswidener")
|
||||||
|
}
|
||||||
|
|
||||||
base {
|
base {
|
||||||
archivesName = project.archives_base_name
|
archivesName = project.archives_base_name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loom {
|
||||||
|
accessWidenerPath = file("src/main/resources/minions.accesswidener")
|
||||||
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
// Add repositories to retrieve artifacts from in here.
|
// Add repositories to retrieve artifacts from in here.
|
||||||
// You should only use this when depending on other mods because
|
// You should only use this when depending on other mods because
|
||||||
@@ -17,6 +25,18 @@ repositories {
|
|||||||
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
|
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
|
||||||
// for more information about repositories.
|
// for more information about repositories.
|
||||||
maven { url 'https://maven.nucleoid.xyz' }
|
maven { url 'https://maven.nucleoid.xyz' }
|
||||||
|
|
||||||
|
exclusiveContent {
|
||||||
|
forRepository {
|
||||||
|
maven {
|
||||||
|
name = "Modrinth"
|
||||||
|
url = "https://api.modrinth.com/maven"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filter {
|
||||||
|
includeGroup "maven.modrinth"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -27,8 +47,11 @@ dependencies {
|
|||||||
|
|
||||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||||
modImplementation include("eu.pb4:polymer-core:${project.polymer_version}")
|
modImplementation "eu.pb4:polymer-core:${project.polymer_version}"
|
||||||
modImplementation include("eu.pb4:sgui:${project.sgui_version}")
|
modImplementation include("eu.pb4:sgui:${project.sgui_version}")
|
||||||
|
modImplementation include("xyz.nucleoid:server-translations-api:${project.server_translations_version}")
|
||||||
|
|
||||||
|
modCompileOnly "maven.modrinth:universal-graves:${project.universal_graves_version}"
|
||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
@@ -44,7 +67,7 @@ processResources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def targetJavaVersion = 17
|
def targetJavaVersion = 21
|
||||||
tasks.withType(JavaCompile).configureEach {
|
tasks.withType(JavaCompile).configureEach {
|
||||||
// ensure that the encoding is set to UTF-8, no matter what the system default is
|
// ensure that the encoding is set to UTF-8, no matter what the system default is
|
||||||
// this fixes some edge cases with special characters not displaying correctly
|
// this fixes some edge cases with special characters not displaying correctly
|
||||||
@@ -76,7 +99,7 @@ jar {
|
|||||||
// configure the maven publication
|
// configure the maven publication
|
||||||
publishing {
|
publishing {
|
||||||
publications {
|
publications {
|
||||||
mavenJava(MavenPublication) {
|
minions (MavenPublication) {
|
||||||
from components.java
|
from components.java
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -87,5 +110,15 @@ publishing {
|
|||||||
// Notice: This block does NOT have the same function as the block in the top level.
|
// Notice: This block does NOT have the same function as the block in the top level.
|
||||||
// The repositories here will be used for publishing your artifact, not for
|
// The repositories here will be used for publishing your artifact, not for
|
||||||
// retrieving dependencies.
|
// retrieving dependencies.
|
||||||
|
maven {
|
||||||
|
def release = "https://maven.foxgalaxy.de/private-releases"
|
||||||
|
def snapshot = "https://maven.foxgalaxy.de/private-snapshot"
|
||||||
|
url = version.endsWith('SNAPSHOT') ? snapshot : release
|
||||||
|
|
||||||
|
credentials {
|
||||||
|
username = "${maven_user}"
|
||||||
|
password = "${maven_password}"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-7
@@ -3,18 +3,21 @@ org.gradle.jvmargs=-Xmx1G
|
|||||||
|
|
||||||
# Fabric Properties
|
# Fabric Properties
|
||||||
# check these on https://modmuss50.me/fabric.html
|
# check these on https://modmuss50.me/fabric.html
|
||||||
minecraft_version=1.20.4
|
minecraft_version=1.21.5
|
||||||
loader_version=0.15.6
|
loader_version=0.16.13
|
||||||
yarn_mappings=1.20.4+build.3
|
yarn_mappings=1.21.5+build.1
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 0.0.1
|
mod_version = 0.2.0-SNAPSHOT
|
||||||
maven_group = io.github.skippyall
|
maven_group = io.github.skippyall
|
||||||
archives_base_name = Minions
|
archives_base_name = Minions
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
# check this on https://modmuss50.me/fabric.html
|
# check this on https://modmuss50.me/fabric.html
|
||||||
fabric_version=0.95.4+1.20.4
|
fabric_version=0.121.0+1.21.5
|
||||||
|
|
||||||
polymer_version=0.7.5+1.20.4
|
polymer_version=0.12.3+1.21.5
|
||||||
sgui_version=1.4.1+1.20.4
|
sgui_version=1.9.0+1.21.5
|
||||||
|
server_translations_version=2.5.0+1.21.5-rc1
|
||||||
|
|
||||||
|
universal_graves_version=3.7.1+1.21.5
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
package io.github.skippyall.minions;
|
|
||||||
|
|
||||||
import eu.pb4.sgui.api.ClickType;
|
|
||||||
import eu.pb4.sgui.api.elements.GuiElement;
|
|
||||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
|
||||||
import eu.pb4.sgui.api.elements.GuiElementInterface;
|
|
||||||
import eu.pb4.sgui.api.gui.SimpleGui;
|
|
||||||
import eu.pb4.sgui.api.gui.SlotGuiInterface;
|
|
||||||
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
|
||||||
import net.minecraft.network.chat.Component;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import net.minecraft.world.inventory.MenuType;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.item.Items;
|
|
||||||
|
|
||||||
public class MinionInventory {
|
|
||||||
public static void openInventory(ServerPlayer player, MinionFakePlayer minion) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void openServerSideInventory(ServerPlayer player, MinionFakePlayer minion) {
|
|
||||||
SimpleGui gui = new SimpleGui(MenuType.GENERIC_3x3, player, false);
|
|
||||||
gui.setTitle(Component.literal("Minion"));
|
|
||||||
gui.setSlot(4, new GuiElementBuilder()
|
|
||||||
.setItem(Items.REDSTONE)
|
|
||||||
.setName(Component.literal("Programming"))
|
|
||||||
.setCallback((i, clickType, clickType1) -> {
|
|
||||||
openProgrammingInventory(player, minion);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
gui.setSlot(3, new GuiElementBuilder()
|
|
||||||
.setItem(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE)
|
|
||||||
.setName(Component.literal("Modules and Detectors"))
|
|
||||||
.setCallback((i, clickType, clickType1) -> {
|
|
||||||
|
|
||||||
})
|
|
||||||
);
|
|
||||||
gui.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void openProgrammingInventory(ServerPlayer player, MinionFakePlayer minion) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void open
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
package io.github.skippyall.minions;
|
|
||||||
|
|
||||||
import eu.pb4.polymer.core.api.item.PolymerItem;
|
|
||||||
import eu.pb4.polymer.core.api.item.PolymerItemUtils;
|
|
||||||
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
|
||||||
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
|
|
||||||
import net.minecraft.network.chat.ComponentContents;
|
|
||||||
import net.minecraft.network.chat.contents.PlainTextContents;
|
|
||||||
import net.minecraft.server.level.ServerLevel;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import net.minecraft.world.InteractionResult;
|
|
||||||
import net.minecraft.world.item.Item;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.item.Items;
|
|
||||||
import net.minecraft.world.item.TooltipFlag;
|
|
||||||
import net.minecraft.world.item.context.UseOnContext;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
public class MinionItem extends Item implements PolymerItem {
|
|
||||||
public MinionItem() {
|
|
||||||
super(new FabricItemSettings());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Item getPolymerItem(ItemStack itemStack, @Nullable ServerPlayer player) {
|
|
||||||
return Items.PLAYER_HEAD;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack getPolymerItemStack(ItemStack stack, TooltipFlag flag, ServerPlayer player) {
|
|
||||||
ItemStack out = PolymerItemUtils.createItemStack(stack, flag, player);
|
|
||||||
//CompoundTag tag = out.getOrCreateTag();
|
|
||||||
//PlayerHeadItem.TAG_SKULL_OWNER;
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*@Override
|
|
||||||
public int getPolymerCustomModelData(ItemStack itemStack, @Nullable ServerPlayer player) {
|
|
||||||
return 10;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
public InteractionResult useOn(UseOnContext context) {
|
|
||||||
System.out.println("Minion spawned "+ context.getItemInHand().getDisplayName());
|
|
||||||
ComponentContents contents = context.getItemInHand().getHoverName().getContents();
|
|
||||||
String name;
|
|
||||||
if(contents instanceof PlainTextContents plainContents) {
|
|
||||||
name = plainContents.text();
|
|
||||||
} else {
|
|
||||||
name = "Minion";
|
|
||||||
}
|
|
||||||
if(!context.getLevel().isClientSide) {
|
|
||||||
MinionFakePlayer.createMinion(name, (ServerLevel) context.getLevel(), (ServerPlayer) context.getPlayer(), context.getClickedPos().getCenter().add(0,0.5,0), 0, 0);
|
|
||||||
}
|
|
||||||
return InteractionResult.SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package io.github.skippyall.minions;
|
|
||||||
|
|
||||||
import eu.pb4.polymer.core.api.entity.PolymerEntityUtils;
|
|
||||||
import io.github.skippyall.minions.networking.ClientToServerNetworking;
|
|
||||||
import net.fabricmc.api.EnvType;
|
|
||||||
import net.fabricmc.api.ModInitializer;
|
|
||||||
import net.fabricmc.fabric.api.networking.v1.ServerConfigurationNetworking;
|
|
||||||
import net.fabricmc.fabric.api.networking.v1.ServerLoginConnectionEvents;
|
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
|
||||||
import net.minecraft.core.Registry;
|
|
||||||
import net.minecraft.core.registries.BuiltInRegistries;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.server.network.ServerLoginPacketListenerImpl;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
public class Minions implements ModInitializer {
|
|
||||||
public static final String MOD_ID = "minions";
|
|
||||||
public static final MinionItem MINION_ITEM = Registry.register(BuiltInRegistries.ITEM, new ResourceLocation(MOD_ID, "minion"), new MinionItem());
|
|
||||||
|
|
||||||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
|
||||||
@Override
|
|
||||||
public void onInitialize() {
|
|
||||||
PolymerEntityUtils.registerType();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package io.github.skippyall.minions.client;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.networking.ClientToServerNetworking;
|
|
||||||
import net.fabricmc.api.ClientModInitializer;
|
|
||||||
import net.fabricmc.fabric.api.client.networking.v1.ClientConfigurationConnectionEvents;
|
|
||||||
import net.fabricmc.fabric.api.client.networking.v1.ClientLoginConnectionEvents;
|
|
||||||
|
|
||||||
public class MinionsClient implements ClientModInitializer {
|
|
||||||
/**
|
|
||||||
* Runs the mod initializer on the client environment.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void onInitializeClient() {
|
|
||||||
ClientConfigurationConnectionEvents.INIT.register(ClientToServerNetworking::onConfigurationInit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,626 +0,0 @@
|
|||||||
package io.github.skippyall.minions.fakeplayer;
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.EnumMap;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import net.minecraft.commands.arguments.EntityAnchorArgument;
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.core.Direction;
|
|
||||||
import net.minecraft.network.protocol.game.ClientboundSetCarriedItemPacket;
|
|
||||||
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
|
|
||||||
import net.minecraft.server.level.ServerLevel;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import net.minecraft.util.Mth;
|
|
||||||
import net.minecraft.world.InteractionHand;
|
|
||||||
import net.minecraft.world.InteractionResult;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.animal.horse.AbstractHorse;
|
|
||||||
import net.minecraft.world.entity.decoration.ItemFrame;
|
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
|
||||||
import net.minecraft.world.entity.vehicle.Boat;
|
|
||||||
import net.minecraft.world.entity.vehicle.Minecart;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
|
||||||
import net.minecraft.world.phys.BlockHitResult;
|
|
||||||
import net.minecraft.world.phys.EntityHitResult;
|
|
||||||
import net.minecraft.world.phys.HitResult;
|
|
||||||
import net.minecraft.world.phys.Vec2;
|
|
||||||
import net.minecraft.world.phys.Vec3;
|
|
||||||
|
|
||||||
public class EntityPlayerActionPack
|
|
||||||
{
|
|
||||||
private final ServerPlayer player;
|
|
||||||
|
|
||||||
private final Map<ActionType, Action> actions = new EnumMap<>(ActionType.class);
|
|
||||||
|
|
||||||
private BlockPos currentBlock;
|
|
||||||
private int blockHitDelay;
|
|
||||||
private boolean isHittingBlock;
|
|
||||||
private float curBlockDamageMP;
|
|
||||||
|
|
||||||
private boolean sneaking;
|
|
||||||
private boolean sprinting;
|
|
||||||
private float forward;
|
|
||||||
private float strafing;
|
|
||||||
|
|
||||||
private int itemUseCooldown;
|
|
||||||
|
|
||||||
public EntityPlayerActionPack(ServerPlayer playerIn)
|
|
||||||
{
|
|
||||||
player = playerIn;
|
|
||||||
stopAll();
|
|
||||||
}
|
|
||||||
public void copyFrom(EntityPlayerActionPack other)
|
|
||||||
{
|
|
||||||
actions.putAll(other.actions);
|
|
||||||
currentBlock = other.currentBlock;
|
|
||||||
blockHitDelay = other.blockHitDelay;
|
|
||||||
isHittingBlock = other.isHittingBlock;
|
|
||||||
curBlockDamageMP = other.curBlockDamageMP;
|
|
||||||
|
|
||||||
sneaking = other.sneaking;
|
|
||||||
sprinting = other.sprinting;
|
|
||||||
forward = other.forward;
|
|
||||||
strafing = other.strafing;
|
|
||||||
|
|
||||||
itemUseCooldown = other.itemUseCooldown;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityPlayerActionPack start(ActionType type, Action action)
|
|
||||||
{
|
|
||||||
Action previous = actions.remove(type);
|
|
||||||
if (previous != null) type.stop(player, previous);
|
|
||||||
if (action != null)
|
|
||||||
{
|
|
||||||
actions.put(type, action);
|
|
||||||
type.start(player, action); // noop
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityPlayerActionPack setSneaking(boolean doSneak)
|
|
||||||
{
|
|
||||||
sneaking = doSneak;
|
|
||||||
player.setShiftKeyDown(doSneak);
|
|
||||||
if (sprinting && sneaking)
|
|
||||||
setSprinting(false);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
public EntityPlayerActionPack setSprinting(boolean doSprint)
|
|
||||||
{
|
|
||||||
sprinting = doSprint;
|
|
||||||
player.setSprinting(doSprint);
|
|
||||||
if (sneaking && sprinting)
|
|
||||||
setSneaking(false);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityPlayerActionPack setForward(float value)
|
|
||||||
{
|
|
||||||
forward = value;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
public EntityPlayerActionPack setStrafing(float value)
|
|
||||||
{
|
|
||||||
strafing = value;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
public EntityPlayerActionPack look(Direction direction)
|
|
||||||
{
|
|
||||||
return switch (direction)
|
|
||||||
{
|
|
||||||
case NORTH -> look(180, 0);
|
|
||||||
case SOUTH -> look(0, 0);
|
|
||||||
case EAST -> look(-90, 0);
|
|
||||||
case WEST -> look(90, 0);
|
|
||||||
case UP -> look(player.getYRot(), -90);
|
|
||||||
case DOWN -> look(player.getYRot(), 90);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
public EntityPlayerActionPack look(Vec2 rotation)
|
|
||||||
{
|
|
||||||
return look(rotation.x, rotation.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityPlayerActionPack look(float yaw, float pitch)
|
|
||||||
{
|
|
||||||
player.setYRot(yaw % 360); //setYaw
|
|
||||||
player.setXRot(Mth.clamp(pitch, -90, 90)); // setPitch
|
|
||||||
// maybe player.moveTo(player.getX(), player.getY(), player.getZ(), yaw, Mth.clamp(pitch,-90.0F, 90.0F));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityPlayerActionPack lookAt(Vec3 position)
|
|
||||||
{
|
|
||||||
player.lookAt(EntityAnchorArgument.Anchor.EYES, position);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityPlayerActionPack turn(float yaw, float pitch)
|
|
||||||
{
|
|
||||||
return look(player.getYRot() + yaw, player.getXRot() + pitch);
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityPlayerActionPack turn(Vec2 rotation)
|
|
||||||
{
|
|
||||||
return turn(rotation.x, rotation.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityPlayerActionPack stopMovement()
|
|
||||||
{
|
|
||||||
setSneaking(false);
|
|
||||||
setSprinting(false);
|
|
||||||
forward = 0.0F;
|
|
||||||
strafing = 0.0F;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public EntityPlayerActionPack stopAll()
|
|
||||||
{
|
|
||||||
for (ActionType type : actions.keySet()) type.stop(player, actions.get(type));
|
|
||||||
actions.clear();
|
|
||||||
return stopMovement();
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityPlayerActionPack mount(boolean onlyRideables)
|
|
||||||
{
|
|
||||||
//test what happens
|
|
||||||
List<Entity> entities;
|
|
||||||
if (onlyRideables)
|
|
||||||
{
|
|
||||||
entities = player.level().getEntities(player, player.getBoundingBox().inflate(3.0D, 1.0D, 3.0D),
|
|
||||||
e -> e instanceof Minecart || e instanceof Boat || e instanceof AbstractHorse);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
entities = player.level().getEntities(player, player.getBoundingBox().inflate(3.0D, 1.0D, 3.0D));
|
|
||||||
}
|
|
||||||
if (entities.size()==0)
|
|
||||||
return this;
|
|
||||||
Entity closest = null;
|
|
||||||
double distance = Double.POSITIVE_INFINITY;
|
|
||||||
Entity currentVehicle = player.getVehicle();
|
|
||||||
for (Entity e: entities)
|
|
||||||
{
|
|
||||||
if (e == player || (currentVehicle == e))
|
|
||||||
continue;
|
|
||||||
double dd = player.distanceToSqr(e);
|
|
||||||
if (dd<distance)
|
|
||||||
{
|
|
||||||
distance = dd;
|
|
||||||
closest = e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (closest == null) return this;
|
|
||||||
if (closest instanceof AbstractHorse && onlyRideables)
|
|
||||||
((AbstractHorse) closest).mobInteract(player, InteractionHand.MAIN_HAND);
|
|
||||||
else
|
|
||||||
player.startRiding(closest,true);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
public EntityPlayerActionPack dismount()
|
|
||||||
{
|
|
||||||
player.stopRiding();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onUpdate()
|
|
||||||
{
|
|
||||||
Map<ActionType, Boolean> actionAttempts = new HashMap<>();
|
|
||||||
actions.values().removeIf(e -> e.done);
|
|
||||||
for (Map.Entry<ActionType, Action> e : actions.entrySet())
|
|
||||||
{
|
|
||||||
ActionType type = e.getKey();
|
|
||||||
Action action = e.getValue();
|
|
||||||
// skipping attack if use was successful
|
|
||||||
if (!(actionAttempts.getOrDefault(ActionType.USE, false) && type == ActionType.ATTACK))
|
|
||||||
{
|
|
||||||
Boolean actionStatus = action.tick(this, type);
|
|
||||||
if (actionStatus != null)
|
|
||||||
actionAttempts.put(type, actionStatus);
|
|
||||||
}
|
|
||||||
// optionally retrying use after successful attack and unsuccessful use
|
|
||||||
if (type == ActionType.ATTACK
|
|
||||||
&& actionAttempts.getOrDefault(ActionType.ATTACK, false)
|
|
||||||
&& !actionAttempts.getOrDefault(ActionType.USE, true) )
|
|
||||||
{
|
|
||||||
// according to MinecraftClient.handleInputEvents
|
|
||||||
Action using = actions.get(ActionType.USE);
|
|
||||||
if (using != null) // this is always true - we know use worked, but just in case
|
|
||||||
{
|
|
||||||
using.retry(this, ActionType.USE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
float vel = sneaking?0.3F:1.0F;
|
|
||||||
// The != 0.0F checks are needed given else real players can't control minecarts, however it works with fakes and else they don't stop immediately
|
|
||||||
if (forward != 0.0F || player instanceof MinionFakePlayer) {
|
|
||||||
player.zza = forward * vel;
|
|
||||||
}
|
|
||||||
if (strafing != 0.0F || player instanceof MinionFakePlayer) {
|
|
||||||
player.xxa = strafing * vel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static HitResult getTarget(ServerPlayer player)
|
|
||||||
{
|
|
||||||
double reach = player.gameMode.isCreative() ? 5 : 4.5f;
|
|
||||||
return Tracer.rayTrace(player, 1, reach, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void dropItemFromSlot(int slot, boolean dropAll)
|
|
||||||
{
|
|
||||||
Inventory inv = player.getInventory(); // getInventory;
|
|
||||||
if (!inv.getItem(slot).isEmpty())
|
|
||||||
player.drop(inv.removeItem(slot,
|
|
||||||
dropAll ? inv.getItem(slot).getCount() : 1
|
|
||||||
), false, true); // scatter, keep owner
|
|
||||||
}
|
|
||||||
|
|
||||||
public void drop(int selectedSlot, boolean dropAll)
|
|
||||||
{
|
|
||||||
Inventory inv = player.getInventory(); // getInventory;
|
|
||||||
if (selectedSlot == -2) // all
|
|
||||||
{
|
|
||||||
for (int i = inv.getContainerSize(); i >= 0; i--)
|
|
||||||
dropItemFromSlot(i, dropAll);
|
|
||||||
}
|
|
||||||
else // one slot
|
|
||||||
{
|
|
||||||
if (selectedSlot == -1)
|
|
||||||
selectedSlot = inv.selected;
|
|
||||||
dropItemFromSlot(selectedSlot, dropAll);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSlot(int slot)
|
|
||||||
{
|
|
||||||
player.getInventory().selected = slot-1;
|
|
||||||
player.connection.send(new ClientboundSetCarriedItemPacket(slot-1));
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum ActionType
|
|
||||||
{
|
|
||||||
USE(true)
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
boolean execute(ServerPlayer player, Action action)
|
|
||||||
{
|
|
||||||
EntityPlayerActionPack ap = ((ServerPlayerInterface) player).getActionPack();
|
|
||||||
if (ap.itemUseCooldown > 0)
|
|
||||||
{
|
|
||||||
ap.itemUseCooldown--;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (player.isUsingItem())
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
HitResult hit = getTarget(player);
|
|
||||||
for (InteractionHand hand : InteractionHand.values())
|
|
||||||
{
|
|
||||||
switch (hit.getType())
|
|
||||||
{
|
|
||||||
case BLOCK:
|
|
||||||
{
|
|
||||||
player.resetLastActionTime();
|
|
||||||
ServerLevel world = player.serverLevel();
|
|
||||||
BlockHitResult blockHit = (BlockHitResult) hit;
|
|
||||||
BlockPos pos = blockHit.getBlockPos();
|
|
||||||
Direction side = blockHit.getDirection();
|
|
||||||
if (pos.getY() < player.level().getMaxBuildHeight() - (side == Direction.UP ? 1 : 0) && world.mayInteract(player, pos))
|
|
||||||
{
|
|
||||||
InteractionResult result = player.gameMode.useItemOn(player, world, player.getItemInHand(hand), hand, blockHit);
|
|
||||||
if (result.consumesAction())
|
|
||||||
{
|
|
||||||
if (result.shouldSwing()) player.swing(hand);
|
|
||||||
ap.itemUseCooldown = 3;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ENTITY:
|
|
||||||
{
|
|
||||||
player.resetLastActionTime();
|
|
||||||
EntityHitResult entityHit = (EntityHitResult) hit;
|
|
||||||
Entity entity = entityHit.getEntity();
|
|
||||||
boolean handWasEmpty = player.getItemInHand(hand).isEmpty();
|
|
||||||
boolean itemFrameEmpty = (entity instanceof ItemFrame) && ((ItemFrame) entity).getItem().isEmpty();
|
|
||||||
Vec3 relativeHitPos = entityHit.getLocation().subtract(entity.getX(), entity.getY(), entity.getZ());
|
|
||||||
if (entity.interactAt(player, relativeHitPos, hand).consumesAction())
|
|
||||||
{
|
|
||||||
ap.itemUseCooldown = 3;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// fix for SS itemframe always returns CONSUME even if no action is performed
|
|
||||||
if (player.interactOn(entity, hand).consumesAction() && !(handWasEmpty && itemFrameEmpty))
|
|
||||||
{
|
|
||||||
ap.itemUseCooldown = 3;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ItemStack handItem = player.getItemInHand(hand);
|
|
||||||
if (player.gameMode.useItem(player, player.level(), handItem, hand).consumesAction())
|
|
||||||
{
|
|
||||||
ap.itemUseCooldown = 3;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void inactiveTick(ServerPlayer player, Action action)
|
|
||||||
{
|
|
||||||
EntityPlayerActionPack ap = ((ServerPlayerInterface) player).getActionPack();
|
|
||||||
ap.itemUseCooldown = 0;
|
|
||||||
player.releaseUsingItem();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
ATTACK(true) {
|
|
||||||
@Override
|
|
||||||
boolean execute(ServerPlayer player, Action action) {
|
|
||||||
HitResult hit = getTarget(player);
|
|
||||||
switch (hit.getType()) {
|
|
||||||
case ENTITY: {
|
|
||||||
EntityHitResult entityHit = (EntityHitResult) hit;
|
|
||||||
if (!action.isContinuous)
|
|
||||||
{
|
|
||||||
player.attack(entityHit.getEntity());
|
|
||||||
player.swing(InteractionHand.MAIN_HAND);
|
|
||||||
}
|
|
||||||
player.resetAttackStrengthTicker();
|
|
||||||
player.resetLastActionTime();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case BLOCK: {
|
|
||||||
EntityPlayerActionPack ap = ((ServerPlayerInterface) player).getActionPack();
|
|
||||||
if (ap.blockHitDelay > 0)
|
|
||||||
{
|
|
||||||
ap.blockHitDelay--;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
BlockHitResult blockHit = (BlockHitResult) hit;
|
|
||||||
BlockPos pos = blockHit.getBlockPos();
|
|
||||||
Direction side = blockHit.getDirection();
|
|
||||||
if (player.blockActionRestricted(player.level(), pos, player.gameMode.getGameModeForPlayer())) return false;
|
|
||||||
if (ap.currentBlock != null && player.level().getBlockState(ap.currentBlock).isAir())
|
|
||||||
{
|
|
||||||
ap.currentBlock = null;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
BlockState state = player.level().getBlockState(pos);
|
|
||||||
boolean blockBroken = false;
|
|
||||||
if (player.gameMode.getGameModeForPlayer().isCreative())
|
|
||||||
{
|
|
||||||
player.gameMode.handleBlockBreakAction(pos, ServerboundPlayerActionPacket.Action.START_DESTROY_BLOCK, side, player.level().getMaxBuildHeight(), -1);
|
|
||||||
ap.blockHitDelay = 5;
|
|
||||||
blockBroken = true;
|
|
||||||
}
|
|
||||||
else if (ap.currentBlock == null || !ap.currentBlock.equals(pos))
|
|
||||||
{
|
|
||||||
if (ap.currentBlock != null)
|
|
||||||
{
|
|
||||||
player.gameMode.handleBlockBreakAction(ap.currentBlock, ServerboundPlayerActionPacket.Action.ABORT_DESTROY_BLOCK, side, player.level().getMaxBuildHeight(), -1);
|
|
||||||
}
|
|
||||||
player.gameMode.handleBlockBreakAction(pos, ServerboundPlayerActionPacket.Action.START_DESTROY_BLOCK, side, player.level().getMaxBuildHeight(), -1);
|
|
||||||
boolean notAir = !state.isAir();
|
|
||||||
if (notAir && ap.curBlockDamageMP == 0)
|
|
||||||
{
|
|
||||||
state.attack(player.level(), pos, player);
|
|
||||||
}
|
|
||||||
if (notAir && state.getDestroyProgress(player, player.level(), pos) >= 1)
|
|
||||||
{
|
|
||||||
ap.currentBlock = null;
|
|
||||||
//instamine??
|
|
||||||
blockBroken = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ap.currentBlock = pos;
|
|
||||||
ap.curBlockDamageMP = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ap.curBlockDamageMP += state.getDestroyProgress(player, player.level(), pos);
|
|
||||||
if (ap.curBlockDamageMP >= 1)
|
|
||||||
{
|
|
||||||
player.gameMode.handleBlockBreakAction(pos, ServerboundPlayerActionPacket.Action.STOP_DESTROY_BLOCK, side, player.level().getMaxBuildHeight(), -1);
|
|
||||||
ap.currentBlock = null;
|
|
||||||
ap.blockHitDelay = 5;
|
|
||||||
blockBroken = true;
|
|
||||||
}
|
|
||||||
player.level().destroyBlockProgress(-1, pos, (int) (ap.curBlockDamageMP * 10));
|
|
||||||
|
|
||||||
}
|
|
||||||
player.resetLastActionTime();
|
|
||||||
player.swing(InteractionHand.MAIN_HAND);
|
|
||||||
return blockBroken;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void inactiveTick(ServerPlayer player, Action action)
|
|
||||||
{
|
|
||||||
EntityPlayerActionPack ap = ((ServerPlayerInterface) player).getActionPack();
|
|
||||||
if (ap.currentBlock == null) return;
|
|
||||||
player.level().destroyBlockProgress(-1, ap.currentBlock, -1);
|
|
||||||
player.gameMode.handleBlockBreakAction(ap.currentBlock, ServerboundPlayerActionPacket.Action.ABORT_DESTROY_BLOCK, Direction.DOWN, player.level().getMaxBuildHeight(), -1);
|
|
||||||
ap.currentBlock = null;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
JUMP(true)
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
boolean execute(ServerPlayer player, Action action)
|
|
||||||
{
|
|
||||||
if (action.limit == 1)
|
|
||||||
{
|
|
||||||
if (player.onGround()) player.jumpFromGround(); // onGround
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
player.setJumping(true);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void inactiveTick(ServerPlayer player, Action action)
|
|
||||||
{
|
|
||||||
player.setJumping(false);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
DROP_ITEM(true)
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
boolean execute(ServerPlayer player, Action action)
|
|
||||||
{
|
|
||||||
player.resetLastActionTime();
|
|
||||||
player.drop(false); // dropSelectedItem
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
DROP_STACK(true)
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
boolean execute(ServerPlayer player, Action action)
|
|
||||||
{
|
|
||||||
player.resetLastActionTime();
|
|
||||||
player.drop(true); // dropSelectedItem
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
SWAP_HANDS(true)
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
boolean execute(ServerPlayer player, Action action)
|
|
||||||
{
|
|
||||||
player.resetLastActionTime();
|
|
||||||
ItemStack itemStack_1 = player.getItemInHand(InteractionHand.OFF_HAND);
|
|
||||||
player.setItemInHand(InteractionHand.OFF_HAND, player.getItemInHand(InteractionHand.MAIN_HAND));
|
|
||||||
player.setItemInHand(InteractionHand.MAIN_HAND, itemStack_1);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public final boolean preventSpectator;
|
|
||||||
|
|
||||||
ActionType(boolean preventSpectator)
|
|
||||||
{
|
|
||||||
this.preventSpectator = preventSpectator;
|
|
||||||
}
|
|
||||||
|
|
||||||
void start(ServerPlayer player, Action action) {}
|
|
||||||
abstract boolean execute(ServerPlayer player, Action action);
|
|
||||||
void inactiveTick(ServerPlayer player, Action action) {}
|
|
||||||
void stop(ServerPlayer player, Action action)
|
|
||||||
{
|
|
||||||
inactiveTick(player, action);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Action
|
|
||||||
{
|
|
||||||
public boolean done = false;
|
|
||||||
public final int limit;
|
|
||||||
public final int interval;
|
|
||||||
public final int offset;
|
|
||||||
private int count;
|
|
||||||
private int next;
|
|
||||||
private final boolean isContinuous;
|
|
||||||
|
|
||||||
private Action(int limit, int interval, int offset, boolean continuous)
|
|
||||||
{
|
|
||||||
this.limit = limit;
|
|
||||||
this.interval = interval;
|
|
||||||
this.offset = offset;
|
|
||||||
next = interval + offset;
|
|
||||||
isContinuous = continuous;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Action once()
|
|
||||||
{
|
|
||||||
return new Action(1, 1, 0, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Action continuous()
|
|
||||||
{
|
|
||||||
return new Action(-1, 1, 0, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Action interval(int interval)
|
|
||||||
{
|
|
||||||
return new Action(-1, interval, 0, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Action interval(int interval, int offset)
|
|
||||||
{
|
|
||||||
return new Action(-1, interval, offset, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
Boolean tick(EntityPlayerActionPack actionPack, ActionType type)
|
|
||||||
{
|
|
||||||
next--;
|
|
||||||
Boolean cancel = null;
|
|
||||||
if (next <= 0)
|
|
||||||
{
|
|
||||||
if (interval == 1 && !isContinuous)
|
|
||||||
{
|
|
||||||
// need to allow entity to tick, otherwise won't have effect (bow)
|
|
||||||
// actions are 20 tps, so need to clear status mid tick, allowing entities process it till next time
|
|
||||||
if (!type.preventSpectator || !actionPack.player.isSpectator())
|
|
||||||
{
|
|
||||||
type.inactiveTick(actionPack.player, this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!type.preventSpectator || !actionPack.player.isSpectator())
|
|
||||||
{
|
|
||||||
cancel = type.execute(actionPack.player, this);
|
|
||||||
}
|
|
||||||
count++;
|
|
||||||
if (count == limit)
|
|
||||||
{
|
|
||||||
type.stop(actionPack.player, null);
|
|
||||||
done = true;
|
|
||||||
return cancel;
|
|
||||||
}
|
|
||||||
next = interval;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!type.preventSpectator || !actionPack.player.isSpectator())
|
|
||||||
{
|
|
||||||
type.inactiveTick(actionPack.player, this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cancel;
|
|
||||||
}
|
|
||||||
|
|
||||||
void retry(EntityPlayerActionPack actionPack, ActionType type)
|
|
||||||
{
|
|
||||||
//assuming action run but was unsuccesful that tick, but opportunity emerged to retry it, lets retry it.
|
|
||||||
if (!type.preventSpectator || !actionPack.player.isSpectator())
|
|
||||||
{
|
|
||||||
type.execute(actionPack.player, this);
|
|
||||||
}
|
|
||||||
count++;
|
|
||||||
if (count == limit)
|
|
||||||
{
|
|
||||||
type.stop(actionPack.player, null);
|
|
||||||
done = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
package io.github.skippyall.minions.fakeplayer;
|
|
||||||
|
|
||||||
import io.netty.channel.embedded.EmbeddedChannel;
|
|
||||||
import net.minecraft.network.Connection;
|
|
||||||
import net.minecraft.network.PacketListener;
|
|
||||||
import net.minecraft.network.chat.Component;
|
|
||||||
import net.minecraft.network.protocol.PacketFlow;
|
|
||||||
|
|
||||||
public class FakeClientConnection extends Connection {
|
|
||||||
public FakeClientConnection(PacketFlow p)
|
|
||||||
{
|
|
||||||
super(p);
|
|
||||||
// compat with adventure-platform-fabric. This does NOT trigger other vanilla handlers for establishing a channel
|
|
||||||
// also makes #isOpen return true, allowing enderpearls to teleport fake players
|
|
||||||
((ClientConnectionInterface)this).setChannel(new EmbeddedChannel());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setReadOnly()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleDisconnection() {
|
|
||||||
getPacketListener().onDisconnect(getDisconnectedReason()==null ? Component.literal("Disconnected"): getDisconnectedReason());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setListenerForServerboundHandshake(PacketListener packetListener)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setListener(PacketListener packetListener) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,201 +0,0 @@
|
|||||||
package io.github.skippyall.minions.fakeplayer;
|
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
|
||||||
import com.mojang.authlib.yggdrasil.ProfileResult;
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.core.UUIDUtil;
|
|
||||||
import net.minecraft.network.chat.Component;
|
|
||||||
import net.minecraft.network.chat.contents.TranslatableContents;
|
|
||||||
import net.minecraft.network.protocol.PacketFlow;
|
|
||||||
import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket;
|
|
||||||
import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket;
|
|
||||||
import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket;
|
|
||||||
import net.minecraft.network.protocol.game.ServerboundClientCommandPacket;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.server.TickTask;
|
|
||||||
import net.minecraft.server.level.ClientInformation;
|
|
||||||
import net.minecraft.server.level.ServerLevel;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import net.minecraft.server.network.CommonListenerCookie;
|
|
||||||
import net.minecraft.world.damagesource.DamageSource;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.EquipmentSlot;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.food.FoodData;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.level.GameType;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
|
||||||
import net.minecraft.world.phys.Vec3;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class MinionFakePlayer extends ServerPlayer {
|
|
||||||
public Runnable fixStartingPosition = () -> {};
|
|
||||||
public boolean isAShadow;
|
|
||||||
public static void createMinion(String username, ServerLevel level, ServerPlayer owner, Vec3 pos, double yaw, double pitch) {
|
|
||||||
MinecraftServer server = level.getServer();
|
|
||||||
server.getProfileCache().getAsync(username).thenAcceptAsync((optional) -> {
|
|
||||||
GameProfile profile = null;
|
|
||||||
if(optional.isPresent()){
|
|
||||||
UUID uuid = optional.get().getId();
|
|
||||||
ProfileResult result = server.getSessionService().fetchProfile(uuid, true);
|
|
||||||
if(result != null) {
|
|
||||||
profile = result.profile();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(profile == null) {
|
|
||||||
profile = new GameProfile(UUIDUtil.createOfflinePlayerUUID(username), username);
|
|
||||||
}
|
|
||||||
MinionFakePlayer instance = new MinionFakePlayer(server, level, profile, ClientInformation.createDefault(), false);
|
|
||||||
instance.fixStartingPosition = () -> instance.moveTo(pos.x, pos.y, pos.z, (float) yaw, (float) pitch);
|
|
||||||
server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), instance, new CommonListenerCookie(profile, 0, instance.clientInformation()));
|
|
||||||
instance.teleportTo(level, pos.x, pos.y, pos.z, (float) yaw, (float) pitch);
|
|
||||||
instance.setHealth(20.0F);
|
|
||||||
instance.unsetRemoved();
|
|
||||||
instance.gameMode.changeGameModeForPlayer(GameType.SURVIVAL);
|
|
||||||
server.getPlayerList().broadcastAll(new ClientboundRotateHeadPacket(instance, (byte) (instance.yHeadRot * 256 / 360)), level.dimension());//instance.dimension);
|
|
||||||
server.getPlayerList().broadcastAll(new ClientboundTeleportEntityPacket(instance), level.dimension());//instance.dimension);
|
|
||||||
//instance.world.getChunkManager(). updatePosition(instance);
|
|
||||||
instance.entityData.set(DATA_PLAYER_MODE_CUSTOMISATION, (byte) 0x7f); // show all model layers (incl. capes)
|
|
||||||
instance.getAbilities().flying = false;
|
|
||||||
instance.setMaxUpStep(0.6F);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unused") //Don't know if I'll need this
|
|
||||||
public static MinionFakePlayer createShadow(MinecraftServer server, ServerPlayer player)
|
|
||||||
{
|
|
||||||
player.getServer().getPlayerList().remove(player);
|
|
||||||
player.connection.disconnect(Component.translatable("multiplayer.disconnect.duplicate_login"));
|
|
||||||
ServerLevel worldIn = player.serverLevel();//.getWorld(player.dimension);
|
|
||||||
GameProfile gameprofile = player.getGameProfile();
|
|
||||||
MinionFakePlayer playerShadow = new MinionFakePlayer(server, worldIn, gameprofile, player.clientInformation(), true);
|
|
||||||
playerShadow.setChatSession(player.getChatSession());
|
|
||||||
server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), playerShadow, new CommonListenerCookie(gameprofile, 0, player.clientInformation()));
|
|
||||||
|
|
||||||
playerShadow.setHealth(player.getHealth());
|
|
||||||
playerShadow.connection.teleport(player.getX(), player.getY(), player.getZ(), player.getYRot(), player.getXRot());
|
|
||||||
playerShadow.gameMode.changeGameModeForPlayer(player.gameMode.getGameModeForPlayer());
|
|
||||||
((ServerPlayerInterface) playerShadow).getActionPack().copyFrom(((ServerPlayerInterface) player).getActionPack());
|
|
||||||
playerShadow.entityData.set(DATA_PLAYER_MODE_CUSTOMISATION, player.getEntityData().get(DATA_PLAYER_MODE_CUSTOMISATION));
|
|
||||||
|
|
||||||
|
|
||||||
server.getPlayerList().broadcastAll(new ClientboundRotateHeadPacket(playerShadow, (byte) (player.yHeadRot * 256 / 360)), playerShadow.level().dimension());
|
|
||||||
server.getPlayerList().broadcastAll(new ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER, playerShadow));
|
|
||||||
//player.world.getChunkManager().updatePosition(playerShadow);
|
|
||||||
playerShadow.getAbilities().flying = player.getAbilities().flying;
|
|
||||||
return playerShadow;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MinionFakePlayer respawnFake(MinecraftServer server, ServerLevel level, GameProfile profile, ClientInformation cli)
|
|
||||||
{
|
|
||||||
return new MinionFakePlayer(server, level, profile, cli, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private MinionFakePlayer(MinecraftServer server, ServerLevel worldIn, GameProfile profile, ClientInformation cli, boolean shadow)
|
|
||||||
{
|
|
||||||
super(server, worldIn, profile, cli);
|
|
||||||
isAShadow = shadow;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEquipItem(final EquipmentSlot slot, final ItemStack previous, final ItemStack stack)
|
|
||||||
{
|
|
||||||
if (!isUsingItem()) super.onEquipItem(slot, previous, stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void kill()
|
|
||||||
{
|
|
||||||
kill(Component.literal("Killed"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void kill(Component reason)
|
|
||||||
{
|
|
||||||
shakeOff();
|
|
||||||
|
|
||||||
if (reason.getContents() instanceof TranslatableContents text && text.getKey().equals("multiplayer.disconnect.duplicate_login")) {
|
|
||||||
this.connection.onDisconnect(reason);
|
|
||||||
} else {
|
|
||||||
this.server.tell(new TickTask(this.server.getTickCount(), () -> {
|
|
||||||
this.connection.onDisconnect(reason);
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick()
|
|
||||||
{
|
|
||||||
if (this.getServer().getTickCount() % 10 == 0)
|
|
||||||
{
|
|
||||||
this.connection.resetPosition();
|
|
||||||
this.serverLevel().getChunkSource().move(this);
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
super.tick();
|
|
||||||
this.doTick();
|
|
||||||
}
|
|
||||||
catch (NullPointerException ignored)
|
|
||||||
{
|
|
||||||
// happens with that paper port thingy - not sure what that would fix, but hey
|
|
||||||
// the game not gonna crash violently.
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void shakeOff()
|
|
||||||
{
|
|
||||||
if (getVehicle() instanceof Player) stopRiding();
|
|
||||||
for (Entity passenger : getIndirectPassengers())
|
|
||||||
{
|
|
||||||
if (passenger instanceof Player) passenger.stopRiding();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void die(DamageSource cause)
|
|
||||||
{
|
|
||||||
shakeOff();
|
|
||||||
super.die(cause);
|
|
||||||
setHealth(20);
|
|
||||||
this.foodData = new FoodData();
|
|
||||||
kill(this.getCombatTracker().getDeathMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getIpAddress()
|
|
||||||
{
|
|
||||||
return "127.0.0.1";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean allowsListing() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void checkFallDamage(double y, boolean onGround, BlockState state, BlockPos pos) {
|
|
||||||
doCheckFallDamage(0.0, y, 0.0, onGround);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Entity changeDimension(ServerLevel serverLevel)
|
|
||||||
{
|
|
||||||
super.changeDimension(serverLevel);
|
|
||||||
if (wonGame) {
|
|
||||||
ServerboundClientCommandPacket p = new ServerboundClientCommandPacket(ServerboundClientCommandPacket.Action.PERFORM_RESPAWN);
|
|
||||||
connection.handleClientCommand(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If above branch was taken, *this* has been removed and replaced, the new instance has been set
|
|
||||||
// on 'our' connection (which is now theirs, but we still have a ref).
|
|
||||||
if (connection.player.isChangingDimension()) {
|
|
||||||
connection.player.hasChangedDimension();
|
|
||||||
}
|
|
||||||
return connection.player;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package io.github.skippyall.minions.fakeplayer;
|
|
||||||
|
|
||||||
import net.minecraft.network.Connection;
|
|
||||||
import net.minecraft.network.chat.Component;
|
|
||||||
import net.minecraft.network.chat.contents.TranslatableContents;
|
|
||||||
import net.minecraft.network.protocol.Packet;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import net.minecraft.server.network.CommonListenerCookie;
|
|
||||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
|
||||||
import net.minecraft.world.entity.RelativeMovement;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class NetHandlerPlayServerFake extends ServerGamePacketListenerImpl
|
|
||||||
{
|
|
||||||
public NetHandlerPlayServerFake(final MinecraftServer minecraftServer, final Connection connection, final ServerPlayer serverPlayer, final CommonListenerCookie i)
|
|
||||||
{
|
|
||||||
super(minecraftServer, connection, serverPlayer, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void send(final Packet<?> packetIn)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void disconnect(Component message)
|
|
||||||
{
|
|
||||||
if (message.getContents() instanceof TranslatableContents text && (text.getKey().equals("multiplayer.disconnect.idling") || text.getKey().equals("multiplayer.disconnect.duplicate_login")))
|
|
||||||
{
|
|
||||||
((MinionFakePlayer) player).kill(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(double d, double e, double f, float g, float h, Set<RelativeMovement> set)
|
|
||||||
{
|
|
||||||
super.teleport(d, e, f, g, h, set);
|
|
||||||
if (player.serverLevel().getPlayerByUUID(player.getUUID()) != null) {
|
|
||||||
resetPosition();
|
|
||||||
player.serverLevel().getChunkSource().move(player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package io.github.skippyall.minions.fakeplayer;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.fakeplayer.EntityPlayerActionPack;
|
|
||||||
|
|
||||||
public interface ServerPlayerInterface
|
|
||||||
{
|
|
||||||
EntityPlayerActionPack getActionPack();
|
|
||||||
}
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
package io.github.skippyall.minions.fakeplayer;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.level.ClipContext;
|
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
import net.minecraft.world.phys.AABB;
|
|
||||||
import net.minecraft.world.phys.BlockHitResult;
|
|
||||||
import net.minecraft.world.phys.EntityHitResult;
|
|
||||||
import net.minecraft.world.phys.HitResult;
|
|
||||||
import net.minecraft.world.phys.Vec3;
|
|
||||||
|
|
||||||
public class Tracer
|
|
||||||
{
|
|
||||||
public static HitResult rayTrace(Entity source, float partialTicks, double reach, boolean fluids)
|
|
||||||
{
|
|
||||||
BlockHitResult blockHit = rayTraceBlocks(source, partialTicks, reach, fluids);
|
|
||||||
double maxSqDist = reach * reach;
|
|
||||||
if (blockHit != null)
|
|
||||||
{
|
|
||||||
maxSqDist = blockHit.getLocation().distanceToSqr(source.getEyePosition(partialTicks));
|
|
||||||
}
|
|
||||||
EntityHitResult entityHit = rayTraceEntities(source, partialTicks, reach, maxSqDist);
|
|
||||||
return entityHit == null ? blockHit : entityHit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BlockHitResult rayTraceBlocks(Entity source, float partialTicks, double reach, boolean fluids)
|
|
||||||
{
|
|
||||||
Vec3 pos = source.getEyePosition(partialTicks);
|
|
||||||
Vec3 rotation = source.getViewVector(partialTicks);
|
|
||||||
Vec3 reachEnd = pos.add(rotation.x * reach, rotation.y * reach, rotation.z * reach);
|
|
||||||
return source.level().clip(new ClipContext(pos, reachEnd, ClipContext.Block.OUTLINE, fluids ?
|
|
||||||
ClipContext.Fluid.ANY : ClipContext.Fluid.NONE, source));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EntityHitResult rayTraceEntities(Entity source, float partialTicks, double reach, double maxSqDist)
|
|
||||||
{
|
|
||||||
Vec3 pos = source.getEyePosition(partialTicks);
|
|
||||||
Vec3 reachVec = source.getViewVector(partialTicks).scale(reach);
|
|
||||||
AABB box = source.getBoundingBox().expandTowards(reachVec).inflate(1);
|
|
||||||
return rayTraceEntities(source, pos, pos.add(reachVec), box, e -> !e.isSpectator() && e.isPickable(), maxSqDist);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EntityHitResult rayTraceEntities(Entity source, Vec3 start, Vec3 end, AABB box, Predicate<Entity> predicate, double maxSqDistance)
|
|
||||||
{
|
|
||||||
Level world = source.level();
|
|
||||||
double targetDistance = maxSqDistance;
|
|
||||||
Entity target = null;
|
|
||||||
Vec3 targetHitPos = null;
|
|
||||||
for (Entity current : world.getEntities(source, box, predicate))
|
|
||||||
{
|
|
||||||
AABB currentBox = current.getBoundingBox().inflate(current.getPickRadius());
|
|
||||||
Optional<Vec3> currentHit = currentBox.clip(start, end);
|
|
||||||
if (currentBox.contains(start))
|
|
||||||
{
|
|
||||||
if (targetDistance >= 0)
|
|
||||||
{
|
|
||||||
target = current;
|
|
||||||
targetHitPos = currentHit.orElse(start);
|
|
||||||
targetDistance = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (currentHit.isPresent())
|
|
||||||
{
|
|
||||||
Vec3 currentHitPos = currentHit.get();
|
|
||||||
double currentDistance = start.distanceToSqr(currentHitPos);
|
|
||||||
if (currentDistance < targetDistance || targetDistance == 0)
|
|
||||||
{
|
|
||||||
if (current.getRootVehicle() == source.getRootVehicle())
|
|
||||||
{
|
|
||||||
if (targetDistance == 0)
|
|
||||||
{
|
|
||||||
target = current;
|
|
||||||
targetHitPos = currentHitPos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
target = current;
|
|
||||||
targetHitPos = currentHitPos;
|
|
||||||
targetDistance = currentDistance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return target == null ? null : new EntityHitResult(target, targetHitPos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package io.github.skippyall.minions.mixins;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.fakeplayer.ClientConnectionInterface;
|
|
||||||
import io.netty.channel.Channel;
|
|
||||||
import net.minecraft.network.Connection;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
|
||||||
|
|
||||||
@Mixin(Connection.class)
|
|
||||||
public abstract class ConnectionMixin implements ClientConnectionInterface {
|
|
||||||
@Override
|
|
||||||
@Accessor //Compat with adventure-platform-fabric
|
|
||||||
public abstract void setChannel(Channel channel);
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
package io.github.skippyall.minions.mixins;
|
|
||||||
|
|
||||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
|
||||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
|
||||||
import com.mojang.authlib.GameProfile;
|
|
||||||
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
|
||||||
import io.github.skippyall.minions.fakeplayer.NetHandlerPlayServerFake;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.network.Connection;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.server.level.ClientInformation;
|
|
||||||
import net.minecraft.server.level.ServerLevel;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import net.minecraft.server.network.CommonListenerCookie;
|
|
||||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
|
||||||
import net.minecraft.server.players.PlayerList;
|
|
||||||
import org.spongepowered.asm.mixin.Final;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
||||||
|
|
||||||
@Mixin(PlayerList.class)
|
|
||||||
public class PlayerListMixin {
|
|
||||||
@Shadow
|
|
||||||
@Final
|
|
||||||
private MinecraftServer server;
|
|
||||||
|
|
||||||
@Inject(method = "load", at = @At(value = "RETURN", shift = At.Shift.BEFORE))
|
|
||||||
private void fixStartingPos(ServerPlayer serverPlayerEntity_1, CallbackInfoReturnable<CompoundTag> cir)
|
|
||||||
{
|
|
||||||
if (serverPlayerEntity_1 instanceof MinionFakePlayer)
|
|
||||||
{
|
|
||||||
((MinionFakePlayer) serverPlayerEntity_1).fixStartingPosition.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@WrapOperation(method = "placeNewPlayer", at = @At(value = "NEW", target = "(Lnet/minecraft/server/MinecraftServer;Lnet/minecraft/network/Connection;Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/server/network/CommonListenerCookie;)Lnet/minecraft/server/network/ServerGamePacketListenerImpl;"))
|
|
||||||
private ServerGamePacketListenerImpl replaceNetworkHandler(MinecraftServer minecraftServer, Connection connection, ServerPlayer serverPlayer, CommonListenerCookie commonListenerCookie, Operation<ServerGamePacketListenerImpl> original)
|
|
||||||
{
|
|
||||||
if (serverPlayer instanceof MinionFakePlayer fake) {
|
|
||||||
return new NetHandlerPlayServerFake(this.server, connection, fake, commonListenerCookie);
|
|
||||||
} else {
|
|
||||||
return original.call(minecraftServer, connection, serverPlayer, commonListenerCookie);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@WrapOperation(method = "respawn", at = @At(value = "NEW", target = "(Lnet/minecraft/server/MinecraftServer;Lnet/minecraft/server/level/ServerLevel;Lcom/mojang/authlib/GameProfile;Lnet/minecraft/server/level/ClientInformation;)Lnet/minecraft/server/level/ServerPlayer;"))
|
|
||||||
public ServerPlayer makePlayerForRespawn(MinecraftServer minecraftServer, ServerLevel serverLevel, GameProfile gameProfile, ClientInformation clientInformation, Operation<ServerPlayer> original, ServerPlayer serverPlayer, boolean bl) {
|
|
||||||
if (serverPlayer instanceof MinionFakePlayer) {
|
|
||||||
return MinionFakePlayer.respawnFake(minecraftServer, serverLevel, gameProfile, clientInformation);
|
|
||||||
}
|
|
||||||
return original.call(minecraftServer, serverLevel, gameProfile, clientInformation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
package io.github.skippyall.minions.mixins;
|
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
|
||||||
import io.github.skippyall.minions.fakeplayer.EntityPlayerActionPack;
|
|
||||||
import io.github.skippyall.minions.fakeplayer.ServerPlayerInterface;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.server.level.ClientInformation;
|
|
||||||
import net.minecraft.server.level.ServerLevel;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.Unique;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
|
|
||||||
@Mixin(ServerPlayer.class)
|
|
||||||
public abstract class ServerPlayerMixin implements ServerPlayerInterface {
|
|
||||||
@Unique
|
|
||||||
public EntityPlayerActionPack actionPack;
|
|
||||||
@Override
|
|
||||||
public EntityPlayerActionPack getActionPack()
|
|
||||||
{
|
|
||||||
return actionPack;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "<init>", at = @At(value = "RETURN"))
|
|
||||||
private void onServerPlayerEntityContructor(MinecraftServer minecraftServer, ServerLevel serverLevel, GameProfile gameProfile, ClientInformation clientInformation, CallbackInfo ci)
|
|
||||||
{
|
|
||||||
this.actionPack = new EntityPlayerActionPack((ServerPlayer) (Object) this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "tick", at = @At(value = "HEAD"))
|
|
||||||
private void onTick(CallbackInfo ci)
|
|
||||||
{
|
|
||||||
actionPack.onUpdate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
package io.github.skippyall.minions.networking;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.Minions;
|
|
||||||
import io.netty.buffer.Unpooled;
|
|
||||||
import net.fabricmc.api.EnvType;
|
|
||||||
import net.fabricmc.api.Environment;
|
|
||||||
import net.fabricmc.fabric.api.client.networking.v1.ClientConfigurationNetworking;
|
|
||||||
import net.fabricmc.fabric.api.networking.v1.PacketSender;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.multiplayer.ClientConfigurationPacketListenerImpl;
|
|
||||||
import net.minecraft.client.multiplayer.ClientHandshakePacketListenerImpl;
|
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.server.network.ServerConfigurationPacketListenerImpl;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
|
|
||||||
public class ClientToServerNetworking {
|
|
||||||
public static final ResourceLocation RL = new ResourceLocation(Minions.MOD_ID, "network");
|
|
||||||
@Environment(EnvType.CLIENT)
|
|
||||||
public static void sendJoinPacket(Player player) {
|
|
||||||
FriendlyByteBuf pbf = new FriendlyByteBuf(Unpooled.buffer());
|
|
||||||
pbf.writeUtf("BN|Init|V0.1");
|
|
||||||
ClientConfigurationNetworking.send(RL, pbf);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Environment(EnvType.CLIENT)
|
|
||||||
public static void onConfigurationInit(ClientConfigurationPacketListenerImpl handler, Minecraft client) {
|
|
||||||
sendJoinPacket(client.player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Environment(EnvType.SERVER)
|
|
||||||
public static void receive(MinecraftServer server, ServerConfigurationPacketListenerImpl handler, FriendlyByteBuf buf, PacketSender responseSender) {
|
|
||||||
String message = buf.readUtf();
|
|
||||||
if (!message.startsWith("BN|")) {
|
|
||||||
Minions.LOGGER.debug("Message with wrong format: " + message);
|
|
||||||
}
|
|
||||||
String[] parts = message.split("|");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
package io.github.skippyall.minions.networking;
|
|
||||||
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class VersionChecker {
|
|
||||||
protected static List<UUID> hasSupportedMod = new ArrayList<>();
|
|
||||||
public static boolean supportVersion(String version) {
|
|
||||||
return version.equals("v0.1");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean useSupportedMod(Player p) {
|
|
||||||
return hasSupportedMod.contains(p.getUUID());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void resetPlayer(UUID uuid) {
|
|
||||||
hasSupportedMod.remove(uuid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package io.github.skippyall.minions.program.block;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.program.variables.Type;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public abstract class CodeBlock {
|
|
||||||
public CodeBlock(String name, List<Type> arguments) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract Object execute(Object... args);
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package io.github.skippyall.minions.program.block;
|
|
||||||
|
|
||||||
public class CodeBlocks {
|
|
||||||
public static final ForwardBlock FORWARD = new ForwardBlock();
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
package io.github.skippyall.minions.program.block;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.program.variables.IntegerType;
|
|
||||||
import io.github.skippyall.minions.program.variables.Type;
|
|
||||||
import io.github.skippyall.minions.program.variables.Types;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ForwardBlock extends CodeBlock{
|
|
||||||
public ForwardBlock() {
|
|
||||||
super("forward", Arrays.asList(Types.INTEGER));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object execute(Object... args) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package io.github.skippyall.minions.program.module;
|
|
||||||
|
|
||||||
import eu.pb4.polymer.core.api.item.PolymerItem;
|
|
||||||
import io.github.skippyall.minions.program.block.CodeBlock;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public abstract class Modul implements PolymerItem {
|
|
||||||
private final String name;
|
|
||||||
Modul(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract List<CodeBlock> getCodeBlocks();
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package io.github.skippyall.minions.program.module;
|
|
||||||
|
|
||||||
public class Modules {
|
|
||||||
MoveModul MOVE = new MoveModul();
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package io.github.skippyall.minions.program.module;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.program.block.CodeBlock;
|
|
||||||
import io.github.skippyall.minions.program.block.CodeBlocks;
|
|
||||||
import io.github.skippyall.minions.program.block.ForwardBlock;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import net.minecraft.world.item.Item;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.item.Items;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class MoveModul extends Modul{
|
|
||||||
MoveModul() {
|
|
||||||
super("Movement");
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<CodeBlock> getCodeBlocks() {
|
|
||||||
List<CodeBlock> codeBlocks = new ArrayList<>();
|
|
||||||
codeBlocks.add(CodeBlocks.FORWARD);
|
|
||||||
return codeBlocks;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Item getPolymerItem(ItemStack itemStack, @Nullable ServerPlayer player) {
|
|
||||||
return Items.PURPLE_GLAZED_TERRACOTTA;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
package io.github.skippyall.minions.program.variables;
|
|
||||||
|
|
||||||
public class IntegerType extends Type{
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
package io.github.skippyall.minions.program.variables;
|
|
||||||
|
|
||||||
public abstract class Type {
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package io.github.skippyall.minions.program.variables;
|
|
||||||
|
|
||||||
public class Types {
|
|
||||||
public static final IntegerType INTEGER = new IntegerType();
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
package io.github.skippyall.minions.server;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.networking.ClientToServerNetworking;
|
|
||||||
import io.github.skippyall.minions.networking.VersionChecker;
|
|
||||||
import net.fabricmc.api.DedicatedServerModInitializer;
|
|
||||||
import net.fabricmc.fabric.api.networking.v1.ServerConfigurationConnectionEvents;
|
|
||||||
import net.fabricmc.fabric.api.networking.v1.ServerConfigurationNetworking;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.server.network.ServerConfigurationPacketListenerImpl;
|
|
||||||
|
|
||||||
public class MinionsServer implements DedicatedServerModInitializer {
|
|
||||||
@Override
|
|
||||||
public void onInitializeServer() {
|
|
||||||
ServerConfigurationNetworking.registerGlobalReceiver(ClientToServerNetworking.RL, ClientToServerNetworking::receive);
|
|
||||||
ServerConfigurationConnectionEvents.CONFIGURE.register(new ServerConfigurationConnectionEvents.Configure() {
|
|
||||||
@Override
|
|
||||||
public void onSendConfiguration(ServerConfigurationPacketListenerImpl handler, MinecraftServer server) {
|
|
||||||
VersionChecker.resetPlayer(handler.getOwner().getId());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package io.github.skippyall.minions;
|
||||||
|
|
||||||
|
import eu.pb4.polymer.core.api.item.PolymerItemGroupUtils;
|
||||||
|
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemGroup;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MinionCreativeTab {
|
||||||
|
public static ItemGroup group;
|
||||||
|
|
||||||
|
private static final List<ItemStack> items = new ArrayList<>();
|
||||||
|
|
||||||
|
public static void add(Item entry) {
|
||||||
|
items.add(entry.getDefaultStack());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void collectEntries(ItemGroup.DisplayContext displayContext, ItemGroup.Entries entries) {
|
||||||
|
entries.addAll(items);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerGroup() {
|
||||||
|
group = FabricItemGroup.builder()
|
||||||
|
.displayName(Text.translatable("minions.generic.mod_name"))
|
||||||
|
.icon(MinionItems.MINION_ITEM::getDefaultStack)
|
||||||
|
.entries(MinionCreativeTab::collectEntries)
|
||||||
|
.build();
|
||||||
|
PolymerItemGroupUtils.registerPolymerItemGroup(Identifier.of(Minions.MOD_ID, "main"), group);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package io.github.skippyall.minions;
|
||||||
|
|
||||||
|
import eu.pb4.polymer.core.api.item.SimplePolymerItem;
|
||||||
|
import io.github.skippyall.minions.minion.MinionItem;
|
||||||
|
import io.github.skippyall.minions.module.Modules;
|
||||||
|
import net.minecraft.component.DataComponentTypes;
|
||||||
|
import net.minecraft.component.type.DamageResistantComponent;
|
||||||
|
import net.minecraft.entity.damage.DamageType;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.registry.Registries;
|
||||||
|
import net.minecraft.registry.Registry;
|
||||||
|
import net.minecraft.registry.RegistryKey;
|
||||||
|
import net.minecraft.registry.RegistryKeys;
|
||||||
|
import net.minecraft.registry.tag.TagKey;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import static io.github.skippyall.minions.Minions.MOD_ID;
|
||||||
|
|
||||||
|
public class MinionItems {
|
||||||
|
public static final TagKey<DamageType> MINION_ITEM_RESISTS = TagKey.of(RegistryKeys.DAMAGE_TYPE, Identifier.of(MOD_ID, "minion_item_resists"));
|
||||||
|
public static final MinionItem MINION_ITEM = registerItem(Identifier.of(MOD_ID, "minion"), settings -> new MinionItem(settings.component(DataComponentTypes.DAMAGE_RESISTANT, new DamageResistantComponent(MINION_ITEM_RESISTS))));
|
||||||
|
public static final SimplePolymerItem BASIC_UPGRADE_BASE = registerItem(Identifier.of(MOD_ID, "basic_upgrade_base"), settings -> new SimplePolymerItem(settings, Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE));
|
||||||
|
public static final SimplePolymerItem ADVANCED_UPGRADE_BASE = registerItem(Identifier.of(MOD_ID, "advanced_upgrade_base"), settings -> new SimplePolymerItem(settings, Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE));
|
||||||
|
|
||||||
|
|
||||||
|
public static <T extends Item> T registerItem(Identifier identifier, Function<Item.Settings, T> constructor, Item.Settings settings) {
|
||||||
|
T item = constructor.apply(settings.registryKey(RegistryKey.of(RegistryKeys.ITEM, identifier)));
|
||||||
|
|
||||||
|
MinionCreativeTab.add(item);
|
||||||
|
|
||||||
|
return Registry.register(Registries.ITEM, identifier, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends Item> T registerItem(Identifier identifier, Function<Item.Settings, T> constructor) {
|
||||||
|
return registerItem(identifier, constructor, new Item.Settings());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void register() {
|
||||||
|
Modules.register();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,21 +1,39 @@
|
|||||||
package io.github.skippyall.minions;
|
package io.github.skippyall.minions;
|
||||||
|
|
||||||
import eu.pb4.polymer.core.api.entity.PolymerEntityUtils;
|
import eu.pb4.polymer.core.api.entity.PolymerEntityUtils;
|
||||||
import io.github.skippyall.minions.minion.MinionItem;
|
import io.github.skippyall.minions.command.MinionsCommand;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import io.github.skippyall.minions.minion.MinionData;
|
||||||
|
import io.github.skippyall.minions.minion.MinionPersistentState;
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
import net.minecraft.registry.Registries;
|
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||||
import net.minecraft.registry.Registry;
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class Minions implements ModInitializer {
|
public class Minions implements ModInitializer {
|
||||||
public static final String MOD_ID = "minions";
|
public static final String MOD_ID = "minions";
|
||||||
public static final MinionItem MINION_ITEM = Registry.register(Registries.ITEM, new Identifier(MOD_ID, "minion"), new MinionItem());
|
|
||||||
|
|
||||||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
|
MinionData.register();
|
||||||
PolymerEntityUtils.registerType();
|
PolymerEntityUtils.registerType();
|
||||||
|
ServerLifecycleEvents.SERVER_STARTED.register(server -> {
|
||||||
|
MinionPersistentState.create(server);
|
||||||
|
MinionPersistentState.INSTANCE.getMinionData().forEach((uuid, data) -> {
|
||||||
|
if(data.isSpawned()) {
|
||||||
|
MinionFakePlayer.spawnMinion(data, server.getOverworld(), null, null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
CommandRegistrationCallback.EVENT.register((commandDispatcher, commandRegistryAccess, registrationEnvironment) -> {
|
||||||
|
MinionsCommand.register(commandDispatcher);
|
||||||
|
});
|
||||||
|
|
||||||
|
MinionItems.register();
|
||||||
|
MinionCreativeTab.registerGroup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package io.github.skippyall.minions;
|
||||||
|
|
||||||
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MinionsTickExecutor {
|
||||||
|
private static final List<Runnable> executeOnNextTick = Collections.synchronizedList(new ArrayList<>());
|
||||||
|
|
||||||
|
public static void register() {
|
||||||
|
ServerTickEvents.START_SERVER_TICK.register(server -> {
|
||||||
|
synchronized (executeOnNextTick) {
|
||||||
|
for (Runnable run:executeOnNextTick) {
|
||||||
|
run.run();
|
||||||
|
}
|
||||||
|
executeOnNextTick.clear();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addExecuteOnNextTick(Runnable run) {
|
||||||
|
executeOnNextTick.add(run);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package io.github.skippyall.minions.client;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.networking.ClientToServerNetworking;
|
|
||||||
import net.fabricmc.api.ClientModInitializer;
|
|
||||||
import net.fabricmc.fabric.api.client.networking.v1.ClientConfigurationConnectionEvents;
|
|
||||||
import net.fabricmc.fabric.api.client.networking.v1.ClientLoginConnectionEvents;
|
|
||||||
|
|
||||||
public class MinionsClient implements ClientModInitializer {
|
|
||||||
/**
|
|
||||||
* Runs the mod initializer on the client environment.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void onInitializeClient() {
|
|
||||||
ClientConfigurationConnectionEvents.INIT.register(ClientToServerNetworking::onConfigurationInit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package io.github.skippyall.minions.command;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Message;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandExceptionType;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||||
|
import com.mojang.brigadier.suggestion.SuggestionProvider;
|
||||||
|
import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
|
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||||
|
import io.github.skippyall.minions.minion.MinionData;
|
||||||
|
import io.github.skippyall.minions.minion.MinionPersistentState;
|
||||||
|
import io.github.skippyall.minions.minion.MinionProfileUtils;
|
||||||
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
public class MinionArgument {
|
||||||
|
public static final SimpleCommandExceptionType MINION_NOT_PRESENT = new SimpleCommandExceptionType(Text.translatable("minions.command.minion.not_present"));
|
||||||
|
|
||||||
|
public static final MinionSuggestionProvider SUGGESTION_PROVIDER = new MinionSuggestionProvider();
|
||||||
|
|
||||||
|
public static MinionData parse(String argument) throws CommandSyntaxException {
|
||||||
|
Optional<MinionData> data = Optional.empty();
|
||||||
|
if(argument.startsWith(MinionProfileUtils.PREFIX)) {
|
||||||
|
data = MinionPersistentState.INSTANCE.getMinionWithName(argument);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
data = Optional.ofNullable(MinionPersistentState.INSTANCE.getMinionData(UUID.fromString(argument)));
|
||||||
|
} catch (IllegalArgumentException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(data.isEmpty()) {
|
||||||
|
throw MINION_NOT_PRESENT.create();
|
||||||
|
}
|
||||||
|
return data.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class MinionSuggestionProvider implements SuggestionProvider<ServerCommandSource> {
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Suggestions> getSuggestions(CommandContext<ServerCommandSource> context, SuggestionsBuilder builder) throws CommandSyntaxException {
|
||||||
|
for (MinionData data : MinionPersistentState.INSTANCE.getMinionDataList()) {
|
||||||
|
builder.suggest(data.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.buildFuture();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package io.github.skippyall.minions.command;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
|
|
||||||
|
import static net.minecraft.server.command.CommandManager.literal;
|
||||||
|
|
||||||
|
public class MinionsCommand {
|
||||||
|
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
||||||
|
dispatcher.register(
|
||||||
|
literal("minions")
|
||||||
|
.then(SpawnSubcommand.SPAWN)
|
||||||
|
.then(MobCapDebugSubcommand.MOB_CAP_DEBUG)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package io.github.skippyall.minions.command;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import io.github.skippyall.minions.mixinhelper.ChunkLevelManager$DistanceFromNearestPlayerTrackerAccessor;
|
||||||
|
import io.github.skippyall.minions.mixinhelper.ChunkLevelManagerAccessor;
|
||||||
|
import io.github.skippyall.minions.mixins.antimobcap.ServerChunkManagerAccessor;
|
||||||
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
|
import net.minecraft.server.world.ChunkTicketManager;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
import static net.minecraft.server.command.CommandManager.literal;
|
||||||
|
|
||||||
|
public class MobCapDebugSubcommand {
|
||||||
|
public static final LiteralArgumentBuilder<ServerCommandSource> MOB_CAP_DEBUG = literal("mobcapdebug")
|
||||||
|
.executes(MobCapDebugSubcommand::mobcapdebugCommand);
|
||||||
|
|
||||||
|
public static int mobcapdebugCommand(CommandContext<ServerCommandSource> context) {
|
||||||
|
ChunkTicketManager ticketManager = ((ServerChunkManagerAccessor)context.getSource().getWorld().getChunkManager()).getTicketManager();
|
||||||
|
int tickedChunkCount = ((ChunkLevelManager$DistanceFromNearestPlayerTrackerAccessor)((ChunkLevelManagerAccessor)ticketManager).minions$getMinionless()).minions$getTickedChunkCount();
|
||||||
|
context.getSource().sendFeedback(() -> Text.of(String.valueOf(tickedChunkCount)), false);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package io.github.skippyall.minions.command;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.arguments.BoolArgumentType;
|
||||||
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import io.github.skippyall.minions.minion.MinionData;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import net.minecraft.command.argument.PosArgument;
|
||||||
|
import net.minecraft.command.argument.Vec3ArgumentType;
|
||||||
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
|
|
||||||
|
import static net.minecraft.server.command.CommandManager.argument;
|
||||||
|
import static net.minecraft.server.command.CommandManager.literal;
|
||||||
|
|
||||||
|
public class SpawnSubcommand {
|
||||||
|
public static final LiteralArgumentBuilder<ServerCommandSource> SPAWN = literal("spawn")
|
||||||
|
.then(argument("minion", StringArgumentType.word())
|
||||||
|
.suggests(MinionArgument.SUGGESTION_PROVIDER)
|
||||||
|
.then(argument("pos", Vec3ArgumentType.vec3()))
|
||||||
|
.executes(context ->
|
||||||
|
spawnCommand(
|
||||||
|
context.getSource(),
|
||||||
|
StringArgumentType.getString(context, "minion"),
|
||||||
|
Vec3ArgumentType.getPosArgument(context, "pos"),
|
||||||
|
false
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
.then(argument("force", BoolArgumentType.bool())
|
||||||
|
.executes(context ->
|
||||||
|
spawnCommand(
|
||||||
|
context.getSource(),
|
||||||
|
StringArgumentType.getString(context, "minion"),
|
||||||
|
Vec3ArgumentType.getPosArgument(context, "pos"),
|
||||||
|
BoolArgumentType.getBool(context, "force")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
public static int spawnCommand(ServerCommandSource source, String minion, PosArgument pos, boolean force) throws CommandSyntaxException {
|
||||||
|
MinionData data = MinionArgument.parse(minion);
|
||||||
|
MinionFakePlayer.spawnMinion(data, source.getWorld(), pos.getPos(source), pos.getRotation(source), force);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package io.github.skippyall.minions.fakeplayer;
|
|
||||||
|
|
||||||
import io.netty.channel.Channel;
|
|
||||||
|
|
||||||
public interface ClientConnectionInterface {
|
|
||||||
void setChannel(Channel channel);
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package io.github.skippyall.minions.fakeplayer;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.fakeplayer.EntityPlayerActionPack;
|
|
||||||
|
|
||||||
public interface ServerPlayerInterface
|
|
||||||
{
|
|
||||||
EntityPlayerActionPack getActionPack();
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package io.github.skippyall.minions.gui;
|
||||||
|
|
||||||
|
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||||
|
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||||
|
import io.github.skippyall.minions.module.command.Command;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import io.github.skippyall.minions.module.ModuleItem;
|
||||||
|
import net.minecraft.screen.ScreenHandlerType;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CommandsGui {
|
||||||
|
public static void openServerModuleCommandGui(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||||
|
List<ModuleItem> modules = minion.getModuleInventory().getModuleItems();
|
||||||
|
|
||||||
|
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X3, player, false);
|
||||||
|
|
||||||
|
gui.setTitle(Text.translatable("minions.gui.module_commands.title"));
|
||||||
|
|
||||||
|
for (int i = 0; i < modules.size(); i++) {
|
||||||
|
ModuleItem module = modules.get(i);
|
||||||
|
gui.setSlot(i, new GuiElementBuilder()
|
||||||
|
.setItem(module.asItem())
|
||||||
|
.setCallback(() -> openServerCommandGui(player, minion, module))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
gui.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void openServerCommandGui(ServerPlayerEntity player, MinionFakePlayer minion, ModuleItem module) {
|
||||||
|
List<Command> commands = module.getCommands();
|
||||||
|
|
||||||
|
SimpleGui commandGui = new SimpleGui(ScreenHandlerType.GENERIC_9X3, player, false);
|
||||||
|
|
||||||
|
commandGui.setTitle(Text.translatable("minions.gui.commands.title", module.asItem().getName()));
|
||||||
|
|
||||||
|
for(int j = 0; j < commands.size(); j++) {
|
||||||
|
Command command = commands.get(j);
|
||||||
|
commandGui.setSlot(j, new GuiElementBuilder()
|
||||||
|
.setItem(command.getItemRepresentation())
|
||||||
|
.setName(command.getName())
|
||||||
|
.addLoreLine(command.getDescription())
|
||||||
|
.setCallback(() -> command.execute(player, minion))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
commandGui.open();
|
||||||
|
}
|
||||||
|
}
|
||||||
+27
-21
@@ -1,59 +1,65 @@
|
|||||||
package io.github.skippyall.minions.minion;
|
package io.github.skippyall.minions.gui;
|
||||||
|
|
||||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||||
import eu.pb4.sgui.api.gui.SimpleGui;
|
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||||
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
import net.minecraft.screen.GenericContainerScreenHandler;
|
|
||||||
import net.minecraft.screen.ScreenHandlerType;
|
import net.minecraft.screen.ScreenHandlerType;
|
||||||
import net.minecraft.screen.SimpleNamedScreenHandlerFactory;
|
|
||||||
import net.minecraft.screen.slot.Slot;
|
import net.minecraft.screen.slot.Slot;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
public class MinionInventory {
|
public class MinionGui {
|
||||||
public static void openInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
public static void openInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||||
openServerSideInventory(player, minion);
|
openServerSideInventory(player, minion);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void openServerSideInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
public static void openServerSideInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||||
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_3X3, player, false);
|
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_3X3, player, false);
|
||||||
gui.setTitle(Text.literal("Minion"));
|
gui.setTitle(minion.getName());
|
||||||
gui.setSlot(4, new GuiElementBuilder()
|
|
||||||
.setItem(Items.REDSTONE)
|
gui.setSlot(1, new GuiElementBuilder()
|
||||||
.setName(Text.literal("Programming"))
|
.setItem(Items.COMMAND_BLOCK)
|
||||||
.setCallback((i, clickType, clickType1) -> {
|
.setName(Text.translatable("minions.gui.main.commands"))
|
||||||
openProgrammingInventory(player, minion);
|
.setCallback((i, clickType, slotActionType) -> {
|
||||||
|
openCommandsGui(player, minion);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
gui.setSlot(3, new GuiElementBuilder()
|
gui.setSlot(3, new GuiElementBuilder()
|
||||||
.setItem(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE)
|
.setItem(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE)
|
||||||
.setName(Text.literal("Modules and Detectors"))
|
.setName(Text.translatable("minions.gui.main.modules"))
|
||||||
.setCallback((i, clickType, clickType1) -> {
|
.setCallback(() -> {
|
||||||
openModuleInventory(player, minion);
|
ModuleInventory.openModuleInventory(player, minion);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
gui.setSlot(5, new GuiElementBuilder()
|
gui.setSlot(5, new GuiElementBuilder()
|
||||||
.setItem(Items.CHEST)
|
.setItem(Items.CHEST)
|
||||||
.setName(Text.literal("Inventory"))
|
.setName(Text.translatable("minions.gui.main.inventory"))
|
||||||
.setCallback((i, clickType, clickType1) -> {
|
.setCallback(() -> {
|
||||||
openMinionInventory(player, minion);
|
openMinionInventory(player, minion);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
gui.setSlot(7, new GuiElementBuilder()
|
||||||
|
.setItem(Items.BARRIER)
|
||||||
|
.setName(Text.translatable("minions.gui.main.pickup"))
|
||||||
|
.setCallback(() -> {
|
||||||
|
minion.kill(minion.getServerWorld());
|
||||||
|
})
|
||||||
|
);
|
||||||
gui.open();
|
gui.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void openCommandsGui(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||||
|
CommandsGui.openServerModuleCommandGui(player, minion);
|
||||||
|
}
|
||||||
|
|
||||||
public static void openProgrammingInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
public static void openProgrammingInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void openModuleInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
|
||||||
player.openHandledScreen(new SimpleNamedScreenHandlerFactory((syncId, playerInventory, player2) -> GenericContainerScreenHandler.createGeneric9x3(syncId, playerInventory, minion.getModuleInventory()), Text.literal("")));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void openMinionInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
public static void openMinionInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||||
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X5, player, false);
|
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X5, player, false);
|
||||||
gui.setTitle(Text.literal("Minion"));
|
gui.setTitle(Text.translatable("minions.gui.inventory.title", minion.getName()));
|
||||||
for (int i = 0; i < minion.getInventory().size(); i++) {
|
for (int i = 0; i < minion.getInventory().size(); i++) {
|
||||||
gui.setSlotRedirect(i, new Slot(minion.getInventory(), i, 0, 0));
|
gui.setSlotRedirect(i, new Slot(minion.getInventory(), i, 0, 0));
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
package io.github.skippyall.minions.gui;
|
||||||
|
|
||||||
|
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||||
|
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||||
|
import io.github.skippyall.minions.input.TextInput;
|
||||||
|
import io.github.skippyall.minions.minion.MinionData;
|
||||||
|
import io.github.skippyall.minions.minion.MinionItem;
|
||||||
|
import io.github.skippyall.minions.minion.MinionProfileUtils;
|
||||||
|
import io.github.skippyall.minions.minion.skin.SkinProvider;
|
||||||
|
import io.github.skippyall.minions.minion.skin.SkinProviders;
|
||||||
|
import net.minecraft.component.DataComponentTypes;
|
||||||
|
import net.minecraft.component.type.ProfileComponent;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.screen.ScreenHandlerType;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class MinionLookGui extends SimpleGui {
|
||||||
|
private ItemStack minionItem;
|
||||||
|
private SkinProvider currentSkinProvider;
|
||||||
|
|
||||||
|
public MinionLookGui(ServerPlayerEntity player, ItemStack minionItem) {
|
||||||
|
super(ScreenHandlerType.GENERIC_9X3, player, false);
|
||||||
|
this.minionItem = minionItem;
|
||||||
|
this.currentSkinProvider = SkinProviders.NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update() {
|
||||||
|
updateName();
|
||||||
|
updateSkin();
|
||||||
|
updateSkinProvider();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateName() {
|
||||||
|
setSlot(10, new GuiElementBuilder()
|
||||||
|
.setItem(Items.OAK_SIGN)
|
||||||
|
.setName(Text.literal(getData().name()))
|
||||||
|
.setCallback(() -> {
|
||||||
|
openRenameGui(player, minionItem);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateSkin() {
|
||||||
|
GuiElementBuilder builder = new GuiElementBuilder()
|
||||||
|
.setItem(Items.PLAYER_HEAD)
|
||||||
|
.setCallback(() -> currentSkinProvider.openSkinMenu(player).thenAccept(skin -> {
|
||||||
|
MinionItem.setData(getData().withSkin(skin), minionItem);
|
||||||
|
}));
|
||||||
|
if(MinionItem.getData(minionItem) != null && MinionItem.getData(minionItem).skin().isPresent()) {
|
||||||
|
builder.setComponent(DataComponentTypes.PROFILE, new ProfileComponent(Optional.empty(), Optional.empty(), getData().skin().get()));
|
||||||
|
}
|
||||||
|
setSlot(16, builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cycleSkinProvider() {
|
||||||
|
int currentId = SkinProviders.SKIN_PROVIDERS.getRawId(currentSkinProvider);
|
||||||
|
currentId++;
|
||||||
|
if(SkinProviders.SKIN_PROVIDERS.size() == currentId) {
|
||||||
|
currentId = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentSkinProvider = SkinProviders.SKIN_PROVIDERS.get(currentId);
|
||||||
|
updateSkinProvider();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateSkinProvider() {
|
||||||
|
setSlot(25, new GuiElementBuilder()
|
||||||
|
.setItem(Items.GREEN_STAINED_GLASS_PANE)
|
||||||
|
.setComponent(DataComponentTypes.CUSTOM_NAME, currentSkinProvider.getDisplayName())
|
||||||
|
.setCallback(this::cycleSkinProvider)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private MinionData getData() {
|
||||||
|
return MinionItem.getDataOrDefault(minionItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void open(ServerPlayerEntity player, ItemStack minionItem) {
|
||||||
|
MinionLookGui gui = new MinionLookGui(player, minionItem);
|
||||||
|
gui.update();
|
||||||
|
gui.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void openRenameGui(ServerPlayerEntity player, ItemStack minionItem) {
|
||||||
|
TextInput.inputSync(player, Text.translatable("minions.gui.look.rename.title"), "Minion", MinionProfileUtils::checkMinionNameWithoutPrefix)
|
||||||
|
.thenAccept(name -> {
|
||||||
|
MinionItem.setData(getData().withName(MinionProfileUtils.PREFIX + name), minionItem);
|
||||||
|
open();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
package io.github.skippyall.minions.gui;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.module.command.Command;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import io.github.skippyall.minions.module.ModuleItem;
|
||||||
|
import io.github.skippyall.minions.program.block.CodeBlock;
|
||||||
|
import net.fabricmc.fabric.impl.transfer.item.ComposterWrapper;
|
||||||
|
import net.fabricmc.fabric.mixin.transfer.JukeboxBlockEntityMixin;
|
||||||
|
import net.minecraft.block.ComposterBlock;
|
||||||
|
import net.minecraft.inventory.Inventories;
|
||||||
|
import net.minecraft.inventory.SimpleInventory;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NbtCompound;
|
||||||
|
import net.minecraft.registry.RegistryWrapper;
|
||||||
|
import net.minecraft.screen.SimpleNamedScreenHandlerFactory;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class ModuleInventory extends SimpleInventory {
|
||||||
|
private final Set<ModuleItem> modules = new HashSet<>();
|
||||||
|
public ModuleInventory() {
|
||||||
|
super(27);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void openModuleInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||||
|
player.openHandledScreen(new SimpleNamedScreenHandlerFactory((syncId, playerInventory, player2) -> new ModuleInventoryScreenHandler(syncId, playerInventory, minion.getModuleInventory()), Text.translatable("minions.gui.modules.title", minion.getName())));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxCountPerStack() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValid(int slot, ItemStack stack) {
|
||||||
|
return (stack.getCount() <= getMaxCountPerStack()) && stack.getItem() instanceof ModuleItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void markDirty() {
|
||||||
|
super.markDirty();
|
||||||
|
updateModules();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateModules() {
|
||||||
|
modules.clear();
|
||||||
|
for (ItemStack heldStack : heldStacks) {
|
||||||
|
if(heldStack.getItem() instanceof ModuleItem moduleItem) {
|
||||||
|
modules.add(moduleItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup lookup) {
|
||||||
|
Inventories.readNbt(nbt, heldStacks, lookup);
|
||||||
|
updateModules();
|
||||||
|
}
|
||||||
|
|
||||||
|
public NbtCompound writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup lookup) {
|
||||||
|
return Inventories.writeNbt(nbt, heldStacks, lookup);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasModule(ModuleItem module) {
|
||||||
|
return modules.contains(module);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<ModuleItem> getModuleItems() {
|
||||||
|
return modules;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Command> getAllCommands() {
|
||||||
|
ArrayList<Command> commands = new ArrayList<>();
|
||||||
|
for(ItemStack stack : heldStacks) {
|
||||||
|
if(stack.getItem() instanceof ModuleItem module) {
|
||||||
|
commands.addAll(module.getCommands());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return commands;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CodeBlock<?,?>> getAllCodeBlocks() {
|
||||||
|
ArrayList<CodeBlock<?,?>> commands = new ArrayList<>();
|
||||||
|
for(ItemStack stack : heldStacks) {
|
||||||
|
if(stack.getItem() instanceof ModuleItem module) {
|
||||||
|
commands.addAll(module.getCodeBlocks());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return commands;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package io.github.skippyall.minions.gui;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.entity.player.PlayerInventory;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.screen.GenericContainerScreenHandler;
|
||||||
|
import net.minecraft.screen.ScreenHandler;
|
||||||
|
import net.minecraft.screen.ScreenHandlerType;
|
||||||
|
import net.minecraft.screen.slot.Slot;
|
||||||
|
|
||||||
|
public class ModuleInventoryScreenHandler extends ScreenHandler {
|
||||||
|
private final int rows = 3;
|
||||||
|
private final ModuleInventory inventory;
|
||||||
|
public ModuleInventoryScreenHandler(int syncId, ModuleInventory inventory) {
|
||||||
|
super(ScreenHandlerType.GENERIC_9X3, syncId);
|
||||||
|
this.inventory = inventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ModuleInventoryScreenHandler(int syncId, PlayerInventory playerInventory, ModuleInventory inventory) {
|
||||||
|
super(ScreenHandlerType.GENERIC_9X3, syncId);
|
||||||
|
int k;
|
||||||
|
int j;
|
||||||
|
GenericContainerScreenHandler.checkSize(inventory, 3 * 9);
|
||||||
|
this.inventory = inventory;
|
||||||
|
inventory.onOpen(playerInventory.player);
|
||||||
|
int i = (rows - 4) * 18;
|
||||||
|
for (j = 0; j < rows; ++j) {
|
||||||
|
for (k = 0; k < 9; ++k) {
|
||||||
|
this.addSlot(new Slot(inventory, k + j * 9, 8 + k * 18, 18 + j * 18) {
|
||||||
|
@Override
|
||||||
|
public boolean canInsert(ItemStack stack) {
|
||||||
|
return super.canInsert(stack) && inventory.isValid(getIndex(), stack);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (j = 0; j < 3; ++j) {
|
||||||
|
for (k = 0; k < 9; ++k) {
|
||||||
|
this.addSlot(new Slot(playerInventory, k + j * 9 + 9, 8 + k * 18, 103 + j * 18 + i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (j = 0; j < 9; ++j) {
|
||||||
|
this.addSlot(new Slot(playerInventory, j, 8 + j * 18, 161 + i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canUse(PlayerEntity player) {
|
||||||
|
return this.inventory.canPlayerUse(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack quickMove(PlayerEntity player, int slot) {
|
||||||
|
ItemStack itemStack = ItemStack.EMPTY;
|
||||||
|
Slot slot2 = this.slots.get(slot);
|
||||||
|
if (slot2 != null && slot2.hasStack()) {
|
||||||
|
ItemStack itemStack2 = slot2.getStack();
|
||||||
|
itemStack = itemStack2.copy();
|
||||||
|
if (slot < this.rows * 9 ? !this.insertItem(itemStack2, this.rows * 9, this.slots.size(), true) : !this.insertItem(itemStack2, 0, this.rows * 9, false)) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
if (itemStack2.isEmpty()) {
|
||||||
|
slot2.setStack(ItemStack.EMPTY);
|
||||||
|
} else {
|
||||||
|
slot2.markDirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return itemStack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClosed(PlayerEntity player) {
|
||||||
|
super.onClosed(player);
|
||||||
|
this.inventory.onClose(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ModuleInventory getInventory() {
|
||||||
|
return inventory;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
package io.github.skippyall.minions.input;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public interface Result<T, E> {
|
||||||
|
static <T> Result<T, String> wrap(UnsafeOperation<T> toWrap) {
|
||||||
|
return wrapCustomError(toWrap, Exception::getMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
static <T, E> Result<T, E> wrapCustomError(UnsafeOperation<T> toWrap, E error) {
|
||||||
|
return wrapCustomError(toWrap, e -> error);
|
||||||
|
}
|
||||||
|
|
||||||
|
static <T, E> Result<T, E> wrapCustomError(UnsafeOperation<T> toWrap, Function<Exception, E> errorTransformer) {
|
||||||
|
try {
|
||||||
|
return new Result.Success<>(toWrap.run());
|
||||||
|
} catch (Exception e) {
|
||||||
|
return new Result.Error<>(errorTransformer.apply(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isSuccess();
|
||||||
|
|
||||||
|
@NotNull T getOrDefault(@NotNull T defaultValue);
|
||||||
|
|
||||||
|
@NotNull T getOrThrow();
|
||||||
|
|
||||||
|
@NotNull E getErrorOrThrow();
|
||||||
|
|
||||||
|
@NotNull Optional<T> getOptional();
|
||||||
|
|
||||||
|
void ifSuccess(@NotNull Consumer<T> handler);
|
||||||
|
|
||||||
|
void ifError(@NotNull Consumer<Error<T, E>> handler);
|
||||||
|
|
||||||
|
record Success<T, E>(@NotNull T result) implements Result<T, E> {
|
||||||
|
@Override
|
||||||
|
public boolean isSuccess() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull T getOrDefault(@NotNull T defaultValue) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull T getOrThrow() {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull E getErrorOrThrow() {
|
||||||
|
throw new RuntimeException("Result was not an Error");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Optional<T> getOptional() {
|
||||||
|
return Optional.of(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void ifSuccess(@NotNull Consumer<T> handler) {
|
||||||
|
handler.accept(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void ifError(@NotNull Consumer<Error<T, E>> handler) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
record Error<T, E>(@NotNull E message) implements Result<T, E> {
|
||||||
|
@Override
|
||||||
|
public boolean isSuccess() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull T getOrDefault(@NotNull T defaultValue) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull T getOrThrow() {
|
||||||
|
throw new RuntimeException("Result was an error: " + message.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull E getErrorOrThrow() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Optional<T> getOptional() {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void ifSuccess(@NotNull Consumer<T> handler) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void ifError(Consumer<Error<T, E>> handler) {
|
||||||
|
handler.accept(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface UnsafeOperation<T> {
|
||||||
|
T run() throws Exception;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
package io.github.skippyall.minions.input;
|
||||||
|
|
||||||
|
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||||
|
import eu.pb4.sgui.api.gui.AnvilInputGui;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.screen.AnvilScreenHandler;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
public class TextInput<T> extends AnvilInputGui {
|
||||||
|
private final GuiElementBuilder valid = new GuiElementBuilder()
|
||||||
|
.setItem(Items.EMERALD_BLOCK)
|
||||||
|
.setName(Text.literal("OK"))
|
||||||
|
.setCallback(this::onConfirm);
|
||||||
|
|
||||||
|
private final GuiElementBuilder invalid = new GuiElementBuilder()
|
||||||
|
.setItem(Items.REDSTONE_BLOCK);
|
||||||
|
private final Function<String, CompletableFuture<Result<T, Text>>> parser;
|
||||||
|
private final CompletableFuture<T> future;
|
||||||
|
private Result<T, Text> result;
|
||||||
|
|
||||||
|
public TextInput(ServerPlayerEntity player, Text title, String defaultValue, Function<String, CompletableFuture<Result<T, Text>>> parser, CompletableFuture<T> future) {
|
||||||
|
super(player, false);
|
||||||
|
setTitle(title);
|
||||||
|
setDefaultInputValue(defaultValue);
|
||||||
|
this.parser = parser;
|
||||||
|
this.future = future;
|
||||||
|
|
||||||
|
updateConfirmButton(defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> CompletableFuture<T> inputSync(ServerPlayerEntity player, Text title, String defaultValue, Function<String, Result<T, Text>> parser) {
|
||||||
|
return input(player, title, defaultValue, (String string) -> CompletableFuture.completedFuture(parser.apply(string)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> CompletableFuture<T> input(ServerPlayerEntity player, Text title, String defaultValue, Function<String, CompletableFuture<Result<T, Text>>> parser) {
|
||||||
|
CompletableFuture<T> future = new CompletableFuture<>();
|
||||||
|
new TextInput<>(player, title, defaultValue, parser, future).open();
|
||||||
|
return future;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CompletableFuture<String> inputString(ServerPlayerEntity player, Text title, String defaultValue) {
|
||||||
|
return inputSync(player, title, defaultValue, Result.Success::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CompletableFuture<Integer> inputInt(ServerPlayerEntity player, Text title, String defaultValue) {
|
||||||
|
return inputSync(player, title, defaultValue, string -> Result.wrapCustomError(() -> Integer.valueOf(string), Text.translatable("minions.command.input.int.fail")));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CompletableFuture<Float> inputFloat(ServerPlayerEntity player, Text title, String defaultValue) {
|
||||||
|
return inputSync(player, title, defaultValue, string -> Result.wrapCustomError(() -> Float.valueOf(string), Text.translatable("minions.command.input.float.fail")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInput(String input) {
|
||||||
|
updateConfirmButton(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateConfirmButton(String input) {
|
||||||
|
parser.apply(input).thenAccept(result -> {
|
||||||
|
this.result = result;
|
||||||
|
if(result.isSuccess()) {
|
||||||
|
setSlot(AnvilScreenHandler.OUTPUT_ID, valid);
|
||||||
|
} else {
|
||||||
|
Text text = result.getErrorOrThrow();
|
||||||
|
setSlot(AnvilScreenHandler.OUTPUT_ID, invalid.setName(text));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClose() {
|
||||||
|
if(!future.isDone()) {
|
||||||
|
future.cancel(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onConfirm() {
|
||||||
|
if(result != null) {
|
||||||
|
result.ifSuccess(success -> {
|
||||||
|
future.complete(success);
|
||||||
|
close();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,132 +0,0 @@
|
|||||||
package io.github.skippyall.minions.minion;
|
|
||||||
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.inventory.Inventories;
|
|
||||||
import net.minecraft.inventory.Inventory;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.util.collection.DefaultedList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A simple {@code Inventory} implementation with only default methods + an item list getter.
|
|
||||||
*
|
|
||||||
* Originally by Juuz
|
|
||||||
*/
|
|
||||||
public interface ImplementedInventory extends Inventory {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the item list of this inventory.
|
|
||||||
* Must return the same instance every time it's called.
|
|
||||||
*/
|
|
||||||
DefaultedList<ItemStack> getItems();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an inventory from the item list.
|
|
||||||
*/
|
|
||||||
static ImplementedInventory of(DefaultedList<ItemStack> items) {
|
|
||||||
return () -> items;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new inventory with the specified size.
|
|
||||||
*/
|
|
||||||
static ImplementedInventory ofSize(int size) {
|
|
||||||
return of(DefaultedList.ofSize(size, ItemStack.EMPTY));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the inventory size.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
default int size() {
|
|
||||||
return getItems().size();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the inventory is empty.
|
|
||||||
* @return true if this inventory has only empty stacks, false otherwise.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
default boolean isEmpty() {
|
|
||||||
for (int i = 0; i < size(); i++) {
|
|
||||||
ItemStack stack = getStack(i);
|
|
||||||
if (!stack.isEmpty()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the item in the slot.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
default ItemStack getStack(int slot) {
|
|
||||||
return getItems().get(slot);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes items from an inventory slot.
|
|
||||||
* @param slot The slot to remove from.
|
|
||||||
* @param count How many items to remove. If there are less items in the slot than what are requested,
|
|
||||||
* takes all items in that slot.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
default ItemStack removeStack(int slot, int count) {
|
|
||||||
ItemStack result = Inventories.splitStack(getItems(), slot, count);
|
|
||||||
if (!result.isEmpty()) {
|
|
||||||
markDirty();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes all items from an inventory slot.
|
|
||||||
* @param slot The slot to remove from.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
default ItemStack removeStack(int slot) {
|
|
||||||
return Inventories.removeStack(getItems(), slot);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replaces the current stack in an inventory slot with the provided stack.
|
|
||||||
* @param slot The inventory slot of which to replace the itemstack.
|
|
||||||
* @param stack The replacing itemstack. If the stack is too big for
|
|
||||||
* this inventory ({@link Inventory#getMaxCountPerStack()}),
|
|
||||||
* it gets resized to this inventory's maximum amount.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
default void setStack(int slot, ItemStack stack) {
|
|
||||||
getItems().set(slot, stack);
|
|
||||||
if (stack.getCount() > stack.getMaxCount()) {
|
|
||||||
stack.setCount(stack.getMaxCount());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clears the inventory.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
default void clear() {
|
|
||||||
getItems().clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Marks the state as dirty.
|
|
||||||
* Must be called after changes in the inventory, so that the game can properly save
|
|
||||||
* the inventory contents and notify neighboring blocks of inventory changes.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
default void markDirty() {
|
|
||||||
// Override if you want behavior.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return true if the player can use the inventory, false otherwise.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
default boolean canPlayerUse(PlayerEntity player) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package io.github.skippyall.minions.minion;
|
||||||
|
|
||||||
|
import com.mojang.authlib.properties.PropertyMap;
|
||||||
|
import com.mojang.datafixers.util.Pair;
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
|
import eu.pb4.polymer.core.api.other.PolymerComponent;
|
||||||
|
import io.github.skippyall.minions.Minions;
|
||||||
|
import net.minecraft.component.ComponentType;
|
||||||
|
import net.minecraft.nbt.NbtCompound;
|
||||||
|
import net.minecraft.nbt.NbtOps;
|
||||||
|
import net.minecraft.registry.Registries;
|
||||||
|
import net.minecraft.registry.Registry;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.Uuids;
|
||||||
|
import net.minecraft.util.dynamic.Codecs;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public record MinionData(UUID uuid, String name, Optional<PropertyMap> skin, boolean isSpawned) {
|
||||||
|
public static final Codec<MinionData> CODEC = RecordCodecBuilder.create(instance ->
|
||||||
|
instance.group(
|
||||||
|
Uuids.CODEC.fieldOf("uuid").forGetter(MinionData::uuid),
|
||||||
|
Codec.STRING.fieldOf("name").forGetter(MinionData::name),
|
||||||
|
Codecs.GAME_PROFILE_PROPERTY_MAP.optionalFieldOf("skin").forGetter(MinionData::skin),
|
||||||
|
Codec.BOOL.optionalFieldOf("isSpawned", false).forGetter(MinionData::isSpawned)
|
||||||
|
).apply(instance, MinionData::new)
|
||||||
|
);
|
||||||
|
|
||||||
|
public static final ComponentType<UUID> COMPONENT = Registry.register(Registries.DATA_COMPONENT_TYPE, Identifier.of(Minions.MOD_ID, "minion_data"), ComponentType.<UUID>builder().codec(Uuids.CODEC).build());
|
||||||
|
|
||||||
|
public static MinionData createDefault() {
|
||||||
|
return new MinionData(UUID.randomUUID(), MinionProfileUtils.newDefaultMinionName(), Optional.empty(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MinionData withUuid(UUID uuid) {
|
||||||
|
return new MinionData(uuid, name, skin, isSpawned);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MinionData withName(String name) {
|
||||||
|
return new MinionData(uuid, name, skin, isSpawned);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MinionData withSkin(Optional<PropertyMap> skin) {
|
||||||
|
return new MinionData(uuid, name, skin, isSpawned);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MinionData withSpawned(boolean isSpawned) {
|
||||||
|
return new MinionData(uuid, name, skin, isSpawned);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NbtCompound writeNbt() {
|
||||||
|
return (NbtCompound) MinionData.CODEC.encode(this, NbtOps.INSTANCE, null).result().orElse(new NbtCompound());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MinionData readNbt(NbtCompound nbt) {
|
||||||
|
return MinionData.CODEC.decode(NbtOps.INSTANCE, nbt).resultOrPartial().map(Pair::getFirst).orElseGet(MinionData::createDefault);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void register() {
|
||||||
|
PolymerComponent.registerDataComponent(COMPONENT);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,49 +2,104 @@ package io.github.skippyall.minions.minion;
|
|||||||
|
|
||||||
import eu.pb4.polymer.core.api.item.PolymerItem;
|
import eu.pb4.polymer.core.api.item.PolymerItem;
|
||||||
import eu.pb4.polymer.core.api.item.PolymerItemUtils;
|
import eu.pb4.polymer.core.api.item.PolymerItemUtils;
|
||||||
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
import io.github.skippyall.minions.gui.MinionLookGui;
|
||||||
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
import net.minecraft.client.item.TooltipContext;
|
import net.minecraft.component.DataComponentTypes;
|
||||||
import net.minecraft.enchantment.Enchantments;
|
import net.minecraft.component.type.TooltipDisplayComponent;
|
||||||
import net.minecraft.item.*;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.nbt.NbtCompound;
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.item.ItemUsageContext;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.item.tooltip.TooltipType;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.text.PlainTextContent;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.text.TextContent;
|
|
||||||
import net.minecraft.util.ActionResult;
|
import net.minecraft.util.ActionResult;
|
||||||
|
import net.minecraft.util.Hand;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.math.Vec2f;
|
||||||
|
import net.minecraft.world.World;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import xyz.nucleoid.packettweaker.PacketContext;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class MinionItem extends Item implements PolymerItem {
|
public class MinionItem extends Item implements PolymerItem {
|
||||||
private boolean canProgram;
|
public MinionItem(Settings settings) {
|
||||||
public MinionItem(boolean canProgram) {
|
super(settings);
|
||||||
super(new FabricItemSettings());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Item getPolymerItem(ItemStack itemStack, @Nullable ServerPlayerEntity player) {
|
public @Nullable Identifier getPolymerItemModel(ItemStack stack, PacketContext context) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Item getPolymerItem(ItemStack itemStack, PacketContext player) {
|
||||||
return Items.ARMOR_STAND;
|
return Items.ARMOR_STAND;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getPolymerItemStack(ItemStack stack, TooltipContext flag, ServerPlayerEntity player) {
|
public ItemStack getPolymerItemStack(ItemStack stack, TooltipType tooltipType, PacketContext player) {
|
||||||
ItemStack out = PolymerItemUtils.createItemStack(stack, flag, player);
|
ItemStack out = PolymerItemUtils.createItemStack(stack, tooltipType, player);
|
||||||
out.addEnchantment(Enchantments.MENDING, 1);
|
out.set(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, true);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void appendTooltip(ItemStack stack, TooltipContext context, TooltipDisplayComponent component, Consumer<Text> tooltip, TooltipType type) {
|
||||||
|
MinionData data = getData(stack);
|
||||||
|
if(data != null) {
|
||||||
|
tooltip.accept(Text.translatable("minions.minion_item.tooltip", data.name()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResult use(World world, PlayerEntity user, Hand hand) {
|
||||||
|
if(user instanceof ServerPlayerEntity serverPlayer) {
|
||||||
|
ItemStack stack = user.getStackInHand(hand);
|
||||||
|
MinionLookGui.open(serverPlayer, stack);
|
||||||
|
return ActionResult.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ActionResult.SUCCESS_SERVER;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ActionResult useOnBlock(ItemUsageContext context) {
|
public ActionResult useOnBlock(ItemUsageContext context) {
|
||||||
String contents = context.getStack().getName().getLiteralString();
|
|
||||||
String name;
|
|
||||||
if(contents != null) {
|
|
||||||
name = contents;
|
|
||||||
} else {
|
|
||||||
name = "Minion";
|
|
||||||
}
|
|
||||||
if(!context.getWorld().isClient) {
|
if(!context.getWorld().isClient) {
|
||||||
MinionFakePlayer.createMinion(name, (ServerWorld) context.getWorld(), (ServerPlayerEntity) context.getPlayer(), canProgram, context.getBlockPos().toCenterPos().add(0,0.5,0), 0, 0);
|
MinionData data = getDataOrDefault(context.getStack());
|
||||||
|
MinionFakePlayer.spawnMinion(data, (ServerWorld) context.getWorld(), context.getBlockPos().toCenterPos().add(0,0.5,0), new Vec2f(0, 0));
|
||||||
}
|
}
|
||||||
|
context.getStack().decrement(1);
|
||||||
return ActionResult.SUCCESS;
|
return ActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setData(MinionData data, ItemStack item) {
|
||||||
|
item.set(MinionData.COMPONENT, data.uuid());
|
||||||
|
MinionPersistentState.INSTANCE.updateMinionData(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static MinionData getData(ItemStack item) {
|
||||||
|
if(item.contains(MinionData.COMPONENT)) {
|
||||||
|
return MinionPersistentState.INSTANCE.getMinionData(item.get(MinionData.COMPONENT));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MinionData getDataOrDefault(ItemStack item) {
|
||||||
|
MinionData data = getData(item);
|
||||||
|
if(data == null) {
|
||||||
|
data = MinionData.createDefault();
|
||||||
|
setData(data, item);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean containsData(ItemStack item) {
|
||||||
|
return item.contains(MinionData.COMPONENT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package io.github.skippyall.minions.minion;
|
||||||
|
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import net.minecraft.nbt.NbtCompound;
|
||||||
|
import net.minecraft.nbt.NbtElement;
|
||||||
|
import net.minecraft.nbt.NbtList;
|
||||||
|
import net.minecraft.registry.RegistryWrapper;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.world.PersistentState;
|
||||||
|
import net.minecraft.world.PersistentStateType;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class MinionPersistentState extends PersistentState {
|
||||||
|
public static final Codec<MinionPersistentState> CODEC = MinionData.CODEC.listOf().xmap(MinionPersistentState::new, MinionPersistentState::getMinionDataList);
|
||||||
|
|
||||||
|
public static PersistentStateType<MinionPersistentState> TYPE = new PersistentStateType<>("minion", MinionPersistentState::new, MinionPersistentState.CODEC, null);
|
||||||
|
|
||||||
|
public static MinionPersistentState INSTANCE;
|
||||||
|
|
||||||
|
private final Map<UUID, MinionData> minionData = new HashMap<>();
|
||||||
|
|
||||||
|
public MinionPersistentState() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public MinionPersistentState(List<MinionData> dataList) {
|
||||||
|
for (MinionData data : dataList) {
|
||||||
|
minionData.put(data.uuid(), data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public MinionData getMinionData(UUID uuid) {
|
||||||
|
return minionData.get(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<UUID, MinionData> getMinionData() {
|
||||||
|
return minionData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MinionData> getMinionDataList() {
|
||||||
|
return List.copyOf(minionData.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateMinionData(MinionData data) {
|
||||||
|
minionData.put(data.uuid(), data);
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMinion(UUID uuid) {
|
||||||
|
return minionData.containsKey(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMinionNameTaken(String name) {
|
||||||
|
return getMinionWithName(name).isPresent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<MinionData> getMinionWithName(String name) {
|
||||||
|
return minionData.values().stream()
|
||||||
|
.filter(data -> data.name().equals(name))
|
||||||
|
.findFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void create(MinecraftServer server) {
|
||||||
|
INSTANCE = server.getWorld(World.OVERWORLD).getPersistentStateManager().getOrCreate(TYPE);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package io.github.skippyall.minions.minion;
|
||||||
|
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import com.mojang.authlib.ProfileLookupCallback;
|
||||||
|
import com.mojang.authlib.properties.PropertyMap;
|
||||||
|
import com.mojang.authlib.yggdrasil.ProfileResult;
|
||||||
|
import com.mojang.brigadier.StringReader;
|
||||||
|
import io.github.skippyall.minions.input.Result;
|
||||||
|
import net.minecraft.block.entity.SkullBlockEntity;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.StringHelper;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ForkJoinPool;
|
||||||
|
|
||||||
|
import static io.github.skippyall.minions.Minions.LOGGER;
|
||||||
|
|
||||||
|
public class MinionProfileUtils {
|
||||||
|
public static final String PREFIX = "+";
|
||||||
|
|
||||||
|
public static GameProfile makeNewMinionProfile(UUID uuidMinion, String username, PropertyMap skin) {
|
||||||
|
if(uuidMinion == null) {
|
||||||
|
uuidMinion = UUID.randomUUID();
|
||||||
|
}
|
||||||
|
|
||||||
|
GameProfile newProfile = new GameProfile(uuidMinion, username);
|
||||||
|
if (skin != null) {
|
||||||
|
newProfile.getProperties().putAll(skin);
|
||||||
|
}
|
||||||
|
LOGGER.info("Minion Profile: {}", newProfile);
|
||||||
|
return newProfile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result<String, Text> checkMinionNameWithoutPrefix(String name) {
|
||||||
|
for(char c : name.toCharArray()) {
|
||||||
|
if(!StringReader.isAllowedInUnquotedString(c)) {
|
||||||
|
return new Result.Error<>(Text.translatable("minions.generic.name.invalid_char"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if((PREFIX + name).length() > 16) {
|
||||||
|
return new Result.Error<>(Text.translatable("minions.generic.name.too_long"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!StringHelper.isValidPlayerName(PREFIX + name)) {
|
||||||
|
return new Result.Error<>(Text.translatable("minions.generic.name.invalid"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(MinionPersistentState.INSTANCE.isMinionNameTaken(PREFIX + name)) {
|
||||||
|
return new Result.Error<>(Text.translatable("minions.generic.name.taken"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Result.Success<>(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String newDefaultMinionName() {
|
||||||
|
int i = 0;
|
||||||
|
while (MinionPersistentState.INSTANCE.isMinionNameTaken("+Minion" + i)) {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return "+Minion" + i;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isMinion(UUID uuid) {
|
||||||
|
return MinionPersistentState.INSTANCE.isMinion(uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package io.github.skippyall.minions.minion;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.Minions;
|
|
||||||
import net.minecraft.inventory.Inventories;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.nbt.NbtCompound;
|
|
||||||
import net.minecraft.registry.RegistryKeys;
|
|
||||||
import net.minecraft.registry.tag.TagKey;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
import net.minecraft.util.collection.DefaultedList;
|
|
||||||
|
|
||||||
public class ModuleInventory implements ImplementedInventory {
|
|
||||||
private static final TagKey<Item> MODULES = TagKey.of(RegistryKeys.ITEM, new Identifier(Minions.MOD_ID,"modules"));
|
|
||||||
private DefaultedList<ItemStack> stacks = DefaultedList.ofSize(27, ItemStack.EMPTY);
|
|
||||||
|
|
||||||
public ModuleInventory() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMaxCountPerStack() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isValid(int slot, ItemStack stack) {
|
|
||||||
return (stack.getCount() <= getMaxCountPerStack()) && stack.isIn(MODULES);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DefaultedList<ItemStack> getItems() {
|
|
||||||
return stacks;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readNbt(NbtCompound nbt) {
|
|
||||||
Inventories.readNbt(nbt, stacks);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeNbt(NbtCompound nbt) {
|
|
||||||
Inventories.writeNbt(nbt, stacks);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
package io.github.skippyall.minions.fakeplayer;
|
//code from https://github.com/gnembon/fabric-carpet
|
||||||
|
package io.github.skippyall.minions.minion.fakeplayer;
|
||||||
|
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
|
|
||||||
+27
-17
@@ -1,10 +1,13 @@
|
|||||||
package io.github.skippyall.minions.fakeplayer;
|
//partially code from https://github.com/gnembon/fabric-carpet
|
||||||
|
package io.github.skippyall.minions.minion.fakeplayer;
|
||||||
|
|
||||||
|
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.mixins.EntityAccessor;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.command.argument.EntityAnchorArgumentType;
|
import net.minecraft.command.argument.EntityAnchorArgumentType;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
@@ -80,6 +83,12 @@ public class EntityPlayerActionPack
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EntityPlayerActionPack stop(ActionType type) {
|
||||||
|
Action previous = actions.remove(type);
|
||||||
|
if (previous != null) type.stop(player, previous);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public EntityPlayerActionPack setSneaking(boolean doSneak)
|
public EntityPlayerActionPack setSneaking(boolean doSneak)
|
||||||
{
|
{
|
||||||
sneaking = doSneak;
|
sneaking = doSneak;
|
||||||
@@ -167,12 +176,13 @@ public class EntityPlayerActionPack
|
|||||||
|
|
||||||
public EntityPlayerActionPack mount(boolean onlyRideables)
|
public EntityPlayerActionPack mount(boolean onlyRideables)
|
||||||
{
|
{
|
||||||
|
|
||||||
//test what happens
|
//test what happens
|
||||||
List<Entity> entities;
|
List<Entity> entities;
|
||||||
if (onlyRideables)
|
if (onlyRideables)
|
||||||
{
|
{
|
||||||
entities = player.getWorld().getOtherEntities(player, player.getBoundingBox().expand(3.0D, 1.0D, 3.0D),
|
entities = player.getWorld().getOtherEntities(player, player.getBoundingBox().expand(3.0D, 1.0D, 3.0D),
|
||||||
e -> e instanceof MinecartEntity || e instanceof BoatEntity || e instanceof AbstractHorseEntity);
|
e -> (e instanceof MinecartEntity || e instanceof BoatEntity || e instanceof AbstractHorseEntity) && ((EntityAccessor)e).invokeCanAddPassenger(player));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -198,7 +208,7 @@ public class EntityPlayerActionPack
|
|||||||
if (closest instanceof AbstractHorseEntity && onlyRideables)
|
if (closest instanceof AbstractHorseEntity && onlyRideables)
|
||||||
((AbstractHorseEntity) closest).interactMob(player, Hand.MAIN_HAND);
|
((AbstractHorseEntity) closest).interactMob(player, Hand.MAIN_HAND);
|
||||||
else
|
else
|
||||||
player.startRiding(closest,true);
|
player.startRiding(closest, !onlyRideables);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public EntityPlayerActionPack dismount()
|
public EntityPlayerActionPack dismount()
|
||||||
@@ -271,14 +281,14 @@ public class EntityPlayerActionPack
|
|||||||
else // one slot
|
else // one slot
|
||||||
{
|
{
|
||||||
if (selectedSlot == -1)
|
if (selectedSlot == -1)
|
||||||
selectedSlot = inv.selectedSlot;
|
selectedSlot = inv.getSelectedSlot();
|
||||||
dropItemFromSlot(selectedSlot, dropAll);
|
dropItemFromSlot(selectedSlot, dropAll);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSlot(int slot)
|
public void setSlot(int slot)
|
||||||
{
|
{
|
||||||
player.getInventory().selectedSlot = slot-1;
|
player.getInventory().setSelectedSlot(slot-1);
|
||||||
player.networkHandler.sendPacket(new UpdateSelectedSlotS2CPacket(slot-1));
|
player.networkHandler.sendPacket(new UpdateSelectedSlotS2CPacket(slot-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,7 +299,7 @@ public class EntityPlayerActionPack
|
|||||||
@Override
|
@Override
|
||||||
boolean execute(ServerPlayerEntity player, Action action)
|
boolean execute(ServerPlayerEntity player, Action action)
|
||||||
{
|
{
|
||||||
EntityPlayerActionPack ap = ((ServerPlayerInterface) player).getActionPack();
|
EntityPlayerActionPack ap = ((ServerPlayerInterface) player).minions$getActionPack();
|
||||||
if (ap.itemUseCooldown > 0)
|
if (ap.itemUseCooldown > 0)
|
||||||
{
|
{
|
||||||
ap.itemUseCooldown--;
|
ap.itemUseCooldown--;
|
||||||
@@ -311,12 +321,12 @@ public class EntityPlayerActionPack
|
|||||||
BlockHitResult blockHit = (BlockHitResult) hit;
|
BlockHitResult blockHit = (BlockHitResult) hit;
|
||||||
BlockPos pos = blockHit.getBlockPos();
|
BlockPos pos = blockHit.getBlockPos();
|
||||||
Direction side = blockHit.getSide();
|
Direction side = blockHit.getSide();
|
||||||
if (pos.getY() < player.getWorld().getTopY() - (side == Direction.UP ? 1 : 0) && world.canPlayerModifyAt(player, pos))
|
if (pos.getY() < player.getServerWorld().getTopYInclusive() - (side == Direction.UP ? 1 : 0) && world.canEntityModifyAt(player, pos))
|
||||||
{
|
{
|
||||||
ActionResult result = player.interactionManager.interactBlock(player, world, player.getStackInHand(hand), hand, blockHit);
|
ActionResult result = player.interactionManager.interactBlock(player, world, player.getStackInHand(hand), hand, blockHit);
|
||||||
if (result.isAccepted())
|
if (result instanceof ActionResult.Success success)
|
||||||
{
|
{
|
||||||
if (result.shouldSwingHand()) player.swingHand(hand);
|
if (success.swingSource() == ActionResult.SwingSource.SERVER) player.swingHand(hand);
|
||||||
ap.itemUseCooldown = 3;
|
ap.itemUseCooldown = 3;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -358,7 +368,7 @@ public class EntityPlayerActionPack
|
|||||||
@Override
|
@Override
|
||||||
void inactiveTick(ServerPlayerEntity player, Action action)
|
void inactiveTick(ServerPlayerEntity player, Action action)
|
||||||
{
|
{
|
||||||
EntityPlayerActionPack ap = ((ServerPlayerInterface) player).getActionPack();
|
EntityPlayerActionPack ap = ((ServerPlayerInterface) player).minions$getActionPack();
|
||||||
ap.itemUseCooldown = 0;
|
ap.itemUseCooldown = 0;
|
||||||
player.stopUsingItem();
|
player.stopUsingItem();
|
||||||
}
|
}
|
||||||
@@ -380,7 +390,7 @@ public class EntityPlayerActionPack
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case BLOCK: {
|
case BLOCK: {
|
||||||
EntityPlayerActionPack ap = ((ServerPlayerInterface) player).getActionPack();
|
EntityPlayerActionPack ap = ((ServerPlayerInterface) player).minions$getActionPack();
|
||||||
if (ap.blockHitDelay > 0)
|
if (ap.blockHitDelay > 0)
|
||||||
{
|
{
|
||||||
ap.blockHitDelay--;
|
ap.blockHitDelay--;
|
||||||
@@ -399,7 +409,7 @@ public class EntityPlayerActionPack
|
|||||||
boolean blockBroken = false;
|
boolean blockBroken = false;
|
||||||
if (player.interactionManager.getGameMode().isCreative())
|
if (player.interactionManager.getGameMode().isCreative())
|
||||||
{
|
{
|
||||||
player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, side, player.getWorld().getTopY(), -1);
|
player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, side, player.getWorld().getTopYInclusive(), -1);
|
||||||
ap.blockHitDelay = 5;
|
ap.blockHitDelay = 5;
|
||||||
blockBroken = true;
|
blockBroken = true;
|
||||||
}
|
}
|
||||||
@@ -407,9 +417,9 @@ public class EntityPlayerActionPack
|
|||||||
{
|
{
|
||||||
if (ap.currentBlock != null)
|
if (ap.currentBlock != null)
|
||||||
{
|
{
|
||||||
player.interactionManager.processBlockBreakingAction(ap.currentBlock, PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK, side, player.getWorld().getTopY(), -1);
|
player.interactionManager.processBlockBreakingAction(ap.currentBlock, PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK, side, player.getWorld().getTopYInclusive(), -1);
|
||||||
}
|
}
|
||||||
player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, side, player.getWorld().getTopY(), -1);
|
player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, side, player.getWorld().getTopYInclusive(), -1);
|
||||||
boolean notAir = !state.isAir();
|
boolean notAir = !state.isAir();
|
||||||
if (notAir && ap.curBlockDamageMP == 0)
|
if (notAir && ap.curBlockDamageMP == 0)
|
||||||
{
|
{
|
||||||
@@ -432,7 +442,7 @@ public class EntityPlayerActionPack
|
|||||||
ap.curBlockDamageMP += state.calcBlockBreakingDelta(player, player.getWorld(), pos);
|
ap.curBlockDamageMP += state.calcBlockBreakingDelta(player, player.getWorld(), pos);
|
||||||
if (ap.curBlockDamageMP >= 1)
|
if (ap.curBlockDamageMP >= 1)
|
||||||
{
|
{
|
||||||
player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, side, player.getWorld().getTopY(), -1);
|
player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, side, player.getWorld().getTopYInclusive(), -1);
|
||||||
ap.currentBlock = null;
|
ap.currentBlock = null;
|
||||||
ap.blockHitDelay = 5;
|
ap.blockHitDelay = 5;
|
||||||
blockBroken = true;
|
blockBroken = true;
|
||||||
@@ -451,10 +461,10 @@ public class EntityPlayerActionPack
|
|||||||
@Override
|
@Override
|
||||||
void inactiveTick(ServerPlayerEntity player, Action action)
|
void inactiveTick(ServerPlayerEntity player, Action action)
|
||||||
{
|
{
|
||||||
EntityPlayerActionPack ap = ((ServerPlayerInterface) player).getActionPack();
|
EntityPlayerActionPack ap = ((ServerPlayerInterface) player).minions$getActionPack();
|
||||||
if (ap.currentBlock == null) return;
|
if (ap.currentBlock == null) return;
|
||||||
player.getWorld().setBlockBreakingInfo(-1, ap.currentBlock, -1);
|
player.getWorld().setBlockBreakingInfo(-1, ap.currentBlock, -1);
|
||||||
player.interactionManager.processBlockBreakingAction(ap.currentBlock, PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK, Direction.DOWN, player.getWorld().getTopY(), -1);
|
player.interactionManager.processBlockBreakingAction(ap.currentBlock, PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK, Direction.DOWN, player.getWorld().getTopYInclusive(), -1);
|
||||||
ap.currentBlock = null;
|
ap.currentBlock = null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
+4
-5
@@ -1,10 +1,11 @@
|
|||||||
package io.github.skippyall.minions.fakeplayer;
|
//code from https://github.com/gnembon/fabric-carpet
|
||||||
|
package io.github.skippyall.minions.minion.fakeplayer;
|
||||||
|
|
||||||
import io.netty.channel.embedded.EmbeddedChannel;
|
import io.netty.channel.embedded.EmbeddedChannel;
|
||||||
import net.minecraft.network.ClientConnection;
|
import net.minecraft.network.ClientConnection;
|
||||||
import net.minecraft.network.NetworkSide;
|
import net.minecraft.network.NetworkSide;
|
||||||
|
import net.minecraft.network.state.NetworkState;
|
||||||
import net.minecraft.network.listener.PacketListener;
|
import net.minecraft.network.listener.PacketListener;
|
||||||
import net.minecraft.text.Text;
|
|
||||||
|
|
||||||
public class FakeClientConnection extends ClientConnection {
|
public class FakeClientConnection extends ClientConnection {
|
||||||
public FakeClientConnection(NetworkSide p)
|
public FakeClientConnection(NetworkSide p)
|
||||||
@@ -22,7 +23,6 @@ public class FakeClientConnection extends ClientConnection {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleDisconnection() {
|
public void handleDisconnection() {
|
||||||
getPacketListener().onDisconnected(getDisconnectReason()==null ? Text.literal("Disconnected"): getDisconnectReason());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -31,7 +31,6 @@ public class FakeClientConnection extends ClientConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPacketListener(PacketListener packetListener) {
|
public <T extends PacketListener> void transitionInbound(NetworkState<T> state, T packetListener) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+118
-91
@@ -1,24 +1,33 @@
|
|||||||
package io.github.skippyall.minions.fakeplayer;
|
//partially code from https://github.com/gnembon/fabric-carpet
|
||||||
|
package io.github.skippyall.minions.minion.fakeplayer;
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.yggdrasil.ProfileResult;
|
import com.mojang.authlib.properties.PropertyMap;
|
||||||
import io.github.skippyall.minions.minion.MinionInventory;
|
import io.github.skippyall.minions.MinionItems;
|
||||||
import io.github.skippyall.minions.minion.ModuleInventory;
|
import io.github.skippyall.minions.minion.MinionData;
|
||||||
import net.fabricmc.fabric.api.entity.FakePlayer;
|
import io.github.skippyall.minions.gui.MinionGui;
|
||||||
|
import io.github.skippyall.minions.minion.MinionItem;
|
||||||
|
import io.github.skippyall.minions.minion.MinionPersistentState;
|
||||||
|
import io.github.skippyall.minions.minion.MinionProfileUtils;
|
||||||
|
import io.github.skippyall.minions.gui.ModuleInventory;
|
||||||
|
import io.github.skippyall.minions.program.runtime.MinionRuntime;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EquipmentSlot;
|
import net.minecraft.entity.EquipmentSlot;
|
||||||
|
import net.minecraft.entity.ItemEntity;
|
||||||
import net.minecraft.entity.MovementType;
|
import net.minecraft.entity.MovementType;
|
||||||
|
import net.minecraft.entity.attribute.EntityAttributes;
|
||||||
import net.minecraft.entity.damage.DamageSource;
|
import net.minecraft.entity.damage.DamageSource;
|
||||||
import net.minecraft.entity.player.HungerManager;
|
import net.minecraft.entity.player.HungerManager;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NbtCompound;
|
||||||
|
import net.minecraft.network.DisconnectionInfo;
|
||||||
import net.minecraft.network.NetworkSide;
|
import net.minecraft.network.NetworkSide;
|
||||||
import net.minecraft.network.packet.c2s.common.SyncedClientOptions;
|
import net.minecraft.network.packet.c2s.common.SyncedClientOptions;
|
||||||
import net.minecraft.network.packet.c2s.play.ClientStatusC2SPacket;
|
import net.minecraft.network.packet.c2s.play.ClientStatusC2SPacket;
|
||||||
import net.minecraft.network.packet.s2c.play.EntityPositionS2CPacket;
|
import net.minecraft.network.packet.s2c.play.EntityPositionSyncS2CPacket;
|
||||||
import net.minecraft.network.packet.s2c.play.EntitySetHeadYawS2CPacket;
|
import net.minecraft.network.packet.s2c.play.EntitySetHeadYawS2CPacket;
|
||||||
import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.ServerTask;
|
import net.minecraft.server.ServerTask;
|
||||||
import net.minecraft.server.network.ConnectedClientData;
|
import net.minecraft.server.network.ConnectedClientData;
|
||||||
@@ -28,107 +37,92 @@ import net.minecraft.text.Text;
|
|||||||
import net.minecraft.text.TranslatableTextContent;
|
import net.minecraft.text.TranslatableTextContent;
|
||||||
import net.minecraft.util.ActionResult;
|
import net.minecraft.util.ActionResult;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.Uuids;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.Vec2f;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.world.GameMode;
|
import net.minecraft.world.GameMode;
|
||||||
import java.util.UUID;
|
import net.minecraft.world.TeleportTarget;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class MinionFakePlayer extends ServerPlayerEntity {
|
public class MinionFakePlayer extends ServerPlayerEntity {
|
||||||
public Runnable fixStartingPosition = () -> {};
|
public Runnable fixStartingPosition = () -> {};
|
||||||
public boolean isAShadow;
|
|
||||||
|
|
||||||
private float moveForward;
|
private float moveForward;
|
||||||
private float moveSideways;
|
private float moveSideways;
|
||||||
|
|
||||||
private boolean programmable;
|
private final ModuleInventory moduleInventory = new ModuleInventory();
|
||||||
private ModuleInventory moduleInventory = new ModuleInventory();
|
private final MinionRuntime runtime = new MinionRuntime(this);
|
||||||
|
|
||||||
public static void createMinion(String username, ServerWorld level, ServerPlayerEntity owner, boolean canProgram, Vec3d pos, double yaw, double pitch) {
|
|
||||||
MinecraftServer server = level.getServer();
|
|
||||||
server.getUserCache().findByNameAsync(username).thenAcceptAsync((optional) -> {
|
|
||||||
GameProfile profile = null;
|
|
||||||
if(optional.isPresent()){
|
|
||||||
UUID uuid = optional.get().getId();
|
|
||||||
ProfileResult result = server.getSessionService().fetchProfile(uuid, true);
|
|
||||||
if(result != null) {
|
|
||||||
profile = result.profile();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(profile == null) {
|
|
||||||
profile = new GameProfile(Uuids.getOfflinePlayerUuid(username), username);
|
|
||||||
}
|
|
||||||
MinionFakePlayer instance = new MinionFakePlayer(server, level, profile, SyncedClientOptions.createDefault(), false, canProgram);
|
|
||||||
instance.fixStartingPosition = () -> instance.refreshPositionAndAngles(pos.x, pos.y, pos.z, (float) yaw, (float) pitch);
|
|
||||||
server.getPlayerManager().onPlayerConnect(new FakeClientConnection(NetworkSide.SERVERBOUND), instance, new ConnectedClientData(profile, 0, instance.getClientOptions()));
|
|
||||||
instance.teleport(level, pos.x, pos.y, pos.z, (float) yaw, (float) pitch);
|
|
||||||
instance.setHealth(20.0F);
|
|
||||||
instance.unsetRemoved();
|
|
||||||
instance.interactionManager.changeGameMode(GameMode.SURVIVAL);
|
|
||||||
server.getPlayerManager().sendToDimension(new EntitySetHeadYawS2CPacket(instance, (byte) (instance.headYaw * 256 / 360)), level.getRegistryKey());//instance.dimension);
|
|
||||||
server.getPlayerManager().sendToDimension(new EntityPositionS2CPacket(instance), level.getRegistryKey());//instance.dimension);
|
|
||||||
//instance.world.getChunkManager(). updatePosition(instance);
|
|
||||||
instance.dataTracker.set(PLAYER_MODEL_PARTS, (byte) 0x7f); // show all model layers (incl. capes)
|
|
||||||
instance.getAbilities().flying = false;
|
|
||||||
instance.setStepHeight(0.6F);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
private final MinionData data;
|
||||||
|
|
||||||
|
public static void spawnMinion(MinionData data, ServerWorld level, @Nullable Vec3d pos, @Nullable Vec2f rot) {
|
||||||
|
spawnMinion(data, level, pos, rot, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused") //Don't know if I'll need this
|
public static void spawnMinion(MinionData data, ServerWorld level, @Nullable Vec3d pos, @Nullable Vec2f rot, boolean force) {
|
||||||
public static MinionFakePlayer createShadow(MinecraftServer server, ServerPlayerEntity player)
|
if(!data.isSpawned() || force) {
|
||||||
|
MinecraftServer server = level.getServer();
|
||||||
|
|
||||||
|
PropertyMap skin = data.skin().orElse(null);
|
||||||
|
|
||||||
|
GameProfile profile = MinionProfileUtils.makeNewMinionProfile(data.uuid(), data.name(), skin);
|
||||||
|
doSpawn(data, profile, server, level, pos, rot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void doSpawn(MinionData data, GameProfile profile, MinecraftServer server, ServerWorld level, @Nullable Vec3d pos, @Nullable Vec2f rot) {
|
||||||
|
MinionFakePlayer instance = new MinionFakePlayer(server, level, profile, SyncedClientOptions.createDefault(), data);
|
||||||
|
MinionPersistentState.INSTANCE.updateMinionData(data.withSpawned(true));
|
||||||
|
|
||||||
|
if(pos != null && rot != null) {
|
||||||
|
instance.fixStartingPosition = () -> instance.refreshPositionAndAngles(pos.x, pos.y, pos.z, rot.x, rot.y);
|
||||||
|
}
|
||||||
|
server.getPlayerManager().onPlayerConnect(new FakeClientConnection(NetworkSide.SERVERBOUND), instance, new ConnectedClientData(profile, 0, instance.getClientOptions(), false));
|
||||||
|
System.out.println(instance.getPos());
|
||||||
|
if(pos != null && rot != null) {
|
||||||
|
instance.teleport(level, pos.x, pos.y, pos.z, Set.of(), rot.x, rot.y, true);
|
||||||
|
}
|
||||||
|
instance.setVelocity(0,0,0);
|
||||||
|
instance.setHealth(20.0F);
|
||||||
|
instance.unsetRemoved();
|
||||||
|
instance.getAttributeInstance(EntityAttributes.STEP_HEIGHT).setBaseValue(0.6F);
|
||||||
|
instance.interactionManager.changeGameMode(GameMode.SURVIVAL);
|
||||||
|
server.getPlayerManager().sendToDimension(new EntitySetHeadYawS2CPacket(instance, (byte) (instance.headYaw * 256 / 360)), level.getRegistryKey());//instance.dimension);
|
||||||
|
server.getPlayerManager().sendToDimension(EntityPositionSyncS2CPacket.create(instance), level.getRegistryKey());//instance.dimension);
|
||||||
|
//instance.world.getChunkManager(). updatePosition(instance);
|
||||||
|
instance.dataTracker.set(PLAYER_MODEL_PARTS, (byte) 0x7f); // show all model layers (incl. capes)
|
||||||
|
instance.getAbilities().flying = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MinionFakePlayer respawnFake(MinecraftServer server, ServerWorld level, GameProfile profile, SyncedClientOptions cli, MinionData data)
|
||||||
{
|
{
|
||||||
player.getServer().getPlayerManager().remove(player);
|
return new MinionFakePlayer(server, level, profile, cli, data);
|
||||||
player.networkHandler.disconnect(Text.translatable("multiplayer.disconnect.duplicate_login"));
|
|
||||||
ServerWorld worldIn = player.getServerWorld();//.getWorld(player.dimension);
|
|
||||||
GameProfile gameprofile = player.getGameProfile();
|
|
||||||
MinionFakePlayer playerShadow = new MinionFakePlayer(server, worldIn, gameprofile, player.getClientOptions(), true, false);
|
|
||||||
playerShadow.setSession(player.getSession());
|
|
||||||
server.getPlayerManager().onPlayerConnect(new FakeClientConnection(NetworkSide.SERVERBOUND), playerShadow, new ConnectedClientData(gameprofile, 0, player.getClientOptions()));
|
|
||||||
|
|
||||||
playerShadow.setHealth(player.getHealth());
|
|
||||||
playerShadow.networkHandler.requestTeleport(player.getX(), player.getY(), player.getZ(), player.getYaw(), player.getPitch());
|
|
||||||
playerShadow.interactionManager.changeGameMode(player.interactionManager.getGameMode());
|
|
||||||
((ServerPlayerInterface) playerShadow).getActionPack().copyFrom(((ServerPlayerInterface) player).getActionPack());
|
|
||||||
playerShadow.dataTracker.set(PLAYER_MODEL_PARTS, player.getDataTracker().get(PLAYER_MODEL_PARTS));
|
|
||||||
|
|
||||||
|
|
||||||
server.getPlayerManager().sendToDimension(new EntitySetHeadYawS2CPacket(playerShadow, (byte) (player.headYaw * 256 / 360)), playerShadow.getWorld().getRegistryKey());
|
|
||||||
server.getPlayerManager().sendToAll(new PlayerListS2CPacket(PlayerListS2CPacket.Action.ADD_PLAYER, playerShadow));
|
|
||||||
//player.world.getChunkManager().updatePosition(playerShadow);
|
|
||||||
playerShadow.getAbilities().flying = player.getAbilities().flying;
|
|
||||||
return playerShadow;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MinionFakePlayer respawnFake(MinecraftServer server, ServerWorld level, GameProfile profile, SyncedClientOptions cli, boolean programmable)
|
private MinionFakePlayer(MinecraftServer server, ServerWorld worldIn, GameProfile profile, SyncedClientOptions cli, MinionData data)
|
||||||
{
|
|
||||||
return new MinionFakePlayer(server, level, profile, cli, false, programmable);
|
|
||||||
}
|
|
||||||
|
|
||||||
private MinionFakePlayer(MinecraftServer server, ServerWorld worldIn, GameProfile profile, SyncedClientOptions cli, boolean shadow, boolean programmable)
|
|
||||||
{
|
{
|
||||||
super(server, worldIn, profile, cli);
|
super(server, worldIn, profile, cli);
|
||||||
isAShadow = shadow;
|
this.data = data;
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isProgrammable() {
|
|
||||||
return programmable;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ModuleInventory getModuleInventory() {
|
public ModuleInventory getModuleInventory() {
|
||||||
return moduleInventory;
|
return moduleInventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityPlayerActionPack getActionPack() {
|
public MinionRuntime getRuntime() {
|
||||||
return ((ServerPlayerInterface)this).getActionPack();
|
return runtime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityPlayerActionPack getMinionActionPack() {
|
||||||
|
return ((ServerPlayerInterface)this).minions$getActionPack();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ActionResult interact(PlayerEntity player, Hand hand) {
|
public ActionResult interact(PlayerEntity player, Hand hand) {
|
||||||
if(player instanceof ServerPlayerEntity spe) {
|
if(player instanceof ServerPlayerEntity spe) {
|
||||||
MinionInventory.openInventory(spe, this);
|
MinionGui.openInventory(spe, this);
|
||||||
}
|
}
|
||||||
return ActionResult.CONSUME;
|
return ActionResult.CONSUME;
|
||||||
}
|
}
|
||||||
@@ -144,23 +138,25 @@ public class MinionFakePlayer extends ServerPlayerEntity {
|
|||||||
if (!isUsingItem()) super.onEquipStack(slot, previous, stack);
|
if (!isUsingItem()) super.onEquipStack(slot, previous, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/*@Override
|
||||||
public void kill()
|
public void kill()
|
||||||
{
|
{
|
||||||
kill(Text.literal("Killed"));
|
kill(Text.literal("Killed"));
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public void kill(Text reason)
|
public void kill(Text reason)
|
||||||
{
|
{
|
||||||
shakeOff();
|
shakeOff();
|
||||||
|
|
||||||
if (reason.getContent() instanceof TranslatableTextContent text && text.getKey().equals("multiplayer.disconnect.duplicate_login")) {
|
if (reason.getContent() instanceof TranslatableTextContent text && text.getKey().equals("multiplayer.disconnect.duplicate_login")) {
|
||||||
this.networkHandler.onDisconnected(reason);
|
this.networkHandler.onDisconnected(new DisconnectionInfo(reason));
|
||||||
} else {
|
} else {
|
||||||
this.server.send(new ServerTask(this.server.getTicks(), () -> {
|
this.server.send(new ServerTask(this.server.getTicks(), () -> {
|
||||||
this.networkHandler.onDisconnected(reason);
|
this.networkHandler.onDisconnected(new DisconnectionInfo(reason));
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MinionPersistentState.INSTANCE.updateMinionData(data.withSpawned(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -181,7 +177,7 @@ public class MinionFakePlayer extends ServerPlayerEntity {
|
|||||||
// happens with that paper port thingy - not sure what that would fix, but hey
|
// happens with that paper port thingy - not sure what that would fix, but hey
|
||||||
// the game not gonna crash violently.
|
// the game not gonna crash violently.
|
||||||
}
|
}
|
||||||
|
runtime.tick();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,9 +217,9 @@ public class MinionFakePlayer extends ServerPlayerEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Entity moveToWorld(ServerWorld serverLevel)
|
public ServerPlayerEntity teleportTo(TeleportTarget target)
|
||||||
{
|
{
|
||||||
super.moveToWorld(serverLevel);
|
super.teleportTo(target);
|
||||||
if (notInAnyWorld) {
|
if (notInAnyWorld) {
|
||||||
ClientStatusC2SPacket p = new ClientStatusC2SPacket(ClientStatusC2SPacket.Mode.PERFORM_RESPAWN);
|
ClientStatusC2SPacket p = new ClientStatusC2SPacket(ClientStatusC2SPacket.Mode.PERFORM_RESPAWN);
|
||||||
networkHandler.onClientStatus(p);
|
networkHandler.onClientStatus(p);
|
||||||
@@ -239,7 +235,7 @@ public class MinionFakePlayer extends ServerPlayerEntity {
|
|||||||
|
|
||||||
public void moveForward(float forward) {
|
public void moveForward(float forward) {
|
||||||
this.moveForward += forward;
|
this.moveForward += forward;
|
||||||
EntityPlayerActionPack actionPack = getActionPack();
|
EntityPlayerActionPack actionPack = getMinionActionPack();
|
||||||
if (moveForward != 0) {
|
if (moveForward != 0) {
|
||||||
actionPack.setForward(moveForward > 0 ? 1 : -1);
|
actionPack.setForward(moveForward > 0 ? 1 : -1);
|
||||||
}
|
}
|
||||||
@@ -247,7 +243,7 @@ public class MinionFakePlayer extends ServerPlayerEntity {
|
|||||||
|
|
||||||
public void moveSideways(float sideways) {
|
public void moveSideways(float sideways) {
|
||||||
this.moveSideways += sideways;
|
this.moveSideways += sideways;
|
||||||
EntityPlayerActionPack actionPack = getActionPack();
|
EntityPlayerActionPack actionPack = getMinionActionPack();
|
||||||
if (moveSideways != 0) {
|
if (moveSideways != 0) {
|
||||||
actionPack.setStrafing(moveSideways > 0 ? 1 : -1);
|
actionPack.setStrafing(moveSideways > 0 ? 1 : -1);
|
||||||
}
|
}
|
||||||
@@ -258,20 +254,51 @@ public class MinionFakePlayer extends ServerPlayerEntity {
|
|||||||
float newForward = (float) (moveForward - movement.z);
|
float newForward = (float) (moveForward - movement.z);
|
||||||
float newSideways = (float) (moveSideways - movement.x);
|
float newSideways = (float) (moveSideways - movement.x);
|
||||||
Vec3d newMovement = movement;
|
Vec3d newMovement = movement;
|
||||||
if ((newForward < 0 && moveForward >= 0) || (newForward > 0 && moveForward <= 0)) {
|
if ((newForward < 0 && moveForward > 0) || (newForward > 0 && moveForward < 0)) {
|
||||||
newMovement = new Vec3d(newMovement.x, newMovement.y, moveForward);
|
newMovement = new Vec3d(newMovement.x, newMovement.y, moveForward);
|
||||||
moveForward = 0;
|
moveForward = 0;
|
||||||
getActionPack().setForward(0);
|
getMinionActionPack().setForward(0);
|
||||||
}else {
|
}else {
|
||||||
moveForward = newForward;
|
moveForward = newForward;
|
||||||
}
|
}
|
||||||
if ((newSideways < 0 && moveSideways >= 0) || (newSideways > 0 && moveSideways <= 0)) {
|
if ((newSideways < 0 && moveSideways > 0) || (newSideways > 0 && moveSideways < 0)) {
|
||||||
newMovement = new Vec3d(newMovement.x, newMovement.y, moveSideways);
|
newMovement = new Vec3d(newMovement.x, newMovement.y, moveSideways);
|
||||||
moveSideways = 0;
|
moveSideways = 0;
|
||||||
getActionPack().setStrafing(0);
|
getMinionActionPack().setStrafing(0);
|
||||||
}else {
|
}else {
|
||||||
moveSideways = newSideways;
|
moveSideways = newSideways;
|
||||||
}
|
}
|
||||||
super.move(movementType, newMovement);
|
super.move(movementType, newMovement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drop(ServerWorld world, DamageSource damageSource) {
|
||||||
|
super.drop(world, damageSource);
|
||||||
|
ItemEntity entity = dropStack(world, toItemStack());
|
||||||
|
if (entity != null) {
|
||||||
|
entity.setNeverDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack toItemStack() {
|
||||||
|
ItemStack stack = new ItemStack(MinionItems.MINION_ITEM);
|
||||||
|
MinionItem.setData(data, stack);
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MinionData getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeCustomDataToNbt(NbtCompound nbt) {
|
||||||
|
super.writeCustomDataToNbt(nbt);
|
||||||
|
nbt.put("modules", moduleInventory.writeNbt(new NbtCompound(), getRegistryManager()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readCustomDataFromNbt(NbtCompound nbt) {
|
||||||
|
super.readCustomDataFromNbt(nbt);
|
||||||
|
moduleInventory.readNbt(nbt.getCompoundOrEmpty("modules"), getRegistryManager());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+5
-3
@@ -1,5 +1,7 @@
|
|||||||
package io.github.skippyall.minions.fakeplayer;
|
//code from https://github.com/gnembon/fabric-carpet
|
||||||
|
package io.github.skippyall.minions.minion.fakeplayer;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.PlayerPosition;
|
||||||
import net.minecraft.network.ClientConnection;
|
import net.minecraft.network.ClientConnection;
|
||||||
import net.minecraft.network.packet.Packet;
|
import net.minecraft.network.packet.Packet;
|
||||||
import net.minecraft.network.packet.s2c.play.PositionFlag;
|
import net.minecraft.network.packet.s2c.play.PositionFlag;
|
||||||
@@ -33,9 +35,9 @@ public class NetHandlerPlayServerFake extends ServerPlayNetworkHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void requestTeleport(double d, double e, double f, float g, float h, Set<PositionFlag> set)
|
public void requestTeleport(PlayerPosition pos, Set<PositionFlag> set)
|
||||||
{
|
{
|
||||||
super.requestTeleport(d, e, f, g, h, set);
|
super.requestTeleport(pos, set);
|
||||||
if (player.getServerWorld().getPlayerByUuid(player.getUuid()) != null) {
|
if (player.getServerWorld().getPlayerByUuid(player.getUuid()) != null) {
|
||||||
syncWithPlayerPosition();
|
syncWithPlayerPosition();
|
||||||
player.getServerWorld().getChunkManager().updatePosition(player);
|
player.getServerWorld().getChunkManager().updatePosition(player);
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
//code from https://github.com/gnembon/fabric-carpet
|
||||||
|
package io.github.skippyall.minions.minion.fakeplayer;
|
||||||
|
|
||||||
|
public interface ServerPlayerInterface
|
||||||
|
{
|
||||||
|
EntityPlayerActionPack minions$getActionPack();
|
||||||
|
}
|
||||||
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
package io.github.skippyall.minions.fakeplayer;
|
//code from https://github.com/gnembon/fabric-carpet
|
||||||
|
package io.github.skippyall.minions.minion.fakeplayer;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package io.github.skippyall.minions.minion.skin;
|
||||||
|
|
||||||
|
import com.mojang.authlib.properties.Property;
|
||||||
|
import com.mojang.authlib.properties.PropertyMap;
|
||||||
|
import io.github.skippyall.minions.input.TextInput;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
public class Base64SkinProvider implements SkinProvider {
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Optional<PropertyMap>> openSkinMenu(ServerPlayerEntity player) {
|
||||||
|
return TextInput.inputString(player, Text.translatable("minions.gui.look.skin.base64.title"), "")
|
||||||
|
.thenApply(base64String -> {
|
||||||
|
PropertyMap map = new PropertyMap();
|
||||||
|
map.put("textures", new Property("textures", base64String));
|
||||||
|
return Optional.of(map);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Text getDisplayName() {
|
||||||
|
return Text.translatable("minions.gui.look.skin.base64");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package io.github.skippyall.minions.minion.skin;
|
||||||
|
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import com.mojang.authlib.properties.PropertyMap;
|
||||||
|
import io.github.skippyall.minions.input.TextInput;
|
||||||
|
import net.minecraft.block.entity.SkullBlockEntity;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
public class NameSkinProvider implements SkinProvider {
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Optional<PropertyMap>> openSkinMenu(ServerPlayerEntity player) {
|
||||||
|
return TextInput.inputString(player, Text.translatable("minions.gui.look.skin.name.title"), "")
|
||||||
|
.thenCompose(SkullBlockEntity::fetchProfileByName)
|
||||||
|
.thenApply(gameProfile -> gameProfile.map(GameProfile::getProperties));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Text getDisplayName() {
|
||||||
|
return Text.translatable("minions.gui.look.skin.name");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package io.github.skippyall.minions.minion.skin;
|
||||||
|
|
||||||
|
import com.mojang.authlib.properties.PropertyMap;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
public interface SkinProvider {
|
||||||
|
CompletableFuture<Optional<PropertyMap>> openSkinMenu(ServerPlayerEntity player);
|
||||||
|
|
||||||
|
Text getDisplayName();
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package io.github.skippyall.minions.minion.skin;
|
||||||
|
|
||||||
|
import com.mojang.serialization.Lifecycle;
|
||||||
|
import io.github.skippyall.minions.Minions;
|
||||||
|
import net.minecraft.registry.Registry;
|
||||||
|
import net.minecraft.registry.RegistryKey;
|
||||||
|
import net.minecraft.registry.SimpleRegistry;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
public class SkinProviders {
|
||||||
|
public static final Registry<SkinProvider> SKIN_PROVIDERS = new SimpleRegistry<>(RegistryKey.ofRegistry(Identifier.of(Minions.MOD_ID, "skin_providers")), Lifecycle.stable());
|
||||||
|
|
||||||
|
public static NameSkinProvider NAME = register(new NameSkinProvider(), "name");
|
||||||
|
public static UUIDSkinProvider UUID = register(new UUIDSkinProvider(), "uuid");
|
||||||
|
public static Base64SkinProvider BASE64 = register(new Base64SkinProvider(), "base64");
|
||||||
|
|
||||||
|
|
||||||
|
public static <T extends SkinProvider> T register(T skinProvider, String path) {
|
||||||
|
return Registry.register(SKIN_PROVIDERS, Identifier.of(Minions.MOD_ID, path), skinProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void register() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package io.github.skippyall.minions.minion.skin;
|
||||||
|
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import com.mojang.authlib.properties.PropertyMap;
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
|
import io.github.skippyall.minions.input.TextInput;
|
||||||
|
import io.github.skippyall.minions.minion.MinionProfileUtils;
|
||||||
|
import net.minecraft.block.entity.SkullBlockEntity;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.Uuids;
|
||||||
|
import net.minecraft.util.dynamic.Codecs;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
public class UUIDSkinProvider implements SkinProvider {
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Optional<PropertyMap>> openSkinMenu(ServerPlayerEntity player) {
|
||||||
|
return TextInput.inputString(player, Text.translatable("minions.gui.look.skin.uuid.title"), "")
|
||||||
|
.thenCompose(uuidString -> SkullBlockEntity.fetchProfileByUuid(UUID.fromString(uuidString)))
|
||||||
|
.thenApply(gameProfile -> gameProfile.map(GameProfile::getProperties));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Text getDisplayName() {
|
||||||
|
return Text.translatable("minions.gui.look.skin.uuid");
|
||||||
|
}
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
package io.github.skippyall.minions.mixinhelper;
|
||||||
|
|
||||||
|
public interface ChunkLevelManager$DistanceFromNearestPlayerTrackerAccessor {
|
||||||
|
void minions$markAsMinionless();
|
||||||
|
void minions$markAsTarget();
|
||||||
|
int minions$getTickedChunkCount();
|
||||||
|
|
||||||
|
boolean minions$isRealPlayerInChunk(long chunkPos);
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package io.github.skippyall.minions.mixinhelper;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectSet;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.server.world.ChunkLevelManager;
|
||||||
|
|
||||||
|
public interface ChunkLevelManagerAccessor {
|
||||||
|
ObjectSet<ServerPlayerEntity> minions$getPlayers(long chunkpos);
|
||||||
|
|
||||||
|
ChunkLevelManager.DistanceFromNearestPlayerTracker minions$getMinionless();
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package io.github.skippyall.minions.mixinhelper;
|
||||||
|
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
public class EntityViewMixinHelper {
|
||||||
|
public static final ThreadLocal<Predicate<Entity>> ADDITIONAL_PREDICATE = ThreadLocal.withInitial(() -> entity -> true);
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package io.github.skippyall.minions.mixins;
|
||||||
|
|
||||||
|
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||||
|
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectSet;
|
||||||
|
import net.minecraft.server.world.ChunkLevelManager;
|
||||||
|
import net.minecraft.server.world.ChunkTicketManager;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
|
||||||
|
@Mixin(value = ChunkLevelManager.class)
|
||||||
|
public class ChunkTicketManagerFixMixin {
|
||||||
|
@WrapOperation(method = "handleChunkLeave", at = @At(value = "INVOKE", target = "Lit/unimi/dsi/fastutil/objects/ObjectSet;remove(Ljava/lang/Object;)Z", remap = false))
|
||||||
|
public boolean filterIfNull(ObjectSet instance, Object o, Operation<Boolean> original) {
|
||||||
|
if (instance != null) {
|
||||||
|
return original.call(instance, o);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;//Unused
|
||||||
|
}
|
||||||
|
|
||||||
|
@WrapOperation(method = "handleChunkLeave", at = @At(value = "INVOKE", target = "Lit/unimi/dsi/fastutil/objects/ObjectSet;isEmpty()Z", remap = false))
|
||||||
|
public boolean filterIfNull(ObjectSet instance, Operation<Boolean> original) {
|
||||||
|
if (instance != null) {
|
||||||
|
return original.call(instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;//Unused
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
|
//code from https://github.com/gnembon/fabric-carpet
|
||||||
package io.github.skippyall.minions.mixins;
|
package io.github.skippyall.minions.mixins;
|
||||||
|
|
||||||
import io.github.skippyall.minions.fakeplayer.ClientConnectionInterface;
|
import io.github.skippyall.minions.minion.fakeplayer.ClientConnectionInterface;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import net.minecraft.network.ClientConnection;
|
import net.minecraft.network.ClientConnection;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package io.github.skippyall.minions.mixins;
|
||||||
|
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||||
|
|
||||||
|
@Mixin(Entity.class)
|
||||||
|
public interface EntityAccessor {
|
||||||
|
@Invoker("canAddPassenger")
|
||||||
|
boolean invokeCanAddPassenger(Entity other);
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package io.github.skippyall.minions.mixins;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.mixinhelper.EntityViewMixinHelper;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.world.EntityView;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||||
|
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
@Mixin(EntityView.class)
|
||||||
|
public interface EntityViewMixin {
|
||||||
|
@ModifyArg(method = "getClosestPlayer(DDDDZ)Lnet/minecraft/entity/player/PlayerEntity;", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/EntityView;getClosestPlayer(DDDDLjava/util/function/Predicate;)Lnet/minecraft/entity/player/PlayerEntity;"))
|
||||||
|
private @Nullable Predicate<Entity> addMinionPredicate(@Nullable Predicate<Entity> targetPredicate) {
|
||||||
|
Predicate<Entity> predicate = EntityViewMixinHelper.ADDITIONAL_PREDICATE.get();
|
||||||
|
if(targetPredicate != null) {
|
||||||
|
return predicate.and(targetPredicate);
|
||||||
|
} else {
|
||||||
|
return predicate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package io.github.skippyall.minions.mixins;
|
||||||
|
|
||||||
|
import com.llamalad7.mixinextras.sugar.Local;
|
||||||
|
import eu.pb4.graves.grave.Grave;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||||
|
|
||||||
|
@Mixin(Grave.class)
|
||||||
|
public class GraveCompatMixin {
|
||||||
|
@ModifyArg(method = "createBlock", at = @At(value = "INVOKE", target = "Leu/pb4/graves/grave/Grave;<init>(JLcom/mojang/authlib/GameProfile;BLnet/minecraft/util/Arm;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/Identifier;Leu/pb4/graves/grave/GraveType;JJILnet/minecraft/text/Text;Ljava/util/Collection;Ljava/util/Collection;ZI)V"))
|
||||||
|
private static boolean createGrave(boolean profile, @Local(argsOnly = true) ServerPlayerEntity player) {
|
||||||
|
if(player instanceof MinionFakePlayer) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return profile;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package io.github.skippyall.minions.mixins;
|
||||||
|
|
||||||
|
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Mixin(MinecraftServer.class)
|
||||||
|
public class MinecraftServerMixin {
|
||||||
|
@ModifyExpressionValue(method = "createMetadataPlayers", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;getPlayerList()Ljava/util/List;"))
|
||||||
|
public List<ServerPlayerEntity> ignoreFakePlayers(List<ServerPlayerEntity> original) {
|
||||||
|
return original.stream()
|
||||||
|
.filter(player -> !(player instanceof MinionFakePlayer))
|
||||||
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package io.github.skippyall.minions.mixins;
|
||||||
|
|
||||||
|
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||||
|
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import io.github.skippyall.minions.mixinhelper.EntityViewMixinHelper;
|
||||||
|
import io.github.skippyall.minions.module.MobSpawningModule;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.mob.MobEntity;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
|
||||||
|
@Mixin(MobEntity.class)
|
||||||
|
public abstract class MobEntityMixin {
|
||||||
|
@WrapOperation(method = "checkDespawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getClosestPlayer(Lnet/minecraft/entity/Entity;D)Lnet/minecraft/entity/player/PlayerEntity;"))
|
||||||
|
public PlayerEntity checkMobDespawningMinion(World instance, Entity entity, double maxDistance, Operation<PlayerEntity> original) {
|
||||||
|
EntityViewMixinHelper.ADDITIONAL_PREDICATE.set(entity2 -> {
|
||||||
|
if(entity2 instanceof MinionFakePlayer minion) {
|
||||||
|
return MobSpawningModule.canMinionDespawnMobs(minion);
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
PlayerEntity player = original.call(instance, entity, maxDistance);
|
||||||
|
EntityViewMixinHelper.ADDITIONAL_PREDICATE.remove();
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
}
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
package io.github.skippyall.minions.mixins;
|
||||||
|
|
||||||
|
import com.llamalad7.mixinextras.sugar.Local;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||||
|
|
||||||
|
@Mixin(PlayerListS2CPacket.Entry.class)
|
||||||
|
public class PlayerListEntryS2CPacket$EntryMixin {
|
||||||
|
@ModifyArg(method = "<init>(Lnet/minecraft/server/network/ServerPlayerEntity;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/s2c/play/PlayerListS2CPacket$Entry;<init>(Ljava/util/UUID;Lcom/mojang/authlib/GameProfile;ZILnet/minecraft/world/GameMode;Lnet/minecraft/text/Text;ZILnet/minecraft/network/encryption/PublicPlayerSession$Serialized;)V"), index = 2)
|
||||||
|
private static boolean removeMinionFromTabList(boolean original, @Local(argsOnly = true) ServerPlayerEntity player) {
|
||||||
|
if(player instanceof MinionFakePlayer) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return original;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,13 @@
|
|||||||
|
//partially code from https://github.com/gnembon/fabric-carpet
|
||||||
package io.github.skippyall.minions.mixins;
|
package io.github.skippyall.minions.mixins;
|
||||||
|
|
||||||
|
import com.llamalad7.mixinextras.injector.ModifyReceiver;
|
||||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||||
|
import com.llamalad7.mixinextras.sugar.Local;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
import io.github.skippyall.minions.fakeplayer.NetHandlerPlayServerFake;
|
import io.github.skippyall.minions.minion.fakeplayer.NetHandlerPlayServerFake;
|
||||||
import net.minecraft.nbt.NbtCompound;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.network.ClientConnection;
|
import net.minecraft.network.ClientConnection;
|
||||||
import net.minecraft.network.packet.c2s.common.SyncedClientOptions;
|
import net.minecraft.network.packet.c2s.common.SyncedClientOptions;
|
||||||
@@ -14,13 +17,16 @@ import net.minecraft.server.network.ConnectedClientData;
|
|||||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import net.minecraft.text.Text;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Mixin(PlayerManager.class)
|
@Mixin(PlayerManager.class)
|
||||||
public class PlayerListMixin {
|
public class PlayerListMixin {
|
||||||
|
|
||||||
@@ -46,8 +52,22 @@ public class PlayerListMixin {
|
|||||||
@WrapOperation(method = "respawnPlayer", at = @At(value = "NEW", target = "(Lnet/minecraft/server/MinecraftServer;Lnet/minecraft/server/world/ServerWorld;Lcom/mojang/authlib/GameProfile;Lnet/minecraft/network/packet/c2s/common/SyncedClientOptions;)Lnet/minecraft/server/network/ServerPlayerEntity;"))
|
@WrapOperation(method = "respawnPlayer", at = @At(value = "NEW", target = "(Lnet/minecraft/server/MinecraftServer;Lnet/minecraft/server/world/ServerWorld;Lcom/mojang/authlib/GameProfile;Lnet/minecraft/network/packet/c2s/common/SyncedClientOptions;)Lnet/minecraft/server/network/ServerPlayerEntity;"))
|
||||||
public ServerPlayerEntity makePlayerForRespawn(MinecraftServer minecraftServer, ServerWorld serverLevel, GameProfile gameProfile, SyncedClientOptions clientInformation, Operation<ServerPlayerEntity> original, ServerPlayerEntity serverPlayer, boolean bl) {
|
public ServerPlayerEntity makePlayerForRespawn(MinecraftServer minecraftServer, ServerWorld serverLevel, GameProfile gameProfile, SyncedClientOptions clientInformation, Operation<ServerPlayerEntity> original, ServerPlayerEntity serverPlayer, boolean bl) {
|
||||||
if (serverPlayer instanceof MinionFakePlayer minion) {
|
if (serverPlayer instanceof MinionFakePlayer minion) {
|
||||||
return MinionFakePlayer.respawnFake(minecraftServer, serverLevel, gameProfile, clientInformation, minion.isProgrammable());
|
return MinionFakePlayer.respawnFake(minecraftServer, serverLevel, gameProfile, clientInformation, minion.getData());
|
||||||
}
|
}
|
||||||
return original.call(minecraftServer, serverLevel, gameProfile, clientInformation);
|
return original.call(minecraftServer, serverLevel, gameProfile, clientInformation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@WrapOperation(method = "onPlayerConnect", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V"))
|
||||||
|
public void noLoginMessage(PlayerManager instance, Text message, boolean overlay, Operation<Void> original, @Local(argsOnly = true) ServerPlayerEntity player) {
|
||||||
|
if(!(player instanceof MinionFakePlayer)) {
|
||||||
|
original.call(instance, message, overlay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ModifyReceiver(method = "checkCanJoin", at = @At(value = "INVOKE", target = "Ljava/util/List;size()I"))
|
||||||
|
public List<ServerPlayerEntity> noMinionCounting(List<ServerPlayerEntity> instance) {
|
||||||
|
return instance.stream()
|
||||||
|
.filter(player -> !(player instanceof MinionFakePlayer))
|
||||||
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package io.github.skippyall.minions.mixins;
|
||||||
|
|
||||||
|
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||||
|
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import net.minecraft.server.PlayerManager;
|
||||||
|
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
|
||||||
|
@Mixin(ServerPlayNetworkHandler.class)
|
||||||
|
public class ServerPlayNetworkHandlerMixin {
|
||||||
|
@Shadow
|
||||||
|
public ServerPlayerEntity player;
|
||||||
|
|
||||||
|
@WrapOperation(method = "cleanUp", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V"))
|
||||||
|
public void noLogoutMessage(PlayerManager instance, Text message, boolean overlay, Operation<Void> original) {
|
||||||
|
if(!(player instanceof MinionFakePlayer)) {
|
||||||
|
original.call(instance, message, overlay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package io.github.skippyall.minions.mixins;
|
package io.github.skippyall.minions.mixins;
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import io.github.skippyall.minions.fakeplayer.EntityPlayerActionPack;
|
import io.github.skippyall.minions.minion.fakeplayer.EntityPlayerActionPack;
|
||||||
import io.github.skippyall.minions.fakeplayer.ServerPlayerInterface;
|
import io.github.skippyall.minions.minion.fakeplayer.ServerPlayerInterface;
|
||||||
import net.minecraft.network.packet.c2s.common.SyncedClientOptions;
|
import net.minecraft.network.packet.c2s.common.SyncedClientOptions;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
@@ -18,7 +18,7 @@ public abstract class ServerPlayerMixin implements ServerPlayerInterface {
|
|||||||
@Unique
|
@Unique
|
||||||
public EntityPlayerActionPack actionPack;
|
public EntityPlayerActionPack actionPack;
|
||||||
@Override
|
@Override
|
||||||
public EntityPlayerActionPack getActionPack()
|
public EntityPlayerActionPack minions$getActionPack()
|
||||||
{
|
{
|
||||||
return actionPack;
|
return actionPack;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package io.github.skippyall.minions.mixins;
|
||||||
|
|
||||||
|
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||||
|
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.server.world.SleepManager;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
|
||||||
|
@Mixin(SleepManager.class)
|
||||||
|
public class SleepManagerMixin {
|
||||||
|
@WrapOperation(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;isSpectator()Z"))
|
||||||
|
public boolean excludeMinions(ServerPlayerEntity instance, Operation<Boolean> original) {
|
||||||
|
if (instance instanceof MinionFakePlayer) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return original.call(instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package io.github.skippyall.minions.mixins;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import io.github.skippyall.minions.module.MobSpawningModule;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.predicate.entity.EntityPredicates;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.server.world.ServerWorld;
|
||||||
|
import net.minecraft.world.SpawnHelper;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
|
||||||
|
@Mixin(SpawnHelper.class)
|
||||||
|
public class SpawnHelperMixin {
|
||||||
|
@Redirect(method = "spawnEntitiesInChunk(Lnet/minecraft/entity/SpawnGroup;Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/world/chunk/Chunk;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/world/SpawnHelper$Checker;Lnet/minecraft/world/SpawnHelper$Runner;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;getClosestPlayer(DDDDZ)Lnet/minecraft/entity/player/PlayerEntity;"))
|
||||||
|
private static PlayerEntity checkMobSpawningMinion(ServerWorld instance, double x, double y, double z, double maxDistance, boolean b) {
|
||||||
|
return instance.getClosestPlayer(x, y, z, maxDistance, EntityPredicates.EXCEPT_SPECTATOR.and(entity -> {
|
||||||
|
if(entity instanceof ServerPlayerEntity player) {
|
||||||
|
if(player instanceof MinionFakePlayer minion) {
|
||||||
|
return MobSpawningModule.canMinionSpawnMobs(minion);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
+86
@@ -0,0 +1,86 @@
|
|||||||
|
package io.github.skippyall.minions.mixins.antimobcap;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import io.github.skippyall.minions.mixinhelper.ChunkLevelManager$DistanceFromNearestPlayerTrackerAccessor;
|
||||||
|
import io.github.skippyall.minions.mixinhelper.ChunkLevelManagerAccessor;
|
||||||
|
import io.github.skippyall.minions.module.MobSpawningModule;
|
||||||
|
import it.unimi.dsi.fastutil.longs.Long2ByteMap;
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectSet;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.server.world.ChunkLevelManager;
|
||||||
|
import net.minecraft.server.world.ChunkTicketManager;
|
||||||
|
import org.spongepowered.asm.mixin.Final;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
@Mixin(value = ChunkLevelManager.DistanceFromNearestPlayerTracker.class)
|
||||||
|
public abstract class ChunkLevelManager$DistanceFromNearestPlayerTrackerMixin extends ChunkPosDistanceLevelPropagatorMixin implements ChunkLevelManager$DistanceFromNearestPlayerTrackerAccessor {
|
||||||
|
@Final
|
||||||
|
@Shadow
|
||||||
|
ChunkLevelManager field_17462;
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
@Final
|
||||||
|
protected Long2ByteMap distanceFromNearestPlayer;
|
||||||
|
|
||||||
|
@Shadow protected abstract boolean isPlayerInChunk(long chunkPos);
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
boolean minions$minionless, minions$target;
|
||||||
|
|
||||||
|
@Inject(method = "isPlayerInChunk", at = @At("RETURN"), cancellable = true)
|
||||||
|
public void minions$filterMinions(long chunkPos, CallbackInfoReturnable<Boolean> cir) {
|
||||||
|
if (minions$minionless) {
|
||||||
|
cir.setReturnValue(minions$isRealPlayerInChunk(chunkPos));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean minions$isRealPlayerInChunk(long chunkPos) {
|
||||||
|
ObjectSet<ServerPlayerEntity> players = ((ChunkLevelManagerAccessor)field_17462).minions$getPlayers(chunkPos);
|
||||||
|
boolean contains = false;
|
||||||
|
if(players != null) {
|
||||||
|
contains = players.stream().anyMatch(player -> {
|
||||||
|
if (player instanceof MinionFakePlayer minion) {
|
||||||
|
return MobSpawningModule.canMinionSpawnMobs(minion);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return contains;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "updateLevels", at = @At("HEAD"))
|
||||||
|
public void minions$sync(CallbackInfo info) {
|
||||||
|
if (minions$target) {
|
||||||
|
((ChunkLevelManagerAccessor)field_17462).minions$getMinionless().updateLevels();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void minions$updateLevel(long chunkPos, int distance, boolean decrease, CallbackInfo info) {
|
||||||
|
if (minions$target && (distance == Integer.MAX_VALUE || minions$isRealPlayerInChunk(chunkPos))) {
|
||||||
|
((ChunkLevelManagerAccessor)field_17462).minions$getMinionless().updateLevel(chunkPos, distance, decrease);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void minions$markAsMinionless() {
|
||||||
|
minions$minionless = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void minions$markAsTarget() {
|
||||||
|
minions$target = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int minions$getTickedChunkCount() {
|
||||||
|
return distanceFromNearestPlayer.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
+52
@@ -0,0 +1,52 @@
|
|||||||
|
package io.github.skippyall.minions.mixins.antimobcap;
|
||||||
|
|
||||||
|
import com.llamalad7.mixinextras.sugar.Local;
|
||||||
|
import io.github.skippyall.minions.mixinhelper.ChunkLevelManager$DistanceFromNearestPlayerTrackerAccessor;
|
||||||
|
import io.github.skippyall.minions.mixinhelper.ChunkLevelManagerAccessor;
|
||||||
|
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectSet;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.server.world.ChunkLevelManager;
|
||||||
|
import net.minecraft.server.world.ChunkTicketManager;
|
||||||
|
import net.minecraft.util.math.ChunkSectionPos;
|
||||||
|
import org.spongepowered.asm.mixin.Final;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
|
@Mixin(ChunkLevelManager.class)
|
||||||
|
public class ChunkLevelManagerMixin implements ChunkLevelManagerAccessor {
|
||||||
|
@Shadow @Final private Long2ObjectMap<ObjectSet<ServerPlayerEntity>> playersByChunkPos;
|
||||||
|
@Shadow @Final private ChunkLevelManager.DistanceFromNearestPlayerTracker distanceFromNearestPlayerTracker;
|
||||||
|
@Unique
|
||||||
|
ChunkLevelManager.DistanceFromNearestPlayerTracker minionless;
|
||||||
|
|
||||||
|
@Inject(method = "<init>", at = @At("RETURN"))
|
||||||
|
public void createMinionlessClone(ChunkTicketManager ticketManager, Executor executor, Executor mainThreadExecutor, CallbackInfo ci) {
|
||||||
|
ChunkLevelManager manager = ((ChunkLevelManager)(Object)this);
|
||||||
|
minionless = manager.new DistanceFromNearestPlayerTracker(8);
|
||||||
|
((ChunkLevelManager$DistanceFromNearestPlayerTrackerAccessor)minionless).minions$markAsMinionless();
|
||||||
|
((ChunkLevelManager$DistanceFromNearestPlayerTrackerAccessor)distanceFromNearestPlayerTracker).minions$markAsTarget();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectSet<ServerPlayerEntity> minions$getPlayers(long chunkpos) {
|
||||||
|
return playersByChunkPos.get(chunkpos);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChunkLevelManager.DistanceFromNearestPlayerTracker minions$getMinionless() {
|
||||||
|
return minionless;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "handleChunkLeave", at = @At(value = "INVOKE", target = "Lit/unimi/dsi/fastutil/objects/ObjectSet;remove(Ljava/lang/Object;)Z", shift = At.Shift.AFTER, remap = false))
|
||||||
|
public void minion$updateMinionlessIfNoMinionInChunk(ChunkSectionPos pos, ServerPlayerEntity player, CallbackInfo ci, @Local long chunk) {
|
||||||
|
if (!((ChunkLevelManager$DistanceFromNearestPlayerTrackerAccessor)minionless).minions$isRealPlayerInChunk(chunk)) {
|
||||||
|
minionless.updateLevel(chunk, Integer.MAX_VALUE, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
package io.github.skippyall.minions.mixins.antimobcap;
|
||||||
|
|
||||||
|
import net.minecraft.server.world.ChunkPosDistanceLevelPropagator;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
@Mixin(ChunkPosDistanceLevelPropagator.class)
|
||||||
|
public class ChunkPosDistanceLevelPropagatorMixin {
|
||||||
|
@Inject(method = "updateLevel", at = @At("HEAD"))
|
||||||
|
public void minions$updateLevel(long chunkPos, int distance, boolean decrease, CallbackInfo info) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package io.github.skippyall.minions.mixins.antimobcap;
|
||||||
|
|
||||||
|
import net.minecraft.server.world.ChunkTicketManager;
|
||||||
|
import net.minecraft.server.world.ServerChunkManager;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
|
|
||||||
|
@Mixin(ServerChunkManager.class)
|
||||||
|
public interface ServerChunkManagerAccessor {
|
||||||
|
@Accessor
|
||||||
|
ChunkTicketManager getTicketManager();
|
||||||
|
}
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
package io.github.skippyall.minions.mixins.antimobcap;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.mixinhelper.ChunkLevelManager$DistanceFromNearestPlayerTrackerAccessor;
|
||||||
|
import io.github.skippyall.minions.mixinhelper.ChunkLevelManagerAccessor;
|
||||||
|
import net.minecraft.server.world.ChunkLevelManager;
|
||||||
|
import net.minecraft.server.world.ChunkTicketManager;
|
||||||
|
import net.minecraft.server.world.ServerChunkManager;
|
||||||
|
import org.spongepowered.asm.mixin.Final;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||||
|
|
||||||
|
@Mixin(ServerChunkManager.class)
|
||||||
|
public class ServerChunkManagerMixin {
|
||||||
|
@Shadow
|
||||||
|
@Final
|
||||||
|
private ChunkLevelManager levelManager;
|
||||||
|
|
||||||
|
@ModifyArg(method = "tickChunks(Lnet/minecraft/util/profiler/Profiler;J)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/SpawnHelper;setupSpawn(ILjava/lang/Iterable;Lnet/minecraft/world/SpawnHelper$ChunkSource;Lnet/minecraft/world/SpawnDensityCapper;)Lnet/minecraft/world/SpawnHelper$Info;"))
|
||||||
|
public int useMinionless(int spawningChunkCount) {
|
||||||
|
return ((ChunkLevelManager$DistanceFromNearestPlayerTrackerAccessor)((ChunkLevelManagerAccessor)levelManager).minions$getMinionless()).minions$getTickedChunkCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package io.github.skippyall.minions.module;
|
||||||
|
|
||||||
|
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||||
|
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||||
|
import io.github.skippyall.minions.module.command.CommandExecutor;
|
||||||
|
import io.github.skippyall.minions.input.TextInput;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.EntityPlayerActionPack;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.screen.ScreenHandlerType;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
public class ActionModules {
|
||||||
|
public static void executeOnce(EntityPlayerActionPack.ActionType actionType, ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||||
|
minion.getMinionActionPack().start(actionType, EntityPlayerActionPack.Action.once());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void executeContinuous(EntityPlayerActionPack.ActionType actionType, ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||||
|
minion.getMinionActionPack().start(actionType, EntityPlayerActionPack.Action.continuous());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void executeInterval(EntityPlayerActionPack.ActionType actionType, ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||||
|
TextInput.inputFloat(player, Text.translatable("minions.command.action.interval.enter"), "3.5").thenAccept(interval -> {
|
||||||
|
int ticks = Math.round(interval * 20);
|
||||||
|
minion.getMinionActionPack().start(actionType, EntityPlayerActionPack.Action.interval(ticks));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void executeStop(EntityPlayerActionPack.ActionType actionType, ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||||
|
minion.getMinionActionPack().stop(actionType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CommandExecutor detailSelectionExecutor(EntityPlayerActionPack.ActionType actionType, Text actionName) {
|
||||||
|
return (player, minion) -> {
|
||||||
|
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_3X3, player, false);
|
||||||
|
gui.setTitle(Text.translatable("minions.command.action.details", actionName));
|
||||||
|
|
||||||
|
gui.setSlot(1, new GuiElementBuilder()
|
||||||
|
.setItem(Items.COMMAND_BLOCK)
|
||||||
|
.setName(Text.translatable("minions.command.action.once", actionName))
|
||||||
|
.setCallback(() -> executeOnce(actionType, player, minion))
|
||||||
|
);
|
||||||
|
gui.setSlot(3, new GuiElementBuilder()
|
||||||
|
.setItem(Items.REPEATING_COMMAND_BLOCK)
|
||||||
|
.setName(Text.translatable("minions.command.action.continuous", actionName))
|
||||||
|
.setCallback(() -> executeContinuous(actionType, player, minion))
|
||||||
|
);
|
||||||
|
gui.setSlot(5, new GuiElementBuilder()
|
||||||
|
.setItem(Items.CHAIN_COMMAND_BLOCK)
|
||||||
|
.setName(Text.translatable("minions.command.action.interval", actionName))
|
||||||
|
.setCallback(() -> executeInterval(actionType, player, minion))
|
||||||
|
);
|
||||||
|
gui.setSlot(4, new GuiElementBuilder()
|
||||||
|
.setItem(Items.BARRIER)
|
||||||
|
.setName(Text.translatable("minions.command.action.stop", actionName))
|
||||||
|
.setCallback(() -> executeStop(actionType, player, minion))
|
||||||
|
);
|
||||||
|
gui.open();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package io.github.skippyall.minions.module;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.Minions;
|
||||||
|
import io.github.skippyall.minions.module.command.SimpleCommand;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.EntityPlayerActionPack;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static io.github.skippyall.minions.module.Modules.register;
|
||||||
|
|
||||||
|
public class AttackModule {
|
||||||
|
public static final SimpleCommand ATTACK_COMMAND = new SimpleCommand(
|
||||||
|
Text.translatable("minions.command.attack.name"),
|
||||||
|
Text.translatable("minions.command.attack.description"),
|
||||||
|
Items.DIAMOND_PICKAXE,
|
||||||
|
ActionModules.detailSelectionExecutor(EntityPlayerActionPack.ActionType.ATTACK, Text.translatable("minions.command.attack.name"))
|
||||||
|
);
|
||||||
|
|
||||||
|
public static final SimpleModuleItem ATTACK_MODULE = register(
|
||||||
|
Identifier.of(Minions.MOD_ID, "attack_module"),
|
||||||
|
List.of(),
|
||||||
|
List.of(ATTACK_COMMAND),
|
||||||
|
Items.DIAMOND_PICKAXE
|
||||||
|
);
|
||||||
|
|
||||||
|
public static void registerMe() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package io.github.skippyall.minions.module;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.Minions;
|
||||||
|
import io.github.skippyall.minions.module.command.SimpleCommand;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import static io.github.skippyall.minions.module.Modules.register;
|
||||||
|
|
||||||
|
public class ChatModule {
|
||||||
|
public static final SimpleModuleItem CHAT_MODULE = register(Identifier.of(Minions.MOD_ID, "chat_module"),
|
||||||
|
new ArrayList<>(), Arrays.asList(
|
||||||
|
new SimpleCommand(Text.of("Message"), Text.of("Send Message in Public Chat"), Items.PAPER, (player, minion) -> minion.getServer().getPlayerManager().broadcast(Text.of("message"), true)),
|
||||||
|
new SimpleCommand(Text.of("Prvt-Message"), Text.of("Send Message to one Person"), Items.TRIAL_KEY, (player, minion) -> {})
|
||||||
|
), Items.PAPER);
|
||||||
|
|
||||||
|
public static void registerMe() {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package io.github.skippyall.minions.module;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.Minions;
|
||||||
|
import io.github.skippyall.minions.module.command.SimpleCommand;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.EntityPlayerActionPack;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static io.github.skippyall.minions.module.Modules.register;
|
||||||
|
|
||||||
|
public class InteractModule {
|
||||||
|
public static final SimpleCommand INTERACT_COMMAND = new SimpleCommand(
|
||||||
|
Text.translatable("minions.command.interact.name"),
|
||||||
|
Text.translatable("minions.command.interact.description"),
|
||||||
|
Items.LEVER,
|
||||||
|
ActionModules.detailSelectionExecutor(EntityPlayerActionPack.ActionType.USE, Text.translatable("minions.command.interact.name"))
|
||||||
|
);
|
||||||
|
|
||||||
|
public static final SimpleModuleItem INTERACT_MODULE = register(
|
||||||
|
Identifier.of(Minions.MOD_ID, "interact_module"),
|
||||||
|
List.of(),
|
||||||
|
List.of(INTERACT_COMMAND),
|
||||||
|
Items.LEVER
|
||||||
|
);
|
||||||
|
|
||||||
|
public static void registerMe() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package io.github.skippyall.minions.module;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.Minions;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static io.github.skippyall.minions.module.Modules.register;
|
||||||
|
|
||||||
|
public class MobSpawningModule {
|
||||||
|
public static final SimpleModuleItem MOB_SPAWNING_MODULE =
|
||||||
|
register(
|
||||||
|
Identifier.of(Minions.MOD_ID, "mob_spawning_module"),
|
||||||
|
List.of(),
|
||||||
|
List.of(),
|
||||||
|
Items.SPAWNER
|
||||||
|
);
|
||||||
|
|
||||||
|
public static boolean canMinionSpawnMobs(MinionFakePlayer minion) {
|
||||||
|
return minion.getModuleInventory().hasModule(MOB_SPAWNING_MODULE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean canMinionDespawnMobs(MinionFakePlayer minion) {
|
||||||
|
return minion.getModuleInventory().hasModule(MOB_SPAWNING_MODULE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerMe() {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package io.github.skippyall.minions.module;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.module.command.Command;
|
||||||
|
import io.github.skippyall.minions.program.block.CodeBlock;
|
||||||
|
import net.minecraft.item.ItemConvertible;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface ModuleItem extends ItemConvertible {
|
||||||
|
List<CodeBlock<?,?>> getCodeBlocks();
|
||||||
|
|
||||||
|
List<Command> getCommands();
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package io.github.skippyall.minions.module;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.MinionItems;
|
||||||
|
import io.github.skippyall.minions.module.command.Command;
|
||||||
|
import io.github.skippyall.minions.program.block.CodeBlock;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.registry.Registries;
|
||||||
|
import net.minecraft.registry.Registry;
|
||||||
|
import net.minecraft.registry.RegistryKey;
|
||||||
|
import net.minecraft.registry.RegistryKeys;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Modules {
|
||||||
|
public static void register() {
|
||||||
|
ChatModule.registerMe();
|
||||||
|
MountModule.registerMe();
|
||||||
|
MoveModule.registerMe();
|
||||||
|
MobSpawningModule.registerMe();
|
||||||
|
InteractModule.registerMe();
|
||||||
|
AttackModule.registerMe();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SimpleModuleItem register(Identifier id, List<CodeBlock<?,?>> codeBlocks, List<Command> commands, Item vanillaItem) {
|
||||||
|
return MinionItems.registerItem(id, settings -> new SimpleModuleItem(codeBlocks, commands, settings, vanillaItem));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package io.github.skippyall.minions.module;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.Minions;
|
||||||
|
import io.github.skippyall.minions.module.command.SimpleCommand;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static io.github.skippyall.minions.module.Modules.register;
|
||||||
|
|
||||||
|
public class MountModule {
|
||||||
|
public static final SimpleCommand MOUNT_COMMAND = new SimpleCommand(
|
||||||
|
Text.of("Mount"),
|
||||||
|
Text.of("Mount the minion to the nearest mountable Entity"),
|
||||||
|
Items.MINECART,
|
||||||
|
(player, minion) -> minion.getMinionActionPack().mount(true)
|
||||||
|
);
|
||||||
|
|
||||||
|
public static final SimpleCommand DISMOUNT_COMMAND = new SimpleCommand(
|
||||||
|
Text.of("Dismount"),
|
||||||
|
Text.of("Dismount the minion"),
|
||||||
|
Items.BARRIER,
|
||||||
|
(player, minion) -> minion.getMinionActionPack().dismount()
|
||||||
|
);
|
||||||
|
|
||||||
|
public static final SimpleModuleItem MOUNT_MODULE =
|
||||||
|
register(Identifier.of(Minions.MOD_ID, "mount_module"),
|
||||||
|
List.of(),
|
||||||
|
List.of(
|
||||||
|
MOUNT_COMMAND,
|
||||||
|
DISMOUNT_COMMAND
|
||||||
|
),
|
||||||
|
Items.MINECART
|
||||||
|
);
|
||||||
|
|
||||||
|
public static void registerMe() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package io.github.skippyall.minions.module;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.Minions;
|
||||||
|
import io.github.skippyall.minions.module.command.SimpleCommand;
|
||||||
|
import io.github.skippyall.minions.input.TextInput;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static io.github.skippyall.minions.module.Modules.register;
|
||||||
|
|
||||||
|
public class MoveModule {
|
||||||
|
public static final SimpleCommand WALK_COMMAND =
|
||||||
|
new SimpleCommand(
|
||||||
|
Text.literal("Walk"),
|
||||||
|
Text.literal("Walk a specific amount of blocks forward"),
|
||||||
|
Items.IRON_BOOTS,
|
||||||
|
(player, minion) -> TextInput.inputFloat(player, Text.literal("Amount of Blocks"), "1")
|
||||||
|
.thenAccept(minion::moveForward)
|
||||||
|
);
|
||||||
|
|
||||||
|
public static final SimpleCommand TURN_RIGHT_COMMAND =
|
||||||
|
new SimpleCommand(
|
||||||
|
Text.literal("Turn Right"),
|
||||||
|
Text.literal("Turn a specific amount of degrees right"),
|
||||||
|
Items.COMPASS,
|
||||||
|
(player, minion) -> TextInput.inputFloat(player, Text.literal("Degrees"), "90")
|
||||||
|
.thenAccept(degrees -> minion.getMinionActionPack().turn(degrees, 0))
|
||||||
|
);
|
||||||
|
|
||||||
|
public static final SimpleCommand TURN_LEFT_COMMAND =
|
||||||
|
new SimpleCommand(
|
||||||
|
Text.literal("Turn Left"),
|
||||||
|
Text.literal("Turn a specific amount of degrees left"),
|
||||||
|
Items.COMPASS,
|
||||||
|
(player, minion) -> TextInput.inputFloat(player, Text.literal("Degrees"), "90")
|
||||||
|
.thenAccept(degrees -> minion.getMinionActionPack().turn(-degrees, 0))
|
||||||
|
);
|
||||||
|
|
||||||
|
public static final SimpleCommand TURN_UP_COMMAND =
|
||||||
|
new SimpleCommand(
|
||||||
|
Text.literal("Turn Up"),
|
||||||
|
Text.literal("Turn a specific amount of degrees up"),
|
||||||
|
Items.COMPASS,
|
||||||
|
(player, minion) -> TextInput.inputFloat(player, Text.literal("Degrees"), "90")
|
||||||
|
.thenAccept(degrees -> minion.getMinionActionPack().turn(0, -degrees))
|
||||||
|
);
|
||||||
|
|
||||||
|
public static final SimpleCommand TURN_DOWN_COMMAND =
|
||||||
|
new SimpleCommand(
|
||||||
|
Text.literal("Turn Down"),
|
||||||
|
Text.literal("Turn a specific amount of degrees down"),
|
||||||
|
Items.COMPASS,
|
||||||
|
(player, minion) -> TextInput.inputFloat(player, Text.literal("Degrees"), "90")
|
||||||
|
.thenAccept(degrees -> minion.getMinionActionPack().turn(0, degrees))
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static final SimpleModuleItem MOVE_MODULE =
|
||||||
|
register(Identifier.of(Minions.MOD_ID, "move_module"),
|
||||||
|
List.of(),
|
||||||
|
List.of(
|
||||||
|
WALK_COMMAND,
|
||||||
|
TURN_RIGHT_COMMAND,
|
||||||
|
TURN_LEFT_COMMAND,
|
||||||
|
TURN_UP_COMMAND,
|
||||||
|
TURN_DOWN_COMMAND
|
||||||
|
),
|
||||||
|
Items.IRON_BOOTS
|
||||||
|
);
|
||||||
|
|
||||||
|
public static void registerMe() {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package io.github.skippyall.minions.module;
|
||||||
|
|
||||||
|
import eu.pb4.polymer.core.api.item.SimplePolymerItem;
|
||||||
|
import io.github.skippyall.minions.module.command.Command;
|
||||||
|
import io.github.skippyall.minions.program.block.CodeBlock;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class SimpleModuleItem extends SimplePolymerItem implements ModuleItem {
|
||||||
|
private final List<CodeBlock<?,?>> codeBlocks;
|
||||||
|
private final List<Command> commands;
|
||||||
|
|
||||||
|
public SimpleModuleItem(List<CodeBlock<?,?>> codeBlocks, List<Command> commands, Settings settings, Item vanillaItem) {
|
||||||
|
super(settings.maxCount(1), vanillaItem);
|
||||||
|
this.codeBlocks = codeBlocks;
|
||||||
|
this.commands = commands;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CodeBlock<?, ?>> getCodeBlocks() {
|
||||||
|
return codeBlocks;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Command> getCommands() {
|
||||||
|
return commands;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package io.github.skippyall.minions.module.command;
|
||||||
|
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
public interface Command extends CommandExecutor {
|
||||||
|
Text getName();
|
||||||
|
Text getDescription();
|
||||||
|
Item getItemRepresentation();
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package io.github.skippyall.minions.module.command;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
|
||||||
|
public interface CommandExecutor {
|
||||||
|
void execute(ServerPlayerEntity player, MinionFakePlayer minion);
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package io.github.skippyall.minions.module.command;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
public class SimpleCommand implements Command {
|
||||||
|
private final Text name;
|
||||||
|
private final Text description;
|
||||||
|
private final Item itemRepresentation;
|
||||||
|
private final CommandExecutor executor;
|
||||||
|
|
||||||
|
public SimpleCommand(Text name, Text description, Item itemRepresentation, CommandExecutor executor) {
|
||||||
|
this.name = name;
|
||||||
|
this.description = description;
|
||||||
|
this.itemRepresentation = itemRepresentation;
|
||||||
|
this.executor = executor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Text getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Text getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Item getItemRepresentation() {
|
||||||
|
return itemRepresentation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||||
|
executor.execute(player, minion);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package io.github.skippyall.minions.networking;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.Minions;
|
|
||||||
import io.netty.buffer.Unpooled;
|
|
||||||
import net.fabricmc.api.EnvType;
|
|
||||||
import net.fabricmc.api.Environment;
|
|
||||||
import net.fabricmc.fabric.api.client.networking.v1.ClientConfigurationNetworking;
|
|
||||||
import net.fabricmc.fabric.api.networking.v1.PacketSender;
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
|
||||||
import net.minecraft.client.network.ClientConfigurationNetworkHandler;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.network.PacketByteBuf;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.server.network.ServerConfigurationNetworkHandler;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
|
|
||||||
public class ClientToServerNetworking {
|
|
||||||
public static final Identifier RL = new Identifier(Minions.MOD_ID, "network");
|
|
||||||
@Environment(EnvType.CLIENT)
|
|
||||||
public static void sendJoinPacket(PlayerEntity player) {
|
|
||||||
PacketByteBuf pbf = new PacketByteBuf(Unpooled.buffer());
|
|
||||||
pbf.writeString("BN|Init|V0.1");
|
|
||||||
ClientConfigurationNetworking.send(RL, pbf);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Environment(EnvType.CLIENT)
|
|
||||||
public static void onConfigurationInit(ClientConfigurationNetworkHandler handler, MinecraftClient client) {
|
|
||||||
sendJoinPacket(client.player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Environment(EnvType.SERVER)
|
|
||||||
public static void receive(MinecraftServer server, ServerConfigurationNetworkHandler handler, PacketByteBuf buf, PacketSender responseSender) {
|
|
||||||
String message = buf.readString();
|
|
||||||
if (!message.startsWith("BN|")) {
|
|
||||||
Minions.LOGGER.debug("Message with wrong format: " + message);
|
|
||||||
}
|
|
||||||
String[] parts = message.split("|");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package io.github.skippyall.minions.networking;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
|
|
||||||
public class VersionChecker {
|
|
||||||
protected static List<UUID> hasSupportedMod = new ArrayList<>();
|
|
||||||
public static boolean supportVersion(String version) {
|
|
||||||
return version.equals("v0.1");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean useSupportedMod(PlayerEntity p) {
|
|
||||||
return hasSupportedMod.contains(p.getUuid());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void resetPlayer(UUID uuid) {
|
|
||||||
hasSupportedMod.remove(uuid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user