use of com.mraof.minestuck.network.MinestuckPacket in project Minestuck by mraof.
the class ClientEditHandler method onKeyPressed.
public static void onKeyPressed() {
MinestuckPacket packet = MinestuckPacket.makePacket(Type.CLIENT_EDIT);
MinestuckChannelHandler.sendToServer(packet);
}
use of com.mraof.minestuck.network.MinestuckPacket in project Minestuck by mraof.
the class ServerEditHandler method onBlockPlaced.
@SubscribeEvent(priority = EventPriority.LOW)
public void onBlockPlaced(BlockEvent.PlaceEvent event) {
if (getData(event.getPlayer()) != null) {
EditData data = getData(event.getPlayer());
if (// If the event was cancelled server side and not client side, notify the client.
event.isCanceled()) {
MinestuckPacket packet = MinestuckPacket.makePacket(Type.SERVER_EDIT, data.connection.givenItems());
MinestuckChannelHandler.sendToPlayer(packet, event.getPlayer());
return;
}
ItemStack stack = event.getItemInHand();
if (DeployList.containsItemStack(stack)) {
SburbConnection c = data.connection;
GristSet cost = c.givenItems()[DeployList.getOrdinal(stack)] ? DeployList.getSecondaryCost(stack) : DeployList.getPrimaryCost(stack);
c.givenItems()[DeployList.getOrdinal(stack)] = true;
if (!c.isMain())
SkaianetHandler.giveItems(c.getClientIdentifier());
if (!cost.isEmpty()) {
GristHelper.decrease(c.getClientIdentifier(), cost);
MinestuckPlayerTracker.updateGristCache(data.connection.getClientIdentifier());
}
event.getPlayer().inventory.mainInventory.set(event.getPlayer().inventory.currentItem, ItemStack.EMPTY);
} else {
GristHelper.decrease(data.connection.getClientIdentifier(), GristRegistry.getGristConversion(stack));
MinestuckPlayerTracker.updateGristCache(data.connection.getClientIdentifier());
}
}
}
use of com.mraof.minestuck.network.MinestuckPacket in project Minestuck by mraof.
the class ServerEditHandler method newServerEditor.
public static void newServerEditor(EntityPlayerMP player, PlayerIdentifier computerOwner, PlayerIdentifier computerTarget) {
if (player.isRiding())
// Don't want to bother making the decoy able to ride anything right now.
return;
SburbConnection c = SkaianetHandler.getClientConnection(computerTarget);
if (c != null && c.getServerIdentifier().equals(computerOwner) && getData(c) == null && getData(player) == null) {
Debug.info("Activating edit mode on player \"" + player.getName() + "\", target player: \"" + computerTarget + "\".");
EntityDecoy decoy = new EntityDecoy((WorldServer) player.world, player);
EditData data = new EditData(decoy, player, c);
if (!c.enteredGame()) {
c.centerX = c.getClientData().getX();
c.centerZ = c.getClientData().getZ();
}
if (!setPlayerStats(player, c)) {
player.sendMessage(new TextComponentString(TextFormatting.RED + "Failed to activate edit mode."));
return;
}
if (c.inventory != null)
player.inventory.readFromNBT(c.inventory);
decoy.world.spawnEntity(decoy);
list.add(data);
MinestuckPacket packet = MinestuckPacket.makePacket(Type.SERVER_EDIT, computerTarget, c.centerX, c.centerZ, c.givenItems());
MinestuckChannelHandler.sendToPlayer(packet, player);
MinestuckPlayerTracker.updateGristCache(c.getClientIdentifier());
}
}
use of com.mraof.minestuck.network.MinestuckPacket in project Minestuck by mraof.
the class CaptchaDeckHandler method captchalougeItem.
public static void captchalougeItem(EntityPlayerMP player) {
ItemStack stack = player.getHeldItemMainhand();
Modus modus = getModus(player);
if (modus != null && !stack.isEmpty()) {
boolean card1 = false, card2 = true;
if (stack.getItem() == MinestuckItems.captchaCard && stack.hasTagCompound() && !stack.getTagCompound().getBoolean("punched")) {
ItemStack newStack = AlchemyRecipeHandler.getDecodedItem(stack);
if (!newStack.isEmpty()) {
card1 = true;
stack = newStack;
card2 = modus.increaseSize();
}
}
if (modus.putItemStack(stack)) {
if (!card2)
launchAnyItem(player, new ItemStack(MinestuckItems.captchaCard, 1));
stack = player.getHeldItemMainhand();
if (card1 && stack.getCount() > 1)
stack.shrink(1);
else
player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
} else if (card1 && card2) {
launchAnyItem(player, stack);
stack = player.getHeldItemMainhand();
if (stack.getCount() == 1)
player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
else
stack.shrink(1);
}
MinestuckPacket packet = MinestuckPacket.makePacket(MinestuckPacket.Type.CAPTCHA, CaptchaDeckPacket.DATA, writeToNBT(modus));
MinestuckChannelHandler.sendToPlayer(packet, player);
}
}
use of com.mraof.minestuck.network.MinestuckPacket in project Minestuck by mraof.
the class CaptchaDeckHandler method useItem.
public static void useItem(EntityPlayerMP player) {
if (!(player.openContainer instanceof ContainerCaptchaDeck))
return;
ContainerCaptchaDeck container = (ContainerCaptchaDeck) player.openContainer;
if (container.inventory.getStackInSlot(0).isEmpty())
return;
ItemStack item = container.inventory.getStackInSlot(0);
Modus modus = getModus(player);
ResourceLocation type = getType(item);
if (type != null) {
if (modus == null) {
MinestuckPlayerData.PlayerData data = MinestuckPlayerData.getData(player);
modus = createInstance(type, Side.SERVER);
modus.player = player;
modus.initModus(null, data.givenModus ? 0 : MinestuckConfig.initialModusSize);
data.givenModus = true;
setModus(player, modus);
container.inventory.setInventorySlotContents(0, ItemStack.EMPTY);
} else {
Modus oldModus = modus;
ResourceLocation oldType = getType(oldModus.getClass());
if (type.equals(oldType))
return;
modus = createInstance(type, Side.SERVER);
modus.player = player;
if (modus.canSwitchFrom(oldModus))
modus.initModus(oldModus.getItems(), oldModus.getSize());
else {
for (ItemStack content : oldModus.getItems()) if (!content.isEmpty())
launchAnyItem(player, content);
modus.initModus(null, oldModus.getSize());
}
setModus(player, modus);
container.inventory.setInventorySlotContents(0, getItem(oldType));
}
} else if (item.getItem().equals(MinestuckItems.captchaCard) && (!item.hasTagCompound() || !item.getTagCompound().getBoolean("punched")) && modus != null) {
ItemStack content = AlchemyRecipeHandler.getDecodedItem(item);
int failed = 0;
for (int i = 0; i < item.getCount(); i++) if (!modus.increaseSize())
failed++;
if (content != null)
for (int i = 0; i < item.getCount() - failed; i++) {
ItemStack toPut = content.copy();
if (!modus.putItemStack(toPut))
launchItem(player, toPut);
}
if (failed == 0)
container.inventory.setInventorySlotContents(0, ItemStack.EMPTY);
else
item.setCount(failed);
}
if (modus != null) {
MinestuckPacket packet = MinestuckPacket.makePacket(MinestuckPacket.Type.CAPTCHA, CaptchaDeckPacket.DATA, writeToNBT(modus));
MinestuckChannelHandler.sendToPlayer(packet, player);
}
}
Aggregations