lots of code
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package io.github.skippyall.minions;
|
||||
|
||||
import eu.pb4.polymer.core.api.entity.PolymerEntityUtils;
|
||||
import io.github.skippyall.minions.minion.MinionItem;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.util.Identifier;
|
||||
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(Registries.ITEM, new Identifier(MOD_ID, "minion"), new MinionItem());
|
||||
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
PolymerEntityUtils.registerType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
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,7 @@
|
||||
package io.github.skippyall.minions.fakeplayer;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
|
||||
public interface ClientConnectionInterface {
|
||||
void setChannel(Channel channel);
|
||||
}
|
||||
@@ -0,0 +1,625 @@
|
||||
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.block.BlockState;
|
||||
import net.minecraft.command.argument.EntityAnchorArgumentType;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.decoration.ItemFrameEntity;
|
||||
import net.minecraft.entity.passive.AbstractHorseEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.entity.vehicle.BoatEntity;
|
||||
import net.minecraft.entity.vehicle.MinecartEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket;
|
||||
import net.minecraft.network.packet.s2c.play.UpdateSelectedSlotS2CPacket;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.hit.EntityHitResult;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec2f;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
public class EntityPlayerActionPack
|
||||
{
|
||||
private final ServerPlayerEntity 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(ServerPlayerEntity 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.setSneaking(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.getYaw(), -90);
|
||||
case DOWN -> look(player.getYaw(), 90);
|
||||
};
|
||||
}
|
||||
public EntityPlayerActionPack look(Vec2f rotation)
|
||||
{
|
||||
return look(rotation.x, rotation.y);
|
||||
}
|
||||
|
||||
public EntityPlayerActionPack look(float yaw, float pitch)
|
||||
{
|
||||
player.setYaw(yaw % 360); //setYaw
|
||||
player.setPitch(MathHelper.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(Vec3d position)
|
||||
{
|
||||
player.lookAt(EntityAnchorArgumentType.EntityAnchor.EYES, position);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityPlayerActionPack turn(float yaw, float pitch)
|
||||
{
|
||||
return look(player.getYaw() + yaw, player.getPitch() + pitch);
|
||||
}
|
||||
|
||||
public EntityPlayerActionPack turn(Vec2f 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.getWorld().getOtherEntities(player, player.getBoundingBox().expand(3.0D, 1.0D, 3.0D),
|
||||
e -> e instanceof MinecartEntity || e instanceof BoatEntity || e instanceof AbstractHorseEntity);
|
||||
}
|
||||
else
|
||||
{
|
||||
entities = player.getWorld().getOtherEntities(player, player.getBoundingBox().expand(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.squaredDistanceTo(e);
|
||||
if (dd<distance)
|
||||
{
|
||||
distance = dd;
|
||||
closest = e;
|
||||
}
|
||||
}
|
||||
if (closest == null) return this;
|
||||
if (closest instanceof AbstractHorseEntity && onlyRideables)
|
||||
((AbstractHorseEntity) closest).interactMob(player, Hand.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.forwardSpeed = forward * vel;
|
||||
}
|
||||
if (strafing != 0.0F || player instanceof MinionFakePlayer) {
|
||||
player.sidewaysSpeed = strafing * vel;
|
||||
}
|
||||
}
|
||||
|
||||
static HitResult getTarget(ServerPlayerEntity player)
|
||||
{
|
||||
double reach = player.interactionManager.isCreative() ? 5 : 4.5f;
|
||||
return Tracer.rayTrace(player, 1, reach, false);
|
||||
}
|
||||
|
||||
private void dropItemFromSlot(int slot, boolean dropAll)
|
||||
{
|
||||
PlayerInventory inv = player.getInventory(); // getInventory;
|
||||
if (!inv.getStack(slot).isEmpty())
|
||||
player.dropItem(inv.removeStack(slot,
|
||||
dropAll ? inv.getStack(slot).getCount() : 1
|
||||
), false, true); // scatter, keep owner
|
||||
}
|
||||
|
||||
public void drop(int selectedSlot, boolean dropAll)
|
||||
{
|
||||
PlayerInventory inv = player.getInventory(); // getInventory;
|
||||
if (selectedSlot == -2) // all
|
||||
{
|
||||
for (int i = inv.size(); i >= 0; i--)
|
||||
dropItemFromSlot(i, dropAll);
|
||||
}
|
||||
else // one slot
|
||||
{
|
||||
if (selectedSlot == -1)
|
||||
selectedSlot = inv.selectedSlot;
|
||||
dropItemFromSlot(selectedSlot, dropAll);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSlot(int slot)
|
||||
{
|
||||
player.getInventory().selectedSlot = slot-1;
|
||||
player.networkHandler.sendPacket(new UpdateSelectedSlotS2CPacket(slot-1));
|
||||
}
|
||||
|
||||
public enum ActionType
|
||||
{
|
||||
USE(true)
|
||||
{
|
||||
@Override
|
||||
boolean execute(ServerPlayerEntity 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 (Hand hand : Hand.values())
|
||||
{
|
||||
switch (hit.getType())
|
||||
{
|
||||
case BLOCK:
|
||||
{
|
||||
player.updateLastActionTime();
|
||||
ServerWorld world = player.getServerWorld();
|
||||
BlockHitResult blockHit = (BlockHitResult) hit;
|
||||
BlockPos pos = blockHit.getBlockPos();
|
||||
Direction side = blockHit.getSide();
|
||||
if (pos.getY() < player.getWorld().getTopY() - (side == Direction.UP ? 1 : 0) && world.canPlayerModifyAt(player, pos))
|
||||
{
|
||||
ActionResult result = player.interactionManager.interactBlock(player, world, player.getStackInHand(hand), hand, blockHit);
|
||||
if (result.isAccepted())
|
||||
{
|
||||
if (result.shouldSwingHand()) player.swingHand(hand);
|
||||
ap.itemUseCooldown = 3;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ENTITY:
|
||||
{
|
||||
player.updateLastActionTime();
|
||||
EntityHitResult entityHit = (EntityHitResult) hit;
|
||||
Entity entity = entityHit.getEntity();
|
||||
boolean handWasEmpty = player.getStackInHand(hand).isEmpty();
|
||||
boolean itemFrameEmpty = (entity instanceof ItemFrameEntity) && ((ItemFrameEntity) entity).getHeldItemStack().isEmpty();
|
||||
Vec3d relativeHitPos = entityHit.getPos().subtract(entity.getX(), entity.getY(), entity.getZ());
|
||||
if (entity.interactAt(player, relativeHitPos, hand).isAccepted())
|
||||
{
|
||||
ap.itemUseCooldown = 3;
|
||||
return true;
|
||||
}
|
||||
// fix for SS itemframe always returns CONSUME even if no action is performed
|
||||
if (player.interact(entity, hand).isAccepted() && !(handWasEmpty && itemFrameEmpty))
|
||||
{
|
||||
ap.itemUseCooldown = 3;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
ItemStack handItem = player.getStackInHand(hand);
|
||||
if (player.interactionManager.interactItem(player, player.getWorld(), handItem, hand).isAccepted())
|
||||
{
|
||||
ap.itemUseCooldown = 3;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
void inactiveTick(ServerPlayerEntity player, Action action)
|
||||
{
|
||||
EntityPlayerActionPack ap = ((ServerPlayerInterface) player).getActionPack();
|
||||
ap.itemUseCooldown = 0;
|
||||
player.stopUsingItem();
|
||||
}
|
||||
},
|
||||
ATTACK(true) {
|
||||
@Override
|
||||
boolean execute(ServerPlayerEntity player, Action action) {
|
||||
HitResult hit = getTarget(player);
|
||||
switch (hit.getType()) {
|
||||
case ENTITY: {
|
||||
EntityHitResult entityHit = (EntityHitResult) hit;
|
||||
if (!action.isContinuous)
|
||||
{
|
||||
player.attack(entityHit.getEntity());
|
||||
player.swingHand(Hand.MAIN_HAND);
|
||||
}
|
||||
player.resetLastAttackedTicks();
|
||||
player.updateLastActionTime();
|
||||
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.getSide();
|
||||
if (player.isBlockBreakingRestricted(player.getWorld(), pos, player.interactionManager.getGameMode())) return false;
|
||||
if (ap.currentBlock != null && player.getWorld().getBlockState(ap.currentBlock).isAir())
|
||||
{
|
||||
ap.currentBlock = null;
|
||||
return false;
|
||||
}
|
||||
BlockState state = player.getWorld().getBlockState(pos);
|
||||
boolean blockBroken = false;
|
||||
if (player.interactionManager.getGameMode().isCreative())
|
||||
{
|
||||
player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, side, player.getWorld().getTopY(), -1);
|
||||
ap.blockHitDelay = 5;
|
||||
blockBroken = true;
|
||||
}
|
||||
else if (ap.currentBlock == null || !ap.currentBlock.equals(pos))
|
||||
{
|
||||
if (ap.currentBlock != null)
|
||||
{
|
||||
player.interactionManager.processBlockBreakingAction(ap.currentBlock, PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK, side, player.getWorld().getTopY(), -1);
|
||||
}
|
||||
player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, side, player.getWorld().getTopY(), -1);
|
||||
boolean notAir = !state.isAir();
|
||||
if (notAir && ap.curBlockDamageMP == 0)
|
||||
{
|
||||
state.onBlockBreakStart(player.getWorld(), pos, player);
|
||||
}
|
||||
if (notAir && state.calcBlockBreakingDelta(player, player.getWorld(), pos) >= 1)
|
||||
{
|
||||
ap.currentBlock = null;
|
||||
//instamine??
|
||||
blockBroken = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ap.currentBlock = pos;
|
||||
ap.curBlockDamageMP = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ap.curBlockDamageMP += state.calcBlockBreakingDelta(player, player.getWorld(), pos);
|
||||
if (ap.curBlockDamageMP >= 1)
|
||||
{
|
||||
player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, side, player.getWorld().getTopY(), -1);
|
||||
ap.currentBlock = null;
|
||||
ap.blockHitDelay = 5;
|
||||
blockBroken = true;
|
||||
}
|
||||
player.getWorld().setBlockBreakingInfo(-1, pos, (int) (ap.curBlockDamageMP * 10));
|
||||
|
||||
}
|
||||
player.updateLastActionTime();
|
||||
player.swingHand(Hand.MAIN_HAND);
|
||||
return blockBroken;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
void inactiveTick(ServerPlayerEntity player, Action action)
|
||||
{
|
||||
EntityPlayerActionPack ap = ((ServerPlayerInterface) player).getActionPack();
|
||||
if (ap.currentBlock == null) return;
|
||||
player.getWorld().setBlockBreakingInfo(-1, ap.currentBlock, -1);
|
||||
player.interactionManager.processBlockBreakingAction(ap.currentBlock, PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK, Direction.DOWN, player.getWorld().getTopY(), -1);
|
||||
ap.currentBlock = null;
|
||||
}
|
||||
},
|
||||
JUMP(true)
|
||||
{
|
||||
@Override
|
||||
boolean execute(ServerPlayerEntity player, Action action)
|
||||
{
|
||||
if (action.limit == 1)
|
||||
{
|
||||
if (player.isOnGround()) player.jump(); // onGround
|
||||
}
|
||||
else
|
||||
{
|
||||
player.setJumping(true);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
void inactiveTick(ServerPlayerEntity player, Action action)
|
||||
{
|
||||
player.setJumping(false);
|
||||
}
|
||||
},
|
||||
DROP_ITEM(true)
|
||||
{
|
||||
@Override
|
||||
boolean execute(ServerPlayerEntity player, Action action)
|
||||
{
|
||||
player.updateLastActionTime();
|
||||
player.dropSelectedItem(false); // dropSelectedItem
|
||||
return false;
|
||||
}
|
||||
},
|
||||
DROP_STACK(true)
|
||||
{
|
||||
@Override
|
||||
boolean execute(ServerPlayerEntity player, Action action)
|
||||
{
|
||||
player.updateLastActionTime();
|
||||
player.dropSelectedItem(true); // dropSelectedItem
|
||||
return false;
|
||||
}
|
||||
},
|
||||
SWAP_HANDS(true)
|
||||
{
|
||||
@Override
|
||||
boolean execute(ServerPlayerEntity player, Action action)
|
||||
{
|
||||
player.updateLastActionTime();
|
||||
ItemStack itemStack_1 = player.getStackInHand(Hand.OFF_HAND);
|
||||
player.setStackInHand(Hand.OFF_HAND, player.getStackInHand(Hand.MAIN_HAND));
|
||||
player.setStackInHand(Hand.MAIN_HAND, itemStack_1);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
public final boolean preventSpectator;
|
||||
|
||||
ActionType(boolean preventSpectator)
|
||||
{
|
||||
this.preventSpectator = preventSpectator;
|
||||
}
|
||||
|
||||
void start(ServerPlayerEntity player, Action action) {}
|
||||
abstract boolean execute(ServerPlayerEntity player, Action action);
|
||||
void inactiveTick(ServerPlayerEntity player, Action action) {}
|
||||
void stop(ServerPlayerEntity 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package io.github.skippyall.minions.fakeplayer;
|
||||
|
||||
import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import net.minecraft.network.ClientConnection;
|
||||
import net.minecraft.network.NetworkSide;
|
||||
import net.minecraft.network.listener.PacketListener;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class FakeClientConnection extends ClientConnection {
|
||||
public FakeClientConnection(NetworkSide 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 tryDisableAutoRead()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleDisconnection() {
|
||||
getPacketListener().onDisconnected(getDisconnectReason()==null ? Text.literal("Disconnected"): getDisconnectReason());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInitialPacketListener(PacketListener packetListener)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPacketListener(PacketListener packetListener) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
package io.github.skippyall.minions.fakeplayer;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.yggdrasil.ProfileResult;
|
||||
import io.github.skippyall.minions.minion.MinionInventory;
|
||||
import io.github.skippyall.minions.minion.ModuleInventory;
|
||||
import net.fabricmc.fabric.api.entity.FakePlayer;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.entity.MovementType;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.entity.player.HungerManager;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.NetworkSide;
|
||||
import net.minecraft.network.packet.c2s.common.SyncedClientOptions;
|
||||
import net.minecraft.network.packet.c2s.play.ClientStatusC2SPacket;
|
||||
import net.minecraft.network.packet.s2c.play.EntityPositionS2CPacket;
|
||||
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.ServerTask;
|
||||
import net.minecraft.server.network.ConnectedClientData;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableTextContent;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.Uuids;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.GameMode;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MinionFakePlayer extends ServerPlayerEntity {
|
||||
public Runnable fixStartingPosition = () -> {};
|
||||
public boolean isAShadow;
|
||||
|
||||
private float moveForward;
|
||||
private float moveSideways;
|
||||
|
||||
private boolean programmable;
|
||||
private ModuleInventory moduleInventory = new ModuleInventory();
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused") //Don't know if I'll need this
|
||||
public static MinionFakePlayer createShadow(MinecraftServer server, ServerPlayerEntity player)
|
||||
{
|
||||
player.getServer().getPlayerManager().remove(player);
|
||||
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)
|
||||
{
|
||||
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);
|
||||
isAShadow = shadow;
|
||||
|
||||
}
|
||||
|
||||
public boolean isProgrammable() {
|
||||
return programmable;
|
||||
}
|
||||
|
||||
public ModuleInventory getModuleInventory() {
|
||||
return moduleInventory;
|
||||
}
|
||||
|
||||
public EntityPlayerActionPack getActionPack() {
|
||||
return ((ServerPlayerInterface)this).getActionPack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult interact(PlayerEntity player, Hand hand) {
|
||||
if(player instanceof ServerPlayerEntity spe) {
|
||||
MinionInventory.openInventory(spe, this);
|
||||
}
|
||||
return ActionResult.CONSUME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult interactAt(PlayerEntity player, Vec3d hitPos, Hand hand) {
|
||||
return interact(player, hand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEquipStack(final EquipmentSlot slot, final ItemStack previous, final ItemStack stack)
|
||||
{
|
||||
if (!isUsingItem()) super.onEquipStack(slot, previous, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void kill()
|
||||
{
|
||||
kill(Text.literal("Killed"));
|
||||
}
|
||||
|
||||
public void kill(Text reason)
|
||||
{
|
||||
shakeOff();
|
||||
|
||||
if (reason.getContent() instanceof TranslatableTextContent text && text.getKey().equals("multiplayer.disconnect.duplicate_login")) {
|
||||
this.networkHandler.onDisconnected(reason);
|
||||
} else {
|
||||
this.server.send(new ServerTask(this.server.getTicks(), () -> {
|
||||
this.networkHandler.onDisconnected(reason);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick()
|
||||
{
|
||||
if (this.getServer().getTicks() % 10 == 0)
|
||||
{
|
||||
this.networkHandler.syncWithPlayerPosition();
|
||||
this.getServerWorld().getChunkManager().updatePosition(this);
|
||||
}
|
||||
try
|
||||
{
|
||||
super.tick();
|
||||
this.playerTick();
|
||||
}
|
||||
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 PlayerEntity) stopRiding();
|
||||
for (Entity passenger : getPassengersDeep())
|
||||
{
|
||||
if (passenger instanceof PlayerEntity) passenger.stopRiding();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeath(DamageSource cause)
|
||||
{
|
||||
shakeOff();
|
||||
super.onDeath(cause);
|
||||
setHealth(20);
|
||||
this.hungerManager = new HungerManager();
|
||||
kill(this.getDamageTracker().getDeathMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIp()
|
||||
{
|
||||
return "127.0.0.1";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowsServerListing() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fall(double y, boolean onGround, BlockState state, BlockPos pos) {
|
||||
handleFall(0.0, y, 0.0, onGround);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity moveToWorld(ServerWorld serverLevel)
|
||||
{
|
||||
super.moveToWorld(serverLevel);
|
||||
if (notInAnyWorld) {
|
||||
ClientStatusC2SPacket p = new ClientStatusC2SPacket(ClientStatusC2SPacket.Mode.PERFORM_RESPAWN);
|
||||
networkHandler.onClientStatus(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 (networkHandler.player.isInTeleportationState()) {
|
||||
networkHandler.player.onTeleportationDone();
|
||||
}
|
||||
return networkHandler.player;
|
||||
}
|
||||
|
||||
public void moveForward(float forward) {
|
||||
this.moveForward += forward;
|
||||
EntityPlayerActionPack actionPack = getActionPack();
|
||||
if (moveForward != 0) {
|
||||
actionPack.setForward(moveForward > 0 ? 1 : -1);
|
||||
}
|
||||
}
|
||||
|
||||
public void moveSideways(float sideways) {
|
||||
this.moveSideways += sideways;
|
||||
EntityPlayerActionPack actionPack = getActionPack();
|
||||
if (moveSideways != 0) {
|
||||
actionPack.setStrafing(moveSideways > 0 ? 1 : -1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move(MovementType movementType, Vec3d movement) {
|
||||
float newForward = (float) (moveForward - movement.z);
|
||||
float newSideways = (float) (moveSideways - movement.x);
|
||||
Vec3d newMovement = movement;
|
||||
if ((newForward < 0 && moveForward >= 0) || (newForward > 0 && moveForward <= 0)) {
|
||||
newMovement = new Vec3d(newMovement.x, newMovement.y, moveForward);
|
||||
moveForward = 0;
|
||||
getActionPack().setForward(0);
|
||||
}else {
|
||||
moveForward = newForward;
|
||||
}
|
||||
if ((newSideways < 0 && moveSideways >= 0) || (newSideways > 0 && moveSideways <= 0)) {
|
||||
newMovement = new Vec3d(newMovement.x, newMovement.y, moveSideways);
|
||||
moveSideways = 0;
|
||||
getActionPack().setStrafing(0);
|
||||
}else {
|
||||
moveSideways = newSideways;
|
||||
}
|
||||
super.move(movementType, newMovement);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package io.github.skippyall.minions.fakeplayer;
|
||||
|
||||
import net.minecraft.network.ClientConnection;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.network.packet.s2c.play.PositionFlag;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ConnectedClientData;
|
||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableTextContent;
|
||||
import java.util.Set;
|
||||
|
||||
public class NetHandlerPlayServerFake extends ServerPlayNetworkHandler
|
||||
{
|
||||
public NetHandlerPlayServerFake(final MinecraftServer minecraftServer, final ClientConnection connection, final ServerPlayerEntity serverPlayer, final ConnectedClientData i)
|
||||
{
|
||||
super(minecraftServer, connection, serverPlayer, i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPacket(final Packet<?> packetIn)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect(Text message)
|
||||
{
|
||||
if (message.getContent() instanceof TranslatableTextContent text && (text.getKey().equals("multiplayer.disconnect.idling") || text.getKey().equals("multiplayer.disconnect.duplicate_login")))
|
||||
{
|
||||
((MinionFakePlayer) player).kill(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestTeleport(double d, double e, double f, float g, float h, Set<PositionFlag> set)
|
||||
{
|
||||
super.requestTeleport(d, e, f, g, h, set);
|
||||
if (player.getServerWorld().getPlayerByUuid(player.getUuid()) != null) {
|
||||
syncWithPlayerPosition();
|
||||
player.getServerWorld().getChunkManager().updatePosition(player);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package io.github.skippyall.minions.fakeplayer;
|
||||
|
||||
import io.github.skippyall.minions.fakeplayer.EntityPlayerActionPack;
|
||||
|
||||
public interface ServerPlayerInterface
|
||||
{
|
||||
EntityPlayerActionPack getActionPack();
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package io.github.skippyall.minions.fakeplayer;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Predicate;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.hit.EntityHitResult;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.RaycastContext;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
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.getPos().squaredDistanceTo(source.getCameraPosVec(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)
|
||||
{
|
||||
Vec3d pos = source.getCameraPosVec(partialTicks);
|
||||
Vec3d rotation = source.getRotationVec(partialTicks);
|
||||
Vec3d reachEnd = pos.add(rotation.x * reach, rotation.y * reach, rotation.z * reach);
|
||||
return source.getWorld().raycast(new RaycastContext(pos, reachEnd, RaycastContext.ShapeType.OUTLINE, fluids ?
|
||||
RaycastContext.FluidHandling.ANY : RaycastContext.FluidHandling.NONE, source));
|
||||
}
|
||||
|
||||
public static EntityHitResult rayTraceEntities(Entity source, float partialTicks, double reach, double maxSqDist)
|
||||
{
|
||||
Vec3d pos = source.getCameraPosVec(partialTicks);
|
||||
Vec3d reachVec = source.getRotationVec(partialTicks).multiply(reach);
|
||||
Box box = source.getBoundingBox().stretch(reachVec).expand(1);
|
||||
return rayTraceEntities(source, pos, pos.add(reachVec), box, e -> !e.isSpectator() && e.canHit(), maxSqDist);
|
||||
}
|
||||
|
||||
public static EntityHitResult rayTraceEntities(Entity source, Vec3d start, Vec3d end, Box box, Predicate<Entity> predicate, double maxSqDistance)
|
||||
{
|
||||
World world = source.getWorld();
|
||||
double targetDistance = maxSqDistance;
|
||||
Entity target = null;
|
||||
Vec3d targetHitPos = null;
|
||||
for (Entity current : world.getOtherEntities(source, box, predicate))
|
||||
{
|
||||
Box currentBox = current.getBoundingBox().expand(current.getTargetingMargin());
|
||||
Optional<Vec3d> currentHit = currentBox.raycast(start, end);
|
||||
if (currentBox.contains(start))
|
||||
{
|
||||
if (targetDistance >= 0)
|
||||
{
|
||||
target = current;
|
||||
targetHitPos = currentHit.orElse(start);
|
||||
targetDistance = 0;
|
||||
}
|
||||
}
|
||||
else if (currentHit.isPresent())
|
||||
{
|
||||
Vec3d currentHitPos = currentHit.get();
|
||||
double currentDistance = start.squaredDistanceTo(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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
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,62 @@
|
||||
package io.github.skippyall.minions.minion;
|
||||
|
||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.screen.GenericContainerScreenHandler;
|
||||
import net.minecraft.screen.ScreenHandlerType;
|
||||
import net.minecraft.screen.SimpleNamedScreenHandlerFactory;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class MinionInventory {
|
||||
public static void openInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||
openServerSideInventory(player, minion);
|
||||
}
|
||||
|
||||
public static void openServerSideInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_3X3, player, false);
|
||||
gui.setTitle(Text.literal("Minion"));
|
||||
gui.setSlot(4, new GuiElementBuilder()
|
||||
.setItem(Items.REDSTONE)
|
||||
.setName(Text.literal("Programming"))
|
||||
.setCallback((i, clickType, clickType1) -> {
|
||||
openProgrammingInventory(player, minion);
|
||||
})
|
||||
);
|
||||
gui.setSlot(3, new GuiElementBuilder()
|
||||
.setItem(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE)
|
||||
.setName(Text.literal("Modules and Detectors"))
|
||||
.setCallback((i, clickType, clickType1) -> {
|
||||
openModuleInventory(player, minion);
|
||||
})
|
||||
);
|
||||
gui.setSlot(5, new GuiElementBuilder()
|
||||
.setItem(Items.CHEST)
|
||||
.setName(Text.literal("Inventory"))
|
||||
.setCallback((i, clickType, clickType1) -> {
|
||||
openMinionInventory(player, minion);
|
||||
})
|
||||
);
|
||||
gui.open();
|
||||
}
|
||||
|
||||
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) {
|
||||
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X5, player, false);
|
||||
gui.setTitle(Text.literal("Minion"));
|
||||
for (int i = 0; i < minion.getInventory().size(); i++) {
|
||||
gui.setSlotRedirect(i, new Slot(minion.getInventory(), i, 0, 0));
|
||||
}
|
||||
gui.open();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package io.github.skippyall.minions.minion;
|
||||
|
||||
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.client.item.TooltipContext;
|
||||
import net.minecraft.enchantment.Enchantments;
|
||||
import net.minecraft.item.*;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.PlainTextContent;
|
||||
import net.minecraft.text.TextContent;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class MinionItem extends Item implements PolymerItem {
|
||||
private boolean canProgram;
|
||||
public MinionItem(boolean canProgram) {
|
||||
super(new FabricItemSettings());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getPolymerItem(ItemStack itemStack, @Nullable ServerPlayerEntity player) {
|
||||
return Items.ARMOR_STAND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPolymerItemStack(ItemStack stack, TooltipContext flag, ServerPlayerEntity player) {
|
||||
ItemStack out = PolymerItemUtils.createItemStack(stack, flag, player);
|
||||
out.addEnchantment(Enchantments.MENDING, 1);
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
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) {
|
||||
MinionFakePlayer.createMinion(name, (ServerWorld) context.getWorld(), (ServerPlayerEntity) context.getPlayer(), canProgram, context.getBlockPos().toCenterPos().add(0,0.5,0), 0, 0);
|
||||
}
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package io.github.skippyall.minions.mixins;
|
||||
|
||||
import io.github.skippyall.minions.fakeplayer.ClientConnectionInterface;
|
||||
import io.netty.channel.Channel;
|
||||
import net.minecraft.network.ClientConnection;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(ClientConnection.class)
|
||||
public abstract class ConnectionMixin implements ClientConnectionInterface {
|
||||
@Override
|
||||
@Accessor //Compat with adventure-platform-fabric
|
||||
public abstract void setChannel(Channel channel);
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
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.NbtCompound;
|
||||
import net.minecraft.network.ClientConnection;
|
||||
import net.minecraft.network.packet.c2s.common.SyncedClientOptions;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.PlayerManager;
|
||||
import net.minecraft.server.network.ConnectedClientData;
|
||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
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(PlayerManager.class)
|
||||
public class PlayerListMixin {
|
||||
|
||||
@Inject(method = "loadPlayerData", at = @At(value = "RETURN", shift = At.Shift.BEFORE))
|
||||
private void fixStartingPos(ServerPlayerEntity serverPlayerEntity_1, CallbackInfoReturnable<NbtCompound> cir)
|
||||
{
|
||||
if (serverPlayerEntity_1 instanceof MinionFakePlayer)
|
||||
{
|
||||
((MinionFakePlayer) serverPlayerEntity_1).fixStartingPosition.run();
|
||||
}
|
||||
}
|
||||
|
||||
@WrapOperation(method = "onPlayerConnect", at = @At(value = "NEW", target = "(Lnet/minecraft/server/MinecraftServer;Lnet/minecraft/network/ClientConnection;Lnet/minecraft/server/network/ServerPlayerEntity;Lnet/minecraft/server/network/ConnectedClientData;)Lnet/minecraft/server/network/ServerPlayNetworkHandler;"))
|
||||
private ServerPlayNetworkHandler replaceNetworkHandler(MinecraftServer server, ClientConnection connection, ServerPlayerEntity serverPlayer, ConnectedClientData commonListenerCookie, Operation<ServerPlayNetworkHandler> original)
|
||||
{
|
||||
if (serverPlayer instanceof MinionFakePlayer fake) {
|
||||
return new NetHandlerPlayServerFake(server, connection, fake, commonListenerCookie);
|
||||
} else {
|
||||
return original.call(server, connection, serverPlayer, commonListenerCookie);
|
||||
}
|
||||
}
|
||||
|
||||
@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) {
|
||||
if (serverPlayer instanceof MinionFakePlayer minion) {
|
||||
return MinionFakePlayer.respawnFake(minecraftServer, serverLevel, gameProfile, clientInformation, minion.isProgrammable());
|
||||
}
|
||||
return original.call(minecraftServer, serverLevel, gameProfile, clientInformation);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
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.network.packet.c2s.common.SyncedClientOptions;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
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(ServerPlayerEntity.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 onServerPlayerEntityConstructor(MinecraftServer minecraftServer, ServerWorld serverLevel, GameProfile gameProfile, SyncedClientOptions clientInformation, CallbackInfo ci)
|
||||
{
|
||||
this.actionPack = new EntityPlayerActionPack((ServerPlayerEntity) (Object) this);
|
||||
}
|
||||
|
||||
@Inject(method = "tick", at = @At(value = "HEAD"))
|
||||
private void onTick(CallbackInfo ci)
|
||||
{
|
||||
actionPack.onUpdate();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
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("|");
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package io.github.skippyall.minions.program;
|
||||
|
||||
import io.github.skippyall.minions.program.statement.StatementList;
|
||||
import io.github.skippyall.minions.program.variables.Variable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MinionRuntime implements Runnable{
|
||||
private boolean run = true;
|
||||
public final Map<String, Variable> variables = new HashMap<>();
|
||||
private final List<StatementList.Run> runs = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while(run) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
run = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package io.github.skippyall.minions.program.block;
|
||||
|
||||
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.program.statement.Arg;
|
||||
import io.github.skippyall.minions.program.variables.Type;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class CodeBlock {
|
||||
private String name;
|
||||
private final List<Type> arguments;
|
||||
private final Type returnType;
|
||||
public CodeBlock(String name, List<Type> arguments, Type returnType) {
|
||||
this.arguments = arguments;
|
||||
this.returnType = returnType;
|
||||
}
|
||||
|
||||
public abstract Object execute(MinionFakePlayer minion, Object... args);
|
||||
|
||||
public boolean fits(Arg arg, int slot) {
|
||||
return arguments.get(slot) == arg.getType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package io.github.skippyall.minions.program.block;
|
||||
|
||||
public class CodeBlocks {
|
||||
public static final GoBlock GO = new GoBlock();
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package io.github.skippyall.minions.program.block;
|
||||
|
||||
import io.github.skippyall.minions.program.variables.Type;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class CodeContainingCodeBlock extends CodeBlock{
|
||||
public CodeContainingCodeBlock(String name, List<Type> arguments, Type returnType) {
|
||||
super(name, arguments, returnType);
|
||||
}
|
||||
|
||||
protected void executeBlocks() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package io.github.skippyall.minions.program.block;
|
||||
|
||||
import io.github.skippyall.minions.fakeplayer.EntityPlayerActionPack;
|
||||
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.fakeplayer.ServerPlayerInterface;
|
||||
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 GoBlock extends CodeBlock{
|
||||
public GoBlock() {
|
||||
super("move", List.of(Types.FLOAT, Types.FLOAT), Types.VOID);
|
||||
}
|
||||
|
||||
public Object execute(MinionFakePlayer minion, Object... args) {
|
||||
EntityPlayerActionPack action = ((ServerPlayerInterface)minion).getActionPack();
|
||||
minion.moveForward((Float) args[0]);
|
||||
minion.moveSideways((Float) args[1]);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package io.github.skippyall.minions.program.block;
|
||||
|
||||
import io.github.skippyall.minions.fakeplayer.EntityPlayerActionPack;
|
||||
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.fakeplayer.ServerPlayerInterface;
|
||||
import io.github.skippyall.minions.program.variables.Type;
|
||||
import io.github.skippyall.minions.program.variables.Types;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class UseBlock extends CodeBlock{
|
||||
public UseBlock(String name, List<Type> arguments, Type returnType) {
|
||||
super("use", List.of(), Types.VOID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object execute(MinionFakePlayer minion, Object... args) {
|
||||
minion.getActionPack().start(EntityPlayerActionPack.ActionType.USE, EntityPlayerActionPack.Action.once());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package io.github.skippyall.minions.program.module;
|
||||
|
||||
import eu.pb4.polymer.core.api.item.PolymerItem;
|
||||
import io.github.skippyall.minions.program.block.CodeBlock;
|
||||
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Module extends Item implements PolymerItem {
|
||||
private final String name;
|
||||
public Module(String name) {
|
||||
super(new FabricItemSettings().maxCount(1));
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getModuleName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public abstract List<CodeBlock> getCodeBlocks();
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package io.github.skippyall.minions.program.module;
|
||||
|
||||
public class Modules {
|
||||
MoveModule MOVE = new MoveModule();
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package io.github.skippyall.minions.program.module;
|
||||
|
||||
import io.github.skippyall.minions.program.block.CodeBlock;
|
||||
import io.github.skippyall.minions.program.block.CodeBlocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MoveModule extends Module {
|
||||
MoveModule() {
|
||||
super("Movement");
|
||||
}
|
||||
|
||||
public List<CodeBlock> getCodeBlocks() {
|
||||
List<CodeBlock> codeBlocks = new ArrayList<>();
|
||||
codeBlocks.add(CodeBlocks.GO);
|
||||
return codeBlocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getPolymerItem(ItemStack itemStack, @Nullable ServerPlayerEntity player) {
|
||||
return Items.PURPLE_GLAZED_TERRACOTTA;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package io.github.skippyall.minions.program.statement;
|
||||
|
||||
import io.github.skippyall.minions.program.variables.Type;
|
||||
|
||||
public interface Arg {
|
||||
Object getValue();
|
||||
Type getType();
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package io.github.skippyall.minions.program.statement;
|
||||
|
||||
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.program.block.CodeBlock;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Statement {
|
||||
private CodeBlock codeBlock;
|
||||
private List<Arg> args;
|
||||
|
||||
public void execute(MinionFakePlayer minion) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package io.github.skippyall.minions.program.statement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class StatementList {
|
||||
private final List<Statement> statements;
|
||||
private boolean finish;
|
||||
|
||||
StatementList() {
|
||||
this(new ArrayList<>());
|
||||
}
|
||||
|
||||
StatementList(List<Statement> statements) {
|
||||
this.statements = statements;
|
||||
}
|
||||
|
||||
public void runNext(Run run) {
|
||||
|
||||
}
|
||||
|
||||
public boolean canRunNext(Run run) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isFinish(Run run) {
|
||||
return finish;
|
||||
}
|
||||
|
||||
public Run createRunInstance() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public class Run {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package io.github.skippyall.minions.program.variables;
|
||||
|
||||
public class FloatType extends Type{
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package io.github.skippyall.minions.program.variables;
|
||||
|
||||
public class IntegerType extends Type{
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package io.github.skippyall.minions.program.variables;
|
||||
|
||||
public abstract class Type {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package io.github.skippyall.minions.program.variables;
|
||||
|
||||
public class Types {
|
||||
public static final IntegerType INTEGER = new IntegerType();
|
||||
public static final FloatType FLOAT = new FloatType();
|
||||
public static final Type VOID = new Type() {};
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package io.github.skippyall.minions.program.variables;
|
||||
|
||||
import io.github.skippyall.minions.program.statement.Arg;
|
||||
|
||||
public class Variable implements Arg {
|
||||
private final Type type;
|
||||
private final String name;
|
||||
private Object value;
|
||||
|
||||
public Variable(Type type, String name) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
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.ServerConfigurationNetworkHandler;
|
||||
|
||||
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(ServerConfigurationNetworkHandler handler, MinecraftServer server) {
|
||||
VersionChecker.resetPlayer(handler.getDebugProfile().getId());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user