use of net.minecraft.util.text.TextComponentTranslation in project minecolonies by Minecolonies.
the class EntityAIWorkLumberjack method checkIfStuckOnLeaves.
/**
* Check if distance to block changed and
* if we are not moving for too long, try to get unstuck.
*
* @param location the block we want to go to.
*/
private void checkIfStuckOnLeaves(@NotNull final BlockPos location) {
final int distance = (int) location.distanceSq(worker.getPosition());
if (previousDistance != distance) {
// something is moving, reset counters
stillTicks = 0;
previousDistance = distance;
return;
}
// Stuck, probably on leaves
stillTicks++;
if (stillTicks < STUCK_WAIT_TIME) {
// Wait for some time before jumping to conclusions
return;
}
// now we seem to be stuck!
worker.setLatestStatus(new TextComponentTranslation("com.minecolonies.coremod.status.stuckinleaves"));
tryGettingUnstuckFromLeaves();
}
use of net.minecraft.util.text.TextComponentTranslation in project minecolonies by Minecolonies.
the class EntityAIWorkSmelter method smeltStuff.
/**
* He will smelt down armor, weapons and tools to smaller pieces here.
* @return the next state to go to.
*/
private AIState smeltStuff() {
worker.setLatestStatus(new TextComponentTranslation(SMELTING_DOWN));
if (walkToBuilding()) {
return getState();
}
if (ItemStackUtils.isEmpty(worker.getHeldItem(EnumHand.MAIN_HAND))) {
progress = 0;
if (InventoryUtils.getItemCountInItemHandler(new InvWrapper(worker.getInventoryCitizen()), EntityAIWorkSmelter::isSmeltableToolOrWeapon) <= 0) {
if (InventoryUtils.hasItemInProvider(getOwnBuilding(), EntityAIWorkSmelter::isSmeltableToolOrWeapon)) {
return START_WORKING;
}
InventoryUtils.transferItemStackIntoNextFreeSlotFromProvider(getOwnBuilding(), InventoryUtils.findFirstSlotInProviderWith(getOwnBuilding(), EntityAIWorkSmelter::isSmeltableToolOrWeapon), new InvWrapper(worker.getInventoryCitizen()));
}
final int slot = InventoryUtils.findFirstSlotInItemHandlerWith(new InvWrapper(worker.getInventoryCitizen()), EntityAIWorkSmelter::isSmeltableToolOrWeapon);
if (slot == -1) {
return START_WORKING;
}
worker.setHeldItem(slot);
}
worker.hitBlockWithToolInHand(getOwnBuilding().getLocation());
if (progress >= getRequiredProgressForMakingRawMaterial()) {
progress = 0;
final int slot = InventoryUtils.findFirstSlotInItemHandlerWith(new InvWrapper(worker.getInventoryCitizen()), EntityAIWorkSmelter::isSmeltableToolOrWeapon);
if (slot == -1) {
worker.setHeldItem(EnumHand.MAIN_HAND, ItemStackUtils.EMPTY);
return START_WORKING;
}
final ItemStack stack = new InvWrapper(worker.getInventoryCitizen()).extractItem(slot, 1, false);
final Tuple<ItemStack, Integer> materialTuple = getMaterialAndAmount(stack);
final ItemStack material = materialTuple.getFirst();
if (!ItemStackUtils.isEmpty(material)) {
material.setCount(materialTuple.getSecond());
material.setItemDamage(0);
new InvWrapper(worker.getInventoryCitizen()).setStackInSlot(slot, material);
incrementActionsDoneAndDecSaturation();
} else {
new InvWrapper(worker.getInventoryCitizen()).setStackInSlot(slot, stack);
}
worker.addExperience(BASE_XP_GAIN);
worker.setHeldItem(EnumHand.MAIN_HAND, ItemStackUtils.EMPTY);
return START_WORKING;
}
progress++;
setDelay(HIT_DELAY);
return getState();
}
use of net.minecraft.util.text.TextComponentTranslation in project minecolonies by Minecolonies.
the class EntityAIWorkSmelter method checkForAdditionalJobs.
/**
* If no clear tasks are given, check if something else is to do.
* @return the next AIState to traverse to.
*/
@Override
protected AIState checkForAdditionalJobs() {
final int amountOfTools = InventoryUtils.getItemCountInProvider(getOwnBuilding(), EntityAIWorkSmelter::isSmeltableToolOrWeapon) + InventoryUtils.getItemCountInItemHandler(new InvWrapper(worker.getInventoryCitizen()), EntityAIWorkSmelter::isSmeltableToolOrWeapon);
if (amountOfTools > 0) {
return SMELTER_SMELTING_ITEMS;
}
worker.setLatestStatus(new TextComponentTranslation(COM_MINECOLONIES_COREMOD_STATUS_IDLING));
setDelay(WAIT_AFTER_REQUEST);
walkToBuilding();
return START_WORKING;
}
use of net.minecraft.util.text.TextComponentTranslation in project Minestuck by mraof.
the class ServerEditHandler method onRightClickBlockControl.
@SubscribeEvent(priority = EventPriority.NORMAL)
public void onRightClickBlockControl(PlayerInteractEvent.RightClickBlock event) {
if (!event.getWorld().isRemote && getData(event.getEntityPlayer()) != null) {
EditData data = getData(event.getEntityPlayer());
Block block = event.getWorld().getBlockState(event.getPos()).getBlock();
ItemStack stack = event.getEntityPlayer().getHeldItemMainhand();
event.setUseBlock(stack.isEmpty() && (block instanceof BlockDoor || block instanceof BlockTrapDoor || block instanceof BlockFenceGate) ? Result.ALLOW : Result.DENY);
if (event.getUseBlock() == Result.ALLOW)
return;
if (stack.isEmpty() || !isBlockItem(stack.getItem()) || event.getHand().equals(EnumHand.OFF_HAND)) {
event.setCanceled(true);
return;
}
cleanStackNBT(stack);
if (DeployList.containsItemStack(stack)) {
GristSet cost = data.connection.givenItems()[DeployList.getOrdinal(stack)] ? DeployList.getSecondaryCost(stack) : DeployList.getPrimaryCost(stack);
if (!GristHelper.canAfford(MinestuckPlayerData.getGristSet(data.connection.getClientIdentifier()), cost)) {
StringBuilder str = new StringBuilder();
if (cost != null) {
for (GristAmount grist : cost.getArray()) {
if (cost.getArray().indexOf(grist) != 0)
str.append(", ");
str.append(grist.getAmount() + " " + grist.getType().getDisplayName());
}
event.getEntityPlayer().sendMessage(new TextComponentTranslation("grist.missing", str.toString()));
}
event.setCanceled(true);
}
} else if (!isBlockItem(stack.getItem()) || !GristHelper.canAfford(data.connection.getClientIdentifier(), stack, false)) {
event.setCanceled(true);
}
if (event.getUseItem() == Result.DEFAULT)
event.setUseItem(Result.ALLOW);
}
}
use of net.minecraft.util.text.TextComponentTranslation in project Minestuck by mraof.
the class CommandGrist method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (args.length < 1 || (!args[0].equalsIgnoreCase("get") && args.length < 2))
throw new WrongUsageException(this.getUsage(sender));
String command = args[0];
PlayerIdentifier identifier;
int offset = 1;
if (!(command.equalsIgnoreCase("set") || command.equalsIgnoreCase("add") || command.equalsIgnoreCase("get"))) {
command = args[1];
identifier = IdentifierHandler.getForCommand(server, sender, args[0]);
offset = 2;
} else {
EntityPlayerMP player = getCommandSenderAsPlayer(sender);
identifier = IdentifierHandler.encode(player);
}
if ((args.length - offset) % 2 != 0)
throw new WrongUsageException(this.getUsage(sender));
String displayName = identifier.getUsername();
if (command.equalsIgnoreCase("set")) {
// Using a GristAmount array instead of a GristSet gives support for setting grist to 0
GristAmount[] grist = parseGrist(args, offset);
for (GristAmount amount : grist) GristHelper.setGrist(identifier, amount.getType(), amount.getAmount());
MinestuckPlayerTracker.updateGristCache(identifier);
notifyCommandListener(sender, this, "commands.grist.setSuccess", displayName);
} else if (command.equalsIgnoreCase("add")) {
GristSet grist = new GristSet(parseGrist(args, offset));
GristHelper.increase(identifier, grist);
MinestuckPlayerTracker.updateGristCache(identifier);
notifyCommandListener(sender, this, "commands.grist.addSuccess", displayName);
} else if (command.equalsIgnoreCase("get")) {
StringBuilder grist = new StringBuilder();
for (GristAmount amount : MinestuckPlayerData.getGristSet(identifier).getArray()) if (amount.getAmount() != 0)
// TODO properly translate display name for client side
grist.append("\n").append(amount.getAmount()).append(" ").append(amount.getType().getDisplayName());
sender.sendMessage(new TextComponentTranslation("commands.grist.get", displayName, grist.toString()));
} else
throw new WrongUsageException("commands.invalidSubCommand", command);
}
Aggregations